Author Topic: [Tutorial] How to add New Animations to your module.  (Read 8231 times)

0 Members and 1 Guest are viewing this topic.

cdvader

  • Guest
[Tutorial] How to add New Animations to your module.
« on: August 12, 2009, 09:41:10 PM »
Introduction.
Greetings, it's CdVader again, with another tutorial. This time, I'll show you how to either Add a new animation or edit old ones. The reason I'm making this tutorial is because of a Post I saw, and that made me think "Hey, why not make a tutorial!" :P . So, Berserker Pride asked this.
Quote from:  Berserker Pride
I wonder if you could duplicate an animation so that you wouldn't have to overwrite an existing throwing type.
And hopefully, I will show you how to do that.

Anyway. Thanks to 'mtarini' we can now edit, add, and do all kinds of things with Animations. Let's begin.

What do we need?
The game.
Mount & Blade - Version 1.011.
Mount & Blade - Module System for Version 1.011.

Some kind of a animation editing program. Here's two of the (probably) most known:
Autodesk 3ds Max
Blender

And the import/export SMD scripts for them.
3ds Max SMD Import/Export
Blender SMD Import
Working Blender Export Script.

And the most important thing of all.
Open BRF

PART 1 - Getting ready.
Okay. First of all, make sure you've got a working copy of Mount & Blade v1.011 and the ModuleSystem all set-up. Before you begin this tutorial, You must have SOME knowledge of the Module System. I highly recommend The Official ModuleSystem Documentation or another, a extremely good (a bit advanced) ModuleSystem Documentation made by Jik. After you have set up the ModuleSystem and gone through the Documentations, we can continue.

Now, install 'mtarinis' Open BRF. Just download & extract it to somewhere, like onto your desktop. OpenBRF is a very good alternative to BRFEdit, because it can edit Animations and Skeletons, which BRFEdit cannot. However, since OpenBRF is still in it's very early development stages (Alpha stage), it doesn't have all the necessary features like Material, Collision or Shader tabs. Thus, currently you should only use OpenBRF for Skeleton and Animation related stuff, and BRFEdit for all the other. But I'm quite sure that soon enough, OpenBRF will be better and more complete.

The next step is to get a Animation and Skeleton editing program. Blender is a bit complicated, but good. And it's also free, which is a really good thing. The other solution - 3ds Max is better in all ways, especially the price part. That's the only downside of Max - It costs around 3500$. I personally use 3ds Max. To get it, either download the 30-day Tutorial or, if you're lucky, you may get a Commercial edition (Or something like that) from school.

Okay, I belive we're ready.

Part 2 - Adding a "new" animation.
If anyone has seen the movie "Braveheart", in the last battle William's good friend inspired his fellow lads to battle by throwing William's giant sword over the field. If you haven't seen the movie, you can see the scene here. William Wallace's sword flight. It's really epic and it can also hurt your enemy real bad (Should the throw hit the enemy). So we'll try to create something like that, expect a bit more simpler, less epic, so you could throw many swords in a row.

Alright. Open 'OpenBRF', go to File > Open and open uni_throws. Whoa, a lot of Opens in that sentence. Ok, click on 'throw_javelin' and Duplicate it (press Right-Click). Rename it (Right-Click again) to 'throw_braveheart'. Go to File > Save and exit OpenBRF. Basically, that's how you duplicate Animations, so you won't run into the problem Berserker Pride had. If you don't duplicate and rename a animation, and then make a new animation line in module_animations.py, it will overwrite the type.

