Cinematic together with AnimationFactory does not work, what did I wrong?

Why does the following code do not animate the spatial i place in the world? I got it from here and it just does nothing, the spatial is added normally to the scene but does not move or change at all. What did i forget to add? Do I have to trigger the Cinematic somehow to start?

[java]

@Override
public void simpleInitApp() {

	Spatial model = create any model here like a cube or load a j3m file
	

	// creating spatial animation for the teapot
	AnimationFactory factory = new AnimationFactory(20, "teapotAnim");
	factory.addTimeTranslation(0, new Vector3f(10, 0, 10));
	factory.addTimeTranslation(20, new Vector3f(10, 0, -10));
	factory.addTimeScale(0, new Vector3f(4, 4, 4));
	factory.addTimeScale(20, new Vector3f(1, 1, 1));
	factory.addTimeRotationAngles(20, 0, 4 * FastMath.TWO_PI, 0);
	
	AnimControl control = new AnimControl();
	control.addAnim(factory.buildAnimation());
	model.addControl(control);

	Cinematic cinematic = new Cinematic(rootNode, 20);
	cinematic.addCinematicEvent(0, new AnimationEvent(model, "teapotAnim",
			LoopMode.DontLoop));
	stateManager.attach(cinematic);

	rootNode.attachChild(model);

[/java]

you have to call cinematic.play() in order for … the cinematic to play :stuck_out_tongue:

1 Like
@nehon said: you have to call cinematic.play() in order for .... the cinematic to play :p

:facepalm:

thanks very much :smiley:

Actually that’s not completely intuitive.
The fact that the cinematic is an AppState could make you think that attaching it would be enough to make it work (like any other appstate…).
I’m not completely satisfied with this design.
So don’t facepalm so fast :wink:

@nehon said: Actually that's not completely intuitive. The fact that the cinematic is an AppState could make you think that attaching it would be enough to make it work (like any other appstate...). I'm not completely satisfied with this design. So don't facepalm so fast ;)

oh maybe one more question, if I want to use a custom speed function and not the normal linear movement how should i do this? For example if I want to slowly increase the speed of the animation or a custom acceleration function to do things like a bounce animation

You can make a custom CinematicEvent (extend AbstractCinematicEvent for convenience).
You have an onUpdate method that is called once per update, and is fed with the tpf.

So to get this clear:

  • The AnimationFactory creates internally a SpatialTrack how the object should move,rotate, scale and puts it into an Animation object
  • The AnimControl gets the Animation object and is added to the spatial (why? how does the cinematic later interact with the AnimControl?)
  • The Cinematic is created and its scene is the complete rootNode (why? can my scene also be only the model?)
  • A AnimationEvent is added to the Cinematic and knows the name of the ealier created Animation object. The AnimationEvent has an AnimChannel and the Animation is set to the channel when the Cinematic later triggers the onPlay method of the AnimationEvent
  • The Cinematic is then added to the state manager and then i can say cinematic.play(); to start it

now you say if I want alternating speeds in my animation I have to create my own CustomAnimationEvent and set it to the cinematic instead of the normal AnimationEvent ? From what I have seen in the AnimationFactory maybe it would be better to create my own class which calculates the correct keyframes and interpolations based on my custom acceleration function and leave the rest as it currently is?

ah and one more problem, if I set the cinematic to loop, the animation is still only played once and then stops:

[java]cinematic.addCinematicEvent(0, new AnimationEvent(model, “teapotAnim”,
LoopMode.Loop));[/java]

edit: ok i fixed it by removing the time limit of the cinematic:

[java]Cinematic cinematic = new Cinematic(rootNode, LoopMode.Loop);
cinematic.addCinematicEvent(0, new AnimationEvent(model, animName,
LoopMode.Loop));[/java]

@nehon said: You can make a custom CinematicEvent (extend AbstractCinematicEvent for convenience). You have an onUpdate method that is called once per update, and is fed with the tpf.

I think I found a bug in the Cinematic class. The initialDuration is never changed from its default 10 seconds when you use for example “new Cinematic(rootNode, LoopMode.Loop);” which causes the animation to break every 10 seconds and reset to the beginning, I think if LoopMode.Loop is passed the initialDuration value should be recalculated as soon as play() is called e.g.

I’ll look into it (i need to macro this sentence)