fun
Happy New Year!
Click to party
Oh, and the code’s a mess.

source
package { import flash.events.MouseEvent; import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Blast; import org.flintparticles.common.counters.Steady; import org.flintparticles.common.energyEasing.Quadratic; import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.events.ParticleEvent; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.threeD.actions.Accelerate; import org.flintparticles.threeD.actions.LinearDrag; 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.Rotation; import org.flintparticles.threeD.initializers.ScaleAllInit; import org.flintparticles.threeD.initializers.Velocity; import org.flintparticles.threeD.papervision3d.PV3DRenderer; import org.flintparticles.threeD.papervision3d.initializers.PV3DObjectClasses; import org.flintparticles.threeD.particles.Particle3D; import org.flintparticles.threeD.zones.ConeZone; import org.flintparticles.threeD.zones.LineZone; import org.flintparticles.threeD.zones.PointZone; import org.flintparticles.threeD.zones.SphereZone; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class HappyNewYear extends BasicView { private var flintRenderer:PV3DRenderer; private var rocket:Emitter3D; private var cameraTarget:DisplayObject3D = DisplayObject3D.ZERO; private var previousMouseX:Number = 0; private var cameraYaw:Number = 0; public function HappyNewYear() { flintRenderer = new PV3DRenderer( scene ); setupRocket(); startRendering(); stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler); } private function setupRocket():void { rocket = new Emitter3D(); rocket.counter = new Steady( 1 ); rocket.addInitializer( new PV3DObjectClasses([HappyWord, NewWord, YearWord]) ); rocket.addInitializer( new ScaleAllInit(.9, 1.4)); rocket.addInitializer( new Position( new LineZone( new Vector3D( 0, -500, 0 ), new Vector3D( 0, -500, 0) ) ) ); rocket.addInitializer( new Velocity( new ConeZone( Vector3D.ZERO, Vector3D.AXISY, 1, 500, 330 ) ) ); rocket.addInitializer( new Lifetime( 3.3 ) ); rocket.addAction( new Age() ); rocket.addAction( new Move() ); rocket.addAction( new Accelerate( new Vector3D( 0, -50, 0 ) ) ); rocket.addAction( new LinearDrag( 0.5 ) ); rocket.addAction( new RandomDrift( 200, 200, 200 ) ); rocket.addEventListener( ParticleEvent.PARTICLE_DEAD, rocket_particleDeadHandler, false, 0, true ); flintRenderer.addEmitter(rocket); rocket.start(); } private function rocket_particleDeadHandler(event:ParticleEvent):void { var explode:Emitter3D = new Emitter3D(); explode.counter = new Blast( 10 ); explode.addInitializer( new PV3DObjectClasses([HappyWord, NewWord, YearWord]) ); explode.addInitializer( new ScaleAllInit(.3, .6)); explode.addInitializer( new Rotation(Vector3D.AXISX, 1, 360)); explode.addInitializer( new Rotation(Vector3D.AXISZ, 1, 360)); explode.addInitializer( new Position( new PointZone( Particle3D( event.particle ).position ) ) ); explode.addInitializer( new Velocity( new SphereZone( Vector3D.ZERO, 1000 ) ) ); explode.addInitializer( new Lifetime( 3 ) ); explode.addAction( new Age( Quadratic.easeIn ) ); explode.addAction( new Move() ); explode.addAction( new Accelerate( new Vector3D( 0, -500, 0 ) ) ); explode.addAction( new LinearDrag( 0.5 ) ); explode.addEventListener( EmitterEvent.EMITTER_EMPTY, explode_emitterEmptyHandler, false, 0, true ); flintRenderer.addEmitter( explode ); explode.start(); } private function explode_emitterEmptyHandler(event:EmitterEvent):void { Emitter3D( event.target ).removeEventListener( EmitterEvent.EMITTER_EMPTY, explode_emitterEmptyHandler ); flintRenderer.removeEmitter( Emitter3D( event.target ) ); } private function stage_mouseMoveHandler(event:MouseEvent):void { var differenceX:Number = event.stageX - previousMouseX; cameraYaw += differenceX; cameraYaw %= 360; previousMouseX = event.stageX; camera.orbit(90, cameraYaw, true, cameraTarget); } } } import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.typography.Text3D; import org.papervision3d.materials.special.Letter3DMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.core.geom.TriangleMesh3D; class HappyWord extends TriangleMesh3D { public function HappyWord() { super( null, new Array(), new Array(), null ); var word:Text3D = new Text3D("Happy", new HelveticaBold(), new Letter3DMaterial(0xfe5555)); addChild(word); } } import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.typography.Text3D; import org.papervision3d.materials.special.Letter3DMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.core.geom.TriangleMesh3D; class NewWord extends TriangleMesh3D { public function NewWord() { super( null, new Array(), new Array(), null ); var word:Text3D = new Text3D("New", new HelveticaBold(), new Letter3DMaterial(0x91c0ff)); addChild(word); } } import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.typography.Text3D; import org.papervision3d.materials.special.Letter3DMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.core.geom.TriangleMesh3D; import org.papervision3d.typography.fonts.HelveticaBold; class YearWord extends TriangleMesh3D { public function YearWord() { super( null, new Array(), new Array(), null ); var word:Text3D = new Text3D("Year", new HelveticaBold(), new Letter3DMaterial(0xfffbbb)); addChild(word); } }
Merry Christmas!
package { import flash.events.Event; import flash.filters.BlurFilter; import flash.geom.Point; import org.flintparticles.common.counters.Steady; import org.flintparticles.common.displayObjects.RadialDot; import org.flintparticles.common.initializers.ImageClass; import org.flintparticles.common.initializers.ScaleImageInit; import org.flintparticles.twoD.actions.DeathZone; import org.flintparticles.twoD.actions.Move; import org.flintparticles.twoD.actions.RandomDrift; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.Position; import org.flintparticles.twoD.initializers.Velocity; import org.flintparticles.twoD.renderers.DisplayObjectRenderer; import org.flintparticles.twoD.zones.LineZone; import org.flintparticles.twoD.zones.PointZone; import org.flintparticles.twoD.zones.RectangleZone; import org.papervision3d.core.effects.view.ReflectionView; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.special.Letter3DMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.typography.Text3D; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class MerryChristmas extends ReflectionView { private var pivotPoint:DisplayObject3D = new DisplayObject3D(); public function MerryChristmas() { viewportReflection.filters = [new BlurFilter(3,3,1)]; setReflectionColor(.5, .5, .5); surfaceHeight = -80; setupText(); setupSnow(); setupTree(); addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private function setupText():void { var rockwell:Rockwell = new Rockwell(); var merryMaterial:Letter3DMaterial = new Letter3DMaterial(0xcc0000); var merry:Text3D = new Text3D("MERRY", rockwell, merryMaterial); var christmasMaterial:Letter3DMaterial = new Letter3DMaterial(0x00cc00); var christmas:Text3D = new Text3D("CHRISTMAS", rockwell, christmasMaterial); merry.z = -700; christmas.z = 500; christmas.rotationY = 180; pivotPoint.addChild(merry); pivotPoint.addChild(christmas); scene.addChild(pivotPoint); } private function setupTree():void { var radius:Number = 300; var height:Number = 500; var total:uint = 100; var looker:DisplayObject3D = new DisplayObject3D(); for(var i:int = 0; i < total; i++) { var material:ColorMaterial; if((i & 1) == 0) material = new ColorMaterial(0xaa0000); else material = new ColorMaterial(0x00aa00); material.doubleSided = true; var plane:Plane = new Plane(material, 30, 30, 1, 1); plane.x = Math.cos(i) * (radius - i * 3); plane.z = Math.sin(i) * (radius - i * 3); plane.y = i / total * height; looker.copyPosition(plane); looker.x = looker.z = 0; plane.lookAt(looker); pivotPoint.addChild(plane); } } private function setupSnow():void { var emitter:Emitter2D = new Emitter2D(); emitter.counter = new Steady(100); emitter.addInitializer(new ImageClass(RadialDot, 2)); emitter.addInitializer(new Position(new LineZone(new Point(-5,-5), new Point(645, -5)))); emitter.addInitializer(new Velocity(new PointZone(new Point(0, 65)))); emitter.addInitializer(new ScaleImageInit(0.75, 2)); emitter.addAction(new Move()); emitter.addAction(new DeathZone(new RectangleZone(-10, -10, 640, 250), true)); emitter.addAction(new RandomDrift(15, 15)); var flintRenderer:DisplayObjectRenderer = new DisplayObjectRenderer(); addChild(flintRenderer); flintRenderer.addEmitter(emitter); emitter.start(); } private function enterFrameHandler(event:Event):void { pivotPoint.rotationY += (viewport.containerSprite.mouseX - pivotPoint.rotationY) * .01; singleRender(); } } }
Dancing Spheres
This was supposed to be something completely different
package { import flash.events.Event; import org.papervision3d.core.effects.BitmapColorEffect; import org.papervision3d.core.math.Number3D; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import org.papervision3d.view.layer.BitmapEffectLayer; import org.papervision3d.view.layer.ViewportLayer; [SWF(width="800", height="600", backgroundColor="#000000", frameRate="60")] public class DancingSpheres extends BasicView { private const LENGTH:Number = 2000; private var yellowSphere:Sphere; public function DancingSpheres() { super(800, 600); camera.fov = 140; var light:PointLight3D = new PointLight3D(); light.x = -1000, light.y = 1000; var yellowMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcccc00); yellowSphere = new Sphere(yellowMaterial, 120); var redMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000); var redSphere:Sphere = new Sphere(redMaterial, 120); redSphere.x = -400; yellowSphere.addChild(redSphere); var bitmapEffectLayer:BitmapEffectLayer = new BitmapEffectLayer(viewport, 800, 600); bitmapEffectLayer.addDisplayObject3D(yellowSphere); bitmapEffectLayer.addDisplayObject3D(redSphere); bitmapEffectLayer.addEffect(new BitmapColorEffect()); viewport.containerSprite.addLayer(bitmapEffectLayer); scene.addChild(yellowSphere); startRendering(); } override protected function onRenderTick(event:Event=null):void { var ray:Number3D = camera.unproject(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY); ray.normalize(); ray.multiplyEq(LENGTH); ray = Number3D.add(ray, new Number3D(camera.x, camera.y, camera.z)); var velocityX:Number = (ray.x - yellowSphere.x) * .1; var velocityY:Number = (ray.y - yellowSphere.y) * .1; var velocityZ:Number = (ray.z - yellowSphere.z) * .1; yellowSphere.x += velocityX; yellowSphere.y += velocityY; yellowSphere.z += velocityZ; if(velocityX > 20) velocityX = 20; if(velocityX < -20) velocityX = -20; yellowSphere.roll(velocityX); renderer.renderScene(scene, camera, viewport); } } }
Drag and Release
Sproing! I’ll go into “camera.unproject” and “rays” in more detail in the future.
package { import flash.events.Event; import flash.events.MouseEvent; import gs.TweenMax; import gs.easing.Elastic; import org.papervision3d.core.geom.Lines3D; import org.papervision3d.core.geom.renderables.Line3D; import org.papervision3d.core.geom.renderables.Vertex3D; import org.papervision3d.core.math.Number3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.materials.special.LineMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class DragAndRelease extends BasicView { private var sphere:Sphere; private var line:Line3D; private const LENGTH:Number = 2000; private var isSpherePressed:Boolean = false; public function DragAndRelease() { viewport.interactive = true; camera.fov = 110; var light:PointLight3D = new PointLight3D(); light.x = -1000, light.y = 1000; var material:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000); material.interactive = true; sphere = new Sphere(material, 200, 12, 12); sphere.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, objectPressHandler); sphere.z = LENGTH + camera.z; stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); var lineMaterial:LineMaterial = new LineMaterial(0x00cc00); var lines:Lines3D = new Lines3D(); line = new Line3D(lines, lineMaterial, 1, new Vertex3D(1000,1000,1000), new Vertex3D(-1000,0,0)); lines.addLine(line); scene.addChild(lines); scene.addChild(sphere); startRendering(); } override protected function onRenderTick(event:Event=null):void { var ray:Number3D = camera.unproject(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY); line.v0.x = ray.x, line.v0.y = ray.y, line.v0.z = ray.z; line.v1.x = sphere.x, line.v1.y = sphere.y, line.v1.z = sphere.z; ray.normalize(); ray.multiplyEq(LENGTH); ray = Number3D.add(ray, new Number3D(camera.x, camera.y, camera.z)); if(isSpherePressed) { sphere.position = ray; } renderer.renderScene(scene, camera, viewport); } private function objectPressHandler(event:InteractiveScene3DEvent):void { TweenMax.killTweensOf(sphere); isSpherePressed = true; } private function mouseUpHandler(event:MouseEvent):void { isSpherePressed = false; TweenMax.to(sphere, 1, {x:0, y:0, z:LENGTH + camera.z, ease:Elastic.easeOut}); } } }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- FDT Theme Designer
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
- MorphController – Mighty Morphing Papervision3D
- End dump
- Test if a plane is within the view of the camera (aka testing if culled)
- Materials Reference
Recent Comments
- BAM5 on haXe Tutorial
- AlexG on Finding 2D Coordinates of a DisplayObject3D
- Josh on ActionScript 3 – Model View Controller (MVC)
- martin everett on requests
- martin everett on requests
- lillacska on Dragging Spheres
- Guy Ritchie on MXML without the Flex framework
- Pedro on ActionScript 3 – Namespaces
- daveevolve on AS3DMod Perlin Noise
- sebomoto on haXe Tutorial
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jan | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
Archives
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




