Part TwoReformatting the SMD we exported from OpenBRF, or: stealing my reformatted SMDREVISION: Apparently this reformatting step is unnecessary with some text programs (including Microsoft Word). I used "notepad" and so needed to reformat my SMD files from Mod Tool. However, forumite mtarini tells me that most text programs will see a nicely formatted SMD already. So, if you use a program other than "notepad", you may find that you don't need to reformat your SMD file after exporting it from Mod Tool.Now open the SMD animation file that you just exported from OpenBRF. You’ll see a hideous mass of text which extends several metres to the right. Animation files exported from M&B with OpenBRF don’t know how to do paragraphing it seems. So, like a narky forumite, we’re going to reformat this SMD so that it’s easy to read and work with. This will help us later on when we export our new animation data from XSI Mod Tool. In fact I’ll just give you the reformatted version – since we only need to have one properly formatted file from M&B, you don’t need to know how to reformat them. We need it because – at least with the way I do it – XSI Mod Tool exports SMDs with some redundant information, and a nicely formatted SMD from the game can help us fix them up quickly.
So, here’s the reformatted “anim_human_ready_slashright_twohanded.smd”. We’ll use this to tidy up whatever animations we export from XSI Mod Tool – don’t worry if you exported some other SMD from OpenBRF, this one will do just as well.
version 1
nodes
0 "abdomen" -1
1 "thigh.L" 0
2 "calf.L" 1
3 "foot.L" 2
4 "thigh.R" 0
5 "calf.R" 4
6 "foot.R" 5
7 "spine" 0
8 "thorax" 7
9 "head" 8
10 "shoulder.L" 8
11 "upperarm.L" 10
12 "forearm.L" 11
13 "hand.L" 12
14 "item.L" 13
15 "shoulder.R" 8
16 "upperarm.R" 15
17 "forearm.R" 16
18 "hand.R" 17
19 "item.R" 18
end
skeleton
time 0
0 0.002980 -0.048350 9.104100 0.000000 -1.570796 1.570796
1 0.628640 1.089370 -0.408870 3.141591 -0.086538 3.141591
2 4.649140 0.006280 -0.152480 0.000000 0.006659 0.000000
3 4.724810 0.000000 0.000000 -0.000382 -1.565503 -3.141211
4 0.615950 -1.120970 -0.411960 3.141591 -0.081798 3.141591
5 4.669700 0.025960 -0.151690 0.000000 0.020869 0.000000
6 4.698490 0.000000 0.000000 -0.000136 -1.556099 -3.141457
7 1.972170 0.012830 0.000000 -0.030366 0.000000 -0.006836
8 1.985240 0.001840 0.000060 0.006341 -0.000196 0.006335
9 2.705030 0.000240 0.000000 0.008152 -0.000346 0.014506
10 1.758180 0.692770 0.008290 -1.777310 -0.023953 1.647033
11 1.454170 0.000000 0.000000 0.108582 0.052931 0.010999
12 2.770650 0.000000 0.000000 -0.021798 0.032954 0.003188
13 2.720050 -0.001310 0.011070 0.139929 -0.013553 0.017038
14 0.642300 0.121820 0.167370 -0.022679 0.034877 1.539277
15 1.758870 -0.686840 -0.024860 1.773674 0.023954 -1.646038
16 1.454170 0.000000 0.000000 -0.108581 0.052931 -0.010999
17 2.771110 0.002230 -0.003730 0.018988 0.030166 -0.002914
18 2.717440 0.001100 0.009450 -0.126333 -0.000301 -0.023219
19 0.647860 -0.124370 0.170260 -0.010578 0.018687 -1.544341
time 25701
0 -1.005780 0.439990 7.513610 2.868206 -1.532449 -1.822081
1 0.628640 1.089370 -0.408870 2.564335 0.637867 2.805891
2 4.649140 0.006280 -0.152480 0.037756 1.245160 0.035694
3 4.724810 0.000000 0.000000 0.666617 -1.139397 2.383906
4 0.615950 -1.120970 -0.411960 -2.854918 0.087993 -2.627975
5 4.669700 0.025960 -0.151690 0.258195 0.941168 0.207119
6 4.698490 0.000000 0.000000 -0.111493 -1.091705 -2.604735
7 1.972170 0.012830 0.000000 -0.410736 -0.018571 -0.095328
8 1.985240 0.001840 0.000060 -0.448526 -0.023778 -0.186137
9 2.705030 0.000240 0.000000 1.352829 -0.075965 0.262798
10 1.758180 0.692770 0.008290 -2.048966 0.934497 1.395724
11 1.454170 0.000000 0.000000 -1.065424 -0.578745 1.199236
12 2.770650 0.000000 0.000000 -0.203261 0.088308 0.521817
13 2.720050 -0.001310 0.011070 1.101839 0.944529 0.282864
14 0.642300 0.121820 0.167370 -0.100639 -0.021199 1.602711
15 1.758870 -0.686840 -0.024860 2.439766 0.022927 -1.316669
16 1.454170 0.000000 0.000000 1.302205 -0.924201 -1.150749
17 2.771110 0.002230 -0.003730 1.402306 0.002712 -0.216053
18 2.717440 0.001100 0.009450 -0.088075 -0.039083 0.356886
19 0.647860 -0.124370 0.170260 -0.010685 0.019148 -1.546891
time 25711
0 -1.005780 0.439990 7.513610 2.868206 -1.532449 -1.822081
1 0.628640 1.089370 -0.408870 2.564335 0.637867 2.805891
2 4.649140 0.006280 -0.152480 0.037756 1.245160 0.035694
3 4.724810 0.000000 0.000000 0.666617 -1.139397 2.383906
4 0.615950 -1.120970 -0.411960 -2.854918 0.087993 -2.627975
5 4.669700 0.025960 -0.151690 0.258195 0.941168 0.207119
6 4.698490 0.000000 0.000000 -0.111493 -1.091705 -2.604735
7 1.972170 0.012830 0.000000 -0.410736 -0.018571 -0.095328
8 1.985240 0.001840 0.000060 -0.448526 -0.023778 -0.186137
9 2.705030 0.000240 0.000000 1.352829 -0.075965 0.262798
10 1.758180 0.692770 0.008290 -2.048966 0.934497 1.395724
11 1.454170 0.000000 0.000000 -1.065424 -0.578745 1.199236
12 2.770650 0.000000 0.000000 -0.203261 0.088308 0.521817
13 2.720050 -0.001310 0.011070 1.101838 0.944530 0.282862
14 0.642300 0.121820 0.167370 -0.100639 -0.021199 1.602711
15 1.758870 -0.686840 -0.024860 2.439766 0.022927 -1.316669
16 1.454170 0.000000 0.000000 1.302205 -0.924201 -1.150749
17 2.771110 0.002230 -0.003730 1.402306 0.002712 -0.216053
18 2.717440 0.001100 0.009450 -0.088075 -0.039083 0.356886
19 0.647860 -0.124370 0.170260 -0.010685 0.019148 -1.546891
end
Copy this text over the text of your unformatted smd (or into a blank text file for that matter), then save the file as “Reformatted anim_human_ready_slashright_twohanded.smd” or whatever. Import the reformatted version into OpenBRF (in OpenBRF, “Import” -> “Skeletal Animation" -> [the reformatted SMD]), and you should see that it works normally. If it doesn’t you’ve probably made a mistake in your reformatting or when you copy-pasted the text from this post (I checked, and copy-pasting it from here works).
Now I’ll tell you how to interpret it!
Interpreting the content of SMD animation filesThis is pretty obvious once you understand it. At the top is a list of the skeleton’s bones (here called “nodes” apparently). You’ll see that there are 20 of them, just like OpenBRF says in the “Data” box, numbered 0-19 (for some bloody reason). Their names are pretty much self-explanatory – for example, “item.R” is the item held in the right hand (the oldschool bastard sword held by the mesh).
Below this list is a line which reads “time 0”. The 20 lines below this refer to the 0th frame of animation. It’s the T pose that skeleton’s stand in by default, and I have no idea why it exists, but it’s in all the animation SMDs I’ve looked at. We’ll leave it here, because it doesn’t hurt, and I don’t know what happens if it’s removed.
You’ll see that the rest of the file is the same sort of stuff repeated. There’s “time 0” and 20 lines of stuff, then “time 25701” and 20 lines of stuff, and finally “time 25711” and another 20 lines of stuff. The last two “times” are actually identical for ready positions (again, I don’t quite know why but we’ll leave it). You can see that these “time” values are the interval values that you can see in the “Data” box in OpenBRF when you look at the relevant animation after splitting “anim_human”. In a full movement with many frames, each frame has a time value. This value tells the game when within the overall animation the frame occurs. So, if you have an attack animation with an interval of 0-10, and some information under the heading “time 5”, the game will put the skeleton into the position defined by that information half the way into the animation. As far as I know, the length of the interval is irrelevant – a longer interval will not make a longer animation. The only relevant thing is the positioning of the frames within the interval. For example, an animation with an interval of 0-10, with frames at 0, 5, and 10 would be identical to an animation with an interval of 0-100 with frames at 0, 50, and 100. After all, the temporal length of the animation is defined elsewhere (and then modified by the weapon speed value and the character’s proficiency). Getting the time values right for your frames is important, because they determine the rate of the various stages of the animation. If this is impossible to understand, don’t worry, it’ll become clearer later when I give an example.
The rows of information under each “time” heading define the positions of the skeleton’s bones within 6 axes – the 3 axes of translation, and the 3 axes of rotation. You’ll see there are 6 columns, 3 for translation first, and then 3 for rotation. Only the “abdomen” bone actually uses translation information as far as I know. If you try translating this bone in XSI Mod Tool, you’ll see that the whole mesh moves with it. You’ll often want to translate this bone, for example when lowering the character’s stance. The other 19 bones use only rotation information. The mesh is not rigged to deform properly when you translate any of these other 19 bones.
As a piece of trivia, the units of rotation used in the SMD files are
radians. One hundred and eighty degrees are equal to pi (3.14blah) radians, so 90 degrees are equal to 1.5707… or some bloody thing. This becomes slightly relevant later when we discover that SMD files exported from XSI Mod Tool are off by 90 degrees of rotation in the abdomen!
Exporting an animation SMD from XSI Mod Tool 7.5Now let’s open up XSI Mod Tool again. We’ll be making a few frames, exporting them as an SMD, tidying up said SMD, and then importing that SMD into OpenBRF. If you get an animation into OpenBRF you can be pretty confident that the game will accept it.
So let’s just make a simple one like before. Indeed we will put this animation in game for lols. And once we’ve done that, you’ll know how to make and implement new animations from scratch! First, move to frame 1 on the timeline, select the everything by dragging a selection box around the whole mesh, press “C” then “K”, then “V” then “K” again. Now the T pose is keyed at frame 1. Next, move to frame 30 on the timeline, select one of the hip bones, press “C”, rotate the bone about 90 degrees, so that the leg is sticking straight out, and press “K” to key this. Now, still on frame 30, select the knee of that leg and rotate it so that the lower leg is pointing towards the ground, then key that. (It may look a bit silly because he’s basically wearing a skirt.) Now move to frame 100, rotate the knee bone so that the leg is straight again, and key that. When you press play, the character should lift his knee, then straighten his leg. It will look extremely unnatural and stupid, and you can fiddle with it however you like, as long as there are only keyframes at 0, 30, and 100. Well really, key however the hell you like, but beware that the detail of my super-specific instructions may no longer apply to you (gasp). Just don’t actually try to animate the movement you want yet, because you need to know a bit more about interval numbers to get the timing right. Save your freaking scene right now.
Now, if you have things keyed at frames 1, 30, and 100 to make a recognisable movement, click on “ValveSource” in the bar at the top of the window, and click on “Export SMD…” in the dropdown menu. In the window that pops up, look in the “Options” box, select “Skeletal Animation (.SMD)” as the file type, and untick all the boxes below. Then click on the three dots next to the field labelled “File”, name your SMD file (“Test animation” or whatever), choose a location for it (I recommend the desktop), press OK in the browsing window, and then OK in the other window. A little loading bar should pop up and fill, and your SMD should have appeared on the desktop. Double click on it to open it, notice the familiar format and be horrified until you read the rest of this sentence wherein I tell you that we won’t actually be working with this SMD.
Exporting an SMD with only the necessary frame information from XSI Mod Tool 7.5If you scroll down in the SMD we just exported from Mod Tool, you’ll see that it has 100 “time” values. It gave us all 100 frames of information, instead of just the three keyframes that we need - 1, 30, and 100. Remember, the game blends keyframes together itself – it doesn’t need the intermediate frames. So, we’ll use Mod Tool to shift our keyframes into the 1st, 2nd, and 3rd positions on the timeline so that the SMD will contain only the necessary information. We’ll then insert the correct time values into the SMD so that the game will blend it together with proper timing.
So, open your animation in XSI Mod Tool 7.5. Select everything and press “0” (zero on the keyboard). Behold the function curves. Be not afraid. Notice the timeline at the bottom of this window. All the colours and positions of the lines mean stuff, but we don’t really care! Drag a selection box from the top to the bottom of the lines (or the bottom to the top if that’s how you choose to live your life), to select them all. They should turn white, and you should see little coloured squares appear on some of the lines at the 1st, 30th, and 100th positions on the timeline. With the lines selected (white), drag another selection box around the squares at the 30th frame. They should turn red and become flanked by black squares. Now press “Ctrl+X” to “cut” this information, move the timeline in the f-curve window to frame 2 (the position immediately after the first set of coloured squares), and press “Ctrl+V” to paste the information in at that point. Now, repeat the process for the information at frame 100, cutting it from there and pasting it in at frame 3. If you find it hard to see things, you can scroll through the f-curve window by dragging the red vertical in its timeline past the visible ends, and you can zoom in and out using the mouse wheel. All the coloured squares should now be above the first 3 frames in the timeline. Now close the f-curve window.
If you select the character now, you’ll see the keyframes are at 1, 2, and 3 on the timeline. When you press play, he’ll snap his leg out like a maniac, but this is okay because we just want the frame information – we’ll be telling the game where to place the keyframes so that they have proper timing. The last thing to do here is to resize the timeline so that it includes only frames 1 to 3. On the far right of the timeline is a dark grey box with “100” in it. Click on this, and enter 3. Done! Your timeline should now have only 3 frames, all with nice little red squares on them when you select the character.
Now, export the SMD for this animation as before. Remember to untick the 3 boxes in the export window. Now have a look in the SMD file. It should look the same as before, but it’ll have only 3 time values. Now we have to reformat it a bit.
Fixing up SMD animation files exported from XSI Mod Tool 7.5Make sure you have my reformatted SMD from the spoiler in this post, and that you’ve checked that it works by importing it into OpenBRF. (If it does work, you should see the static pose held by the character before a two-handed attack from the right – there will be no actual movement.)
Open the SMD file we just exported from XSI Mod Tool. You’ll notice that its contents are slightly different from the reformatted file. For one thing, it has 22 bones in the list at the top – numbered 0-21 – and 22 lines of bone information for each time value. This is because XSI Mod Tool has given us the information for the skin and an extra node between the feet. This information is strange and incomprehensible and will cause OpenBRF to become paralysed with fear. So we have to remove it and make the file look like the reformatted version. The bones also have funny names, since beings from XSI Mod Tool are all descended from and named after the almighty Thigh. You can probably work out the equivalents of all these names, but you don’t need to.
So to fix it up, open the reformatted SMD that I put in this post, and open your new animation SMD with the 3 time values. In the reformatted SMD, select everything above “time 25701” and press “Ctrl+C” to copy it. Now, in the SMD for your new animation, select everything above “time 1”, and press “Ctrl+V” to paste the stuff from the reformatted SMD over it. If you want to save your new SMD as you work on it, I suggest saving it under a new name in case you make some invisible mistake (my favourite kind). Now your new SMD has a proper list of bones at the top, the T pose information at “time 0”, as well as the information for your 3 keyframes. Now we need to renumber the other time values, and remove the information for the two redundant bones (“0” and “1”, also known as “thigh.mesh” and “thigh” [peace be upon him]). Lastly, we’ll renumber the remaining bones, which are already in the right order, so that they run from 0-19.
So, for times 1, 2, and 3, delete the top two rows of bone information. That is, delete the rows beginning with 0 and 1. Now, acquire carpal tunnel syndrome by renumbering all the remaining rows so that they are numbered from 0 to 19 under each time value. I recommend using the keyboard – replace a number, then use the arrow keys to get to the next row, replace that, and so on. It doesn’t take long once you get the hang of it. Obviously, each number needs to be 2 lower than it is – so 2 becomes 0, 3 becomes 1 and so on. You must renumber them manually, because the information beside these numbers is unique, so you can't just paste over it (though there might be some fancy way of replacing them en masse which I haven’t thought of). Now replace the time values so that the 4 time values for the whole SMD are, in order: 0, 1, 30, and 100.
Don’t freak out about spaces at the ends of lines and stuff like that. As far as I know, SMDs are pretty tolerant of that stuff. I mean, we made some pretty big changes when we reformatted the animation exported from OpenBRF.
Anyway, once you’ve finished tidying up the SMD, save it under a new name (in case you made a mistake). Now import this SMD into OpenBRF, note that the character has been rotated forwards by 90 degrees, and behold the whacky movement!
To fix the orientation of the character, open your SMD again (the one that you just tested in OpenBRF). Copy the “0” line of information from “time 0”, and paste it over the “0” lines in all the other time values. Like I said before, for some reason SMDs from XSI are off by 90 degrees of rotation in the abdomen. Copying the information from “time 0” – the T pose taken directly from M&B – will fix that. You can also subtract 1.570796 (half pi to 6 decimals) from the second column of rotation information in all the frames taken from XSI. You’ll probably need to do this subtraction for more advanced animations, since you may well want to rotate the “abdomen” (really the hips) for some movements. It’s possible that you can also fix the rotation by moving the character around in XSI before exporting, but I haven’t tried that properly.
The hard way to fix the orientation of the character is to change the rotation information for the abdomen bone directly in the SMD. The easy way is to rotate the abdomen bone in Mod Tool backwards by 90 degrees of global rotation. To do this, at each keyframe select the abdomen bone, select global, as opposed to local, rotation in the panel at the right, then hold down shift and move the mouse to rotate the bone in regular steps until you’ve rotated it back 90 degrees. Key this rotation at each keyframe before you export the animation, and the orientation of the character will be correct in OpenBRF and (later) in the game.
In fact, XSI throws off the
translation of the abdomen as well. You can probably fix this in XSI Mod Tool like you can with rotation, but at the moment I fix it by going into the SMD and swapping the second and third rows of translation information for the abdomen bone at each frame, and then changing the sign of the second colomn (i.e., make a positive number negative and vice versa). Of course, if your character’s hips don’t move in the animation, you can just copy the information from an earlier row rather than making the same adjustment over and over.
By fiddling with the SMD, then viewing it in OpenBRF, you can work out what rows and columns affect what and by how much – I’ve actually fixed hand positioning and footwork on some of my animations by fiddling with the text of the SMDs directly. (If you haven’t been put off this animation method by now, I’ll make you a batch of cookies or something.)
Test your SMD after doing these fixes (import the animation into OpenBRF), to make sure it works. If the character is upside down or has moved in the wrong direction, it means you rotated the abdomen the wrong way in XSI Mod Tool, swapped the wrong columns in the SMD, or inserted/deleted a minus sign in the wrong place. Just fiddle around and observe the results of each act of fiddling until you work out what does what. It’s all sickeningly logical.
Adding a new, properly formatted animation SMD to “skeletons.brf” so that it can be referenced to appear in the gameFinally! We’re up to the last stage before you can make your own animations from scratch and get them into M&B! For FREE!
Open OpenBRF, and open “skeletons.brf”. Click on the “Animation” tab. The list should show “anim_human” and nothing else, yet. Click on “Import” in the bar at the top of the window, and click on “Skeletal Animation” in the dropdown menu. Select your new, properly formatted SMD that you tested successfully in OpenBRF before. Now, the list should show “anim_human” and your new animation. Click on it and it should play in a ridiculous looking loop. The “Data” box should say that there are 20 bones, 3 frames, and that the interval is 0-99. It subtracts “1” from all the time values for some reason, don’t worry about it. If you move through the “time of frame” thingy, it should show 1 as 0, 2 as 29, and 3 as 99.
If everything is correct here, and “anim_human” is intact, save the file. Don’t change the destination or anything like that, we want to overwrite the “skeletons.brf” that’s in CommonRes.
Using Python to replace an existing animation with our new animation for our new moduleThis is very simple. Make sure you followed
Armagan’s tutorial for setting up the module system so that it targets your new module folder. I recommend that you also backup any Python files that you mess with, and put them somewhere where you’ll know what they are. Though of course, if you set up the module system correctly, Native will be unchanged because the module system will not be targeting the Native folder.
When you’ve done all that, open your module system folder, right click on “module_animations.py”, and click on “Edit with IDLE” in the dropdown menu. I think two windows will open. We’re after the one with the red text and hashes at the top, and we can close the other. You can read the text at the top if you like.
We’re going to replace one of the game’s “ready positions” with our new animation. So, press “Ctrl+F” to search for text, and search for “ready_thrust_onehanded”. Under this is some text that says “[ready_durn, “anim_human”, SOME NUMBER, SOME OTHER NUMBER, blend_in_ready],”. I can’t remember exactly what it says, because I’m looking at an edited version! Anyway, all you need to do is change the text that says “anim_human” here to the name of your new animation that you saved in “skeletons.brf”. Then, you change the interval numbers to the numbers that were shown in the “Data” window of OpenBRF. You can also change “ready_durn” if you wish. This defines the duration of your animation, and I recommend changing it to a specific time (maybe half a second or a whole second), so you can see that interval length makes no difference to animation speed.
You also need to remove the text from the top line that says “acf_parallels_for_look_slope”. This line tells the game that the ready position changes depending on the pitch of the camera. I don’t actually know how to animate so that it will change with the pitch. I think you need to make more animations, one for highest pitch and one for lowest, and reference those somehow so that he game blends between them depending on the camera pitch. Anyway, we’ll just delete it so that our animation will look the same regardless of camera pitch.
So, after all that, the relevant text in Python should look something like this:
["ready_thrust_onehanded", acf_thrust|acf_anim_length(100)|acf_rotate_body|acf_enforce_rightside,
[1, "Test_animation2", 0, 99, blend_in_ready],
I named my animation “Test_animation2”, as you can see, and gave it a duration of “1” (1 second). This text should be properly formatted – I copied it from my post into Python and it was identical.
Done! Now save the file and close it. Then, in your module system folder, double click on “build_module.bat” to build your new module. Once this has finished, assuming there were no errors, you can fire up M&B and have a look at your new animation in-game. If you replaced the same animation as I did, you can see your new animation by holding down the attack button for a thrust attack with a one-handed sword. It should look quite hilarious.
Conclusion That concludes this part of the tutorial. Assuming I wrote it properly, you now know how to replace animations in M&B with your own new animations. The same procedure can be used for attacks and ready positions, and you can probably do much the same for other animations, including walk-cycles and so on, though I haven’t made any of these myself.
In the next post, I’ll (more briefly but still comprehensively) show you two methods for animating movements and getting them in-game with proper timing. One of these methods involves making and using visual references and is (luckily for us) essentially foolproof.