requests

Flint Particle System with Papervision3D

Monday, December 15th, 2008 | examples, requests | Comments

Flint -> http://flintparticles.org/

Flint is very cool. It just has a bit of a learning curve (as does Papervision3D). Here’s a “Hello Word” example that I hope will help. There are MANY other options that I’m not covering here. This is just about as simple as it gets with still having some kind of movement.


source

package
{
	import org.flintparticles.common.actions.Action;
	import org.flintparticles.common.actions.Age;
	import org.flintparticles.common.counters.Steady;
	import org.flintparticles.common.initializers.Lifetime;
	import org.flintparticles.threeD.actions.Move;
	import org.flintparticles.threeD.actions.RandomDrift;
	import org.flintparticles.threeD.emitters.Emitter3D;
	import org.flintparticles.threeD.geom.Vector3D;
	import org.flintparticles.threeD.initializers.Position;
	import org.flintparticles.threeD.initializers.Velocity;
	import org.flintparticles.threeD.papervision3d.PV3DRenderer;
	import org.flintparticles.threeD.papervision3d.initializers.PV3DObjectClass;
	import org.flintparticles.threeD.zones.PointZone;
	import org.flintparticles.threeD.zones.Zone3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class Papervision3DWithFlint extends BasicView
	{
		private const NUM_SPHERES_PER_SECOND:Number = 1;
 
		private var emitter:Emitter3D;
		private var pv3dRenderer:PV3DRenderer;
 
		public function Papervision3DWithFlint()
		{
			emitter = new Emitter3D();
			emitter.counter = new Steady(NUM_SPHERES_PER_SECOND);
 
			//initializers
			var displayObject3dType:PV3DObjectClass = new PV3DObjectClass(Sphere);
			emitter.addInitializer(displayObject3dType);
 
			var starting3DPosition:Vector3D = new Vector3D( 0, -700, 0);
			var starting3DZone:Zone3D = new PointZone(starting3DPosition);
			var startingPosition:Position = new Position(starting3DZone);
			emitter.addInitializer(startingPosition);
 
			var direction:Vector3D = new Vector3D(0, 100, 0);
			var zone:Zone3D = new PointZone(direction);
			var velocity:Velocity = new Velocity(zone); 
			emitter.addInitializer(velocity);
 
			var lifetime:Lifetime = new Lifetime(20);
			emitter.addInitializer(lifetime);			
 
			//actions
			var ageAction:Action = new Age();
			emitter.addAction(ageAction);
 
			var moveAction:Action = new Move();
			emitter.addAction(moveAction);
 
			var drift:Action = new RandomDrift(1000, 0, 1000);
			emitter.addAction( drift );
 
 
			//Flint renderer matches emitter 3d coordinates to pv3d coordinates
			//*does not actually render the pv3d scene*
			pv3dRenderer = new PV3DRenderer(scene);
			pv3dRenderer.addEmitter(emitter);
 
			//start emitter		
			emitter.start();
			//start pv3d rendering
			startRendering();
		}
	}
}

Tags:

Portal

Tuesday, December 9th, 2008 | examples, requests | Comments


source

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
 
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.view.layer.ViewportLayer;
	import org.papervision3d.view.layer.util.ViewportLayerSortMode;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class Portal extends BasicView
	{
		private var portalViewport:Viewport3D = new Viewport3D();
		private var portalScene:Scene3D = new Scene3D();
		private var portalPlane:Plane;
 
		private var exposedViewport:Viewport3D = new Viewport3D();
		private var exposedScene:Scene3D = new Scene3D();
 
		private var mainSphere:Sphere;
		private var exposedSphere:Sphere;
 
		public function Portal()
		{
			addChild(exposedViewport);
			addChild(portalViewport);
 
			setupExposedViewport();
			setupPortalViewport();
			setupMainViewport();
 
			startRendering(); 	
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
		}
 
		private function setupExposedViewport():void
		{
			var bitmapData:BitmapData = new BitmapData(640, 480, false, 0xffffff);
			var bitmap:Bitmap = new Bitmap(bitmapData);
			bitmap.x = -320;
			bitmap.y = -240;
 
			var viewportLayer:ViewportLayer = new ViewportLayer(exposedViewport, null);
			viewportLayer.addChild(bitmap);
			exposedViewport.containerSprite.addLayer(viewportLayer);
 
			var light:PointLight3D = new PointLight3D();
			var flatShadeMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000, 0x2b2b2b, 10);
			exposedSphere = createSpheres(flatShadeMaterial);
 
			var viewportLayer2:ViewportLayer = new ViewportLayer(exposedViewport, exposedSphere);
			for each(var sphere:Sphere in exposedSphere.children)
			{
				viewportLayer2.addDisplayObject3D(sphere);
			}
			exposedViewport.containerSprite.addLayer(viewportLayer2);
 
			viewportLayer.layerIndex = 1;
			viewportLayer2.layerIndex = 2;
			exposedViewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;
 
			exposedScene.addChild(exposedSphere);
 
			exposedViewport.containerSprite.mask = portalViewport;
		}
 
		private function setupPortalViewport():void
		{
			var whiteMaterial:ColorMaterial = new ColorMaterial(0xffffff);
			portalPlane = new Plane(whiteMaterial);
			portalPlane.z = -500;
			portalScene.addChild(portalPlane);
		}
 
		private function setupMainViewport():void
		{
			var wireframeMaterial:WireframeMaterial = new WireframeMaterial(0xffffff);
			mainSphere = createSpheres(wireframeMaterial);
 
			scene.addChild(mainSphere);
		}
 
		private function keyDownHandler(event:KeyboardEvent):void
		{
			switch(event.keyCode)
			{
				case Keyboard.UP:
					camera.moveForward(10);
					break;
 
				case Keyboard.DOWN:
					camera.moveBackward(10);
					break;	
			}
		}
 
		private function createSpheres(material:MaterialObject3D):Sphere
		{
			var parentSphere:Sphere = new Sphere(material);
 
			var child1:Sphere = new Sphere(material);
			child1.x = -500;
			var child2:Sphere = new Sphere(material);
			child2.x = 500;
			var child3:Sphere = new Sphere(material);
			child3.y = 500;
			var child4:Sphere = new Sphere(material);
			child4.y = -500;
 
			parentSphere.addChild(child1);
			parentSphere.addChild(child2);
			parentSphere.addChild(child3);
			parentSphere.addChild(child4);
 
			return parentSphere;
		}
 
		override protected function onRenderTick(event:Event=null):void
		{
			mainSphere.rotationY++;
			exposedSphere.rotationY++;
 
			portalPlane.moveForward(500);
			portalPlane.rotationY = -viewport.containerSprite.mouseX / 320 * 90;
			portalPlane.moveBackward(500);
 
 
			renderer.renderScene(portalScene, camera, portalViewport);
			renderer.renderScene(exposedScene, camera, exposedViewport);
			renderer.renderScene(scene, camera, viewport);
		}
	}
}

