Page 1 of 9 12345 ... LastLast
Results 1 to 30 of 252

Thread: Animations

  1. #1
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Animations

    Well just to let you guys know: I started looking into the animation files a bit.
    I already wrote a python script that can extract them from the .idx/.dat file - it seems they aren't packed or anything since Verci's old cas importer was able to import them (well they didn't work properly, but it didn't crash, either).
    So what I'm planning to do right now is to figure out how the .cas files are described by leeching a bit of know-how from the cas importer :P

    As for the idx file (only pack.idx):
    It has a header consisting of the string "ANIM.PACKV:|", then a long 9 and then a long with the number of entries.
    Each entry then consists of:
    Bytes Variable type Explanation
    0-3 long strlen+10 of the tag (below)
    4-7 long byte offset in pack.dat
    8-11 long byte length in pack.dat
    12-15 float Unclear so far, often 1.0 (first four additional bytes of the strlen+10)
    16-25 - These are the other 6 additional bytes in the strlen+10*
    strlen String tag (qualified path for the animation)

    *They seem to be 0x3F**00140014 - 0014 is 5120 as a short which sounds probable. No idea about the first two bytes.

  2. #2

    Default Re: Animations

    Just briefly, yes the old Verci script works halfway. It can extract, if you replace the title string above with the RTW version, and the animations are half-way ok, but still not 100% good. Caliban wrote a post somewhere here that the reason is that in M2 bones are weighted, whereas in RTW they weren't.


    Caliban, is it a secure fact that once the animations are extracted and work properly, they don't have to be put back into the packed files again, and work using that anim_db switch you once posted?
    Last edited by SigniferOne; 04-10-2007 at 14:55.

  3. #3
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    The bones section at the top of the .dat file has
    the idle pose of the standard skeleton in the first three
    floats after the null terminated ASCII string. There's 19
    floats in each data section between the bone strings,
    3 are the idle pose offsets, 3 probably 0.0 rotations, and
    who knows for the remaining 13 floats.

    Edit: Sorry, not the first three. Skip the first float after the
    bone string, then the next three floats are the idle pose offsets.
    Last edited by KnightErrant; 04-10-2007 at 16:47.

  4. #4
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Animations

    KE: Are you talking about the skeletons.dat? I was looking at the pack.dat
    I got the impression we could still extract the skeletons with xidx?

    Edit: By the way, don't forget ICQ XD
    Last edited by alpaca; 04-10-2007 at 17:01.

  5. #5
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Oops, my mistake, wrong .dat.

    Edit: What does ICQ XD mean?
    Last edited by KnightErrant; 04-10-2007 at 17:04.

  6. #6
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Animations

    Well I don't really know how the skeletons work at any rate.
    Do they just link the bones in the .cas/.mesh files to the anims?

  7. #7
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Don't know, the only .cas files I've worked through are the
    _idle ones in animations/engine and they're short.
    They just have the idle pose for rigging the skeletons.
    I was digging for where the human animations were.
    Last edited by KnightErrant; 04-10-2007 at 17:21.

  8. #8

    Default Re: Animations

    Hi KE et al

    Quote Originally Posted by KnightErrant
    Don't know, the only .cas files I've worked through are the
    _idle ones in animations/engine and they're short.
    They just have the idle pose for rigging the skeletons.
    I was digging for where the human animations were.
    I've just about finished the CAS figure to Mikshape converter, and I've already got code to convert m2tw animations to Milkshape, including the quaternion to euler changes. It shouldn't take too long (famous last words?) to do the re-convert.

    The main issue is that the way the figure cas' are set up it's easier to convert to Milkshape ascii.

    Cheers

    GrumpyOldMan

  9. #9
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Awww, no fair, does this mean the adventure doesn't continue
    with animations?

    @alpaca
    Sorry for the hijack.

  10. #10

    Default Re: Animations

    Hi KE

    Quote Originally Posted by KnightErrant
    Awww, no fair, does this mean the adventure doesn't continue
    with animations?
    Yes, KE, there will be more adventures, we've only just begun to convert. I finally ironed out the conversion of RTW cas files into a milkshape file with a m2tw skeleton (I'll put up a pic in the mesh thread soon). You'll be happy to know that they work ok with vanilla m2tw animations. More adventures planned
    - get the milkshape animations back into cas (pass me the 4 pound hammer )
    - once we've done that, we can look at straight converting of RTW animations to m2tw
    - there's always the bogey of adding new skeletons (once we get the skeleton stuff straight in our heads, it's doable because Caliban said they rebuilt the skeletons and animations on the fly so they're not hard coded)

    Lots of stuff to do yet.

    Quote Originally Posted by KnightErrant
    @alpaca
    Sorry for the hijack.
    Me too

    Cheers

    GrumpyOldMan

  11. #11
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Animations

    Haha well if you already got it figured out
    So you already extracted the pack.dat? Why didn't you say?

    Anyways, I'll have a look at the skeletons then.

    Edit: By the way, does anybody have any resources on bone weigthing?
    Last edited by alpaca; 04-11-2007 at 13:03.

  12. #12
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Well I have to start learning somewhere, so I wrote an extractor
    to pull the cas's out of pack.dat using the offsets in the index file.
    Pulled out 30 to look at. The first 5 bytes are the header where
    the first short is the number of anim frames. The other 3 bytes are
    14 00 14 hex or 20 0 20. The only question is what comes first,
    quaternions or pose data. I saw some 0.0 0.0 0.0 1.0 values so that
    answered two things: quats come first and CA uses the {q1, q2, q3, q4}
    convention where q4 is the special one. I transformed them to Euler
    angle using the 321 convention and got this for the first anim frame
    for CR_spear_charge.cas:

    Code:
    Number of animation frames: 11
    Remaining header: 20  0  20
    Quaternion data and maybe Euler angles (using 321)?
      q1              q2               q3              q4             sum of squares         yaw (deg)         pitch (deg)        roll (deg) 
    ============ anim quaternion frame 0 ============
    +0.2538955510   +0.1681092978   -0.0226481762   +0.9522412419    sum squs = +1.0000000095  +2.5657103993   +19.3696683429  +30.2967888994
    -0.3953365684   -0.0070954142   +0.1987117827   +0.8967565298    sum squs = +0.9999999935  +21.4590405866   +8.3019773363  -46.0049588155
    +0.1825654358   +0.0634186864   +0.0113932779   +0.9810800552    sum squs = +0.9999999497  +2.6276101260   +6.9081227284  +21.2413852449
    +0.0005502258   +0.0181907974   -0.2293124646   +0.9731827378    sum squs = +1.0000000555  -26.5251008404   +2.0435025817  -0.4169129706
    +0.0379701219   +0.0379873700   -0.0190575924   +0.9983747005    sum squs = +1.0000000050  -2.0214710134   +4.4332999853  +4.2777858328
    +0.1421776563   +0.1788186878   +0.0416587740   +0.9726633430    sum squs = +1.0000000412  +8.0495681889   +19.6342635762  +18.0275697089
    -0.2416000813   -0.3342688680   +0.0259645525   +0.9106149077    sum squs = +0.9999999436  +15.0756420060   -36.6006764153  -34.7298720077
    +0.0000000000   +0.0000000000   +0.0000000000   +1.0000000000    sum squs = +1.0000000000  +0.0000000000   +0.0000000000  +0.0000000000
    +0.0000000000   +0.0000000000   +0.0000000000   +1.0000000000    sum squs = +1.0000000000  +0.0000000000   +0.0000000000  +0.0000000000
    -0.0013705824   -0.0047476389   -0.0055176513   +0.9999725819    sum squs = +1.0000000275  -0.6315546125   -0.5448992324  -0.1540581944
    -0.0002179843   -0.0194163416   -0.3695584238   +0.9290046096    sum squs = +1.0000000350  -43.3998593387   -2.0766736500  +0.7995938917
    -0.0381897017   -0.6430811286   -0.0234443955   +0.7644858360    sum squs = +1.0000000244  +4.4177386253   -80.0780864235  -9.4322343545
    +0.0172815081   +0.1676424295   -0.1667936444   +0.9714819789    sum squs = +0.9999999898  -19.7157479464   +19.3591213839  -1.3571896291
    -0.0011378765   +0.0047027008   +0.0202233475   +0.9997837543    sum squs = +0.9999999494  +2.3170456268   +0.5414182810  -0.1194701201
    -0.2264718562   -0.1660457850   +0.4406757355   +0.8526102304    sum squs = +1.0000000133  +56.0534307300   -4.7922679610  -32.3030476656
    -0.0418538116   +0.8028841019   +0.0247014631   +0.5941508412    sum squs = +1.0000000070  +7.4251721953   +72.9670051832  +1.9701113044
    +0.0022718122   +0.0688987225   +0.0323999561   +0.9970948100    sum squs = +1.0000000124  +3.7581457004   +7.8887411361  +0.5203097663
    -0.3605583012   -0.4344316721   -0.1733115017   +0.8069881797    sum squs = +0.9999999651  +3.4140766971   -55.7042659859  -49.9541032693
    +0.2243260294   +0.1274575591   +0.0513146892   +0.9647793770    sum squs = +1.0000000404  +9.2202763455   +12.8802680946  +27.2221190368
    -0.0548719205   -0.0131644774   +0.1631041616   +0.9849938154    sum squs = +1.0000000151  +18.8304236382   -0.4603295875  -6.4533948925
    ============ anim quaternion frame 1 ============
    The next block should be the position or pose data so its done as
    triples:

    Code:
    Pose data: 
    ================== anim pose frame 0 ============
    +0.0000000000   +0.0000000000   +0.0000000000
     +0.0952388272   +0.0007522855   -0.0000000016
     +0.0225613043   -0.4644488990   +0.0143959904
     +0.0241626762   -0.3995066285   -0.0316338763
     -0.0000000072   +0.2124620080   +0.0000000010
     -0.0002945314   +0.2115578204   +0.0000000317
     -0.0000617032   +0.2349731475   +0.0000000667
     +0.0003562687   +0.0108105456   -0.0034470414
     +0.0016836965   +0.1178482845   -0.0744606182
     +0.0132546313   +0.1300114095   -0.0273839347
     +0.1653589308   -0.0517836995   +0.0034832763
     +0.3022064567   +0.0111386590   -0.0137692019
     +0.2838370204   -0.0030556649   +0.0263375491
     -0.0102220755   +0.1300113946   -0.0273839198
     -0.1678023189   -0.0517838039   +0.0034833569
     -0.3021733761   +0.0111954454   -0.0144314468
     -0.2838012874   -0.0032004488   +0.0267044865
     -0.0952387974   +0.0007523632   +0.0000000220
     -0.0216093566   -0.4641438425   +0.0230784863
     -0.0250774939   -0.3986378312   -0.0406115353
     ================== anim pose frame 1 ============

    This looks right because it matches the standard skeleton:

    Code:
    0.0       ,   0.0        ,   0.0        
    -0.095239 ,   0.007520   ,   0.0        
    -0.022561 ,   -0.464449  ,   0.014396   
    -0.024163 ,   -0.399507  ,   -0.031634  
    0.0       ,   0.212462   ,   0.0        
    0.000295  ,   0.211558   ,   0.0        
    0.000062  ,   0.234973   ,   0.0        
    -0.000356 ,   0.010810   ,   -0.003447  
    -0.001684 ,   0.117848   ,   -0.074461  
    -0.013255 ,   0.130011   ,   -0.027384  
    -0.165359 ,   -0.051784  ,   0.003483   
    -0.302206 ,   0.011139   ,   -0.013769  
    -0.283837 ,   -0.003056  ,   0.026338   
    0.010222  ,   0.130011   ,   -0.027384  
    0.167802  ,   -0.051784  ,   0.003483   
    0.302173  ,   0.011195   ,   -0.014431  
    0.283801  ,   -0.003200  ,   0.026704   
    0.095239  ,   0.000752   ,   0.0        
    0.021609  ,   -0.464144  ,   0.023078   
    0.025077  ,   -0.398638  ,   -0.040612
    (Don't worry about the signs on the x values, The standard skeleton
    was made to work with Milkshape so there's always to x -> -x transform
    for that.)

    So far, so good. The problem is I still have 76 floats left over that look like
    this:

    Code:
    What the heck are these data: 
    We have 76 leftover floats
    +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0145724751   +0.0491957590   +0.0002147975
     +0.0301976539   +0.1019454375   +0.0004450644
     +0.0437174141   +0.1475874335   +0.0006442972
     +0.0519736372   +0.1754599810   +0.0007659923
     +0.0510471202   +0.1819434315   +0.0005802182
     +0.0442738384   +0.1494659334   +0.0006524611
     +0.0348668732   +0.0312059894   +0.0020629363
     +0.0234865602   -0.0744927898   +0.0031001847
     +0.0119119827   -0.0558995418   +0.0018968056
     +0.0000000000   +0.0000000000   +0.0000000001
     +0.5000000000   +0.0000000000   +0.0000000000
     +0.0000000000   +0.0000000001   +0.0000000000
     +0.0000000000   +0.0000000000   +0.0000000000
     +0.0000000000
    For a big 4.5 second animation like CR_spear_die_galloping.cas it's
    worse, I have 556 floats left over, mostly zeroes or repeating values
    but no idea what they are. The pose data on the last anim frame
    still looks ok, I don't think I've slipped data by miscalculating the
    frame offsets.

    Another GrumpyOldMan question is this:

    If I have my rotation matrix parametrized by the quaternions as

    Code:
             _                                                                                           _
            |                                                                                             |
            |   q1^2 - q2^2 - q3^2 + q4^2      2 * ( q1*q2 + q3*q4 )         2 * ( q1*q3 - q2*q4 )        |
            |                                                                                             |
            |   2 * ( q1*q2 - q3*q4 )          -q1^2 + q2^2 - q3^2 + q4^2    2 * ( q2*q3 + q1*q4 )        |
    R   =   |                                                                                             |
            |   2 * ( q1*a3 + a2*q4 )          2 * ( q2*q3 - q1*q4 )         -q1^2 - q2^2 + q3^2 + q4^2   |
            |                                                                                             |
            |_                                                                                           _|

    and similarly for Euler's

    Code:
            _                                                                                        _
           |                                                                                          |
           |     cos(psi) cos(theta)           sin(psi) cos(theta)             -sin(theta)            |
           |                                                                                          |
    R   =  |            -                              -                        cos(theta) sin(phi)   |
           |                                                                                          |
           |            -                              -                        cos(theta) cos(phi)   |
           |_                                                                                        _|
    is that Mete's convention or is it one of the other 11 sets?
    Last edited by KnightErrant; 04-12-2007 at 01:38.

  13. #13

    Default Re: Animations

    Hi KE

    I didn't quote your reply, so I hope I get everything clear for you.

    The next lot of floats after the skeleton are global position vectors for the bones, so number of frames by number of bones by x, y, z. (I get a lot more than 76 floats here are you sure you just haven't printed off the first three float values of each frame's worth??). Although the local positon value hasn't changed, you have to remember this is preprocesed to plug into the engine. The only significant one to worry about is the y value for the first bone this give the movement perpendicular to the ground plane.

    Next there is number of frames by x and z 'incremental' movement for the first bone (pelvis). This shows you how much the figure moves parallel to the ground plane each frame.

    Below is the function I'm using for Quat to Euler conversion :-

    Code:
    QuatToEuler(a4,a1,a2,a3);data read in from original file - a1,a2,a3,a4
    
    
    Function QuatToEuler(w#,x#,y#,z#)
    	Local sint#, cost#, sinv#, cosv#, sinf#, cosf#
    	Local cost_temp#
    
    	sint = (2 * w * y) - (2 * x *z)
    	cost_temp = 1.0 - (sint * sint)
    
    	If Abs(cost_temp) > QuatToEulerAccuracy
    		cost = Sqr(cost_temp)
    	Else
    		cost = 0
    	EndIf
    
    	If Abs(cost) > QuatToEulerAccuracy
    		sinv = ((2 * y * z) + (2 * w * x)) / cost
    		cosv = (1 - (2 * x * x) - (2 * y * y)) / cost
    		sinf = ((2 * x * y) + (2 * w * z)) / cost
    		cosf = (1 - (2 * y * y) - (2 * z * z)) / cost
    	Else
    		sinv = (2 * w * x) - (2 * y * z)
    		cosv = 1 - (2 * x * x) - (2 * z * z)
    		sinf = 0
    		cosf = 1
    	EndIf
    
    	; Generate the output rotation
    	roll# = -ATan2(sinv, cosv) ;  inverted due to change in handedness of coordinate system
    	pitch# = ATan2(sint, cost)
    	yaw# = ATan2(sinf, cosf)
    End Function
    Don't worry about the QuatToEulerAccuracy, I thought it was a bit fancy-shmancy, so I just deleted the constant but haven't updated the function yet. Read it as '0'.

    I wrote this code a while ago and it exports the animation but facing in the -z direction. Shouldn't take much to fix but the Menu/Tools/Mirror All fixes the orientation.

    Now the results come out as calculated roll equalling pitch, calculated pitch equalling yaw and calculated yaw equalling negative roll. I've never got around to cleaning it up as long as I was getting the right numbers out .

    If you want to take the language for a shareware ride I can pass the code onto you.

    Cheers

    GrumpyOldMan

  14. #14

    Default Re: Animations

    Hi alpaca

    Quote Originally Posted by alpaca
    Edit: By the way, does anybody have any resources on bone weigthing?
    You could have a look at

    http://www.chumba.ch/chumbalum-soft/...84&postcount=1

    which is Mete from Milkshape's very basic instruction on using the bone weight editors. Have a look through the forum, I seem to remember there being other posts (by Wes H??) on working with bone weights on Sims2 figures.

    Cheers

    GrumpyOldMan

  15. #15
    feed me! Member Ashdnazg's Avatar
    Join Date
    Dec 2006
    Location
    Haifa, Israel
    Posts
    54

    Default Re: Animations

    I couldn't see if this was seen earlier, so I post this anyway.
    I had a wee look in Verc's script, and the second short in the header is the number of bones.
    About the fifth byte, I think he actually skipped it.
    a.k.a Lord hokomoko @ the Lordz Modding Collective

  16. #16
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    @GOM
    Python is being unkind to me tonight and I can't find
    my bug yet, but I still wanted to clarify two things:

    (1) Went through the quaternion to yaw, pitch, and roll
    and I think I'm following the same conventions. Meaning I
    followed my quat vs euler matrices and worked through your
    QuatToEuler function and I arrive at the same ATan2
    relations for the angles. So I think
    your code for rotations x, y, z -> roll, pitch, yaw is right
    without having to interchange roll->pitch, pitch->yaw, and
    yaw->roll. Does Milkshape really require this (excluding the roll
    minus sign)?

    (2) Byte counts: My example last night was for the CR_spear_charge.cas
    which is a small one (7 KB) . If I count bytes this way

    Code:
    5                                 - header
    nframes*NBONES*4*4     - quaternion block
    nframes*NBONES*4*3     - pose block
    nframes*4*3                 - global block  (only bone_pelvis)
    nframes*4*3                 - relative block (only bone_pelvis)
    40 final bytes, or 10 float - leftovers
    Last 8 bytes always seem to be FF FF 0F 00 00 00 00 00, so maybe a
    terminating signature.

    This seems to square with the bytelength in the index file so I think
    this is ok. For 11 anim frames I get 33+33+10=76 floats that I had last
    night. So the global block and the relative block track the movement
    of the single bone_pelvis to give the overall traversal of the model, and
    the quaternions give the relative animation?

    The game then seems to be, merge a .cas with a .ms3d and write the
    anim stuff to the joint section, suitably merging the global and relative to
    the pose data, since Milkshape doesn't have extra places for this, and
    put the transformed quats into the rotation angles part. Reverse process
    is separate the global and relative from the position vectors, reconvert
    angles back to quaternions and write out a new .cas.

    Is the jerky nature of the unpacked .cas files simply that the number of
    bones in the standard skeleton for M2TW is different from RTW so the anim
    frames aren't coming out right? Caliban has hinted that someone could
    simply (simply?) change the MaxScript script to fix this but no one has
    stepped to the plate.

    Back to fighting Python, I can see the data I want in xvi32 put it won't print
    out for me. This is finally the end for me, it's easier to simply read the data
    in hex than it is to try to print it out.

  17. #17

    Default Re: Animations

    @KE

    I've just got to close down for a while before I throw the mouse through the monitor, getting very sick of looking at hex for RTW cas files.

    It's terrible to see two old addicts in the clutches of their vice, isn't it?

    The jerky movement is indeed just a matter of trying to cram RTW rotations onto a m2tw skeleton, it just requires a simple renumbering operation I imagine within the plugin/script - disregarding the cloak bones and taking into account the clavicles, jawbone and eyebrow.

    Cheers

    GrumpyOldMan

  18. #18
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    I know the feeling... I think I'll slow down on anims and finish
    writing instead. Hate leaving loose strings about. Thanks for
    the info re jerky animations, that's what I thought from Caliban's
    comments.

  19. #19

    Default Re: Animations

    By the way, Verc's animation script, though fantastic, was buggy at least in two respects:

    1) it produced flickering animations for certain skeletons, wherein a bone would very quickly rotate 180 degrees back and forth. Sometimes hoplites would flicker their shields, and sometimes horses would flicker with their legs.

    2) it could not modify most turn animations. The actual turn often proceeded in-game smooth enough, but the soldier would instantly turn back to his original position, and then turn back to his new direction again, and then back, etc etc. He couldn't complete turning back and forth, and you would have to order the entire unit to go elsewhere, upon which he'd stop and run with the rest of his unit. It's almost as if the script didn't register that the angle of the soldier's orientation was changed to the desired angle, and the engine kept trying to turn him; or it could be something else.
    Last edited by SigniferOne; 04-13-2007 at 20:09.

  20. #20
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Animations

    C'mon guys, no turning back now

  21. #21
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Naw, not turning back, just finishing up things before the plunge.
    Found out a little more today. The 8 floats before the final 8 signature
    bytes follow this form:

    first is the length of time of the animation, e.g. an 11 frame animation
    is 0.5 seconds (1/20 of a second per frame, first frame starts at 0.0), a
    91 frame animation is 4.5 seconds, etc.

    second SEEMS to be the maximum excursion of all the entries in the relative
    block or, same thing, the maximum excursion of bone_pelvis.

    third, fourth, and fifth are just the last frame of the relative positions,
    sort of like a registration position.

    sixth, seventh, and eighth: no clue. They're not the same as any other
    entry when they're non-zero. For the stationary animations (non walking,
    running) they're usually zeros.

    Anyway, just finishing up a little utility to convert binary .cas files to an
    editable text form that can be converted back to .cas by the same
    converter. Not the way I would want to do it, but it might be fun for
    people to play with until the Milkshape stuff is sorted out. Just need to
    add a script to turn Euler angles into quaternions that people can use
    to change entries.
    Last edited by KnightErrant; 04-14-2007 at 02:19.

  22. #22

    Default Re: Animations

    Hi KE

    Here is some more code to work with quats and eulers:-

    Code:
    ; Change these constants if you notice slips in accuracy
    Const QuatToEulerAccuracy# = 0.001
    Const QuatSlerpAccuracy#   = 0.0001
    
    ;convert a Rotation to a Quat
    Function EulerToQuat(pitch#,yaw#,roll#)
    ;NB roll is inverted due to change in handedness of coordinate systems
    Local cr# = Cos(-roll/2)
    Local cp# = Cos(pitch/2)
    Local cy# = Cos(yaw/2)
    Local sr# = Sin(-roll/2)
    Local sp# = Sin(pitch/2)
    Local sy# = Sin(yaw/2)
    ;These variables are only here to cut down on the number of multiplications
    Local cpcy# = cp * cy
    Local spsy# = sp * sy
    Local spcy# = sp * cy
    Local cpsy# = cp * sy
    ;Generate the output quat
    w# = cr * cpcy + sr * spsy
    vectorx = sr * cpcy - cr * spsy
    vectory = cr * spcy + sr * cpsy
    vectorz = cr * cpsy - sr * spcy
    End Function
    
    ; convert a Quat to a Rotation
    Function QuatToEuler(quatx#,quaty#,quatz#,quatw#)
    Local sint#, cost#, sinv#, cosv#, sinf#, cosf#
    Local cost_temp#
    sint = (2 * quatw * quaty) - (2 * quatx * quatz)
    cost_temp = 1.0 - (sint * sint)
    If Abs(cost_temp) > QuatToEulerAccuracy
    	cost = Sqr(cost_temp)
    	Else
    	cost = 0
    	EndIf
    If Abs(cost) > QuatToEulerAccuracy
    	sinv = ((2 * quaty * quatz) + (2 * quatw * quatx)) / cost
    	cosv = (1 - (2 * quatx * quatx) - (2 * quaty * quaty)) / cost
    	sinf = ((2 * quatx * quaty) + (2 * quatw * quatz)) / cost
    	cosf = (1 - (2 * quaty * quaty) - (2 * quatz * quatz)) / cost
    	Else
    	sinv = (2 * quatw * quatx) - (2 * quaty * quatz)
    	cosv = 1 - (2 * quatx * quatx) - (2 * quatz * quatz)
    	sinf = 0
    	cosf = 1
    	EndIf
    ;Generate the output rotation
    vectorx = -ATan2(sinv, cosv) ;  inverted due to change in handedness of coordinate system
    vectory = ATan2(sint, cost)
    vectorz = ATan2(sinf, cosf)
    End Function
    
    ;use this to interpolate between quaternions
    Function QuatSlerp(Ax#,Ay#,Az#,Aw#,Bx#,By#,Bz#,Bw#,t#)
    Local scaler_w#, scaler_x#, scaler_y#, scaler_z#
    Local omega#, cosom#, sinom#, scale0#, scale1#
    cosom = Ax * Bx + Ay * By + Az * Bz + Aw * Bw
    If cosom <= 0.0
    	cosom = -cosom
    	scaler_w = -Bw
    	scaler_x = -Bx
    	scaler_y = -By
    	scaler_z = -Bz
    	Else
    	scaler_w = Bw
    	scaler_x = Bx
    	scaler_y = By
    	scaler_z = Bz
    	EndIf
    If (1 - cosom) > QuatSlerpAccuracy
    	omega = ACos(cosom)
    	sinom = Sin(omega)
    	scale0 = Sin((1 - t) * omega) / sinom
    	scale1 = Sin(t * omega) / sinom
    	Else
    	;Angle too small: use linear interpolation instead
    	scale0 = 1 - t
    	scale1 = t
    	EndIf
    vectorx# = scale0 * start\x + scale1 * scaler_x
    vectory# = scale0 * start\y + scale1 * scaler_y
    vectorz# = scale0 * start\z + scale1 * scaler_z
    w# = scale0 * start\w + scale1 * scaler_w
    Return w#
    End Function
    
    ; result will be the same rotation as doing q1 then q2 (order matters!)
    Function MultiplyQuat#(Ax#,Ay#,Az#,Aw#,Bx#,By#,Bz#,Bw#)
    Local a#, b#, c#, d#, e#, f#, g#, h#
    a = (Aw + Ax) * (Bw + Bx)
    b = (Az - Ay) * (By - Bz)
    c = (Aw - Ax) * (By + Bz)
    d = (Ay + Az) * (Bw - Bx)
    e = (Ax + Az) * (Bx + By)
    f = (Ax - Az) * (Bx - By)
    g = (Aw + Ay) * (Bw - Bz)
    h = (Aw - Ay) * (Bw + Bz)
    w# = b + (-e - f + g + h) / 2
    vectorx# = a - ( e + f + g + h) / 2
    vectory# = c + ( e - f + g - h) / 2
    vectorz# = d + ( e - f - g + h) / 2
    Return w#
    End Function
    Should be enough to fill in your weekend

    edit :- If you haven't looked already

    http://www.gamasutra.com/features/19...ernions_01.htm ,

    most of the code is based on this.

    Cheers

    GrumpyOldMan
    Last edited by GrumpyOldMan; 04-14-2007 at 02:54.

  23. #23
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Many thanks for the references, most of the quaternion stuff I've
    got is from memos at work. There's a group that uses them for attitude
    control for reentry vehicles in simulations which doesn't really
    translate easily to moving bones around. Oh, it did hit me yesterday about
    the cyclic permutation for the yaw, pitch, and roll, of course Mete's
    convention has the y-axis as the vertical. D'oh!

    Edit: Went and joined, lots of refs on quaternions in gaming. Even a few
    physics ones!
    Last edited by KnightErrant; 04-14-2007 at 04:07.

  24. #24
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Well, I tested unpacking all the cas files and found examples
    violating almost all of the rules from a couple posts back.
    The first of the last eight floats is the animation time in
    seconds. The header in descr_skeletons.dat say there will always
    be an odd number of frames so this number will always be a multiple
    of a tenth of a second. Otherwise the remaining seven floats I have
    no rules for.

    The header bytes aren't always 20 0 20 (14 00 14 hex), they have lots
    of variations especially for the stratmap anims. The final 8 bytes aren't
    always FF FF 0F 00 00 00 00 00 they have lots of variations too.
    Here's a chunk with some stratmap examples from the extraction log:

    Code:
     31         20   20         data/animations/MTW2_Swordsman/MTW2_Swordsman_at_mid_c_stab_v1_s1_slashrl_fail.cas                                 39586546  18149         255 255  15   0   0   0   0   0
     47         20   20         data/animations/MTW2_Swordsman/MTW2_Swordsman_at_mid_c_stab_v1_s1_slashrl_success.cas                              39604695  27493         255 255  15   0   0   0   0   0
     23         20   20         data/animations/MTW2_Swordsman/MTW2_Swordsman_at_overhead_c_stab_fail.cas                                          39632188  13477         255 255  15   0   0   0   0   0
     29         20   20         data/animations/MTW2_Swordsman/MTW2_Swordsman_at_overhead_c_stab_success.cas                                       39645665  16981         255 255  15   0   0   0   0   0
     55         20    1         data/animations/MTW2_Swordsman/MTW2_Swordsman_basepose.cas                                                         39662646  19625           1   0   0   0   0   0   0   0
     41         20   20         data/animations/MTW2_Swordsman/MTW2_Swordsman_charge_jump_attack.cas                                               39682271  23989         255 255  15   0   0   0   0   0
     99         20    1         data/animations/New_Crew/Crew_Stand_to_Wide_Push.CAS                                                               39706260  35289           1   0   0   0   0   0   0   0
     25         20    1         data/animations/New_Crew/Crew_Wide_Push.CAS                                                                        39741549   8945           1   0   0   0   0   0   0   0
     39         20    1         data/animations/New_Crew/Crew_Wide_Push_to_Crew_Stand.CAS                                                          39750494  13929           1   0   0   0   0   0   0   0
     67          2    1         data/animations/New_Swordman/Weapon/Sword_Default.CAS                                                              39764423   4601           1   0   0   0   0   0   0   0
     59         19    1         data/animations/SM_D01 Diplomat unselected idle 01.cas                                                             39769024  20105           1   0   0   0   0   0   0   0
     51         19    1         data/animations/SM_D01 Diplomat unselected idle 02.cas                                                             39789129  17385           1   0   0   0   0   0   0   0
     45         19    1         data/animations/SM_D01 Diplomat unselected idle 03.cas                                                             39806514  15345           1   0   0   0   0   0   0   0
     21         19    1         data/animations/SM_D03 Diplomat selected idle.cas                                                                  39821859   7185           1   0   0   0   0   0   0   0
     25         19    1         data/animations/SM_D06 Diplomat walk loop.cas                                                                      39829044   8545           1   0   0   0   0   0   0   0
     35         19    1         data/animations/SM_D11 Diplomat standing to stepping backwards.cas                                                 39837589  11945           1   0   0   0   0   0   0   0
     35         19    1         data/animations/SM_D12 Diplomat stepping backwards loop.cas                                                        39849534  11945           1   0   0   0   0   0   0   0
     25         19    1         data/animations/SM_D13 Diplomat stepping backwards to stand.cas                                                    39861479   8545           1   0   0   0   0   0   0   0
     23         19    1         data/animations/STRAT LID_08_Stand 2 90 right.cas                                                                  39870024   7865           1   0   0   0   0   0   0   0
     23         19    1         data/animations/STRAT LID_09_Stand 2 90 left.cas                                                                   39877889   7865           1   0   0   0   0   0   0   0
    107         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_assassinate.cas                                                   39885754  59537         255 255   7   0   0   0   0   0
     25         19    1         data/animations/Stratmap_Assassin/Strat_Assassin_basepose.cas                                                      39945291   8545           1   0   0   0   0   0   0   0
     39         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_die_backward_1.cas                                                39953836  21729         255 255   7   0   0   0   0   0
     83         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_die_forward_1.cas                                                 39975565  46193         255 255   7   0   0   0   0   0
     41         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_no_mp_idle.cas                                                    40021758  22841         255 255   7   0   0   0   0   0
     15         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_no_mp_to_stand_A.cas                                              40044599   8385         255 255   7   0   0   0   0   0
    131         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_sabotage.cas                                                      40052984  72881         255 255   7   0   0   0   0   0
     33         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_selected.cas                                                      40125865  18393         255 255   7   0   0   0   0   0
     41         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_idle.cas                                                  40144258  22841         255 255   7   0   0   0   0   0
     11         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_idle_selected.cas                                         40167099   6161         255 255   7   0   0   0   0   0
    111         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_lf_idle_1.cas                                             40173260  61761         255 255   7   0   0   0   0   0
     81         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_lf_idle_2.cas                                             40235021  45081         255 255   7   0   0   0   0   0
     85         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_lf_idle_3.cas                                             40280102  47305         255 255   7   0   0   0   0   0
     29         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_to_no_mp.cas                                              40327407  16169         255 255   7   0   0   0   0   0
     25         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_to_walk.cas                                               40343576  13945         255 255   7   0   0   0   0   0
     59         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_to_walk_backward.cas                                      40357521  32849         255 255   7   0   0   0   0   0
     33         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_turn_90_ccw.cas                                           40390370  18393         255 255   7   0   0   0   0   0
     33         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_stand_A_turn_90_cw.cas                                            40408763  18393         255 255   7   0   0   0   0   0
     35         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_unselected.cas                                                    40427156  19505         255 255   7   0   0   0   0   0
     33         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_walk.cas                                                          40446661  18393         255 255   7   0   0   0   0   0
     27         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_walk_backward.cas                                                 40465054  15057         255 255   7   0   0   0   0   0
     29         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_walk_backward_to_stand_A.cas                                      40480111  16169         255 255   7   0   0   0   0   0
     25         19   19         data/animations/Stratmap_Assassin/Strat_Assassin_walk_to_stand_A.cas                                               40496280  13945         255 255   7   0   0   0   0   0
     55         19   19         data/animations/Stratmap_Diplomat/Strat_Diplomat_backward_1.cas                                                    40510225  30625         255 255   7   0   0   0   0   0
     21         19    1         data/animations/Stratmap_Diplomat/Strat_Diplomat_basepose.cas                                                      40540850   7185           1   0   0   0   0   0   0   0
    105         19   19         data/animations/Stratmap_Diplomat/Strat_Diplomat_conduct_diplomacy.cas                                             40548035  58425         255 255   7   0   0   0   0   0
     67         19   19         data/animations/Stratmap_Diplomat/Strat_Diplomat_forward_1.cas                                                     40606460  37297         255 255   7   0   0   0   0   0
     41         19   19         data/animations/Stratmap_Diplomat/Strat_Diplomat_no_mp_idle.cas                                                    40643757  22841         255 255   7   0   0   0   0   0
    The header and trailers are in decimal and I'm showing the three header
    bytes as a short and a byte so 20 0 20 is shown as 20 20.

    I modified two .cas files for MTW2_Spear and tried putting them in game
    using the no_animdb=1 and no_animdb=true under [util] in my cfg file
    under the assumption it was like the io_filefirst switch, i.e. only put in
    modified files under /data/animations. No joy. Thinking it might be an
    all or nothing I put the whole unpacked animations directory and
    renamed pack.dat and pack.idx. This just crashed. That's all the experiments
    so far.

    Edit: The .evt event files referred to in descr_skeleton.txt aren't in pack.dat
    so is it crashing because they're not there? Couldn't find them by hexing through
    events.dat, that's related to other sound events.
    Last edited by KnightErrant; 04-15-2007 at 20:04.

  25. #25

    Default Re: Animations

    Erf, the .evt files caused a major problem in RTW also, and ultimately led to downfall of all attempts by CA helpers to allow us to keep animations unpacked. They always had to be packed back into the files, or else the game would crash. (Editing the animations and then stuffing them back into pack files was only way of modding them.) Maybe Caliban can help us there.

  26. #26
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    Ahh, thanks for that info. Reading zxiang1983's thread has me thinking
    re-packing is the only way to get this to work too. Kind of ugly if that's
    the only way, though.

  27. #27
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    OK, documentation is out of the way. Back to the fun stuff.
    Wrote an animmerge script to combine a stock ms3d mesh with
    a cas file. Here's the walk animation in Milkshape:



    EDIT: Forgot the significant part, the shields held up is done by changing the animations in Milkshape.

    and also the celebration .cas in Milkshape:




    From here you use the animextract utility to extract to a .cas to put in
    game as:



    EDIT: These are the shields held up in-game.

    NOTE This ain't right, everybody has become left-handed. Not that I mind, I'm
    left-handed myself.

    Unresolved Problems:

    (1) Does no_animdb=1 work? PM into Caliban hasn't been answered.
    Can't unpack skeleton.dat into the /animations directory because OS constraints don't allow a file without an extension to have the same
    name as a directory. (Repeating xziang1983 here, been down this road.)

    (2) Unpack in a higher directory? Maybe, haven't tried this.

    (3) Unpack in a lower directory? Same answer, try later.

    (4) Repacking the pack isn't that bad. Live with it.

    (5) Maybe the TYPE files have an implied extension we just don't know
    about. This would be nice but we need information.

    (6) What the heck is the global data? I just saved it in the materials comment
    section but need to know what it really is. Also the mystery 8 floats at
    the end, also written into the materials comment section.

    (7) Outside the bounds, but the TYPE files (using the language of
    descr_skeleton.txt) have bone info in them, can these be modded
    to change the sizes of units re Bwian's question in the mesh thread?
    Last edited by KnightErrant; 04-26-2007 at 06:35.

  28. #28
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Animations

    Haha those sergeants are really screwed
    The arms look weird... hmm, maybe the game saves some bone positions you didn't export correctly?

  29. #29
    Member Member KnightErrant's Avatar
    Join Date
    Jan 2007
    Location
    Huntsville, Alabama USA
    Posts
    458

    Default Re: Animations

    I just don't know how to use Milkshape. The verts didn't
    move with the joints when I edited the keyframes. Anyway,
    just an experiment for repacking and putting modded cas's
    back in game.

    Got a reply from Caliban. He showed me a .jpg of his /animations
    directory. Could not see from that if the type files were unpacked
    there or not but the .evt files are definately there so they need to
    be found and unpacked.

    I asked for two experiments: try searching for navy_strat*.* and
    fs_camel*.*. If these don't turn up any files then skeletons.dat
    isn't meant to be unpacked and the question should be settled.

    I've been looking at the data at the top of the type files
    before it gets to the animation families and the standard skeleton rig is
    in there. These could probably be modded to make custom
    animations for re-rigged figures, i.e. like dwarves etc., if the engine
    will accept more entries in skeletons.dat and skeletons.idx.

  30. #30

    Default Re: Animations

    Search in the skeleton.dat? Not sure if I follow you right here but if your looking for animations in there with this as part of the filename you wont find them, however the animations in the descr_skeletons file under the fs_camel and strat_navy all reference cas's are in the dat. Sorry if I'm not with you here, having trouble following this

    About the evt files, looking at one of the ones that's not packed theres reference to anim_cannon_creak or similar, events.dat has the same text followed by paths for relevant sounds. Looking around a bit in there theres stuff like anim_archer_aim which in turn corresponds to text in the skeleton.dat at the archers animations. Possible they're packed in here?
    Last edited by Casuir; 04-26-2007 at 23:07.

Page 1 of 9 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO