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); } } }
No comments yet.
Leave a comment
Search
Recent Posts
- 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
- Dynamic Text on a Plane
- Maya Texture Baking
- Creating a Custom VectorVision Font
- Workshop video and example dump
- 3D Math Book Recommendation
- Heading to New York. brb ;)
- Launching Flex4.org
- Flex 4 Layouts and Groups
- Flex 4 States
- How to click on stuff in Papervision3D - Viewport, ViewportLayers, InteractiveScene3DEvent, Mouse3D, and MovieMaterial Buttons
Recent Comments
- alexxcz on MorphController - Mighty Morphing Papervision3D
- andre venancio on 3D Math Book Recommendation
- DS on Dynamic Text on a Plane
- John Lindquist on Maya Texture Baking
- Itai on Maya Texture Baking
- Javier on End dump
- samBrown on End dump
- tf on archive
- Pan on requests
- Martin Lindelöf on requests

