Switching a MovieMaterial on the face of a Cube – replaceMaterialByName
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import org.papervision3d.materials.MovieMaterial; 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 SwitchingMovieMaterialsOnACube extends BasicView { private var cube:Cube; private var currentAsset:Class = blueBoxAsset; public function SwitchingMovieMaterialsOnACube() { var materialsList:MaterialsList = new MaterialsList(); //blueBoxAsset is the classname of the movie from the library in the MovieMaterials .swc //you have to create a new material for each side or the materialsList will replace all //the materials when you try to replace one side materialsList.addMaterial(createMovieMaterialFromAsset(blueBoxAsset), "front"); materialsList.addMaterial(createMovieMaterialFromAsset(blueBoxAsset), "back"); materialsList.addMaterial(createMovieMaterialFromAsset(blueBoxAsset), "left"); materialsList.addMaterial(createMovieMaterialFromAsset(blueBoxAsset), "right"); materialsList.addMaterial(createMovieMaterialFromAsset(blueBoxAsset), "top"); materialsList.addMaterial(createMovieMaterialFromAsset(blueBoxAsset), "bottom"); cube = new Cube(materialsList); scene.addChild(cube); startRendering(); stage.addEventListener(MouseEvent.CLICK, stage_clickHandler); } //Creates a MovieMaterial based on a class reference //in this case, movieClips in the .swc private function createMovieMaterialFromAsset(asset:Class):MovieMaterial { var movieAsset:MovieClip = MovieClip(new asset()); var movieMaterial:MovieMaterial = new MovieMaterial(movieAsset, true, true, true); movieMaterial.doubleSided = true; return movieMaterial; } private function stage_clickHandler(event:MouseEvent):void { var movieMaterial:MovieMaterial; if(currentAsset == blueBoxAsset) { movieMaterial = createMovieMaterialFromAsset(redBoxAsset); currentAsset = redBoxAsset; } else { movieMaterial = createMovieMaterialFromAsset(blueBoxAsset); currentAsset = blueBoxAsset; } //since the camera defaults to -1000 z, the "back" is the "front" cube.replaceMaterialByName(movieMaterial, "back"); } override protected function onRenderTick(event:Event = null):void { cube.rotationX += (viewport.containerSprite.mouseY * .25 - cube.rotationX) * .1; cube.rotationY += (viewport.containerSprite.mouseX * .25- cube.rotationY) * .1; super.onRenderTick(event); } } }
-
John Lindquist
-
Izaias
-
mateus
-
psych
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
- list of lpn courses on SpringCamera3D and Driving a Car
- rn to bsn in montgomery al on archive
- PowerPoint Recovery on Eclipse Theme Designer Preview
- cheat mw3 on Test if a plane is within the view of the camera (aka testing if culled)
- Goa Hotels on Looking around the inside of a Sphere
- cheat gratuit on Looking around the inside of a Sphere
- Application Development on Robotlegs + Flight + Union Platform
- nexium on Moving Faces
- buy nexium on Holy Sphere
- buy aldara online on Tweening a “moveForward()” behavior
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


