material
Cube with different sides – MaterialsList
package { import flash.display.Bitmap; import flash.events.Event; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.materials.shaders.PhongShader; import org.papervision3d.materials.shaders.ShadedMaterial; import org.papervision3d.materials.shaders.Shader; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.primitives.Cube; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class CubeWithDifferentSides extends BasicView { [Embed(source="assets/back.jpg")] private var backAsset:Class; [Embed(source="assets/bottom.jpg")] private var bottomAsset:Class; [Embed(source="assets/front.jpg")] private var frontAsset:Class; [Embed(source="assets/left.jpg")] private var leftAsset:Class; [Embed(source="assets/right.jpg")] private var rightAsset:Class; [Embed(source="assets/top.jpg")] private var topAsset:Class; private var light:PointLight3D; private var cube:Cube; public function CubeWithDifferentSides() { var materialsList:MaterialsList = new MaterialsList(); light = new PointLight3D(); materialsList.addMaterial(createShadedMaterial( new backAsset() ), "back"); materialsList.addMaterial(createShadedMaterial( new bottomAsset() ), "bottom"); materialsList.addMaterial(createShadedMaterial( new frontAsset() ), "front"); materialsList.addMaterial(createShadedMaterial( new leftAsset() ), "left"); materialsList.addMaterial(createShadedMaterial( new rightAsset() ), "right"); materialsList.addMaterial(createShadedMaterial( new topAsset() ), "top"); cube = new Cube(materialsList, 500, 500, 500, 5, 5, 5); scene.addChild(cube); startRendering(); } private function createShadedMaterial(bitmap:Bitmap):ShadedMaterial { var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData, true); var shader:Shader = new PhongShader(light, 0xffffff, 0x333333, 10, bitmap.bitmapData, bitmap.bitmapData); var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader); return shadedMaterial; } override protected function onRenderTick(event:Event=null):void { cube.rotationY += (viewport.containerSprite.mouseX - cube.rotationY) * .1; cube.rotationX += (viewport.containerSprite.mouseY - cube.rotationX) * .1; renderer.renderScene(scene, camera, viewport); } } }
Shaders / ShadedMaterial Example
package { import flash.display.Bitmap; import flash.events.Event; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.materials.shaders.PhongShader; import org.papervision3d.materials.shaders.ShadedMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class ShadersExample extends BasicView { [Embed(source="assets/santa.jpg")] private var santaAsset:Class; private var plane:Plane; public function ShadersExample() { camera.z = -500; var santaBitmap:Bitmap = new santaAsset() as Bitmap; var light:PointLight3D = new PointLight3D(); var bitmapMaterial:BitmapMaterial = new BitmapMaterial(santaBitmap.bitmapData, true); var shader:PhongShader = new PhongShader(light, 0xffffff, 0x000000, 10); var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader); shadedMaterial.doubleSided = true; plane = new Plane(shadedMaterial); scene.addChild(plane); startRendering(); } override protected function onRenderTick(event:Event=null):void { plane.rotationY = viewport.containerSprite.mouseX / 4; 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
- Katie on Augmented Reality – Recursive Webcam
- 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
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





