Sorry forgot to post code:
package
{
import away3d.animators.Animator;
import away3d.animators.PathAnimator;
import away3d.animators.VertexAnimator;
import away3d.animators.data.*;
import away3d.cameras.*;
import away3d.containers.*;
import away3d.core.base.*;
import away3d.core.geom.Path;
import away3d.core.utils.*;
import away3d.loaders.*;
import away3d.loaders.utils.AnimationLibrary;
import away3d.materials.*;
import away3d.primitives.Cube;
import away3d.primitives.Plane;
import away3d.test.Button;
import flash.display.*;
import flash.events.*;
import flash.geom.Vector3D;
import flash.utils.Timer;
[SWF(backgroundColor="#FFFFFF", frameRate="30", quality="LOW",
width="1000", height="600")]
public class Intermediate_MD2AnimationWithPrefabPathAnimi extends
Sprite
{
//dolphin md2 file
[Embed(source="assets/dolphin.md2",mimeType="application/octet-
stream")]
private var DolphinMesh:Class;
//engine variables
private var scene:Scene3D;
private var camera:HoverCamera3D;
private var view:View3D;
//material objects
private var material:BitmapMaterial;
//scene objects
private var md2:Md2;
private var model:Mesh;
//navigation variables
private var move:Boolean = false;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var lastMouseX:Number;
private var lastMouseY:Number;
private var loader:LoaderCube;
private var pathAnimator:PathAnimator;
private var time:Number = 0;
private var travellerCont:Object3D;
private var myAnim:VertexAnimator;
private var result:Array;
private var path:Dolphinpath;
public function Intermediate_MD2AnimationWithPrefabPathAnimi()
{
Debug.active = true;
init();
}
private function init():void
{
initEngine();
initMaterials();
initObjects();
initPath();
}
private function initEngine():void
{
scene = new Scene3D();
camera = new HoverCamera3D();
camera.panAngle = 45;
camera.tiltAngle = 20;
camera.hover(true);
camera.z = -20000;
view = new View3D({x:400, y:300});
view.camera = camera;
view.scene = scene;
view.addSourceURL("srcview/index.html");
addChild(view);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function initMaterials():void
{
material = new
BitmapFileMaterial("assets/dolphin_f.jpg");
}
private function initObjects():void
{
var plane:Plane = new Plane({width:4000, height:10000,
yUp:true,
material:(new ColorMaterial(0xffddc7)), bothsides:true});
plane.y = -1880;
plane.z = 100;
scene.addChild(plane);
md2 = new Md2();
md2.fps = 7;
model = md2.parseGeometry(DolphinMesh) as Mesh;
model.material = material;
model.scale(0.04);
model.z = 20000;
scene.addChild(model);
model.animationLibrary.getAnimation("jump").animator.play();
}
private function initPath():void
{
var cube:Cube = new Cube();
view.scene.addChild(cube);
/* For manual path creation. Same results as with Prefab
class
(below)
var objects:Array = new Array();
objects.push(new Vector3D(-2000, 200, 0), new
Vector3D(0, -400,
600), new Vector3D(2000, 200, 0));
objects.push(new Vector3D(2000, 200, 0), new
Vector3D(0, 0, -300),
new Vector3D(6000, 1500, 0));
objects.push(new Vector3D(6000, 1500, 0), new
Vector3D(10000, 1000,
-600), new Vector3D(16000, 700, 0));
var objectPath:Path = new Path(objects);
pathAnimator = new PathAnimator(objectPath, model,
{alignToPath:true, offset:new Vector3D(0,200,0), fps:.3});*/
path = new Dolphinpath(model);
}
private function onEnterFrame(event:Event):void
{
if (path)
{
time = time + .1;
path.update(time);
}
view.render();
view.scene.updateTime();
}
}
}
On Feb 2, 4:27 pm, bandy <[email protected]> wrote:
> Thank you for your reply Fabrice. Yes I can preview the md2 anim
> travelling on the Path in Prefab.
>
> I export the path with its animation (Export/Path for Away3D, 3.5.3
> and higher).
> Apart from a naming issue (the Prefab-exported Path class is called
> PathAWpath_0, but the Prefab-exported PathAnimator class refers to
> AWpath_0, in line 19: super(new AWpath_0(), object3d, o).
>
> After renaming it, it works like other paths I have created,
> unfortunately, without the md2 doing its thing.
> I am using scene.updateTime() and pathAnimator.update() in the
> Enterframe. I've examined every post on this forum it seems on this
> subject and I'm pretty sure I've done everything I should, but I can't
> claim great coder competency, so sorry to keep banging on about this.
> I gingerly post my code below. It is using an imported md2 and Prefab
> Path and PathAnim. Could you please point out the error/s or point me
> in another direction of investigation?
>
> On Feb 1, 9:18 pm, Fabrice3D <[email protected]> wrote:
>
>
>
> > do you update in enterframe your animation?> the only example I have seen
> > is the Minotaur in the labyrinth
>
> > Prefab does it (you can preview md2 animation following your path) and so
> > does Away 3.5 and 3.6
>
> > Fabrice
>
> > On Feb 1, 2011, at 9:33 AM, bandy wrote:
>
> > > The error I was getting when using the PathAnimator with an animated
> > > md2 disappeared when the class was transferred to from 3.5 to 3.6. The
> > > md2 now glides around on the Path, but it does not execute its own
> > > animation, it is still. (The only way I can get it to change locations
> > > while animating is to change its x,y or z values in the Enterframe. )
>
> > > Can someone say that they are able to do get an animated md2 to simply
> > > follow a Path using PathAnimator while still animating? The only
> > > example I have seen is the Minotaur in the labyrinth by Fabrice from a
> > > Extrude demo but that is using an old away3d version. I have used all
> > > sorts of combinations of classes exported from Prefab, different
> > > md2's, scene.updateTime, different methods to update the PathAnimator.
> > > Funnily, I see nothing on this subject anywhere, whereas I would have
> > > thought it would be the obvious thing to try to do before trying
> > > advanced character control. Is it because of limited usefulness that
> > > nobody is interested? Thanks for any help.
>
> > > On Jan 27, 8:43 pm, bandy <[email protected]> wrote:
> > >> 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
>
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -