Vertex Animation?

Users who are viewing this thread

In the 'A Clash of Kings' mod, there's a sword called a Witcher Silver 2h Sword. I've gotten the item in to the Floris mod. However when you draw the sword in-game, the sword goes in to your hands, but also remains in the sheath, creating the effect of having two swords.
Now, with another item from another mod I successfully integrated into the Floris mod, the sheathing and drawing works correctly, which I assume is because the model of the sheath is a vertex animation, with two parts; the sword and sheath together, and just the sheath.
My question is; how can I turn the witcher sword in to working the same way?

In OpenBRF, there are three files for this sword:
1. witcher_silver_sword_2h - this is the sword on it's own
2. witcher_silver_sword_2h_scabbard - this is the sword on it's own
3. witcher_silver_sword_2h_scabbard.1 - this is the sheath on it's own

How can I merge the two scabbard files in to a combined animated file, so as to make something that unsheathes properly in-game? Is this actually do-able with a program like OpenBRF? 
 
It is doable, it should be easy.

First, the theory:

You want a vertex animation featuring three frames:
Frame 0: unused (time 0)
Frame 1: scabbard+sheathed sword (time 0)
Frame 2: empty scabbard (time 10)

Note: actually you never need the blade. In the above, "sword" means only its visible parts, typically the handle only.

Never forget that, in a vertex animation, all frames must have the same number of vertices.
Therefore, in Frame 2, the sword model is still there, only it is invisible, e.g. it is shrunk to a point or it is tiny and all hidden inside the scabbard (this is also true for native scabbard models). A bit wasteful, but that's the way it is.

Now, how to get there (more or less).

Start with: a sword model, a scabbard model.

0) optional: remove the blade from the sword model, to optimize.
E.g., depending on your model, you can select the sword and "Split it into connected components", then delete all the superfous pieces, then select all the rest (multiple selection, with Ctrl), then "Combine meshes".

1) replicate the sword model (select it, then"Duplicate"; or, just Ctrl+C, Ctrl+V).

2) replicate the scabbard model too.

3) select one copy of the sword model, "Roto-translate-rescale...".
  Reduce its size to 0.1% or whatever.
  This will be the tiny, invisible sword model for frame 2.

4) Select the normal sized sword AND one copy of the scabbard
    (multiple selection are done by keeping CTRL pressed when clicking).
    "Combine meshes". This will be frame 1.

5) Select the shrunk sword AND the other copy of the scabbard
  (important: select them in the same order as in the previous step!!!)
    "Combine mesh", again. This will be frame 2.

6) Duplicate frame 1 to use it also as frame 0 (or duplicate frame 2, it doesn't matter)

7) Now re-order the three models in the list so that they are in correct order
    (Frame 0 above, then Frame 1, then Frame 2).
    Do so by moving each one up and down the list (select it, then Alt+Up and Alt+Down).
    That's the easiest, least error-prone way to specify the order of the frames.

:cool: Now multi-select the tree ordered frames, and "Merge as frames in a vertex ani".

(if you did something wrong, OpenBRF will complain now, as it cannot merge in this way models with mismatching vertex counts.  Also, the texture will appear garbled if you messed the order of the submeshes)

9) In the resulting vertex animation, manually edit the times for the three frames, as discussed above (0,0,10).
    OR: select an existing working scabbard, copy it (Ctrl+C), then select your newly made scabbard animation,
    then "Edit" -> "Paste timings"

10) Clean up, deleting any WIP models.

To avoid getting confused, you can always rename any WIP model as you make them (shortcut: F2).






 
Hi, mtarini, I saw your tutorial about vertex animation in OpenBRF, can you explain please how to add vertex animation in proper frames of skeletal animation, like it is in animation of firing and reloading bows, crossbows and muskets?
Or maybe you know where can I find answer? I searched and asked everythere and no one answered me:sad:
 
can you explain please how to add vertex animation in proper frames of skeletal animation,

vertex animations and skeletal animations are totally unrelated things in this system.

The games uses vertex animations in a few hardwired ways only, and I don't think it will be easy, or possible at all, to convince the game to use vertex animations for any other purpose.

The list of uses of vertex animations employed by the game is:
  • for the icons of moving things on the map
  • for the quivers, showing progressively fewer arrows
  • for the body armours changing their shape according to the gender (or, more generally, the "skin") of the wearer
  • for closing/opening hands/gloves (judging by the assets: but then it seems this is not actually done; open gloves only used in inventory, closes fist is always used in all scenes)
  • for the bows being tended during the draw-arrow animation
  • for the scabbards looking empty when they are not holding their weapon