Tags:

Animating a Collada File from 3ds max

Sunday, December 7th, 2008 | requests, tutorials | Comments

Pablo made another great video tutorial about using a custom class he made to control frame animations of a collada file. He asked me to host it since his free screencast account couldn’t handle all the traffic he was getting :) It’s likely that we’ll take these concepts into the actual Papervision3D library, but if you need this *right now*, you’ll need his class.

Watch tutorial

Thanks, Pablo.

Tags: ,

Collada with CellShader and PointLight3D

Sunday, December 7th, 2008 | examples, requests | Comments

Pretty much the same as the last example, but this one has a Cell Shader overlaying the BitmapMaterial. Also, the light follows the camera as the camera orbits the collada model.

Drag mouse to orbit. Scroll wheel to zoom.

source

package
{
	import flash.display.Bitmap;
	import flash.events.MouseEvent;
	import flash.utils.ByteArray;
 
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.shaders.CellShader;
	import org.papervision3d.materials.shaders.ShadedMaterial;
	import org.papervision3d.objects.parsers.DAE;
	import org.papervision3d.view.BasicView;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class CellShadedCollada extends BasicView
	{
		[Embed(source="assets/c.DAE", mimeType = "application/octet-stream")]
		private var daeAsset:Class;
 
		[Embed(source="assets/materials/c.png")]
		private var materialAsset:Class;
 
		private var cameraPitch:Number = 90;
		private var cameraYaw:Number = 270;
		private var isOrbiting:Boolean = false;
		private var previousMouseX:Number;
		private var previousMouseY:Number;
		private var light:PointLight3D;
 
		public function CellShadedCollada()
		{
			var byteArray:ByteArray = new daeAsset() as ByteArray;
			var dae:DAE = new DAE();
			dae.load(byteArray);
 
			var bitmap:Bitmap = new materialAsset() as Bitmap;
			var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData, true);
 
			light = new PointLight3D();
 
			var cellShader:CellShader = new CellShader(light, 0xffffff, 0x000000, 10);
			var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, cellShader);
 
			dae.materials.addMaterial(shadedMaterial, "cMaterial");
 
			scene.addChild(dae);
 
			startRendering();
 
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
		}
 
		private function mouseWheelHandler(event:MouseEvent):void
		{
			camera.moveForward(10 * event.delta);
		}
 
		private function onMouseDown(event:MouseEvent):void
		{
			isOrbiting = true;
			previousMouseX = event.stageX;
			previousMouseY = event.stageY;
		}
 
		private function onMouseUp(event:MouseEvent):void
		{
			isOrbiting = false;
		}
 
		private function onMouseMove(event:MouseEvent):void
		{
			var differenceX:Number = event.stageX - previousMouseX;
			var differenceY:Number = event.stageY - previousMouseY;
 
			if(isOrbiting)
			{
				cameraPitch += differenceY;
				cameraYaw += differenceX;
 
				cameraPitch %= 360;
				cameraYaw %= 360;
 
				cameraPitch = cameraPitch > 0 ? cameraPitch : 0.0001;
				cameraPitch = cameraPitch < 90 ? cameraPitch : 89.9999;
 
				previousMouseX = event.stageX;
				previousMouseY = event.stageY;
 
				camera.orbit(cameraPitch, cameraYaw);
				light.position = camera.position;
			}
		}
 
	}
}

Tags: , ,

Search

Recommended Books

Speaking at FITC Toronto

 

May 2012
M T W T F S S
« May    
 123456
78910111213
14151617181920
21222324252627
28293031  

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...