Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3055 Members - Latest Member: TipEpismKeype

11. February 2012, 01:07:38 PM
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)animation synchronized to custom "game time"
Pages: [1]
Print
Author Topic: animation synchronized to custom "game time"  (Read 317 times)
kerno
Just dropped in

Offline Offline

Posts: 18


View Profile
« on: 14. March 2010, 01:59:07 PM »

Hi,
I've got available MD2 model with a couple of key frames. Now I'd like to make smooth transition between any two of these frames (not necessarily subsequent) and have it synced to some abstract game time-line. Ie. the game time may be stopped (RTS with pause) or accelerated/slowed down, also it should be possible to animate same model (shared instance) at different speeds.

Now, what I could understand (based on pretty fresh SVN sources) is that I could make a new class inheriting ModelAnimation and override update(), calculate the right animation progress, then have instances of this new animation created with (the controllers with) the right animation key frames in my own sequence...
This seems a bit complicated so I'm guessing I've missed something. Can you, please, comment/suggest any simpler solution or where to find sample source code? (don't do my homework - just point me in the right direction, please).

And one more: when I call getSharedInstance on MD2 model and turn animation on the shared instance, then only the body, and not attached shapes are animated. I guess that I should copy/reattach the tags/animations but I wonder if it's intended?

Thanks & regards / K
Logged
horati
Global Moderator
Getting respectable
*****
Offline Offline

Posts: 393


View Profile
« Reply #1 on: 15. March 2010, 03:16:59 AM »

I don't know the detailed answers to your questions; however, there are several classes with Interpolator in the class name that may be useful to you.  Several of them do pieces of what you describe, at least inside their implementation.
Logged

Kevin
"It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k."
http://stackoverflow.com/users/3474/sylvarking
kerno
Just dropped in

Offline Offline

Posts: 18


View Profile
« Reply #2 on: 20. March 2010, 07:00:37 AM »

I did the coding and the results are below. Please, take a look if it's correct. However, it seems I'd need to do that on each animation transition (ie. create animation with last frame of animation that ended and first frame of new animation) to provide smooth transition, right? Is there really no easier way?

Code:
    public static ModelAnimation createSubAnimation(ModelAnimation originalAnimation, String animationName, Collection<Integer> frameNumbers, float fps) {
        int frameCount = frameNumbers.size();

        //create controllers for each model subshape with set of selected frames
        List<KeyFrameController> controllers = new ArrayList<KeyFrameController>();
        for (KeyFrameController originalController : originalAnimation.getControllers()) {
            MeshDeformationKeyFrameController meshDeformationController = (MeshDeformationKeyFrameController) originalController;
            MeshDeformationKeyFrame[] controllerFrames = new MeshDeformationKeyFrame[frameCount];
            int newFrameNo = 0;
            for (int origFrameNo : frameNumbers) {
                controllerFrames[newFrameNo] = meshDeformationController.getFrame(origFrameNo);
                newFrameNo++;
            }
            controllers.add(new MeshDeformationKeyFrameController(controllerFrames, meshDeformationController.getTarget()));
        }

        ModelAnimation customAnimation = new ModelAnimation(animationName, frameCount, fps, controllers.toArray(new KeyFrameController[controllers.size()]));

        { //create mount transforms with set of selected frames
            int mountCount = originalAnimation.getMountTransformFrame(0).length;
            Matrix4f[][] customMountTransformFrames = new Matrix4f[frameCount][mountCount];
            int newFrameNo = 0;
            for (int origFrameNo : frameNumbers) {
                for (int mountNo = 0; mountNo != mountCount; mountNo++) {
                    customMountTransformFrames[newFrameNo][mountNo] = originalAnimation.getMountTransformFrame(origFrameNo)[mountNo];
                }
                newFrameNo++;
            }
            customAnimation.setMountTransformFrames(customMountTransformFrames);
        }
        return customAnimation;
    }
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #3 on: 20. March 2010, 08:06:42 AM »

You could create one animation for each transition, that has only two keyframes and that interpolates smoothly between them.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic