AS3DMod Twist
package { import com.as3dmod.ModifierStack; import com.as3dmod.modifiers.Twist; import com.as3dmod.plugins.pv3d.LibraryPv3d; import flash.events.Event; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.GouraudMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class As3dModTwist extends BasicView { private var plane:Plane; private var modifierStack:ModifierStack; private var twist:Twist; public function As3dModTwist() { var light:PointLight3D = new PointLight3D(); var cellMaterial:GouraudMaterial = new GouraudMaterial(light, 0xcc0000, 0x111111, 10); cellMaterial.doubleSided = true; plane = new Plane(cellMaterial, 800, 800, 20, 20); plane.rotationX = 45; plane.rotationY = 45; modifierStack = new ModifierStack(new LibraryPv3d(), plane); twist = new Twist(); modifierStack.addModifier(twist); scene.addChild(plane); startRendering(); } override protected function onRenderTick(event:Event=null):void { plane.rotationY += (viewport.containerSprite.mouseX - plane.rotationY) * .1; twist.angle += (viewport.containerSprite.mouseY * Math.PI / 180 - twist.angle) * .1; modifierStack.apply(); super.onRenderTick(event); } } }
Looking around the inside of a Sphere
package { import flash.events.Event; import flash.ui.Mouse; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.core.utils.Mouse3D; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.special.CompositeMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import org.papervision3d.view.layer.ViewportLayer; import org.papervision3d.view.layer.util.ViewportLayerSortMode; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class LookingAroundTheInsideOfASphere extends BasicView { private var lookAtMe:DisplayObject3D; private var sphere:Sphere; private var mouse3D:Mouse3D; private var plane:Plane; public function LookingAroundTheInsideOfASphere() { viewport.interactive = true; mouse3D = viewport.interactiveSceneManager.mouse3D; Mouse3D.enabled = true; lookAtMe = new DisplayObject3D(); var wireframeMaterial:WireframeMaterial = new WireframeMaterial(0x444444); var colorMaterial:ColorMaterial = new ColorMaterial(0xdddddd); var sphereMaterial:CompositeMaterial = new CompositeMaterial(); sphereMaterial.addMaterial(wireframeMaterial); sphereMaterial.addMaterial(colorMaterial); sphereMaterial.interactive = true; sphereMaterial.doubleSided = true; sphere = new Sphere(sphereMaterial, 500, 24, 18); var planeMaterial:MaterialObject3D = new ColorMaterial(0xcc0000); planeMaterial.doubleSided = true; plane = new Plane(planeMaterial, 50, 50); var viewportLayer:ViewportLayer = new ViewportLayer(viewport, plane); viewportLayer.layerIndex = 1; viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT; viewport.containerSprite.addLayer(viewportLayer); scene.addChild(plane); camera.z = -300; camera.target = lookAtMe; scene.addChild(sphere); startRendering(); Mouse.hide(); } override protected function onRenderTick(event:Event=null):void { lookAtMe.x += (mouse3D.x - lookAtMe.x) * .03; lookAtMe.y += (mouse3D.y - lookAtMe.y) * .03; plane.copyTransform(mouse3D); super.onRenderTick(event); } } }
Tweening the Camera and Tweening lookAt()
This example shows how to make a target object (in this case “lookAtMe”) and have the camera target it using camera.target = lookAtMe. Also, the arrow will behave similarly by calling arrow.lookat(lookAtMe) in onRenderTick. For added effect, the light follows around lookAtMe.
package { import flash.events.Event; import gs.TweenMax; import gs.easing.Cubic; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.materials.shadematerials.GouraudMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import org.pv3d.objects.Arrow; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class TweeningLookAt extends BasicView { private var arrow:Arrow; private var light:PointLight3D; private var lookAtMe:DisplayObject3D; private var lookAtTarget:DisplayObject3D; public function TweeningLookAt() { viewport.interactive = true; light = new PointLight3D(); var material:MaterialObject3D; material = new GouraudMaterial(light, 0xdddddd, 0xcc0000, 10); arrow = new Arrow(material); arrow.scale = .5; scene.addChild(arrow); for(var i:int = 0; i < 20; i++) { var randomColor:Number = Math.random() * 0x555555; var lightColor:Number = 0xdddddd; material = new FlatShadeMaterial(light, lightColor, randomColor, 10); material.interactive = true; var sphere:Sphere = new Sphere(material, 200, 6, 6); sphere.x = Math.random() * 4000 - 2000; sphere.y = Math.random() * 4000 - 2000; sphere.z = Math.random() * 2000 + 300; scene.addChild(sphere); sphere.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, sphere_objectClickHandler); sphere.lookAt(arrow); } lookAtMe = new DisplayObject3D(); lookAtMe.z = 1000; lookAtTarget = new DisplayObject3D(); camera.target = lookAtMe; scene.addChild(lookAtMe); startRendering(); } private function sphere_objectClickHandler(event:InteractiveScene3DEvent):void { lookAtTarget.copyTransform(event.displayObject3D); lookAtTarget.moveForward(500); var time:Number = 1; var tweenObject:Object = {}; tweenObject.x = lookAtTarget.x; tweenObject.y = lookAtTarget.y; tweenObject.z = lookAtTarget.z; tweenObject.ease = Cubic.easeInOut; TweenMax.to(lookAtMe, time, tweenObject); } override protected function onRenderTick(event:Event=null):void { light.x = lookAtMe.x; light.y = lookAtMe.y; light.z = lookAtMe.z; arrow.lookAt(lookAtMe); super.onRenderTick(event); } } }
Cube Inside Faces and Outside Faces
*updated to address comments
package { import flash.display.Bitmap; import flash.events.Event; import flash.events.MouseEvent; import org.papervision3d.core.proto.MaterialObject3D; 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.materials.shaders.Shader; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.primitives.Cube; import org.papervision3d.view.BasicView; import org.papervision3d.view.stats.StatsView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class InsideFacesOfACube extends BasicView { [Embed(source="assets/back.jpg")] private var backAsset:Class; [Embed(source="assets/bottom.jpg")] private var bottomAsset:Class; [Embed(source="assets/front.jpg")] private var frontAsset:Class; [Embed(source="assets/left.jpg")] private var leftAsset:Class; [Embed(source="assets/right.jpg")] private var rightAsset:Class; [Embed(source="assets/top.jpg")] private var topAsset:Class; [Embed(source="assets/287.jpg")] private var environmentAsset:Class; private var light:PointLight3D; private var cube:Cube; private var materialsList:MaterialsList; private var sides:int = Cube.ALL; public function InsideFacesOfACube() { createMaterialsList(); cube = new Cube(materialsList, 500, 500, 500, 5, 5, 5, sides); scene.addChild(cube); startRendering(); stage.addEventListener(MouseEvent.CLICK, stage_clickHandler); } private function createMaterialsList():void { materialsList = new MaterialsList(); light = new PointLight3D(); materialsList.addMaterial(createShadedMaterial(backAsset), "back"); materialsList.addMaterial(createShadedMaterial(bottomAsset), "bottom"); materialsList.addMaterial(createShadedMaterial(frontAsset), "front"); materialsList.addMaterial(createShadedMaterial(leftAsset), "left"); materialsList.addMaterial(createShadedMaterial(rightAsset), "right"); materialsList.addMaterial(createShadedMaterial(topAsset), "top"); } private function createShadedMaterial(bitmapAsset:Class):MaterialObject3D { var bitmap:Bitmap = new bitmapAsset() as Bitmap; var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData, true); var shader:Shader = new CellShader(light, 0xffffff, 0xaaaaaa, 10); var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader); return shadedMaterial; } private function stage_clickHandler(event:MouseEvent):void { if(sides == Cube.ALL) { sides = Cube.NONE; } else { //you could also specify specific sides you want //i.e. - if you want every side but the front do: //sides = Cube.ALL - Cube.Front; //or if you only want the top and the bottom do: //sides = Cube.TOP + Cube.BOTTOM; sides = Cube.ALL; } scene.removeChild(cube); createMaterialsList(); var tempRotationX:Number = cube.rotationX; var tempRotationY:Number = cube.rotationY; cube = new Cube(materialsList, 500, 500, 500, 5, 5, 5, sides); cube.rotationX = tempRotationX; cube.rotationY = tempRotationY; scene.addChild(cube); } override protected function onRenderTick(event:Event=null):void { cube.rotationY += (viewport.containerSprite.mouseX - cube.rotationY) * .1; cube.rotationX += (viewport.containerSprite.mouseY - cube.rotationX) * .1; renderer.renderScene(scene, camera, viewport); } } }
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); } }
Search
Subscribe
Recent Posts
- AS3DMod Twist
- Looking around the inside of a Sphere
- Tweening the Camera and Tweening lookAt()
- Cube Inside Faces and Outside Faces
- Happy New Year!
- Slerp Explorer
- Quaternion Explorer
- Click then Tween Camera to Plane
- Switching a MovieMaterial on the face of a Cube - replaceMaterialByName
- Merry Christmas!
- Flint Pixels 2 - Random Drift and Rotate Emitter
- Papervision3D with Box2DFlash Part 4 - Distance Joint
- Flint Pixels
- Papervision3D with AS3Dmod Hello World Example
- .swc and .zip updated to revision 851


