blog.x-e.ro / extending the basic view : making papervision3D setup simpler

extending the basic view

as3 :: making papervision3D setup simpler

the core PV3D team has released a new class called the basicView. the idea here is to create one object that already contains the camera, scene, viewport, and render engine needed to made a 3D scene in flash. 

after reading the post about it on andy’s blog, you can see that this is a very simple technique. but lets take it one step further. why not create a new actionscipt project that extends basic view?! its very simple, and makes setting up your scene a snap!

package {
	import com.fontvirus.*;
	
	import flash.display.*;
	import flash.events.Event;
	
	import org.papervision3d.cameras.*;
	import org.papervision3d.core.render.data.RenderStatistics;
	import org.papervision3d.lights.*;
	import org.papervision3d.materials.shadematerials.*;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.scenes.*;
	import org.papervision3d.view.*;
   [SWF(backgroundColor="#000000")]
	
	public class basicPV3D extends BasicView
	{
		private var thelight    :PointLight3D;
		private var thing       :Sphere;
		private var fps         :FlashFPS;
		private var stats       :RenderStatistics;
		public function basicPV3D():void
		{
			super(0,0,true,true,Camera3D.TYPE);
			stats = this.renderer.renderScene(this.scene, this.camera, this.viewport);
			this.viewport.autoClipping = false;
			init3D();
		}
		private function init3D():void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			fps = new FlashFPS(0x006600, 0x000000, 0xffffff, 0, "kb");
			addChild(fps);
			thelight = new PointLight3D();
			scene = new Scene3D();
			thing = new Sphere(new PhongMaterial(thelight, 0x00FF00, 0x000000, 4), 500, 10, 14);
			scene.addChild(thing);
			startRendering();	
		}
		override protected function onRenderTick(event:Event=null):void
		{
			fps.update("rendered: " + stats.shadedTriangles + " polys");
			thing.rotationY++;
			super.onRenderTick(event);
		}
	}
}

this demo is so basic i decided not to post a swf...
but this can be run using flex builder 3 or flash cs3 and the papervision3D - 2.0 great white sources.

loading...

loading...