PathAnimator.alignToPath() but always looking forward?

Software: Away3D 4.x

Ascanio, Newbie
Posted: 13 May 2013 11:42 AM   Total Posts: 29

Hi, I’m building a gauge pointer that moves along a non-circular path.

I’ve seen that the PathAnimator class uses the Mesh’s .lookAt() method to achieve orientation to path of the _target Mesh.

The problem with this is that when you invert the “direction” of movement, the _target Mesh will turn to “look” in the opposite direction.

I’ve been tampering with Mesh.transform, Mesh.scale and Mesh.rotate to compensate for this, but can’t seem to figure out how to make it work.

rotateX, rotateY and rotateZ do affect the Mesh, but I can’t seem to find the right combination to have the _target’s local Z and X axes to rotate according to the position on the path while the _target’s local Y axis remains fixed, thus preventing the _target from “looking in the direction of movement”.

   

Ascanio, Newbie
Posted: 13 May 2013 12:06 PM   Total Posts: 29   [ # 1 ]

Ok, found the trick.
It’s a matter of rotating by 180 degrees about the UP axis of the target Mesh and INVERTING rotations about other axes.

Remember that the transformations applied by PathAnimator will be already available in the target Mesh’s .rotationX, .rotationY and .rotationZ properties in an ENTER_FRAME listener, so you can manipulate the values or simply overwrite them.

Cool smile

   

Avatar
Fabrice Closier, Administrator
Posted: 13 May 2013 12:33 PM   Total Posts: 1265   [ # 2 ]

Depending on your model orientation (right/left handed etc), you might indeed need to setup a rotation on yaxis. But right after you need to apply it.
mesh.rotationY = 180;
MeshHelper.applyRotations(mesh);

or fix the model in your 3d editor.

Rest will work with no additional changes.

   

Ascanio, Newbie
Posted: 13 May 2013 12:46 PM   Total Posts: 29   [ # 3 ]

Hi Fabrice! I will indeed look into it.
But the rotation is being affected even without the MeshHelper method, why is that?

   

Avatar
Fabrice Closier, Administrator
Posted: 13 May 2013 12:57 PM   Total Posts: 1265   [ # 4 ]

That’s the whole point of the animator… it affects the meshes transforms for you.
Because your model needs to have the correct alignment visually, depending on your editor, the mesh may seamed to be driven from a side or from behind. Hence why you need to use MeshHelper or correct in your editor.
In your editor, giving a rotationY = will not work if you export with a format that does support transforms. obj format woudl for instance, as the transforms ar ebaked into the vertices.
You need to apply the transform at objectlevel. MeshHelper does this for you. It transforms the vertices, using the mesh transforms, and reset the rotation values to 0.
In short a mesh with rotation = 90, if you do MeshHelper.applyRotations(mesh); If you trace the rotationY value after apply, it will trace 0. Visually there will be no changes between mesh with rotationY prior apply and after. Once applied (and if the correction rotation value was correct), your model will be correctly oriented by the animator.

   

Ascanio, Newbie
Posted: 13 May 2013 01:07 PM   Total Posts: 29   [ # 5 ]

Aha, I got it right while you were writing your answer.

In fact, I think I’m better without “baking” (pass me the term) the transforms to the geometry, for two reasons.

1) I only need to compensate for the transformations the PathAnimator applies, when it applies them. So I do it on a temporary basis, not permanent.

2) I am using multiple instances of the pointer (or needle) mesh, in my instrument cluster: MeshHelper.applyRotations() affects the actual geometry, turning every instance alike.

I know this is not the best course of action.. having part of the framework doing the gross work, and then applying fine tuning later.
The best way would be to infer the plane that is normal to the path at the current position, and then use any useful bit of that info, transforming the target Mesh only once.

   

Avatar
Fabrice Closier, Administrator
Posted: 13 May 2013 01:23 PM   Total Posts: 1265   [ # 6 ]

I think I’m better without “baking”.
You handle your project as you please of course!
But now you know what is going on.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X