However, if you want to actually add in completely new, from-scratch animations, then either open 'skeletons.brf' using OpenBRF and export the skeleton there as 'Nude' or go to Tools > Edit Reference Data, click on the Skeleton tab and click on "human" and Export it as 'Nude'. Get the new, exported Nude skeleton to Blender or 3ds Max using a SMD Importer. When exporting from Max, make sure you tick it to a "Sequence" instead of "Referene". I am not sure about how it works in Blender. Currently, the OpenBRF's exporter is a bit unfinished (OpenBRF is still in Alpha stage), so all of the bones seem to be out of place, but you can actually create new animations, the only down-side is that it is harder to understand the skeleton than normal. However, do not fret, OpenBRF's Importer seems to re-fix the screwed up bone system. Importing it is really easy too, just open an existing .brf file (Can't make new ones currently) and go to Import > Skeletal Animation. That's it.
Okay, so in short, look at the old, existing animations to see how much Frames you approximately you need, export a Nude skeleton without any animations, make your animation, Import as Skeletal Animation and watch your new animation!
If you want to see a example, download this file. Don't worry, it's an .AVI so it cannot be a virus. It's a basic animation showed in OpenBRF I did just to test.

Okay, 'new' animation set-up, we can now move on. Go where your ModuleSystem is located, and open "module_animations.py", "header_items.py" and, not so necessary but for the sake of keeping it simple, "module_items.py". First, we will edit module_animations.py. Copy "ready_javelin" and "release_javelin" approximately at line 509. Paste them (replacing the old "unused_human_anims") at line 1123. Make sure you replace the old animations. Now, rename the stuff to _braveheart. Should look like this.

Code: [Select]
["ready_braveheart", acf_rotate_body,
   [0.3, "throw_braveheart", 0, 30, blend_in_ready],
 ],
 ["release_braveheart", acf_rotate_body,
   [1.0, "throw_braveheart", 55, 100, arf_blend_in_0],
 ],

Basically, these small script parts "define" the animation. If you look at the first script, 4 major things catch your eye. "ready_braveheart" is the first, that is the animation ID, used for referencing the animation. The next thing is "acf_rotate_body", which is pretty easy to guess. It rotates the body. The next thing is "throw_braveheart". That is the name of the animation resource/sequence, and the last one, "blend_in_ready", is basically a line that makes the animation blend in with other animations. The "0, 30" part is the frame count. Now you know all that is necessary, and we can move on.

Go to header_items.py. Find "itcf_throw_javelin" and copy the whole thing to the bottom of the itcf_ list, right before the itc_cleaver. Rename it to itcf_throw_braveheart". If you did it right, it should look like this.

Code: [Select]
itcf_force_64_bits                                   = 0x8000000000000000
itcf_throw_braveheart                                   = 0x0000000000040000
itc_cleaver

And now we make a new itc_ . Basically, from my understanding, an itc_ (item capabilities) is a list of various animations packed together. If you put itc_scimitar to your item, you will not be able to stab/thrust, because the itc_ doesn't have itcf_thrust_onehanded. itcf_, again from my understanding, is necessary to link into itc_ tag. So, now you have two choices. You either make a new itc_ OR simply put itcf_ to your item. However, I prefer to use itc_ in any case, because then it looks cleaner and you can, if needed, add other animations to the itc_ later. So let's make a new itc_ called itc_braveheart below itc_greatlance. If you did it right, it should look like this.

Code: [Select]
itc_greatlance = itcf_thrust_onehanded_lance |itcf_thrust_onehanded_lance_horseback| itcf_thrust_polearm
itc_braveheart = itcf_force_64_bits | itcf_throw_braveheart
ixmesh_inventory   = 0x1000000000000000

I'm not 100% sure why the itcf_force_64_bits is for, but most of the itc_ seem to have it, and it works with it perfectly, so it's better we keep it in. Okay. We can now save and move on to module_items.py. In module_items.py, simply copy 'practice_javelin' or other javelin kind of weapon, and paste it at the very end, right before the last ']'. If you did it right, it should look something like this.

Code: [Select]
["rabati", "Rabati", [("rabati",0)], itp_type_head_armor   ,0, 278 , weight(2)|abundance(100)|head_armor(20)|body_armor(0)|leg_armor(0) ,imodbits_cloth ],
["braveheart_sword", "Braveheart Sword", [("b_bastard_sword",0),("b_bastard_sword", ixmesh_carry)], itp_type_thrown |itp_primary|itp_bonus_against_shield ,itc_braveheart|itcf_carry_quiver_back|itcf_show_holster_when_drawn, 0, weight(5) | spd_rtng(91) | shoot_speed(28) | thrust_damage(27, blunt) | max_ammo(50) | weapon_length(75), imodbits_thrown],
]

As you can see, we have added itc_braveheart to the item. I also kept the old itcf_carry_quiver_back, just to show that you can have both itc_ and itcf_ on the item. You can and should add the two itcf_ to itc_braveheart. Then it looks much cleaner. Okay. You've got ALL basically ready, I hope I haven't forgot anything or something like that. Now start making decapitation animations! And don't forget to post some feedback...

Enjoy,
cdvader.

Critical Update (15/08/09) - You *can not* make a completely new .brf file from scratch and put your custom animation in it, else you will get a RGL error. However, you *can* add your new custom animation to an existing .brf file in CommonRes/ which has the prefix ani_ and you will not get a RGL error.
I have yet to test if adding ani_ or uni_ to your custom mod .brf files work.

Credits.
A big thanks to mtarini for Open-BRF.
And, of course, a big thanks to Armagan for Mount & Blade.
« Last Edit: August 15, 2009, 06:21:32 PM by cdvader »

