package { import alternativa.engine3d.lights.OmniLight; import alternativa.engine3d.materials.TextureMaterial; import alternativa.engine3d.materials.VertexLightTextureMaterial; import alternativa.engine3d.primitives.Box; import alternativa.engine3d.primitives.Plane; import alternativa.engine3d.resources.BitmapTextureResource; import com.bit101.components.Label; import flash.display.BitmapData; import flash.display.Sprite; import org.libspark.alternativa3d.camera.CameraType; import org.libspark.alternativa3d.controllers.OrbitCameraController; import org.libspark.alternativa3d.view.AlternativaTemplate; [SWF(frameRate = "60")] public class Main extends AlternativaTemplate { public static const CUBE_LENGTH:int = 350; // size of cube public static const CUBE_NUM:int = 120; // amount of cube public function Main() { super({ backgroundColor:0xFFFFFF, cameraType : CameraType.ORBIT, useDiagram : true }); } [Embed(source = '/assets/ceil.png')] private const MAT_IMAGE:Class; [Embed(source = '/assets/shadow_opacity.png')] private const SHADOW_IMAGE_OP:Class; private var light:OmniLight; override protected function atInit():void { // オムニライト(無指向性の照明) light = new OmniLight(0xFFFFFF, 0, 9000); scene.addChild(light); // craete shadow material var shadowMat:TextureMaterial = new TextureMaterial(new BitmapTextureResource(new BitmapData(2, 2, false, 0x0)), new BitmapTextureResource((new SHADOW_IMAGE_OP).bitmapData), 0.75); // create box material var ceilMat:VertexLightTextureMaterial = new VertexLightTextureMaterial(new BitmapTextureResource((new MAT_IMAGE).bitmapData)); // create box for (var i:int = 0; i < CUBE_NUM; i++) { var box:Box = new Box(CUBE_LENGTH, CUBE_LENGTH, CUBE_LENGTH, 1, 1, 1, false, ceilMat); scene.addChild(box); // random position and rotation box.x = 6000 * (Math.random() - 0.5); box.y = 6000 * (Math.random() - 0.5); box.z = 2000 * Math.random() + 300; box.rotationX = 2 * Math.PI * Math.random(); box.rotationY = 2 * Math.PI * Math.random(); box.rotationZ = 2 * Math.PI * Math.random(); // crate shadow var shadow:Plane = new Plane(CUBE_LENGTH * 2, CUBE_LENGTH * 2, 1, 1, false, false, null, shadowMat); shadow.x = box.x; shadow.y = box.y; shadow.z = 0; shadow.scaleX = shadow.scaleY = 1 - shadow.z / 2000; scene.addChild(shadow); } // カメラコントローラーのカスタマイズ var orbit:OrbitCameraController = cameraController as OrbitCameraController; orbit.maxDistance = 4000; orbit.minLatitude = 5; orbit.setDistance(4000, false); // スタッツ表示 (camera.diagram as Sprite).graphics.beginFill(0x0, 0.75); (camera.diagram as Sprite).graphics.drawRect(-2, -2, 84, 89); // 表示作成 var label:Label = new Label(this, 8, 4, "STAGE3D LIGHTING DEMO "); label.scaleX = label.scaleY = 2; new Label(this, 10, 30, "PLASE DRAG STAGE"); } override protected function atPreRender():void { // 照明はカメラに追随させる light.x = camera.x; light.y = camera.y; light.z = camera.z; } } }