I am replacing my RotationTrack code with AnimationTrack and replacing this old deprecated function (THAT WORKS FINE):
Note that my object is a .obj object a node with two geometries.
[java]
cinematic.addCinematicEvent(trigger_time, new RotationTrack(
((Node) spatialToMove).getChild(0), rotation_angle,
rot_duration));
cinematic.addCinematicEvent(trigger_time, new RotationTrack(
((Node) spatialToMove).getChild(1), rotation_angle,
rot_duration));
cinematic.addCinematicEvent(trigger_time, new RotationTrack(
((Node) spatialToMove).getChild(2), rotation_angle,
rot_duration));
[/java]
with this function:
[java]
// create rotate animation
rotateAnimation(spatialToMove, rot_duration, “rotate”+rotateCounter,
rotation_angle, oldX, oldY, oldZ);
// add cinematic event to cinematic buffer
cinematic.addCinematicEvent(trigger_time, new AnimationTrack(((Node) spatialToMove).getChild(0), “rotate”+rotateCounter, LoopMode.DontLoop));
cinematic.addCinematicEvent(trigger_time, new AnimationTrack(((Node) spatialToMove).getChild(1), “rotate”+rotateCounter, LoopMode.DontLoop));
cinematic.addCinematicEvent(trigger_time, new AnimationTrack(((Node) spatialToMove).getChild(2), “rotate”+rotateCounter, LoopMode.DontLoop));
// increment counter for next event
rotateCounter++;
[/java]
I get the following error:
[java][/java]
Mar 7, 2012 3:10:05 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.cinematic.events.AnimationTrack.(AnimationTrack.java:77)
Mar 7, 2012 3:10:05 PM com.jme3.renderer.lwjgl.LwjglRenderer cleanup
INFO: Deleting objects and invalidating state
Mar 7, 2012 3:10:05 PM com.jme3.input.lwjgl.LwjglMouseInput destroy
INFO: Mouse destroyed.
Mar 7, 2012 3:10:05 PM com.jme3.input.lwjgl.LwjglKeyInput destroy
INFO: Keyboard destroyed.
Mar 7, 2012 3:10:05 PM com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
INFO: Display destroyed.
[java][/java]
exactly at this line>>>> cinematic.addCinematicEvent(trigger_time, new AnimationTrack(((Node) spatialToMove).getChild(0), “rotate”+rotateCounter, LoopMode.DontLoop));
as the spatial child is being a null ptr although it’s being passed to AnimatrionTrack
PS: Something I don’t get with jMe is that in both functions I have to give it the child node in order to rotate it and not just use spatialToMove as a node.
@garnaout said:
PS: Something I don't get with jMe is that in both functions I have to give it the child node in order to rotate it and not just use spatialToMove as a node.
You have to pass the spatial that has the AnimControl attached to.
what do you do in rotateAnimation(spatialToMove, rot_duration, "rotate"+rotateCounter, rotation_angle, oldX, oldY, oldZ); ?
oh my bad I thought I also posted it
[java]
/** Generic function to create animation used in AnimationTrack for coast, rotate, etc */
public void rotateAnimation(Spatial spatial, float animationDuration, String animationID,
Quaternion angle, float oldX, float oldY, float oldZ)
{
AnimationFactory factory = new AnimationFactory(animationDuration, animationID);
factory.addTimeTranslation(0, new Vector3f(oldX, oldY, oldZ));
//factory.addTimeRotation(0, new Quaternion(0,0,0,0));
factory.addTimeRotation(animationDuration, angle);
AnimControl control = spatial.getControl(AnimControl.class);
if( control == null){
control = new AnimControl();
spatial.addControl(control);
}
control.addAnim(factory.buildAnimation());
}
[/java]
ok so…you add an AnimControl to spatialToMove, then you pass spatialToMove.getChild(0) to the AnimationTrack.
the child geom has no AnimationControl hence the NPE. Why do you pass the children separately?
just pass spatialToMove once.
because that object has several parts (children) that sometimes I want to rotate separately (think of it like a chopper and its rotor).
then you have to create the anim for each sub geom