amade

  • Grandmaster Knight
  • *
  • Own up and take it like a man
    • View Profile
    • Studio Wossname
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #1 on: August 13, 2009, 12:34:00 AM »
Excellent tutorial! I'll try it out with Blender and tell you how it goes once I figure some things out!

Don't you just love herding cattle?
*end.transmission - Studio Wossname*
___________________________________________________________________________________________________________________________

   .

cdvader

  • Guest
Re: [Tutorial] How to add New Animations to your module.
« Reply #2 on: August 13, 2009, 12:47:34 AM »
Yup. Thanks for the feedback. And I thought this was a hot topic. :P . By the way, if you want to set custom animation types, look at the other itcf_ files. For example, if you want to have a reload animation, you need to make "itcf_reload_customanimation". If you want to have parry, set it to "itcf_parry_customanimation". I'm pretty sure this is how it works.

I hope you get the main idea.
cdvader, baned with what the Hexadecimal numbers mean.

EDIT: Also, you can make some pretty awesome stuff by simply editing the existing animations, too. For example, I exported the "equip_arms" animation sequence from "ani_equip_arms.brf" as a .smd and opened it in 3ds Max, looked for the right sequence what I wanted and came up with this.

Code: [Select]
["equip_custom_arm", 0, [1.0, "equip_arms", 132, 153, arf_blend_in_0]],
 #["unequip_custom_arm", 0, [1.0, "equip_arms", 153, 132, arf_blend_in_0]], #Untested.

I think it's pretty cool. And I think it's unused. Basically, it equips something with the right hand in a rather long reach. Probably useful for giant longswords.
« Last Edit: August 13, 2009, 01:06:36 AM by cdvader »

amade

  • Grandmaster Knight
  • *
  • Own up and take it like a man
    • View Profile
    • Studio Wossname
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #3 on: August 13, 2009, 01:39:58 AM »
Drat, SMD import works fine now but openBRF export still screws up my skeletons in Blender edit: and can't import it back properly. Won't be able to test this yet... I'm gonna make a bug report first.
« Last Edit: August 13, 2009, 03:24:30 AM by amade »

Don't you just love herding cattle?
*end.transmission - Studio Wossname*
___________________________________________________________________________________________________________________________

   .

mtarini

  • Resource Wrangler
  • Knight at Arms
  • *
  • [TLD] and [OpenBRF]
    • View Profile
    • [home]
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #4 on: August 13, 2009, 02:45:30 AM »
cool tutorial... thanks!

But, can you relate on: how can I add a custom run animation (say) so that that some characters use it,  other don't?
For example, say I wanted orcs in a fantasy module to walk/pose/run differently from humans...




amade

  • Grandmaster Knight
  • *
  • Own up and take it like a man
    • View Profile
    • Studio Wossname
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #5 on: August 13, 2009, 03:34:19 AM »
Quote
However, do not fret, OpenBRF's Importer seems to re-fix the screwed up bone system.

Doesn't work this way for me atm, it did for version 0.0.7 but only with SMDs exported from openBRF.

Quote
When exporting from Max, make sure you tick it to a "Sequence" instead of "Referene".
Ach, I think there may be a problem here. The only option I have with my Blender export script is "Selected as reference model".

What's the difference between sequence & reference? If I can't export as sequence does that mean that time stamps/frames don't work?

Don't you just love herding cattle?
*end.transmission - Studio Wossname*
___________________________________________________________________________________________________________________________

   .

Rize

  • Sergeant Knight at Arms
  • *
  • It's a monkey, no matter what you say!
    • View Profile
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #6 on: August 13, 2009, 09:00:24 AM »
 This tutorial rules! There's tons of new animations I'll make for my mod!
« Last Edit: August 13, 2009, 01:49:35 PM by Rize »

cdvader

  • Guest
Re: [Tutorial] How to add New Animations to your module.
« Reply #7 on: August 13, 2009, 09:25:03 AM »
Amade, the OpenBRF's Exporter screws up the skeleton, yes, but when you re-import the SMD file to OpenBRF, the skeleton seems to be re-fixed.

mtarini, I haven't found anything for the Skins system, like the item system (I mean, I don't think there's itcf_ flags for other stuff expect items). However, if you want to have your orcs run differently, you could try putting the right prefix before the animation...

