Alternativa3D "Hello world + shadow + box!" application
I am test a open source now the alternativa engine 3d, because I like to make 3d game with flash 11.I rewrite a standard application 'Hello world' to add shadow in this one. I am happy!!! It's easy.
Alternativa3D box shadow screen shot.
package {
import alternativa.engine3d.controllers.*;
import alternativa.engine3d.core.*;
import alternativa.engine3d.lights.*;
import alternativa.engine3d.materials.*;
import alternativa.engine3d.primitives.*;
import alternativa.engine3d.resources.*;
import alternativa.engine3d.shadows.*;
import flash.display.*;
import flash.events.*;
/**
* Alternativa3D "Hello world + shadow + box!" application.
*/
public class HelloAlternativa3D extends Sprite {
private var rootContainer:Object3D = new Object3D();
private var camera:Camera3D;
private var stage3D:Stage3D;
private var box:Box;
public function HelloAlternativa3D() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage3D = stage.stage3Ds[0];
stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
stage3D.requestContext3D();
}
private function onContextCreate(e:Event):void {
var grass_diffuse:BitmapTextureResource = new BitmapTextureResource(new BitmapData(1, 1, false, 0xFF0000));
var grass_normal:BitmapTextureResource = new BitmapTextureResource(new BitmapData(1, 1, false, 0x7F7FFF));
var box_normal:BitmapTextureResource = new BitmapTextureResource(new BitmapData(1, 1, false, 0xFFFFFF));
grass_diffuse.upload(stage3D.context3D);
grass_normal.upload(stage3D.context3D);
box_normal.upload(stage3D.context3D);
// Camera and view
camera = new Camera3D(0.1, 10000);
camera.view = new View(stage.stageWidth, stage.stageHeight, false, 0, 0, 4);
addChild(camera.view);
addChild(camera.diagram);
// Initial position
camera.rotationX = -120*Math.PI/180;
camera.y = -800;
camera.z = 400;
rootContainer.addChild(camera);
// Light sources
var ambientLight:AmbientLight = new AmbientLight(0x333333);
ambientLight.intensity = 3;
ambientLight.z = 200;
ambientLight.y = -200;
ambientLight.x = 200;
rootContainer.addChild(ambientLight);
var directionalLight:DirectionalLight = new DirectionalLight(0xFFFF99);
directionalLight.z = 20000;
directionalLight.y = -20000;
directionalLight.x = 20000;
directionalLight.intensity = 1;
directionalLight.lookAt(2000, 0, 0);
rootContainer.addChild(directionalLight);
// Primitive box
box = new Box(150, 150, 150, 1, 1, 1, false);
box.z = 100;
var material:VertexLightTextureMaterial = new VertexLightTextureMaterial(grass_normal, box_normal, 1);
box.setMaterialToAllSurfaces(material);
rootContainer.addChild(box);
var plane:Plane = new Plane(800, 800);
var planeMaterial:StandardMaterial = new StandardMaterial(grass_diffuse, grass_normal);
plane.setMaterialToAllSurfaces(planeMaterial);
rootContainer.addChild(plane);
// Shadow
var shadow:DirectionalLightShadow = new DirectionalLightShadow(1000, 1000, -500, 500, 512, 2);
shadow.biasMultiplier = 0.97;
//shadow.addCaster(plane);
shadow.addCaster(box);
directionalLight.shadow = shadow;
for each (var resource:Resource in rootContainer.getResources(true)) {
resource.upload(stage3D.context3D);
}
// Listeners
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void {
// Width and height of view
camera.view.width = stage.stageWidth;
camera.view.height = stage.stageHeight;
// Rotation
box.rotationZ -= 0.01;
// Render
camera.render(stage3D);
}
}
}
Alternativa shadow cube source zip Flash Develop project.
I made Alternativa3d and jiglib.
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :