Home Technical Talk

Getting rotation/translation data per keyframe

Guessmyname
polycounter lvl 6
Offline / Send Message
Guessmyname polycounter lvl 6
Hello. I'm trying to animate a model for the Spring engine, which for those that don't know handles animations on a piece-by-piece basis in code (it's sliiightly outdated...). I've made an animation in 3dsmax, but I don't know how to get the rotations/translations (local axis) out per keyframe so I can use them in Spring's unit scripting system. Simply having the object selected with the rotation tool on the keyframe doesn't work, as the axis boxes at the bottom of the screen just display 0,0,0. Right clicking the keyframe can get them, but this is fiddly and time-consuming, whilst the curve editor doesn't give the precise rotations, and it doesn't seem to give in the local axis. I don't suppose there are any tools or plugins (or hell, a model format I could export to and open in Notepad++) that would export all this data at once, simply to make life easier?

This, incidentally, is the model in question:
Atredies_polyc.jpg
(ignore the bird-running arms; I'll animate them later, once I have the walkscript working)

Any help, comments or advice welcome. Thanks for any help you can give!

Replies

  • cw
    Offline / Send Message
    cw polycounter lvl 17
    have a look in maxscript docs for how to access controllers and the timeline.

    also the use of 'in coordsys' command might be of use.

    once you have an idea how to do those things in maxscript you'll be able to start to work it out. :D

    good luck! any more qs ask again. :D
  • Guessmyname
    Offline / Send Message
    Guessmyname polycounter lvl 6
    Okay, think I've nearly got it, just stuck on how to get the rotations and translations of an object. Can I use .pos, or is it something keyframe specific?

    Current script is looking like this:
    -- 3dsMax to Spring animation export tool
    
    /*
    So, process goes something like this:
    For every object in the selection...
        For every keyframe said object has...
            Get the translations / rotations in the local axis
            Build the animation control
            Move Commands for the axis if translation != 0
            Turn Commands for the axis if translation != 0
            Sleep Command for the length of the keyframe
    */
    
    -- default filename
    defaultFilenm = "Spring Lua Animation" + ".txt"
    
    -- get the wanted filename
    filenm = getSaveFileName  -- '\' means 'continue this line'
    filename: defaultFilenm 
    types: "ASCII Text (*.txt)/*.txt"
    caption: "Save File As"
    
    -- open it
    fs = createFile filenm
    
    -- print some stuff
    print defaultFilenm to: fs
    print "--You'll have to edit this, you lazy gits" to: fs
    
    theseObj = selection
    
    for i=1 to selection.count do
    (
        for j=1 to numkeys theseObj do
        (
            currentObj = selection[i]
            a = in coordsys local currentObj./*something!*/
            b = /*Y-Axis translation*/
            c = /*Z-Axis translation*/
            d = /*X-Axis rotation*/
            f = /*Y-Axis rotation*/
            g = /*Z-Axis rotation*/
            
            format "falderol % % % % % % /n" a b c d f g to: fs --I haven't set it up yet
        )
    )
    
    Need to figure out what the 'something!' should be. Pos? X/Y/Z tracks? Can I access that from a selected object? Long story short, I'm suspecting I've made a mistake or two somewhere...
  • cw
    Offline / Send Message
    cw polycounter lvl 17
    as i say I think controllers are the way forward! I havent got the docs open atm so I'll leave it nice and vague so you can have fun learning. :D

    u can use .pos for position I expect as I'm guessing the controllers are bog standard eulerXYZ?

    as for angles, you get it from the object in a quaternion form IIRC and have to convert to euler and pull ut the bits you need.

    Good luck!
  • Guessmyname
    Offline / Send Message
    Guessmyname polycounter lvl 6
    Gah. Still stuck. Anyone know of any plugins or scripts involving animation? So I can get a look at them, see how they did things, that sort of thing...
  • Rick Stirling
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    I'm on my mac today so don't have max open, so the syntax I give you might be wrong, but will hopefully send you in the right direction.


    I assume you will want to be working in parent space.

    TrPos = in coordsys parent $.pos
    TrRot = in coordsys parent $.rotation

    You may need to use $.transform.pos and $.transform.rotation


    Are you exporting bone animation data? Maxscript will also give you that information:

    bone.position, bone.rotation. bone.transform gives you the position, rotation and scale as a matrix.
  • Guessmyname
    Offline / Send Message
    Guessmyname polycounter lvl 6
    Not bone. Sadly, Spring doesn't (yet) support bone animation. It's all per-object. I actually wanted local space, but that's fine (just switch it to in coordsys local, right?).

    How do I get that for specific keyframes, though? I can get where the keyframes (.pos.controller.keys) are, and the values out of the first keyframe (.pos.controller.value), but that's as far as I've got. From as far as I can tell from the help files, you're meant to use something like .pos.controller.keys[key].value, but that just chucks up errors...
  • Rick Stirling
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    Are you sure it's local? If you have any sort of hierarchy it's usually the rotation relative to the parent that you want.
  • Guessmyname
    Offline / Send Message
    Guessmyname polycounter lvl 6
    Fairly sure it's local. Still, it's easy to switch it if it turns out I'm wrong.
Sign In or Register to comment.