Thanks, I'll do so
On Jan 27, 8:22 pm, Fabrice3D <[email protected]> wrote: > I do not have the time to test your code atm, but looking at your code, I see > few glitches... > > You feed the Path with Number3D's while its supposed to be Vector3D > same applies to your init object where offset is as Number3D instead of > Vector3D > property aligntoPath should be alignToPath. > The jpg embed, why is it static? > > aside your main problem I do see lines such as horseMesh = new Mesh(); > and next like its equal to the handle. > > if (_keyLeft) {_view.camera.x -= > 15*Math.cos(_view.camera.rotationY*Math.PI/180); > don't you want to use moveLeft, moveRight here? > > I think you should clean up/check your code a bit first... > then comment most of it, inclusif your mouse behaviours > keep just view, camera and enterframe. > > first load and addchild the mesh, if no errors, > generate material and asign to model, if ok > generate Path object, if ok > generate animator, if ok > then start the animation update. > if something move as expected, then add complexity with mouseEvents etc.. > > if you proceed step wize like this, you will spare yourself headackes... > > Fabrice > > On Jan 27, 2011, at 8:12 AM, bandy wrote: > > > Fabrice, thank you for the reply. I did as you suggested and combined > > the initPathAnimation code and the onModelLoaded method into one > > method like below, but get > > Error from ZoomFocusLens? > > > Error: isNaN(sz) > > at away3d.cameras.lenses::ZoomFocusLens/project()[C:\Users\admin > > \Adobe Flash Builder 4\CITYWALKTHROUGH\src\away3d\cameras\lenses > > \ZoomFocusLens.as:106] > > at away3d.core.project::MeshProjector/primitives()[C:\Users\admin > > \Adobe Flash Builder 4\CITYWALKTHROUGH\src\away3d\core\project > > \MeshProjector.as:152] > > at away3d.core.traverse::PrimitiveTraverser/apply()[C:\Users\admin > > \Adobe Flash Builder 4\CITYWALKTHROUGH\src\away3d\core\traverse > > \PrimitiveTraverser.as:103] > > at away3d.core.base::Object3D/traverse()[C:\Users\admin\Adobe Flash > > Builder 4\CITYWALKTHROUGH\src\away3d\core\base\Object3D.as:1596] > > at away3d.containers::ObjectContainer3D/traverse()[C:\Users\admin > > \Adobe Flash Builder 4\CITYWALKTHROUGH\src\away3d\containers > > \ObjectContainer3D.as:353] > > at away3d.containers::View3D/render()[C:\Users\admin\Adobe Flash > > Builder 4\CITYWALKTHROUGH\src\away3d\containers\View3D.as:964] > > at testpath/onEnterFrame()[C:\Users\admin\Adobe Flash Builder > > 4\CITYWALKTHROUGH\src\testpath.as:211] > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> . > > > Profuse apologies that this is elementary, but you said I should only > > declare something when I am sure it is fully loaded. The onModelLoaded > > method is only run when the > > Loader3DEvent.LOAD_SUCCESS is fired, (and the md2 loads fine before > > trying to add it to the pathAnimator). Should I be checking if the > > pathAnimator is loaded? ( I haven't seen code doing that). > > > Code with initPathAnimation code and the onModelLoaded method > > combined, as suggested by you: > > > package > > { > > import away3d.animators.PathAnimator; > > import away3d.animators.VertexAnimator; > > import away3d.cameras.Camera3D; > > import away3d.containers.ObjectContainer3D; > > import away3d.containers.Scene3D; > > import away3d.containers.View3D; > > import away3d.core.base.Mesh; > > import away3d.core.base.Object3D; > > import away3d.core.geom.*; > > import away3d.core.geom.Path; > > import away3d.core.math.*; > > import away3d.events.Loader3DEvent; > > import away3d.loaders.Loader3D; > > import away3d.loaders.Md2; > > import away3d.loaders.utils.AnimationLibrary; > > import away3d.materials.*; > > import away3d.primitives.Cube; > > import away3d.primitives.Plane; > > import away3d.primitives.Sphere; > > import away3d.primitives.Torus; > > > import flash.display.*; > > import flash.events.*; > > import flash.geom.Point; > > import flash.utils.getTimer; > > > [SWF(backgroundColor="#cccccc", frameRate="60", quality="LOW", > > width="800", height="600")] > > public class testpath extends Sprite > > { > > [Embed(source="assets/dolphin_f.jpg" )] > > private static var horse:Class; > > > private var scene:Scene3D; > > private var _view:View3D; > > private var cam:Camera3D; > > private var m_modelMaterial:BitmapFileMaterial; > > > private var traveller:Object3D; > > private var travellerCont:ObjectContainer3D; > > private var horsePath:Path; > > > private var _scrub:Boolean = false; > > > private var _lastPoint:Point = new Point(); > > > private var horseMesh:Mesh; > > private var time:Number = 0; > > > private var pathAnimator:PathAnimator; > > > public function testpath(): void > > { > > initEngine(); > > > loadModel(); > > //initAnimations(); > > initListeners(); > > > } > > > private function initEngine():void{ > > cam = new Camera3D(); > > ///cam.focus = 100; > > //cam.zoom = 10; > > //cam.x = 1000; > > //cam.y = 200; > > cam.z = -2000; > > _view = new View3D(); > > _view.x = 400; > > _view.y = 300; > > scene = new Scene3D(); > > _view.scene = scene; > > _view.camera = cam; > > > cam.lookAt(scene.position); > > > addChild(_view); > > > } > > > private function loadModel():void > > { > > m_modelMaterial = new > > BitmapFileMaterial("assets/dolphin_f.jpg"); > > > var loader:Loader3D = new Loader3D(); > > var md2:Md2 = new Md2(); > > md2.scaling = 8; > > md2.material = m_modelMaterial; > > > loader.loadGeometry("assets/dolphin.md2", md2); > > > > > loader.addEventListener(Loader3DEvent.LOAD_SUCCESS,onModelLoaded); > > //scene.addChild(loader); > > } > > > private function onModelLoaded(event:Loader3DEvent):void > > { > > horseMesh = new Mesh(); > > horseMesh = event.loader.handle as Mesh ; > > trace((horseMesh ).geometryLibrary); > > var animdata:AnimationLibrary = > > horseMesh.animationLibrary; > > var myAnim:VertexAnimator = > > animdata.getAnimation("jump").animator > > as VertexAnimator; > > myAnim.delay = 0; > > myAnim.loop = true; > > myAnim.fps = 5; > > myAnim.interpolate = true; > > myAnim.play(); > > //mesh.sortFaces = true; > > //horseCont = new ObjectContainer3D(horseMesh); > > horseMesh.z = 5000; > > > _view.scene.addChild(horseMesh); > > var objectPath:Array = new Array(); > > > objectPath.push(new Number3D(-2000, 200, 0), new > > Number3D(0, -400, > > 600), new Number3D(2000, 200, 0)); > > objectPath.push(new Number3D(2000, 200, 0), new > > Number3D(0, 0, > > -300), new Number3D(6000, 1500, 0)); > > objectPath.push(new Number3D(6000, 1500, 0), new > > Number3D(10000, > > 1000, -600), new Number3D(16000, 700, 0)); > > > //create the path object to be used again for the path > > animator > > horsePath = new Path(objectPath); > > //path = new HorsePath1(); > > > var init:Object = {aligntoPath:true, offset:new > > Number3D(0,200,0), > > rotations:null, fps:24, easein:false, easeout:false} > > pathAnimator = new PathAnimator(horsePath, horseMesh , > > init); > > > } > > > private function initListeners():void > > { > > addEventListener( Event.ENTER_FRAME, onEnterFrame); > > stage.addEventListener(Event.RESIZE, onResize); > > stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown); > > stage.addEventListener(MouseEvent.MOUSE_UP,_onMouseUp); > > stage.addEventListener(MouseEvent.MOUSE_OUT, _onMouseLeave); > > onResize(); > > } > > > private function onResize(event:Event = null):void > > { > > _view.x = stage.stageWidth / 2; > > _view.y = stage.stageHeight / 2; > > //SignatureBitmap.y = stage.stageHeight - Signature.height; > > } > > > /*private function initAnimations():void > > { > > > }*/ > > > private function _onMouseDown(ev : MouseEvent) : void > > { > > _scrub = true; > > _lastPoint.x = stage.mouseX; > > _lastPoint.y = stage.mouseY; > > > } > > private function _onMouseUp(ev : MouseEvent) : void > > { > > _scrub = false; > > stage.removeEventListener(Event.MOUSE_LEAVE, > > _onMouseLeave); > > } > > private function _onMouseLeave(ev : Event) : void > > { > > _scrub = false; > > stage.removeEventListener(Event.MOUSE_LEAVE, > > _onMouseLeave); > > > } > > > private function onEnterFrame(event:Event): void{ > > if (pathAnimator) { > > time += (time=0.001>1)?0:time+001; > > pathAnimator.update(time); > > > } > > if (_scrub) { > > _view.camera.rotationX -= (stage.mouseY - > > _lastPoint.y) /200 ; > > _view.camera.rotationY += (stage.mouseX - > > _lastPoint.x)/200; > > } > > // Move forward or backward > > /*if (_keyUp) { > > > _view.camera.moveForward(15*Math.cos(_view.camera.rotationX*Math.PI/ > > 180)); > > > > _view.camera.moveUp(-15*Math.sin(_view.camera.rotationX*Math.PI/ > > 180)); > > } else if (_keyDown) { > > > _view.camera.moveBackward(15*Math.cos(_view.camera.rotationX*Math.PI/ > > 180)); > > > > _view.camera.moveDown(-15*Math.sin(_view.camera.rotationX*Math.PI/ > > 180)); > > } > > // Sidestep left/right > > if (_keyLeft) { > > > _view.camera.x -= > > 15*Math.cos(_view.camera.rotationY*Math.PI/180); > > _view.camera.z += > > 15*Math.sin(_view.camera.rotationY*Math.PI/180); > > } else if (_keyRight) { > > _view.camera.x += > > 15*Math.cos(_view.camera.rotationY*Math.PI/180); > > _view.camera.z -= > > 15*Math.sin(_view.camera.rotationY*Math.PI/180); > > }*/ > > _view.render(); > > } > > } > > } > > > On Jan 25, 8:46 pm, Fabrice3D <[email protected]> wrote: > >> just move your initPathAnimation(); to the "onModelLoaded" method, > >> as you check if animator exist on enterframe, but you assume the target > >> that it's supposed to update is there. > >> it is a good practice to declare everything after you are sure all is > >> loaded. > > >> a Prefab tip: > >> if you keep windows of animator, path editor open > >> select your md2 model, and play the sequence you want, you could debug the > >> pathanimation, sequence speed etc > >> and output most of your code in few secs... > > >> Fabrice > > >> On Jan 25, 2011, at 9:49 AM, bandy wrote: > > >>> Hi All, > >>> I have been trying to get an animated md2 to move along a path using > >>> pathanimator without any luck. > >>> The error it gives is > > ... > > read more »
