Archive for January 2nd, 2009
Cube Inside Faces and Outside Faces
*updated to address comments
package { import flash.display.Bitmap; import flash.events.Event; import flash.events.MouseEvent; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.materials.shaders.CellShader; 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; import org.papervision3d.view.stats.StatsView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class InsideFacesOfACube 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; [Embed(source="assets/287.jpg")] private var environmentAsset:Class; private var light:PointLight3D; private var cube:Cube; private var materialsList:MaterialsList; private var sides:int = Cube.ALL; public function InsideFacesOfACube() { createMaterialsList(); cube = new Cube(materialsList, 500, 500, 500, 5, 5, 5, sides); scene.addChild(cube); startRendering(); stage.addEventListener(MouseEvent.CLICK, stage_clickHandler); } private function createMaterialsList():void { materialsList = new MaterialsList(); light = new PointLight3D(); materialsList.addMaterial(createShadedMaterial(backAsset), "back"); materialsList.addMaterial(createShadedMaterial(bottomAsset), "bottom"); materialsList.addMaterial(createShadedMaterial(frontAsset), "front"); materialsList.addMaterial(createShadedMaterial(leftAsset), "left"); materialsList.addMaterial(createShadedMaterial(rightAsset), "right"); materialsList.addMaterial(createShadedMaterial(topAsset), "top"); } private function createShadedMaterial(bitmapAsset:Class):MaterialObject3D { var bitmap:Bitmap = new bitmapAsset() as Bitmap; var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData, true); var shader:Shader = new CellShader(light, 0xffffff, 0xaaaaaa, 10); var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader); return shadedMaterial; } private function stage_clickHandler(event:MouseEvent):void { if(sides == Cube.ALL) { sides = Cube.NONE; } else { //you could also specify specific sides you want //i.e. - if you want every side but the front do: //sides = Cube.ALL - Cube.Front; //or if you only want the top and the bottom do: //sides = Cube.TOP + Cube.BOTTOM; sides = Cube.ALL; } scene.removeChild(cube); createMaterialsList(); var tempRotationX:Number = cube.rotationX; var tempRotationY:Number = cube.rotationY; cube = new Cube(materialsList, 500, 500, 500, 5, 5, 5, sides); cube.rotationX = tempRotationX; cube.rotationY = tempRotationY; scene.addChild(cube); } 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); } } }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- 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
- End dump
- Test if a plane is within the view of the camera (aka testing if culled)
- Materials Reference
- Perlin Blob
Recent Comments
- BAM5 on haXe Tutorial
- AlexG on Finding 2D Coordinates of a DisplayObject3D
- Josh on ActionScript 3 – Model View Controller (MVC)
- martin everett on requests
- martin everett on requests
- lillacska on Dragging Spheres
- Guy Ritchie on MXML without the Flex framework
- Pedro on ActionScript 3 – Namespaces
- daveevolve on AS3DMod Perlin Noise
- sebomoto on haXe Tutorial
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


