Cinematics system for JME3

Actually we are planning to implement spatial animation.



There is a PositionTrack class right now that would do what you want, but once spatial animation is in we will remove those class to avoid confusion.



The spatial animation will work as bone animation, with different channels etc… but it’s yet to be fully supported.

but for now with the PositionTrack can I include speed states (like accelerate , decelerate, etc)?

[java]cinematic.addCinematicEvent(0, new PositionTrack(model, new Vector3f(1, 0, 0), 2));

cinematic.addCinematicEvent(2, new PositionTrack(model, new Vector3f(2, 0, 0), 3));[/java]

This will do the job knowing that I have the speed and distance so I can get the duration. However, I really need to implement accelerate, decelerate, etc (meaning the duration now is “not” constant). How do I do that?

then you can crate your own track, see the TestCinematic example

Nehon sorry I can’t seem to figure it out. To clarify my question, I created a topic for it and it’s still un resolved. Can anyone please help?



http://hub.jmonkeyengine.org/groups/general-2/forum/topic/jme3-beginner-using-cinematics-to-acceleratedecelerate/

I understand that it has to do with the AbstractCinematic but I still cannot figure it out if anyone can help.



thanks

Make your own track and put it at time 0 in the cinematic.

This track will handle your data and compute the position of the spatial on each update.

There are convenience methods in fast math to interpolate between 2 positions linearly or following splines.

Speed = Distance/Time → Distance = speed * time. using this you can compute the position on each frame because you got time, and you’ll have to provide speed.



Now for acceleration, you have to increase the speed over time…

If I understood you correctly, that’s what I did and it did not work:





[java]float speed_loop = speed;

float acceleration_factor = 0.0002f;

float max_speed = 6;

while(speed_loop <= max_speed)

{

cinematic.addCinematicEvent(moveEventsList.get(j).tpf, new PositionTrack(spatialToMove, new Vector3f(moveEventsList.get(j).x,

moveEventsList.get(j).y, moveEventsList.get(j).z), getDuration(speed_loop, currentLocation.distance(newLocation) ) ));

speed_loop += acceleration_factor;

}[/java]



the function get duration takes speed_loop and current location and updates the duration (expecting that it will decrease by every increase in speed). However, this does not work as intended and what happens is that it will quickly loop the speed reaching the max speed and pass it along (plus a weird vibration of the spatial)



I am sorry if that is a simple task but i’m just a beginner in Jme3.



thanks

forget the PositionTrack it can’t work like this

create your own track

[java]

cinematic.addCinematicEvent(0, new AbstractCinematicEvent() {



@Override

public void onPlay() {

}



@Override

public void onUpdate(float tpf) {

//COMPUTE POSITION OF THE SPATIAL HERE

//1. compute the speed (you got a protected “time” variable that holds the time since the event started)

//2. interpolate between the 2 positions according to the speed

//3. move the spatial.

}



@Override

public void onStop() {

}



@Override

public void onPause() {

}

});

[/java]

And Can I use it several times? Can I create as many as I want having several onUpdate(tpf) ???

I will be using it as:

cinematic.addCinematicEvent(event_trigger_time, new AbstractCinematicEvent() {

// blah blah blah

}

No, use just one of it that starts at 0 and compute all of your data

First of all thanks Nehon for the wonderful contribution!

Now I would like to report a possible bug:



The following works fine:

AnimationTrack animTrack = new AnimationTrack(obj.model, animName, LoopMode.Loop);



The following returns a NullPointerException:

AnimationTrack animTrack = new AnimationTrack(obj.model, animName);

animTrack.setLoopMode(LoopMode.Loop);



Is it actually a bug, or am I doing something wrong?

looks like a bug, could you post the entire stack trace? (i cannot test it ATM)

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.cinematic.events.AnimationTrack.setLoopMode(AnimationTrack.java:156)

at JMECinematicWrapper.AddAnimationEvent(JMECinematicWrapper.java:98)

at BallScript.simpleInitApp(BallScript.java:25)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)

at java.lang.Thread.run(Thread.java:722)

1 Like

mhh ok i guess the channel is null

i’ll fix it thanks

That was my guess too…

PS: Will I get the fixed version automatically through JMP updates, or do I need to do something more?

If you use nightly tomorrow, if you use stable, next time a stable is released, which is not scheduled right now.

Hi @nehon,



I have done a cool dialogue system for RPG my game, and pretty sastified with it…



Basicly the words displayed in a Substitle track, and display line by line in the specific time and scripted in Groovy…



but I want to allow user to choose what they want to talk in dialogues…

However, now I have to pause the whole cinematic and wait for user to choose what they want.

that means I want a Event to be fire after another event…



So what is the pattern I should use for such scenerio (Event Listener may be) ?

We have found a memory leak when using Cinematics. Our program creates multiple Cinematics that are used only once and then dereferenced. We have profiled the number of active objects after each “Run”. In the table below a “Run” includes:

  1. Instantiation of a new Cinematic
  2. Setup and start of the new Cinematic
  3. Upon finish of the Cinematic it is dereferenced, as well as all of the referenced objects within each Cinematic Event
  4. Garbage Collection is called



    This is the active object profile of the objects we observed to appear to have not been disposed by the Garbage Collector:

    Internal Active Objects

    Run 1st 2nd 3rd 4th 5th

    Vector3f 3720 5817 6687 7209 8079

    bone 225 573 718 805 950

    bone[] 177 202 212 218 228

    skeleton 57 69 74 77 82



    We are sorry that we don’t currently have the time to create a test project. This may be sufficient information; however, we should be able to help next week with a small test project to demonstrate the issue.



    Thank you for your time

    Dustin

Hello @nehon. Could you take a look at this thread.