The list above might be incomplete, but unfortunately the point is that whatever you are trying to do with vertex animations, either it is something that native does already, or you probably won't be able to make your MOD do it.

In each case in the list, the animations are used in very strict way. For example, in the quiver case, the "time" of a frame of the animation actually represents the number of remaining ammo. So if your are trying to do customize something the game does, your best bet is to replicate an existing, working vertex animation from native (number of frames, time assigned to each frame).
 
Thank you for answer:smile:
I saw vertex animation in animations of reloading and shooting from bows, crossbows and muskets, so I thought adding vertex animation to certain frames of skeletal animations is possible. It seems, I was wrong:sad:
Oh, and maybe you have any ideas how can I make animations of standing and walkind with musket on left shoulder like here?
0nt_sGLDY50.jpg

I think my brains will explode soon because of this:smile:
 
I'm don't have very updated information (e.g. for WB) but I'll tell you what I know:

You can probably attempt to replicate the pose you are showing me, including the positioning of the musket, with skeletal animations.

In the M&B skeleton, the positioning of the weapon (or in general any hand-held object) is just another "bone" (remember a (skeletal) animation basically consist in a sequence of poses).
This means that a pose determines not only how each joint is positioned (knees, shoulder, etc) but also how the hand held object is rotated (in either hand).
This is separated from the position of the hand itself (i.e. the wrist articulation).

So the most natural way to get the effect you seek could be to make stance/walk (/run?) (skeletal) animations with the hand held object in the pose you want, i.e. rotated to go over the shoulder.

For this idea to work with you, you will need to overcome one obstacle or two:

1) the hand pose: you probably need a slightly more open hand than the default closed-fist used in native. I don't think the game give modders any chance of changing hand positions (despite the fact that the hand/glove models come in two poses; I think the "open" pose is only used in the inventory, and the closed one is used in all other situations).
So your best route here, I think, is to substitute the fist pose, for all involved hands, with a new semi-closed pose designed to look at least decent for rifle holding and every other situation.

2) the rifle placement: in M&B, an animation cannot specify positions of the articulations, but only their rotations (the former are specified once and for all in the skeletons). So when defining a new pose you can only pivot the rifle around its origin, i.e. the (0,0,0) point of the reference frame used by the 3D model. In OpenBRF, that is indicated by a dot on the "floor".
This means that any given weapon, whenever it is held by a character, will touch the middle of the right hand always in the same point of the weapon (the zero of the object model), regardless of the pose/animation. In a rifle mesh, that point is is around where the trigger is, because that is where the right-hand touches it when the rifle is operated. So a pose can dictate that the rifle is vertical, like in your image, but the hand would meet the rifle about where the trigger is, which is not where it should. I hope I explained the problem. I'm not sure how to solve this. There are a few possibilities.

3) finally, you need to convince the game to use your new animations for stance / walking / (running?), the one with the rifle over the shoulder, instead of the default ones. This might be a bit of a problem too. In pre Warband M&B, it was quite a problem to convince the game to use custom animations for general movement (but relatively easy to script that for stances).

The solutions to these problems are very different depending of what you want to achieve exactly.

One scenario is that you want the rifle-over-shoulder thing to happen only to NPC, and only in non-combat related situations, e.g. for guards standing and patrolling on non-combat scene like cities.
One different, more difficult thing to do would be to make troops (and players), in combat scenes (or actually in any scene), carry the rifle over the shoulder while moving and/or standing, then switch to the firing rifle grab in when preparing to shoot;  this is a much more challenging thing to do, for a mod.

For the first scenario: just prepare a special "parade rifle" object, which is not to be used in actual combat, and as the origin where you need it; then prepare a "rifle guard stance" / "walk". Script that the NPC non-combat troop is equipped with the parade-rifle and moves / stands with the custom animation.

For the combat scenario: that a bit more tricky. Maybe one good option is to hijack the "carry position" mechanism of the game. "Carry positions" are locations where the game puts objects with are owned by the guy but are unequipped, like sheathed swords. A carry position is expressed as a combination of a bone (e.g. the hip) + a position relative to that bone (including rotation and translation). It would be cool if a new "carry position" was defined to carry rifles in hand over shoulder (it would use the right-hand-item bone). That would be nice because when "equipping" the rifle the rifle would go in the "firing grab".  The problem is that the carry position, as far as I know, are hardwired in M&B (i.e. not moddable) and new ones cannot be defined by a mod; maybe you can redefine them to be somewhere different.
 