Code: [Select]
Default:
["run_right_onehanded", acf_enforce_lowerbody,
   [0.8, "run_man_right_onehanded", 0, 24, arf_use_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
 ],

New bit:
["run_right_onehanded_orc", acf_enforce_lowerbody,
   [0.8, "run_orc_right_onehanded", 0, 24, arf_use_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
 ],

'run_right_onehanded_orc' is the name of the custom animation. I think they're hardcoded using the prefixes. Example, for equipping items, you do 'equip_onehanded_orc'. That's why you need to keep run_right_onehanded but add in your last, custom bit _orc.
'run_orc_right_onehanded' is the name of the sequence. Same as above.

The only fault to this is that I don't know how to "link" them to your Skin type. Oh and, by Skin type I mean module_skins.py and header_troops.py . The Skins are the tf_ flags, basically.

Rize, thanks. I got a free commercial edition. :)
« Last Edit: August 13, 2009, 09:27:53 AM by cdvader »

amade

  • Grandmaster Knight
  • *
  • Own up and take it like a man
    • View Profile
    • Studio Wossname
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #8 on: August 13, 2009, 09:35:10 AM »
Amade, the OpenBRF's Exporter screws up the skeleton, yes, but when you re-import the SMD file to OpenBRF, the skeleton seems to be re-fixed.

That's what I thought too, but after editing it in Blender and reimporting into openBRF it gave me an error message (reported in the openBRF thread). Wouldn't work anyway, 'cos the Blender export script I used didn't have an option for exporting animation sequence.

I did find a new script which can export animation sequence after some searching and it works alright (after a hell lot of trial and error) but there's a certain problem where BRFedit can import the output SMDs just fine yet openBRF can't and simply crashes. I think I know what the problem is but I don't want to burden mtarini with any more than what I've piled on him :'P

I'll see if I can modify the export script to make it work with openBRF. If all else fails I'll post some more info about it and ask for help.

edit: eierkopf has released BRFexport script for Blender which solves this problem. See updated links in cdvader's first post.
« Last Edit: August 15, 2009, 06:46:44 PM by amade »

Don't you just love herding cattle?
*end.transmission - Studio Wossname*
___________________________________________________________________________________________________________________________

   .

cdvader

  • Guest
Re: [Tutorial] How to add New Animations to your module.
« Reply #9 on: August 13, 2009, 10:11:29 AM »
Well, wunderboy's 3ds Max SMD exporter works. For now, a fixed exporter would be really good. And with your extremely detailed bug report, it might be possible.

cdvader

Dain Ironfoot

  • Grandmaster Knight
  • *
  • No sex please, we're dwarves
    • View Profile
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #10 on: August 13, 2009, 11:24:31 AM »
Hrmm. So we can define unique attack animations to an item this way.. what about unique idles, runs etc..
Ry'n ni yma o hyd

HokieBT

  • Grandmaster Knight
  • *
  • may the force be with you
    • View Profile
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #11 on: August 13, 2009, 01:11:42 PM »

Dain - vader said 'you could try' but I don't think he's tried this.  I briefly tried similar stuff in the past and couldn't get it to work so I think we're stuck with one "run" animation, etc.  But if somebody can get this to work it would be very cool.
 

Dain Ironfoot

  • Grandmaster Knight
  • *
  • No sex please, we're dwarves
    • View Profile
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #12 on: August 13, 2009, 01:26:48 PM »
Yes.. that's what I thought.. idles and movement animations are hardcoded to a particular item type.
Ry'n ni yma o hyd

cdvader

  • Guest
Re: [Tutorial] How to add New Animations to your module.
« Reply #13 on: August 13, 2009, 01:58:43 PM »
Yup, I haven't tried it. But I'm quite sure you can actually have new run, idle, etc animations by a simple method. Let's say we take run_right_onehanded. As far as I understand, you can not and MUST not edit the name or other stuff. However, it's said in comments that you can edit the sequence/resource and it's length.

Code: [Select]
["run_right_onehanded", acf_enforce_lowerbody,
   [0.8, "run_man_right_onehanded", 0, 24, arf_use_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
 ],

Change it to...

 ["run_right_onehanded", acf_enforce_lowerbody,
   [0.8, "run_man_right_onehanded_new", 1, 25, arf_use_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
 ],

The "run_,am_right_onehanded_new" is the new resource/sequence.
The 1,25 are the new sequence lengths. Other things are not edited.

I'm posive that it works. BUT! You're still stuck to only one run animation.
cdvader

mtarini

  • Resource Wrangler
  • Knight at Arms
  • *
  • [TLD] and [OpenBRF]
    • View Profile
    • [home]
  • Faction: Neutral
Re: [Tutorial] How to add New Animations to your module.
« Reply #14 on: August 13, 2009, 02:00:56 PM »
Only one run?  :cry:

Uhm... a glimpse of hope comes from the presence in the native game of a "feminine stance" reserved for female characters.
I've see a brf file with that stance (an animation), and I think that I've seen it used, in-game, by female characters only.

How is that achieved?
Maybe that is done with a more general mechanism which could be reused for, say orcs?
("orcs" could be a third... gender, so to speak - ahah)