Archive for November 19th, 2008
Mouse3D moving light
Mouse3D is bound to the interactiveSceneManager of your viewport. So to get the 3d “renderHitData” of where your mouse is, you need to:
Mouse3D.enabled = true; viewport.interactive = true; mouse3D = viewport.interactiveSceneManager.mouse3D;
Then you can get 3d data from your mouse3D object like you would any other DisplayObject3D. Just remember the mouse will need to be over an object with a “material.interactive = true” to get any data back.
package { import flash.events.Event; import flash.ui.Mouse; import org.papervision3d.core.utils.Mouse3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.PhongMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class Mouse3DExample extends BasicView { private var mouse3D:Mouse3D; private var pivotPoint:DisplayObject3D; private var light:PointLight3D; public function Mouse3DExample() { var headerText:headerContainer = new headerContainer(); headerText.header.text = "Mouse over the sphere to move the light"; addChild(headerText); viewport.interactive = true; Mouse3D.enabled = true; mouse3D = viewport.interactiveSceneManager.mouse3D; light = new PointLight3D(true); pivotPoint = new DisplayObject3D(); var material:PhongMaterial = new PhongMaterial(light, 0xcc0000, 0x000000, 10); material.interactive = true; var sphere:Sphere = new Sphere(material, 500, 30, 30); sphere.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler); sphere.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler); var smallSphere1:Sphere = new Sphere(new PhongMaterial(light, 0x00cc00, 0x000000, 10), 100, 10, 10); var smallSphere2:Sphere = new Sphere(new PhongMaterial(light, 0x0000cc, 0x000000, 10), 100, 10, 10); smallSphere1.x = -500; smallSphere1.y = 500; smallSphere2.x = 400; smallSphere2.y = -600; pivotPoint.addChild(smallSphere1); pivotPoint.addChild(smallSphere2); scene.addChild(sphere); scene.addChild(pivotPoint); scene.addChild(light); addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private function objectOverHandler(event:InteractiveScene3DEvent):void { Mouse.hide(); } private function objectOutHandler(event:InteractiveScene3DEvent):void { Mouse.show(); } private function enterFrameHandler(event:Event):void { pivotPoint.yaw(1); pivotPoint.pitch(.5); light.copyTransform(mouse3D); light.moveBackward(100); singleRender(); } } }
Fireball
Run for your lives!!!
package { import flash.display.Bitmap; import gs.TweenMax; import gs.easing.Quad; import org.papervision3d.core.effects.BitmapFireEffect; import org.papervision3d.core.effects.BitmapMotionEffect; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import org.papervision3d.view.layer.BitmapEffectLayer; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class Fireball extends BasicView { [Embed(source="assets/3138.jpg")] private var bitmapAsset:Class; public function Fireball() { var headerText:headerContainer = new headerContainer(); headerText.header.text = "Fireball"; addChild(headerText); var bitmapEffectLayer:BitmapEffectLayer = new BitmapEffectLayer(viewport); var bitmap:Bitmap = Bitmap(new bitmapAsset); var material:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData); var sphere:Sphere = new Sphere(material, 100, 10, 10); scene.addChild(sphere); var bitmapFireEffect:BitmapFireEffect = new BitmapFireEffect(10); bitmapEffectLayer.addEffect(bitmapFireEffect); bitmapEffectLayer.addDisplayObject3D(sphere); viewport.containerSprite.addLayer(bitmapEffectLayer); startRendering(); var bezierThrough:Array = []; for(var i:int = 0; i < 10; i++) { var bezierPoint:Object = {}; bezierPoint.x = Math.random() * 2000 - 1000; bezierPoint.y = Math.random() * 2000 - 1000; bezierPoint.z = Math.random() * 1000 - 500; bezierThrough.push(bezierPoint); } TweenMax.to(sphere, 20, {x:1000, y:1000, z:1000, bezierThrough:bezierThrough, yoyo:true, ease:Quad.easeInOut}); } } }
Bumpmap using EnvMapMaterial
OooOOoOOhh pretty.
package { import flash.display.Bitmap; import flash.filters.BlurFilter; import flash.geom.Point; import gs.TweenMax; import gs.easing.Quad; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.materials.shaders.EnvMapShader; import org.papervision3d.materials.shaders.ShadedMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class BumpMapDemo extends BasicView { [Embed(source="assets/3138-bump.jpg")] private var envAsset:Class; [Embed(source="assets/3138.jpg")] private var bumpMapAsset:Class; public function BumpMapDemo() { var headerText:headerContainer = new headerContainer(); headerText.header.text = "Bumpmap Demo: Textures from FilterForge"; addChild(headerText); var light:PointLight3D = new PointLight3D(); light.z = -500; var envBitmap:Bitmap = new envAsset(); var bumpMapBitmap:Bitmap = new bumpMapAsset(); //smooth it out bumpMapBitmap.bitmapData.applyFilter(bumpMapBitmap.bitmapData, bumpMapBitmap.bitmapData.rect, new Point(0,0), new BlurFilter(3,3,3)); var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bumpMapBitmap.bitmapData); var envMapShader:EnvMapShader = new EnvMapShader(light, envBitmap.bitmapData, envBitmap.bitmapData, 0, bumpMapBitmap.bitmapData); var material:ShadedMaterial = new ShadedMaterial(bitmapMaterial, envMapShader); //a nice round sphere var sphere:Sphere = new Sphere(material, 500, 18, 18); scene.addChild(sphere); startRendering(); TweenMax.to(sphere, 10, {localRotationY:360, localRotationX:180, yoyo:true, ease:Quad.easeInOut}); } } }
Switching parents at runtime
This example comes from a conversation I had with Andy. You can actually do a lot of neat tricks by swapping parents, especially when you start rotating the parents.
package { import gs.TweenMax; import org.papervision3d.core.math.Matrix3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class SwitchingParentsAtRuntime extends BasicView { private var parent1:Sphere; private var parent2:Sphere; private var childSphere:Sphere; private var light:PointLight3D; public function SwitchingParentsAtRuntime() { var headerText:headerContainer = new headerContainer(); headerText.header.text = "Click a red sphere to set as parent"; addChild(headerText); viewport.interactive = true; light = new PointLight3D(); var parentMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000); parentMaterial.interactive = true; var childMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0x00cc00); parent1 = new Sphere(parentMaterial, 300, 10, 10); parent1.x = -500; parent1.y = 500; parent1.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, objectPressHandler); parent1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler); parent1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler); parent2 = new Sphere(parentMaterial, 300, 10, 10); parent2.x = 500; parent2.y = -500; parent2.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, objectPressHandler); parent2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler); parent2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler); childSphere = new Sphere(childMaterial, 100, 10, 10); childSphere.name = "child"; scene.addChild(parent1); scene.addChild(parent2); parent1.addChild(childSphere); childSphere.x = 500; TweenMax.to(parent1, 2, {y:-500, yoyo:true}); TweenMax.to(parent2, 2, {y:500, yoyo:true}); startRendering(); } private function objectPressHandler(event:InteractiveScene3DEvent):void { var parentSphere:Sphere = Sphere(event.target); if(childSphere.parent == parentSphere) { //do nothing }else { var childSphereWorldMatrix:Matrix3D = childSphere.world; var inverse:Matrix3D = new Matrix3D(); var tempParentMatrix:Matrix3D = new Matrix3D(); inverse.calculateInverse(parentSphere.world); tempParentMatrix.calculateMultiply(inverse, childSphereWorldMatrix); childSphere.copyTransform(tempParentMatrix); //get the parent of the child to //remove the child from the parent :) childSphere.parent.removeChild(childSphere); parentSphere.addChild(childSphere); } } private function objectOverHandler(event:InteractiveScene3DEvent):void { viewport.buttonMode = true; } private function objectOutHandler(event:InteractiveScene3DEvent):void { viewport.buttonMode = false; } } }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- 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
- Perlin Blob
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
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