Thanks for answer:smile:

But I must say, maybe I explained that bad, or screenshot isn't clear, but the problems I asked about are:
1) rifle must be on LEFT shoulder (all you explained so well for rifle on RIGHT shoulder is already done in NW (as example), and it is more than simple solution to add NW-animations instead of appropriate Warband-animations)
2) rifle must touch bone of left hand higher than usually in game, so fingers of left hand must be under rifle's butt, not near the trigger.

I thought solution can be
- or adding vertex animation (which will replace usuall model of rifle to such model, that will be in position like I need, but I know now that unfortunately it is impossible),
- or changing these mystic numbers like (0, 0, 0) after some animations (sorry, I didn't understand it even from your detailed answer, can I change position of rifle relatively to hand bone or just rotation of it or what is it?),
- or difficult way - via script, to replace usuall rifle just for animations of standing and walking for another model of rifle, which will be in left hand in position I want it to be, and when these two animations are not in use - rifle swiches back to usuall model.

I really hope some of these two ways can work (or that there is some other way to make it work), I want my mod be historicaly accurate in most (if not all) sides.
 
1) rifle must be on LEFT shoulder
2) rifle must touch bone of left hand higher than usually in game, so fingers of left hand must be under rifle's butt, not near the trigger.

Apologies, I didn't notice it was the LEFT shoulder... (but I was aware of problem 2, which I discussed).

Also, I'm a bit out of the scene, and I'm not familiar with NW. I wonder: is it the same as a WarBand mod, or TW changed hardwired stuff also? And, I wonder how openBRF deals with it.

In any case... I'm not sure it can be done, but if it can, then the "carry position" trick I suggested would work for left hand just as well.

To restate: "carry-positions" are used to let an item descriptor specify things like:
"this weapons is to be carried at carry-position XXX"
  (when part of the active equipment, but not currently equipped, like sheathed blades or shields on back)
Carry-position 0..24 are internally tied to something like:
"put this at ____ position and ____ rotation w.r.t. the _____ bone of the skeleton".

For example, carry positions are such as "on back", on "right hip", etc. There are like 24 of them, IIRC.
You can see them listed in openBRF, when you "mount on one bone..." a given item.

What I'm suggestion is that, if there's a way to modify/add carry positions, you could make one for "rifles-carried-on-left-hand-over-shoulder".

It would be totally possible for a carry-position to correctly specify that, including moving the rifle up (with respect to the  "item-held-in-left-hand" bone), and gluing it to the left hand, thus solving both problem 1 and 2.
(it would still be a bit tricky to make it sure the rifle always precisely touches the shoulder as well... the animations must be edited carefully)

The problem is that carry-positions are (or, used to be) hard-wired, and there's no easy way to modify them (as far as I know).
Still, there could be some way to modify them with some really deep hack in the original game code, or see if anyone did anything like this. This would probably also imply "sacrificing" one of the existing 16 existing carry-positions, i.e. replacing it with your new one.
Similar deep hacks were done for other purposes.

It is also possible that M&B evolved, since I last checked this, to allow modders customize carry-positions, if not by standard modding  py files, maybe by other means like savage editing of the various files in "data" folder (e.g. item_modifiers.txt). It sure would be nice if TW did something like that (moar power to modders!!!).

While this solution is not easily attained, it probably would have some cool merits, like having the troops embrace the rifle (passing it from left to right hand, too) when time has come for them to stop just carrying around the thing and start shooting with it.

tl;dr: does anybody know about a way, however hackish, to customize carry-positions in game?
 
I can do all the steps but when I combine the handle mesh with the scabbard, the handle has taken on the texture of the scabbard and has become as you say 'garbled'. Is there a way to fix this so that the handle and scabbard each retain the textures of the mesh they were combined from?
 
Oh, I didn't consider that your "handle" (blade-less sword) and your scabbard models used different textures. That's bad :wink:

Usually, this problem (you want to combine two objects using different textures) is handled with the so called "multi-meshes" mechanism:

multi-mesh: having the two mesh called, say, 'castle.1' and 'castle.2' -- the game will see a single item, called just 'castle', which is the combination of the two, yet each of the two meshes uses its own material (and, so, texture).

BUT, for your case, I'm not sure that scabbards, or animated meshes in general, can use this.
Its suspicious that no scabbard in native does. Maybe they can. If you try this, please report!

The usual solution is to make the two models simply share the same texture.
Incidentally, this is also more efficient, both in rendering time and (often) for memory.

If your models do not originally share the same texture, you need to combine the two textures into one, and then update the uv-mapping of both models accordingly.

This is best done "manually", by skillfully combining the pieces of textures you need into one sheet. First you assemble the texture in a image editor, then you re-position the UV accordingly in a 3D modelling software (wings3D, blender...).


Alternatively, there is also an option to do it "mechanically". In this case, OpenBRF can help. 
Small tutorial:

* First step, construct a unified texture by simply placing the two original textures next to each other.

This must be done in some image editing software (e.g. photoshop, if you have the plugin to export dds files). Be accurate. If you start with two squared textures, you now have a 2:1 rectangular texture.

* Second step, update the UV mappings (on both meshes).

Note that, even if the texture is now a 2:1 rectangle, UV coordinates still go from 0 to 1 in both directions. The vertical coord, the "V", is good as it is.
The new horizontal coord (the "U" coord) is found as such:
for the mesh using the texture which went to the left:    new_U = old_U * 0.5,
for the mesh using the texture which went to the right:  new_U = old_U * 0.5  + 0.5 .

In openBRF, you can do this with the command: "transform texture coords...".
Scale U by 50%, and, for the second mesh only, add 0.5 to it.

But again, maybe you want to do it manually instead.


Regardless, only when both objects finally use the same material, you can proceed as above.
 
mtarini said:
1) rifle must be on LEFT shoulder
2) rifle must touch bone of left hand higher than usually in game, so fingers of left hand must be under rifle's butt, not near the trigger.

Apologies, I didn't notice it was the LEFT shoulder... (but I was aware of problem 2, which I discussed).

Also, I'm a bit out of the scene, and I'm not familiar with NW. I wonder: is it the same as a WarBand mod, or TW changed hardwired stuff also? And, I wonder how openBRF deals with it.

In any case... I'm not sure it can be done, but if it can, then the "carry position" trick I suggested would work for left hand just as well.

To restate: "carry-positions" are used to let an item descriptor specify things like:
"this weapons is to be carried at carry-position XXX"
  (when part of the active equipment, but not currently equipped, like sheathed blades or shields on back)
Carry-position 0..24 are internally tied to something like:
"put this at ____ position and ____ rotation w.r.t. the _____ bone of the skeleton".

For example, carry positions are such as "on back", on "right hip", etc. There are like 24 of them, IIRC.
You can see them listed in openBRF, when you "mount on one bone..." a given item.

What I'm suggestion is that, if there's a way to modify/add carry positions, you could make one for "rifles-carried-on-left-hand-over-shoulder".

It would be totally possible for a carry-position to correctly specify that, including moving the rifle up (with respect to the  "item-held-in-left-hand" bone), and gluing it to the left hand, thus solving both problem 1 and 2.
(it would still be a bit tricky to make it sure the rifle always precisely touches the shoulder as well... the animations must be edited carefully)

The problem is that carry-positions are (or, used to be) hard-wired, and there's no easy way to modify them (as far as I know).
Still, there could be some way to modify them with some really deep hack in the original game code, or see if anyone did anything like this. This would probably also imply "sacrificing" one of the existing 16 existing carry-positions, i.e. replacing it with your new one.
Similar deep hacks were done for other purposes.

It is also possible that M&B evolved, since I last checked this, to allow modders customize carry-positions, if not by standard modding  py files, maybe by other means like savage editing of the various files in "data" folder (e.g. item_modifiers.txt). It sure would be nice if TW did something like that (moar power to modders!!!).

While this solution is not easily attained, it probably would have some cool merits, like having the troops embrace the rifle (passing it from left to right hand, too) when time has come for them to stop just carrying around the thing and start shooting with it.

tl;dr: does anybody know about a way, however hackish, to customize carry-positions in game?

Thank you for answer again, mtarini:smile:

NW - Napoleonic Wars, very nice mod, they threw away all stuff from singleplayer, added guns which can destroy walls and kill soldiers, also added officers, musicians (with possibility of playing different marshes) and colourbearers who give bonuses to shooting and melee, new menus etc. But I'm not sure they changed hardwared stuff, all I used from NW worked perfectly with Warband. And OpenBRF deals great, very useful tool indeed.

