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); } } }
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
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


