snippets
Papervision3D in MXML
This falls under the “just because I can” category
Just copy and paste this code into any Flex project with the Papervision3D.swc in the libs and you’re good to go!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?xml version="1.0" encoding="utf-8"?> <view:BasicView xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:view="org.papervision3d.view.*" xmlns:scenes="org.papervision3d.scenes.*" xmlns:primitives="org.papervision3d.objects.primitives.*" xmlns:materials="org.papervision3d.materials.*" opaqueBackground="#ffffff" added="startRendering();" > <view:scene> <scenes:Scene3D> <scenes:objects> <primitives:Sphere x="300"> <primitives:material> <materials:ColorMaterial fillColor="0xcc0000"/> </primitives:material> </primitives:Sphere> </scenes:objects> </scenes:Scene3D> </view:scene> </view:BasicView> |
Carousel with Forward Facing Planes
Yes, it’s another Carousel post, but people just seem to keep on asking for them.
Instead of going through all the trig, I just used the handy Casa Lib for the circle management. There are some other great utility classes with Casa, so make sure to check it out.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package { import flash.events.Event; import flash.geom.Point; import org.casalib.math.geom.Ellipse; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; [SWF(width="900", height="480", backgroundColor="#ffffff", frameRate="60")] public class CarouselWithForwardPlanes extends BasicView { private static const NUM_PLANES:int = 10; private static const RADIUS:Number = 600; private var diameter:Number = RADIUS * 2; //defines the carousel (thanks to CASA) private var circle:Ellipse = new Ellipse(-RADIUS, -RADIUS, diameter, diameter); private var planes:Array = []; public function CarouselWithForwardPlanes() { for(var i:int = 0; i < NUM_PLANES; i++) { var color:Number = Math.random() * 0xffffff; var colorMaterial:ColorMaterial = new ColorMaterial(color); var plane:Plane = new Plane(colorMaterial, 150, 150); //get the x and y (or z) point based on the current index var point:Point = circle.getPointOfDegree(360 / NUM_PLANES * i); plane.x = point.x; plane.z = point.y; planes.push(plane); scene.addChild(plane); } startRendering(); } override protected function onRenderTick(event:Event = null):void { var n:int = 0; for each(var plane:Plane in planes) { var degrees:Number = 360 / NUM_PLANES * n; var mouseDegrees:Number = viewport.containerSprite.mouseX / 2; var totalDegrees:Number = degrees + mouseDegrees; var point:Point = circle.getPointOfDegree(totalDegrees); plane.x = point.x; plane.z = point.y; n++; } super.onRenderTick(event); } } } |
Distance between two Number3Ds
var n1:Number3D = new Number3D(500, 0, 0); var n2:Number3D = new Number3D(0, 0, 500); var distance:Number = Number3D.sub(n1, n2).modulo;
Adding a BasicView to a Flex UIComponent
While I would always encourage to separate your code into separate classes to follow best OOP practices, the example below will “get the job done”.
Since the Flex framework is based off UIComponents and you can’t directly add Sprites (or BasicViews) to a UIComponent, you have to dig into the UIComponents rawChildren (meaning Sprites) to add Papervision3D.
<?xml version="1.0" encoding="utf-8"?> <mx:Application width="640" height="480" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="applicationComplete()"> <mx:Script> <![CDATA[ /* There are two similar methods: 1. using rawChildren 2. using $addChild with the mx_interal namespace Method #2 is commented out below */ // use namespace mx_internal; //method #2 import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; private function applicationComplete():void { var basicView:BasicView = new BasicView(); var sphere:Sphere = new Sphere(); basicView.scene.addChild(sphere); basicView.startRendering(); pv3dPanel.rawChildren.addChild(basicView); //method #1 // pv3dPanel.$addChild(basicView); //method #2 } ]]> </mx:Script> <mx:Panel id="pv3dPanel" title="Papervision3D Panel" width="640" height="480"/> </mx:Application>
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- 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
Recent Comments
- Xdragosy on Ribbons
- As on What is BasicView?
- Godie_dito on Dynamic Text on a Plane
- Angel Kaido on Following line
- bambii7 on faq
- Felipe on TweenMax – Tweening a timeline (Advanced Tweening)
- Ocatarinabelachichix on about
- Rajiv on faq
- Rajiv on 3ds max texture baking for Papervision3D
- Anupam Biswas on Maya Texture Baking
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « May | ||||||
| 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 | |||
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