I was aware of problem 2, which I discussed
Yes, but I didn't understand it fully, am I right that it is impossible to move rifle relatively to item-bone with module system?
And can you please explain, if you do know, what mean these values (bold):
Code:
 ["stand_staff", 0, amf_client_prediction,
   [2.0, "staff_cstance", 0, 60, arf_use_stand_progress|arf_cyclic|arf_blend_in_1, 0, (0, 0, 0), 0.0],  
 ],
 ["stand_crossbow", 0, amf_client_prediction,
   [2.0, "staff_cstance", 0, 60, arf_use_stand_progress|arf_cyclic|arf_stick_item_to_left_hand, pack2f(0.40, 0.94)], 
 ],
I thought it is something about position of item relatively to item-bone and it is possible to move item in three coordinates relatively to item-bone, am I wrong?

Idea of making such animation with carry_position is promising, but there will be problems if soldier will take another weapon or will fight empty-handed (game will think he is empty-handed but he wil hold rifle anyway), but it is good idea for guards in scenes, so also is possible to make another poses with weapons.

But I think for all in battle scenes it must be done via script, replacing weapon to other model in needed coordinates only for these two animations (standing and walking), unless it is possible somehow change coordinates of item model just for certain animations in module system.
 
do you know, what mean these values (bold):

I'm not sure. I vaguely remember that one of them might be the position where the character is moved to, after it finishes the animation.
For example, if the animation does a step forward, you want the character to end it a bit in front to where it was before.
Another one, maybe, was things like the position where the projectile (and/or the smoke) is spawned (with respect to the weapon).
Another one might be the recover time (how long before the next animation can start?)

Does anybody know better?

Am I right that it is impossible to move rifle relatively to item-bone with module system?

I think you are, or, at least, I'm not aware of any mean to control that directly. :sad:

There are the workarounds we are discussing, naturally.

Let's enumerate all the possibilities we discussed so far, plus a few new ones:

1* Switch to a different item by scripting (a, as it could be called, "parade rifle" positioned differently),
2* Giving the rifle a "sheathed" version, for when it is carried in left hand,
    (which would use a new custom "carry-position", which would be based on the left-hand-item bone)
3* Using a different "frame" of a vertex animation for the carried-over-shoulder situation

And the new ones (discussed below):

4* A custom shader to move the rifle in the correct position, when carried?
5* Carry the rifle as an equipped shield?

Each of the 5 has its own difficulties to be overcome before they can actually work.
The good thing is that, its five separate battles, it just take to win one! :smile:

Some considerations for each case:

1) When I last did my modding-scripting things, it would have been a problem for a script to identify to exact moment when the rifle is equipped/unequipped.
But it is true that some short delay could be tolerated. This is because the "parade rifle" (the version which is designed to be carried over shoulder) would differ from the "action rifle" (the version which shoots), only for the positioning, so holding the wrong one for a short while is no big deal, only a minor graphical glitch.

Also, not sure how seamlessly a script can switch items, especially equipped items, without disrupting animations (and ammo count etc).
Also, the wrong positioning is probably only only one problem.
For example, how to customize animations so that the parade rifle goes over the shoulder, unless ?

2) it's might be difficult (or impossible) to customize carry positions. Plus the problems you mention, which maybe could be overcame, at least for AI,
e.g. by providing AI troops with the right equipment so they never resort to direct fist-fighting; or something else to prevent that.

3)  I remember trying hard to control which frame of a per-vertex animation is used, in various different occasions, and always failing.
Maybe things are changed now.

4) Here's the idea: a custom shader could easily shift the rifle forward (its forward, i.e. toward the bayonet to be clear).
But, how to make the shader "understand" when this has to be done?
Ok, here is a VERY crude, possible hack:
one could make the rifle model use a custom shader which.... shifts it forward whenever it is held vertically.
(The transition can be smooth: the more vertical, the bigger the shift, from 0 to the right maximal amount.)
Naturally, this means that whenever the rifle is held vertical, for whatever reason, then it is shifted up.
One should think if this is ok or not (I think it might be).
Technically, it would be totally possible for a shader to do so, because a shader always "knows" the current model-view matrix,
i.e. how vertical the object being rendered is.
Naturally, if this is the first custom shader in your mod, then there is a price to pay:
(e.g. installing your mod will become a bit more complicated for your end users, at least if things are still in the way I've left them).

5) Here's the idea: a shield, as you know, is tied to the left forearm bone.
So, maybe, it is possible to position a "parade" rifle so that this is more or less correct in most animations?
A possible thing to combine with 1. Lots of problems to hammer down, naturally.
 
Back
Top Bottom