Flashで使える3Dゲームエンジン「yogurt3d」
「yogurt3d」は3Dゲームの開発に使えるActionscript3.0ライブラリです。
Maya、 XSI Softimage、 3D Studio Maxなどの3D作成ソフトと連携が取れるようです。
詳しくは以下
デモ
サイト内にはタワーディフェンスや、キャラクターをキーボードで操作できるデモがあります。
以下はタワーディフェンスの様子。普通に遊べます。
単純な3Dの描画は以下のようなコードで実装できるようです。
package { import com.yogurt3d.Yogurt3D; import com.yogurt3d.core.materials.MaterialBitmap; import com.yogurt3d.core.sceneobjects.SceneObjectRenderable; import com.yogurt3d.presets.primitives.sceneobjects.BoxSceneObject; import com.yogurt3d.presets.renderers.trianglesort.RendererTriangleSort; import flash.display.GraphicsSolidFill; import flash.display.Sprite; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.geom.Vector3D; import mx.core.BitmapAsset; import utils.*; [SWF(width='800',height='600',frameRate='60',backgroundColor='0x000000')] public class Tutorial1 extends Sprite { [Embed(source="../resources/yogurt.png")] private var m_embeddedTexture:Class; private var m_texture:BitmapAsset = new m_embeddedTexture() as BitmapAsset; public var ko:KeyObject; private var m_mouseDown:Boolean = false; private var mousePosX:Number=0,mousePosY:Number=0,mousePosX_prev:Number=0,mousePosY_prev:Number=0; private var renderableObject:SceneObjectRenderable; private var angleX:Number = 0; private var angleY:Number = 0; private var rot_speed:Number = 0.5; public function Tutorial1() { KeyObject.stage = this.stage; ko = new KeyObject(this); Yogurt3D.defaultSetup(); Yogurt3D.fps = stage.frameRate; stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseUpDownEventListener); stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveEventListener); stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpDownEventListener); stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelEventListener); Yogurt3D.defaultContext.renderer = new RendererTriangleSort(); Yogurt3D.defaultCamera.setProjectionPerspective(50.0, 800.0/600.0, 1, 400 ); Yogurt3D.defaultViewport.setViewport( 0.0, 0.0, 800.0, 600.0 ); Yogurt3D.defaultCamera.transformation.positionWrtParent = new Vector3D(0, 0, 20); addChild(Yogurt3D.defaultViewport); Yogurt3D.enginePreUpdateCallback = run; renderableObject = new BoxSceneObject(5,5,8,2,3,4); renderableObject.material = new MaterialBitmap(m_texture.bitmapData); renderableObject.material.graphicsStroke.thickness = 1; renderableObject.material.graphicsStroke.fill = new GraphicsSolidFill(0xFFFFFF); Yogurt3D.defaultScene.addChild(renderableObject); Yogurt3D.startAutoUpdate(); } public function run():void { if(ko.keysDown[87])//W { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.zAxisWrtParent, -1); } if(ko.keysDown[65])//A { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.xAxisWrtParent, -1); } if(ko.keysDown[83])//S { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.zAxisWrtParent, 1); } if(ko.keysDown[68])//D { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.xAxisWrtParent, 1); } if(ko.keysDown[32])//SPACE { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.yAxisWrtParent, 1); } if(ko.keysDown[16])//SHIFT { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.yAxisWrtParent, -1); } } private function mouseUpDownEventListener(_e:MouseEvent):void { m_mouseDown = _e.buttonDown; } private function mouseMoveEventListener(_e:MouseEvent):void { mousePosX_prev = mousePosX; mousePosY_prev = mousePosY; mousePosX = Yogurt3D.defaultViewport.mouseX; mousePosY = Yogurt3D.defaultViewport.mouseY; if (m_mouseDown) { angleX += rot_speed*(mousePosY_prev-mousePosY); angleY += rot_speed*(mousePosX_prev-mousePosX); if(angleX > 90) angleX = 90; if(angleX < -90) angleX = -90; Yogurt3D.defaultCamera.transformation.resetRotation(); Yogurt3D.defaultCamera.transformation.rotateYWrtWorld(angleY); Yogurt3D.defaultCamera.transformation.rotateXWrtObject(angleX); } } private function mouseWheelEventListener(_e:MouseEvent):void { Yogurt3D.defaultCamera.transformation.translateInDirectionWrtParent(Yogurt3D.defaultCamera.transformation.zAxisWrtParent, -_e.delta/5); } public function keyPressed(evt:KeyboardEvent):void { ko.keysDown[evt.keyCode] = true; } public function keyReleased(evt:KeyboardEvent):void { delete ko.keysDown[evt.keyCode]; } } }
3Dゲームにチャレンジしてみたい方はいかがでしょうか。
最新情報をお届けします
- Website: http://www.yogurt3d.com/
- Download: http://www.yogurt3d.com/?page_id=7