Hi, Might be a set of noob problems, but here goes...
I'm excited to find the Jeep3DSTest tech demo, http://www.infiniteturtles.co.uk/projects/away3d/demos/Jeep3DSTest/Jeep3DSTest.html since I'm starting on a project that requires loading 3DS models and building variations on rotation interaction. I've run into the following problems, however, that have me scratching my head... Version 1.9.4 It appears from the original import statements in Jeep3DSTest source that the demo was built for the 1.9.4 release at the latest. The 2.x releases have a different package hierarchy. If I run the demo using 1.9.4, the following problems arise: - after a medium to large number of rotations (say from 25 to 100), the distance between the camera and the model either increases to infinity, or decreases to 0 Version 2.2 (trunk) After some modification to the import statements, I can run the same Jeep3DSTest demo using a 2.x library. However, then the following problems arise: - the maxX (and minX), maxY (and minY), and maxZ (and minZ) functions return different values than under the 1.9.4 library. The numbers appear suspect to me, as they are equidistant from zero in each axis, *and* they are all the same value implying the model is a cube-- which on inspection and in comparison to 1.9.4 values it is not. - the pivotPoint function returns a value of 0,0,0, which after the model loads seems incorrect as well, as the pivotPoint (for rotation, anyway) is actually under the rear axle of the model - the initial reorienting attempt using rotationX and rotationY functions, which worked in 1.9.4, do not appear to have an effect in the 2.x library To see these issues in action, please refer to the two versions of Jeep3DSTest below, with modifications to "trace" the values in question (and to avoid compiler warnings about "onMouseDown" handler naming...) Any assistance or guidance is much appreciated. slhenty *************************** [Jeep3DSTest_A3D_1.9.4, referenced as the document class in an 800x600 .fla stage file] package { import away3d.core.material.*; import away3d.core.math.Number3D; import away3d.core.render.*; import away3d.core.scene.*; import away3d.loaders.*; import away3d.objects.*; //import com.adobe.viewsource.ViewSource; import flash.display.*; import flash.events.*; [SWF(backgroundColor="#222266", frameRate="30")]; public class Jeep3DSTest_A3D_1_9_4 extends Sprite { //[Embed(source="images/signature.swf")] //public static var SignatureSwf:Class //public var Signature:MovieClip; public var view:View3D; public var jeep:Object3DLoader; public var pan:Boolean; /** * Constructor */ public function Jeep3DSTest_A3D_1_9_4() { //setup stage stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; //include right-click viewsource //ViewSource.addMenuItem(this, "srcview/index.html"); //setup view view = new View3D(); addChild(view); jeep = Max3DS.load("images/jeep1.3ds", {texturePath:"images/", name:"jeep", loadersize:100}); jeep.rotationX = -68; jeep.rotationZ = 180; jeep.addOnSuccess(initJeep); view.scene.addChild(jeep); //setup signature //Signature = MovieClip(new SignatureSwf()); //addChild(Signature); //setup listeners //stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); stage.addEventListener(Event.ENTER_FRAME, handleEnterFrame); //stage.addEventListener(Event.RESIZE, onResize); stage.addEventListener(Event.RESIZE, handleResize); //stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); stage.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown); //stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp); handleResize(null); } /** * DEBUG: notify of load success */ public function loadSuccess(event:Event):void { trace("load SUCCESS"); initJeep(event); } /** * DEBUG: notify of load error */ public function loadError(event:Event):void { trace("load ERROR"); } /** * format jeep after loading */ public function initJeep(event:Event):void { //scale trace("Before scaling..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); jeep.handle.scale(10); trace("After scaling..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); //adjust internal coords (jeep.handle as ObjectContainer3D).movePivot((jeep.handle.maxX + jeep.handle.minX)/2, (jeep.handle.maxY + jeep.handle.minY)/2, (jeep.handle.maxZ + jeep.handle.minZ)/2); trace("After movePivot..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); //recenter jeep.handle.x = jeep.handle.y = jeep.handle.z = 0; trace("After recenter..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); } public var lastMouseX:Number = 0; public var lastMouseY:Number = 0; public var zeroPosition:Number3D = new Number3D(0, 0, 0); /** * enterframe handler */ //public function onEnterFrame(event:Event):void public function handleEnterFrame(event:Event):void { view.camera.moveTo(zeroPosition); if (pan) { view.camera.pan(-0.3*(lastMouseX - stage.mouseX)); view.camera.tilt(-0.3*(lastMouseY - stage.mouseY)); } lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; view.camera.moveBackward(400); if (pan) { trace("distance to center: " + view.camera.distanceTo(jeep)); } view.render(); } /** * resize handler */ //private function onResize(event:Event):void private function handleResize(event:Event):void { view.x = stage.stageWidth/2; view.y = stage.stageHeight/2; //Signature.y = stage.stageHeight - Signature.height; } /** * mousedown handler */ //private function onMouseDown(event:MouseEvent):void private function handleMouseDown(event:MouseEvent):void { //initialise mouse movement lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; pan = true; //stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); stage.addEventListener(Event.MOUSE_LEAVE, handleStageMouseLeave); } /** * mouseup handler */ //private function onMouseUp(event:MouseEvent):void private function handleMouseUp(event:MouseEvent):void { pan = false; //stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); stage.removeEventListener(Event.MOUSE_LEAVE, handleStageMouseLeave); } /** * mouseleave handler (to prevent sticking mouse buttons) */ //private function onStageMouseLeave(event:Event):void private function handleStageMouseLeave(event:Event):void { pan = false; //stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); stage.removeEventListener(Event.MOUSE_LEAVE, handleStageMouseLeave); } } } *************************** [Jeep3DSTest_A3D_2.2, referenced as the document class in an 800x600 .fla stage file] package { //import away3d.core.material.*; import away3d.materials.*; import away3d.core.math.Number3D; import away3d.core.render.*; //import away3d.core.scene.*; import away3d.containers.*; import away3d.loaders.*; //import away3d.objects.*; //import com.adobe.viewsource.ViewSource; import flash.display.*; import flash.events.*; [SWF(backgroundColor="#222266", frameRate="30")] public class Jeep3DSTest_A3D_2_2 extends Sprite { //[Embed(source="images/signature.swf")] //public static var SignatureSwf:Class //public var Signature:MovieClip; public var view:View3D; public var jeep:Object3DLoader; public var pan:Boolean; /** * Constructor */ public function Jeep3DSTest_A3D_2_2() { //setup stage stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; //include right-click viewsource //ViewSource.addMenuItem(this, "srcview/index.html"); //setup view view = new View3D(); addChild(view); jeep = Max3DS.load("images/jeep1.3ds", {texturePath:"images/", name:"jeep", loadersize:100}); // jeep.addOnSuccess(loadSuccess); // jeep.addOnError(loadError); jeep.rotationX = -68; jeep.rotationZ = 180; jeep.addOnSuccess(initJeep); view.scene.addChild(jeep); //setup signature //Signature = MovieClip(new SignatureSwf()); //addChild(Signature); //setup listeners //stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); stage.addEventListener(Event.ENTER_FRAME, handleEnterFrame); //stage.addEventListener(Event.RESIZE, onResize); stage.addEventListener(Event.RESIZE, handleResize); //stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); stage.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown); //stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp); handleResize(null); } /** * DEBUG: notify of load success */ public function loadSuccess(event:Event):void { trace("load SUCCESS"); initJeep(event); } /** * DEBUG: notify of load error */ public function loadError(event:Event):void { trace("load ERROR"); } /** * format jeep after loading */ public function initJeep(event:Event):void { //scale trace("Before scaling..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); trace("pivotPoint x, y, z: " + jeep.handle.pivotPoint.x + ", " + jeep.pivotPoint.y + ", " + jeep.pivotPoint.z); jeep.handle.scale(10); trace("After scaling..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); trace("pivotPoint x, y, z: " + jeep.handle.pivotPoint.x + ", " + jeep.pivotPoint.y + ", " + jeep.pivotPoint.z); //adjust internal coords (jeep.handle as ObjectContainer3D).movePivot((jeep.maxX + jeep.minX)/2, (jeep.maxY + jeep.minY)/2, (jeep.maxZ + jeep.minZ)/2); trace("After movePivot..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); trace("pivotPoint x, y, z: " + jeep.handle.pivotPoint.x + ", " + jeep.pivotPoint.y + ", " + jeep.pivotPoint.z); //recenter jeep.handle.x = jeep.handle.y = jeep.handle.z = 0; trace("After recenter..."); trace("Max x, y, z: " + jeep.handle.maxX + ", " + jeep.handle.maxY + ", " + jeep.handle.maxZ); trace("Min x, y, z: " + jeep.handle.minX + ", " + jeep.handle.minY + ", " + jeep.handle.minZ); trace("pivotPoint x, y, z: " + jeep.handle.pivotPoint.x + ", " + jeep.pivotPoint.y + ", " + jeep.pivotPoint.z); } public var lastMouseX:Number = 0; public var lastMouseY:Number = 0; public var zeroPosition:Number3D = new Number3D(0, 0, 0); /** * enterframe handler */ //public function onEnterFrame(event:Event):void public function handleEnterFrame(event:Event):void { view.camera.moveTo(zeroPosition.x, zeroPosition.y, zeroPosition.z); if (pan) { view.camera.pan(-0.3*(lastMouseX - stage.mouseX)); view.camera.tilt(-0.3*(lastMouseY - stage.mouseY)); } lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; view.camera.moveBackward(400); if (pan) { trace("distance to center: " + view.camera.distanceTo(jeep)); } view.render(); } /** * resize handler */ //private function onResize(event:Event):void private function handleResize(event:Event):void { view.x = stage.stageWidth/2; view.y = stage.stageHeight/2; //Signature.y = stage.stageHeight - Signature.height; } /** * mousedown handler */ //private function onMouseDown(event:MouseEvent):void private function handleMouseDown(event:MouseEvent):void { //initialise mouse movement lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; pan = true; //stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); stage.addEventListener(Event.MOUSE_LEAVE, handleStageMouseLeave); } /** * mouseup handler */ //private function onMouseUp(event:MouseEvent):void private function handleMouseUp(event:MouseEvent):void { pan = false; //stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); stage.removeEventListener(Event.MOUSE_LEAVE, handleStageMouseLeave); } /** * mouseleave handler (to prevent sticking mouse buttons) */ //private function onStageMouseLeave(event:Event):void private function handleStageMouseLeave(event:Event):void { pan = false; //stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); stage.removeEventListener(Event.MOUSE_LEAVE, handleStageMouseLeave); } } }
