Revision: 25245
Updated Code
at March 24, 2010 09:42 by LeeProbert
Updated Code
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.geom.Rectangle; import org.papervision3d.events.FileLoadEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapColorMaterial; import org.papervision3d.materials.BitmapFileMaterial; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.shadematerials.GouraudMaterial; import org.papervision3d.materials.shadematerials.PhongMaterial; import org.papervision3d.materials.shaders.GouraudShader; import org.papervision3d.materials.shaders.PhongShader; import org.papervision3d.materials.shaders.ShadedMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.parsers.DAE; import org.papervision3d.objects.primitives.Cube; import org.papervision3d.objects.primitives.PaperPlane; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; public class ShirtModelView extends BasicView { private var model:DAE; private var light:PointLight3D; private var angle:Number = 0; private var distance:Number = 250; private var speed:Number = 0.2; private var rangeX:Number = 0.02; private var rangeY:Number = 0.02; private var rangeZ:Number = 0.05; private var targetRotationX:Number = 0; [Embed(source="uv-map-MEDIUM.png")] [Bindable] public var uvMap:Class; protected var cube:Cube; //------------------------------------------------------------------------------- public function ShirtModelView() { super(0,0,true); loadModel("t-shirt_with_material_and_uv.dae"); //_camera.zoom = 1000 / _camera.focus + 1; //camera.far = camera.far *4; //camera.useCulling = false; light = new PointLight3D(); light.z = -200; light.y = 300; scene.addChild(light); /*var cubeMaterials:MaterialsList = new MaterialsList(); var colorMaterial:ColorMaterial = new ColorMaterial(0xff0000,0.5); colorMaterial.doubleSided = true; cubeMaterials.addMaterial(colorMaterial,"all"); cube = new Cube(cubeMaterials,500,500,500); scene.addChild(cube); camera.target = cube;*/ startRendering(); } //------------------------------------------------------------------------------- private function loadModel(path:String) : void { model = new DAE(false,"model"); var mlist:MaterialsList = new MaterialsList(); var bitmapMaterial:BitmapMaterial = new BitmapMaterial(Bitmap(new uvMap()).bitmapData); bitmapMaterial.smooth = true; var shader:GouraudShader = new GouraudShader(light,0xffffff,0x000000,10); var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial,shader); //var shader:PhongShader = new PhongShader(light,0xffffff,0x333333,25); //var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial,shader); mlist.addMaterial(shadedMaterial,"teamkit-uv-map_jp"); //* model.load(path,mlist); model.addEventListener(FileLoadEvent.LOAD_COMPLETE, modelLoaded); //model.culled = false; //*/ } //------------------------------------------------------------------------------- private function modelLoaded(event : FileLoadEvent) : void { trace("materials:"+model.materials); light.lookAt(model); model.scaleX = model.scaleY = model.scaleZ = 5; /* var bmpData:BitmapData = model.getMaterialByName("teamkit-uv-map_jp").bitmap; bmpData.fillRect(new Rectangle(10,10,200,200),0xff0000); */ scene.addChild(model); camera.target = model; } //------------------------------------------------------------------------------- override protected function onRenderTick(e:Event=null):void { model.yaw(0.1); //cube.yaw(0.5); //* camera.x += (mouseX - (stage.stageWidth * 0.5) - (camera.x * rangeX)) * speed; camera.y += (mouseY- (stage.stageHeight * 0.5) - (camera.y * rangeY)) * speed; camera.z += ((-mouseY * 2) - camera.z ) * rangeZ; camera.moveForward(camera.distanceTo(model) - distance); //*/ super.onRenderTick(e); } } }
Revision: 25244
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 24, 2010 09:41 by LeeProbert
Initial Code
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.geom.Rectangle; import org.papervision3d.events.FileLoadEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapColorMaterial; import org.papervision3d.materials.BitmapFileMaterial; import org.papervision3d.materials.BitmapMaterial; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.shadematerials.GouraudMaterial; import org.papervision3d.materials.shadematerials.PhongMaterial; import org.papervision3d.materials.shaders.GouraudShader; import org.papervision3d.materials.shaders.PhongShader; import org.papervision3d.materials.shaders.ShadedMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.parsers.DAE; import org.papervision3d.objects.primitives.Cube; import org.papervision3d.objects.primitives.PaperPlane; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; public class ShirtModelView extends BasicView { private var model:DAE; private var light:PointLight3D; private var angle:Number = 0; private var distance:Number = 250; private var speed:Number = 0.2; private var rangeX:Number = 0.02; private var rangeY:Number = 0.02; private var rangeZ:Number = 0.05; private var targetRotationX:Number = 0; [Embed(source="uv-map-MEDIUM.png")] [Bindable] public var uvMap:Class; protected var cube:Cube; //------------------------------------------------------------------------------- public function ShirtModelView() { super(0,0,true); loadModel("t-shirt_with_material_and_uv.dae"); //_camera.zoom = 1000 / _camera.focus + 1; //camera.far = camera.far *4; //camera.useCulling = false; light = new PointLight3D(); light.z = -200; light.y = 300; scene.addChild(light); /*var cubeMaterials:MaterialsList = new MaterialsList(); var colorMaterial:ColorMaterial = new ColorMaterial(0xff0000,0.5); colorMaterial.doubleSided = true; cubeMaterials.addMaterial(colorMaterial,"all"); cube = new Cube(cubeMaterials,500,500,500); scene.addChild(cube); camera.target = cube;*/ startRendering(); } //------------------------------------------------------------------------------- private function loadModel(path:String) : void { model = new DAE(false,"model"); var mlist:MaterialsList = new MaterialsList(); var bitmapMaterial:BitmapMaterial = new BitmapMaterial(Bitmap(new uvMap()).bitmapData); bitmapMaterial.smooth = true; var shader:GouraudShader = new GouraudShader(light,0xffffff,0x000000,10); var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial,shader); //var shader:PhongShader = new PhongShader(light,0xffffff,0x333333,25); //var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial,shader); mlist.addMaterial(shadedMaterial,"teamkit-uv-map_jp"); //* model.load(path,mlist); model.addEventListener(FileLoadEvent.LOAD_COMPLETE, modelLoaded); //model.culled = false; //*/ } //------------------------------------------------------------------------------- private function modelLoaded(event : FileLoadEvent) : void { trace("materials:"+model.materials); light.lookAt(model); model.scaleX = model.scaleY = model.scaleZ = 5; /* var bmpData:BitmapData = model.getMaterialByName("teamkit-uv-map_jp").bitmap; bmpData.fillRect(new Rectangle(10,10,200,200),0xff0000); */ scene.addChild(model); camera.target = model; } //------------------------------------------------------------------------------- override protected function onRenderTick(e:Event=null):void { model.yaw(0.1); //cube.yaw(0.5); //* camera.x += (mouseX - (stage.stageWidth * 0.5) - (camera.x * rangeX)) * speed; camera.y += (mouseY- (stage.stageHeight * 0.5) - (camera.y * rangeY)) * speed; camera.z += ((-mouseY * 2) - camera.z ) * rangeZ; camera.moveForward(camera.distanceTo(model) - distance); //*/ super.onRenderTick(e); } } }
Initial URL
Initial Description
Initial Title
Import DAE and add external file as material
Initial Tags
textmate
Initial Language
ActionScript 3