private var body1:DAE; private var body2:DAE; private var bodyOnScene:DAE; //Flags private var isDragging:Boolean = false; private var stats:StatsView; private var morphSlider_breast:Slider; private var morphSlider_waist:Slider; private var morphSlider_pelvis:Slider; private var stateText:TextField; public function MorphTest1() { super(600, 600, false, false, "CAMERA3D"); preparePv3d(); loadAssets(); createObjects(); addControls(); addListeners(); startRendering(); } public function preparePv3d():void { camera.z = -800; camera.zoom = 20; stats = new StatsView(renderer); stage.addChild(stats); } public function loadAssets():void { var daeFile:String = "assets/woman_body_deatached_mat2.DAE"; body1 = new DAE(); body1.load(daeFile); body1.addEventListener(FileLoadEvent.LOAD_PROGRESS, loadProgress); body1.addEventListener(FileLoadEvent.LOAD_COMPLETE, daeLoadComplete); bodyOnScene = new DAE(); bodyOnScene.load(daeFile); bodyOnScene.addEventListener(FileLoadEvent.LOAD_PROGRESS, loadProgress); bodyOnScene.addEventListener(FileLoadEvent.LOAD_COMPLETE, daeLoadComplete); var daeFile2:String = "assets/woman_body_deatached_mat2_max.DAE"; body2 = new DAE(); body2.load(daeFile2); body2.addEventListener(ProgressEvent.PROGRESS, loadProgress); body2.addEventListener(Event.COMPLETE, daeLoadComplete); } public function createObjects():void { bodyOnScene.scale = body1.scale = body2.scale = 30; bodyOnScene.y = -150; bodyOnScene.rotationX = 90; bodyOnScene.rotationY = 30; scene.addChild(bodyOnScene); } public function addControls():void { morphSlider_breast = new Slider(); stage.addChild(morphSlider_breast); morphSlider_breast.y = 100; morphSlider_breast.x = 610; morphSlider_breast.name = "Breast"; morphSlider_waist = new Slider(); stage.addChild(morphSlider_waist); morphSlider_waist.y = 200; morphSlider_waist.x = 610; morphSlider_waist.name = "Waist"; morphSlider_pelvis = new Slider(); stage.addChild(morphSlider_pelvis); morphSlider_pelvis.y = 300; morphSlider_pelvis.x = 610; morphSlider_pelvis.name = "Hips"; morphSlider_breast.liveDragging = morphSlider_waist.liveDragging = morphSlider_pelvis.liveDragging = true; morphSlider_breast.maximum = morphSlider_waist.maximum = morphSlider_pelvis.maximum = 100; morphSlider_breast.minimum = morphSlider_waist.minimum = morphSlider_pelvis.minimum = 0; morphSlider_breast.width = morphSlider_waist.width = morphSlider_pelvis.width = 180; stateText = new TextField(); stateText.autoSize = TextFieldAutoSize.LEFT; var format:TextFormat = new TextFormat("Arial", 10, 0xff00000) stateText.defaultTextFormat = format stage.addChild(stateText) stateText.x = 200; stateText.y = 5; stateText.text = "Loading Collada"; } public function addListeners():void { stage.addEventListener(MouseEvent.MOUSE_DOWN, onPressHandler); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler); morphSlider_breast.addEventListener(SliderEvent.CHANGE, onSliderChangeHandler); morphSlider_waist.addEventListener(SliderEvent.CHANGE, onSliderChangeHandler); morphSlider_pelvis.addEventListener(SliderEvent.CHANGE, onSliderChangeHandler); } public function onPressHandler(event:MouseEvent):void { isDragging = true; } public function onMouseUpHandler(event:MouseEvent):void { isDragging = false; } public function onSliderChangeHandler(event:SliderEvent):void { trace(event.target.name) switch(event.target.name) { case("Breast"): { morphingThing("Breast-node-Node_001", morphSlider_breast.value/100); break; } case("Waist"): { morphingThing("Waist-node-Node_001", morphSlider_waist.value/100); break; } case("Hips"): { morphingThing("Pelvis-node-Node_001", morphSlider_pelvis.value/100); break; } } } public function morphingThing(childname:String, lerpstep:Number) { for (var i:int = 0; i < body1.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices.length; i++) { var v:Vertex3D = bodyOnScene.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i]; v.x = lerp(body1.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i].x, body2.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i].x, lerpstep); v.y = lerp(body1.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i].y, body2.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i].y, lerpstep); v.z = lerp(body1.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i].z, body2.getChildByName("COLLADA_Scene").getChildByName(childname).geometry.vertices[i].z, lerpstep); v.calculateNormal(); } for each(var face:Triangle3D in body1.getChildByName("COLLADA_Scene").getChildByName(childname).faces) face.createNormal(); } override protected function onRenderTick(event:Event=null):void { rotateCamera(); super.onRenderTick(event); } private function rotateCamera():void{ if(isDragging && mouseX < 600){ var x:Number = (stage.mouseX - stage.stageWidth/2) / 4; camera.moveLeft(x); var y:Number = (stage.mouseY - stage.stageHeight/2) / 6; camera.moveDown(y); if (camera.y > 1000 || camera.y < -200) camera.moveDown(-y); } } private function loadProgress(e:FileLoadEvent):void { stateText.text = "Loading Collada: " + Math.floor((e.bytesLoaded / e.bytesTotal) * 100) + "%" + " " +(e.bytesLoaded +"/"+ e.bytesTotal); } private function daeLoadComplete(e:Event):void { stateText.text = "Complete Collada"; } public function lerp(coord1:Number, coord2:Number, lerpstep:Number):Number { return(coord1+(coord2-coord1)*lerpstep); }
28.03.2008. 21:33
Very interesting but not working...
Can you put source package?
(no import, no class extends in your example)
Thanks a lots
Example extends BasicView class of Pv3D
Libs is:
import flash.display.BitmapData;
import flash.display.Displayobject;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.ProgressEvent;
import fl.events.SliderEvent;
import fl.controls.Slider;
import org.papervision3d.core.geom.renderables.Triangle3D;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.objects.Displayobject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.view.BasicView;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.view.stats.StatsView;
enjoy :)
yes thanks,
I have problem with slider, but it's okay (I have create personnal slider with movieclip).
But I can't export good model with 3dsmax. I used multiverse export, but not working.
Can you says me how we have do this? (sorry for my very very bad english...)
When export collada from 3dsmax, be sure to check:
Triangulate
Bake matrices
It better do with Feeling Software ColladaMax Plug-in http://www.feelingsoftware.com
Thank you for the posts and sharing!
And also I'm very puzzled that how I can set my collada model with the child node
"..." which is able to be modified in flash?
my xx.dae childnode is like this, but without any vertices able to modified..
Can you give me a little help about it?
//----------------------------------------
-7.93588e-007 1.92647e-006 0.498984
4.37114e-008 1 4.37114e-008 -180
0.0155011 0.0164224 0.0180208
5.75164e-005 270.993 -0.000267029
//----------------------------------------
lync,
Perhaps you incorrectly address to the child...
when you loaded DAE or Collada you can see traces like this:
INFO: Displayobject3D: Cube
if DAE use:
myDae.getChildByName("COLLADA_Scene").getChildByName("Cube").geometry.vertices[0].x = 500
to access first vertex, or if Collada just:
myCollada.getChildByName("Cube").geometry.vertices[0].x = 500
Where can I download this?
Write a comment
* = required field