Hi, i’d like to show you how to initialize the engine.

Make sure your version is 1.3,go and download it here

And make sure your build target is greater than flash player 11.3

private var controller:CameraController;

CameraController is the bridge from user to the camera,he controls camera with mouse&keyboard events,his keyboard event stores data to a public array,so you can easily listen your own keyboard event as well.

public function HelloWorld() {
	stage.scaleMode = StageScaleMode.NO_SCALE;
	stage.align = StageAlign.TOP_LEFT;
	stage.frameRate = 60;

	EngineBase.stage = stage;
	EngineBase.stage3d = stage.stage3Ds[0];
	EngineBase.camera = new Camera3D();
	EngineBase.root = new Container3D();
	EngineBase.manager = new BasicManager();
	EngineBase.view = new ViewPort(800, 600);
	EngineBase.view.culling = new BasicCulling();
	addChild(EngineBase.view.diagram);

	controller = new CameraController();
	controller.mouseEnabled = true;
	controller.keyboardEnabled = true;
	controller.speed = 10;

	EngineBase.view.addEventListener(Event.CONTEXT3D_CREATE, onContext3DCreated);
}

Let’s have a look at demo’s constructor. In order to initialize the engine, you’ll need to value those static methods in nest.control.EngineBase, then listen viewPort’s Context3D_Create event to initialize your 3d scene. Make sure you initialized the engine first then your scene.

private function onContext3DCreated(e:Event):void {
	stage.addEventListener(Event.RESIZE, onResize);
	stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);

	var data:MeshData = PrimitiveFactory.createBox();
	var material:ColorMaterial = new ColorMaterial(0xffffff);
	material.light = new AmbientLight();
	material.light.next = new DirectionalLight(0xffffff, -1, -1);
	material.update();

	var mesh:Mesh = new Mesh(data, material);
	EngineBase.root.addChild(mesh);

	EngineBase.camera.position.z = -200;
	EngineBase.camera.changed = true;
}

Then we create our 3d scene.

We start from creating a colored box.

First, we need mesh’s vertex, triangle, uv … data, they are stored in MeshData.

Your can create one with PrimitiveFactory or you can generate one from nest.control.parsers.*

Then we dress our mesh with ColorMaterial, and we can setup material’s lights.

Material’s light is a linked list. The first one is an AmbientLight. And be aware of fragment constant’s limitions. Check n3d’s API for more help.

private function onEnterFrame(e:Event):void {
	controller.update();
	EngineBase.view.calculate();
}

Finally we update our controller&view and we are done! Enjoy!

Code
Demo

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>