package { import alternativa.engine3d.core.Object3D; import alternativa.engine3d.lights.AmbientLight; import alternativa.engine3d.lights.OmniLight; import alternativa.engine3d.lights.SpotLight; import alternativa.engine3d.materials.VertexLightTextureMaterial; import alternativa.engine3d.primitives.Box; import alternativa.engine3d.resources.BitmapTextureResource; import flash.display.BitmapData; import flash.utils.getTimer; import org.libspark.alternativa3d.camera.CameraType; import org.libspark.alternativa3d.controllers.OrbitCameraController; import org.libspark.alternativa3d.view.AlternativaTemplate; [SWF(frameRate = "60")] public class MolehillCreature extends AlternativaTemplate { private static const CHILDREN_NUM:uint = 35; private static const ROT_NUM:uint = 20; private var higes:Array = []; private var spotLight:OmniLight; public function MolehillCreature() { super({ backgroundColor: 0xFFFFFF, cameraType:CameraType.ORBIT, useDiagram: true }); } override protected function atInit():void { // スポットライト(一部分を照らす照明) spotLight = new OmniLight(0xFFFFFF, 500, 10000); scene.addChild(spotLight); // アンビエントライト(全体を照らす照明) var light:AmbientLight = new AmbientLight(0x888888); scene.addChild(light); // create 3d objects for (var i:int = 0; i < ROT_NUM; i++) { var hige:Object3D = new Object3D(); scene.addChild(hige); hige.rotationY = i * 360 / ROT_NUM; var distance:Number = 200; for (var j:int = 0; j < CHILDREN_NUM; j++) { // テクスチャ作成 var color:uint = 0xFF0000 + 0x000800 * j; var bmd:BitmapData = new BitmapData(2, 2, true, 0xFF000000 + color); var texture:BitmapTextureResource = new BitmapTextureResource(bmd); var m:VertexLightTextureMaterial = new VertexLightTextureMaterial(texture); var s:Box = new Box(50, 50, 50); s.setMaterialToAllSurfaces(m); s.scaleX = s.scaleY = s.scaleZ = 1 - 1 / CHILDREN_NUM * j; distance += 70 * s.scaleX; s.z = distance; hige.addChild(s); if (higes[ j ] == null) higes[ j ] = []; higes[ j ][ i ] = s } } // カメラの移動処理を変更 (cameraController as OrbitCameraController).minDistance = 1000; } override protected function atPreRender():void { // Hige Animation for (var j:int = 0; j < higes.length; j++) { for (var i:int = 0; i < higes[ j ].length; i++) { var rot:Number = getTimer() / 1000 + 100 * i; higes[ j ][ i ].x = Math.sin(rot) * 30 * j higes[ j ][ i ].y = Math.cos(rot) * 10 * j } } // スポットカメラはカメラに追随させる spotLight.x = camera.x; spotLight.y = camera.y; spotLight.z = camera.z; } } }