Skip navigation

This is a flexified, simplified version of John Grden’s earth demo. Create a new Flex project called “GreatWhiteExperiment1”, add the GreatWhite source path, and paste the code:  

package {
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import org.papervision3d.cameras.FreeCamera3D;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	import org.papervision3d.materials.shaders.FlatShader;
	import org.papervision3d.materials.special.ParticleMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.objects.special.ParticleField;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	
	[SWF(backgroundColor="0x000000", width="900", height="600", frameRate="30")]
	public class GreatWhiteExperiment1 extends Sprite
	{
		private var renderer:BasicRenderEngine
		private var scene:Scene3D;
		private var camera:FreeCamera3D;
		private var viewport:Viewport3D;
		
		// 3d Objects
		private var pointLight:PointLight3D;
		private var earth:Sphere;
		
		public function GreatWhiteExperiment1()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			renderer = new BasicRenderEngine();
			scene = new Scene3D();
			camera = new FreeCamera3D();
			viewport  = new Viewport3D(0, 0, true, false);
			addChild(viewport);
			 
			camera.z = -350;
			camera.focus = 1100;
			camera.zoom = 1;
			
			pointLight = new PointLight3D(true);
			scene.addChild(pointLight);
			pointLight.moveUp(350);
			pointLight.moveRight(350);
			
			var earthMaterial:ColorMaterial = new ColorMaterial(0x00CCCC);
			
			//var earthBumpMaterial:MovieAssetMaterial = new MovieAssetMaterial("earthMapBump2");
			//phong only, no bump
			//var earthShader:PhongShader = new PhongShader(pointLight, 0xFFFFFF,0x404040,20);
			//phong with bump
			
			// create shader
			//var earthShader:PhongShader = new PhongShader(pointLight, 0xFFFFFF, 0x303030, 20, null, null);
			var earthShader:FlatShader = new FlatShader(pointLight, 0xFFFFFF, 0);
			
			// combine shader with original material, for a shaded material
			//var earthShadedMaterial:ShadedMaterial = new ShadedMaterial(earthMaterial, earthShader);
			var earthShadedMaterial:FlatShadeMaterial = new FlatShadeMaterial(pointLight, 0xFFFFFF, 0);
			
			// add to sphere
			earth = new Sphere(earthShadedMaterial, 250, 12, 12);

			scene.addChild(earth);

			createStars();
			 
			stage.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
		}
		
		private function handleEnterFrame(e:Event):void
		{
			earth.yaw(-.5);
			camera.x=camera.y=camera.z=0;
			camera.yaw(.5);
			camera.moveBackward(1000);
			
			renderer.renderScene(scene, camera, viewport);
		}
		
		private function createStars():void
		{
			//Create a new particle material;
			var pm:ParticleMaterial = new ParticleMaterial(0xFFFFFF,1);
			
			//Create a new particlefield.
			var particleField:ParticleField = new ParticleField(pm, 2000, 5000, 5000, 5000);
			scene.addChild(particleField);
		}
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: