Triangle3D
TriangleMesh3D – Create your own mesh
This shows you how to make little baby triangles. If you put enough of these together with the proper coordinates and rotations, you could make a Tyrannosaurs Rex!
package { import flash.events.Event; import org.papervision3d.core.geom.TriangleMesh3D; import org.papervision3d.core.geom.renderables.Triangle3D; import org.papervision3d.core.geom.renderables.Vertex3D; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class TriangleMesh3DExample extends BasicView { private var triangleMesh3d:TriangleMesh3D; public function TriangleMesh3DExample() { var material:ColorMaterial = new ColorMaterial(0xcc0000); material.doubleSided = true; //all the 200's are points of a triangle var vertex3D_1:Vertex3D = new Vertex3D(-200, -200, 0); var vertex3D_2:Vertex3D = new Vertex3D(200, -200, 0); var vertex3D_3:Vertex3D = new Vertex3D(-200, 200, 0); var triangleVertices:Array = [vertex3D_1, vertex3D_2, vertex3D_3]; //use null because we haven't created its parent mesh yet var triangle3d:Triangle3D = new Triangle3D(null, triangleVertices, material); var triangleFaces:Array = [triangle3d]; triangleMesh3d = new TriangleMesh3D(material, triangleVertices, triangleFaces, null); //for the triangle to be "renderable", it needs to know who its daddy is //this is the same property as the "null" parameter a few lines above triangle3d.instance = triangleMesh3d; scene.addChild(triangleMesh3d); startRendering(); } override protected function onRenderTick(event:Event=null):void { triangleMesh3d.rotationY = -viewport.containerSprite.mouseX / 2; super.onRenderTick(event); } } }
Swapping materials on faces
I starting playing around with the last post and got this:
package { import flash.display.BitmapData; import flash.events.Event; import flash.geom.ColorTransform; import flash.geom.Rectangle; import org.papervision3d.core.geom.renderables.Triangle3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.materials.BitmapColorMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class SwappingMaterialsOnFaces extends BasicView { private const WHITE:uint = 4294967295; private const COLOR:uint = 0x141414; private var whiteMaterial:BitmapColorMaterial; private var sphere:Sphere private var rect:Rectangle; private var whiteColorTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 3, 3, 7); private var bitmaps:Array = []; private var currentFace3d:Triangle3D = null; public function SwappingMaterialsOnFaces() { viewport.interactive = true; whiteMaterial = new BitmapColorMaterial(0xffffff); whiteMaterial.interactive = true; sphere = new Sphere(whiteMaterial, 500, 30, 20); sphere.addEventListener(InteractiveScene3DEvent.OBJECT_MOVE, sphere_objectMoveHandler); scene.addChild(sphere); rect = whiteMaterial.bitmap.rect; startRendering(); } private function sphere_objectMoveHandler(event:InteractiveScene3DEvent):void { if(currentFace3d != event.face3d) { var bitmapMaterial:BitmapColorMaterial = new BitmapColorMaterial(COLOR);; bitmapMaterial.interactive = true; event.face3d.material = bitmapMaterial; bitmaps.push(event.face3d.material.bitmap); currentFace3d = event.face3d; } } override protected function onRenderTick(event:Event=null):void { sphere.rotationY += .3; for(var i:int = 0; i < bitmaps.length; i++) { if(BitmapData(bitmaps[i]).getPixel32(0,0) != WHITE) { BitmapData(bitmaps[i]).colorTransform(rect, whiteColorTransform); }else { bitmaps.splice(i, 1); } } renderer.renderScene(scene, camera, viewport); } } }
Per Face Material
package { import flash.events.Event; import org.papervision3d.core.geom.renderables.Triangle3D; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#ffffff", frameRate="60")] public class PerFaceMaterial extends BasicView { private var sphere:Sphere public function PerFaceMaterial() { sphere = new Sphere(null, 400, 30, 20); for each(var face:Triangle3D in sphere.geometry.faces) { var color:Number = Math.random() * 0xffffff; face.material = new ColorMaterial(color); } scene.addChild(sphere); startRendering(); } override protected function onRenderTick(event:Event=null):void { sphere.rotationY += .3; renderer.renderScene(scene, camera, viewport); } } }
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
- 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
Recent Comments
- software akuntansi terbaik on Back in the saddle
- loan rates on Augmented Reality – Recursive Webcam
- loan rates on Looking around the inside of a Sphere
- reverse phone lookup on Looking around the inside of a Sphere
- Oidhreachta on The Spotlight Effect (Dimming the unselected)
- Hosting company on archive
- aanbae on Back in the saddle
- Domain registration on Looking around the inside of a Sphere
- website designing company on Looking around the inside of a Sphere
- Honda Motor on Augmented Reality – Recursive Webcam
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 | ||||
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




