Sign in to follow this  
Norman Barrows

placing weapon in hand in attack animations

Recommended Posts

Norman Barrows    7179

so i'm working on the attack animations for CAVEMAN.

 

63 weapons times two views (1st and 3rd person) times 2 sexes( male and female) = 252 animations total.

 

i'm finding that for each weapon i must set the rotation and translation of the weapon relative to the player's hand to place the weapon in the hand correctly. these are constant values which, once determined, will never change.

 

i've created a "mesh / model manipulator" which i can "hook up" to any mesh or model drawn with one line of code, and edit its transform in real time in the game. i use it to position the weapon in the player's hand correctly, then write down the rotations and translations, and then go back and hard code the numbers into the drawing routines. 

 

i've considered "soft coding" the values, but it seems like a lot of work and sort of a lazy way to get around waiting for a 55 second link time for each code change.

 

the "mesh / model manipulator" can currently handle 10 meshes or models at once. a typical animation only has 1-3 meshes or models that need to be manipulated. so i can "hook up" the manipulator to the animations for multiple weapons, recompile once, then run the game and adjust all those weapons and get my numbers, then code in all the values and recompile once again. short of making making the "mesh / model manipulator" handle more meshes / models at once (such as 100 at once), i'm not sure what else i can do.

 

how is this sort of thing usually handled?

 

i'm taking a weapon, rotating and translating it relative to the player's hand, applying an animation rotation / translation, then calling a routine that applies the hand's transform and draws.

 

for 3rd person animations, i use the limb based modeling and animation system in the game. i have a routine that draws a weapon at the player's hand, based on the current frame of animation for the model of the player. but i'll still need to adjust the position and rotation of the weapon to fit correctly in the hand. so far, i've only done 3 of the 3rd person attack animations.

 

 

 

Share this post


Link to post
Share on other sites
Tispe    1468

I have seen that in the palm of the hand, a bone sticks out that you can attach a weapon onto. All the weapon vertices indexes to that bone, with no skinning to any other bone. This particular bone can also be a direct child from the root bone, it is then the animators job to transform the bone in the animation track such that it follows the hand correctly.

 

You can get away with using the default hand bone by offsetting the vertices such that it is aligned correctly. But having an additional bone that the center of the weapon is attached to allows you to "flip it" around and other neat effects.

Edited by Tispe

Share this post


Link to post
Share on other sites
Norman Barrows    7179

this is similar to what i'm doing now. except i'm using a limb system, not a skinned mesh and bones.

 

in the limb system, the limb meshes are essentially equivalent to the skeleton in a skinned mesh.

 

for first person, i only draw the forearms, not a whole model.   the origin of the attachment point for the forearm parent limb is the elbow, not the palm, like in a weapon bone. it wouldn't be difficult to move the attachment point to the palm, but all that does is start the weapon closer to the hand, it still doesn't place the weapon precisely, with the hand appearing to grip it in a realistic manner. 

 

do most shooter type games not sweat such details? or do they use a "weapon and hand" model for 1st person attack animations?

Share this post


Link to post
Share on other sites
Norman Barrows    7179


I have seen that in the palm of the hand, a bone sticks out that you can attach a weapon onto. All the weapon vertices indexes to that bone, with no skinning to any other bone. This particular bone can also be a direct child from the root bone, it is then the animators job to transform the bone in the animation track such that it follows the hand correctly.

 

this would imply that they treat the weapon as an extension of the skinned mesh, and use something like 3ds max to create the animations and then just export the meshes and animations and play them back in the game. so its the 3d artists (animators) who are doing this tweak in the 3d modeling software. no wonder i find it so tedious ! <g>.

 

for 3rd person animations i can do a similar thing in the game's built-in limb based modeler and animator. but the adjustment will be done with code, so the character model and weapon model can be separate and interchangeable. that way i can use any weapon with any character model, and just have one set of weapons models, and one set of character models, instead of having a weapon-character model pair for each combo. there are over 200 female character models and over 300 male character models in the game. this is possible because limbs and textures on the limb based models are interchangeable. its all done with 2 bodies (male and female), about 10 heads (5 of each sex), about 10 hairstyles (5 of each sex), and about two dozen skin tones.

 

so normally the weapon is an extension of the skinned mesh mapped to a "weapon bone", and the adjustment is done in 3ds max or the like by the 3d artist / animator.

Share this post


Link to post
Share on other sites
Tispe    1468

I am not familiar with the limb system. In my project each character has a face, weapon, shield, helm, armor, gloves, leggings and boots. Each has its own texture. That is 8 texture changes and 8 drawcalls just to draw one character. With this system I can swap any mesh on the fly to create a mix of wearable equipment.

Share this post


Link to post
Share on other sites
Norman Barrows    7179


I am not familiar with the limb system.

 

in a limb based system, the skinned mesh is split up into separate limb meshes (head, body, upper and lower legs and arms). the limb meshes are static. no mesh deformation, no dynamic buffers, etc, so they draw FAST! limbs are assembled into a model, the same way bones are assembled into a skeleton. in essence, the limbs ARE the bones. the downside is seams where limbs join, but this can be minimized by making limb ends match well. generally speaking, a limb based system seems to typically allow about 8 to 9 times as many characters to be drawn onscreen at once vs skinned mesh systems. in 2000, directx's skinned mesh demo could do about 6 skinned meshes on the hardware at the time, compared to about 50 for limb based. on a baseline windows 7 box, i'm shooting for 200-400 onscreen at once. i've never truly stress tested it, but i have tested drawing over 150 characters at once with no problems - and these are true animated characters, no impostors, no instancing, etc.

 

 

 

 


In my project each character has a face, weapon, shield, helm, armor, gloves, leggings and boots.

 

each is a separate mesh? above and beyond the basic body mesh?

 

don't you have to make an adjustment for each weapon mesh to fit it to the body mesh correctly?

 

or do you just have one body mesh, one weapon mesh, and just change textures? which means you place the weapon mesh in relation to the body mesh one time and are done.

 

i too will have to deal with equipment as well: vest armor, leggins, shield, helm, cloak, boots, mittens, sacks, hats, and waterbags. each type will need to be adjusted to the body model once. perhaps twice, once for female body model and once for male. each type of object uses just a single mesh for all equipment of that type. so for example, there's just one vest armor mesh, and i just change textures for different types of vest armor.

Share this post


Link to post
Share on other sites
Tispe    1468

the limb meshes are static. no mesh deformation

 

Ah, I know this by the name "Rigid Body Animation", see this paper http://mathinfo.univ-reims.fr/image/dxMesh/extra/d3dx_skinnedmesh.pdf

 

 

 


each is a separate mesh? above and beyond the basic body mesh?

Yes, I got 8 different meshes. I am working on a way to merge them to one mesh, then perhaps set 8 textures at once and expand the vertex structure to index each face to a texture. Im not sure about it though.

 

 

 


don't you have to make an adjustment for each weapon mesh to fit it to the body mesh correctly?

Nope, each weapon has a center, (0, 0, 0) and when all vertices are transformed by the right bone, it is always in the palm of the hand, even during animation.

 

 

 


or do you just have one body mesh, one weapon mesh, and just change textures?

No, I have hundreds of weapons, shields, helms, armors, gloves, leggings and boots meshes each with their own texture. All of which fit together and are interchangable.

 

 

 


each type will need to be adjusted to the body model once. perhaps twice, once for female body model and once for male.

Different races/genders kinda requires its own unique mesh. So a "Hauberk" armor would have to be modeled for each type (race, gender). This is because a husky male Orc needs a more broad-chested look than a thin female humanoid. So the same hauberk armor is shaped differently, else all races and genders would look the same.

Edited by Tispe

Share this post


Link to post
Share on other sites
Norman Barrows    7179

I know this by the name "Rigid Body Animation"

 

yes, i believe that's the term.

 

 

 


Yes, I got 8 different meshes. I am working on a way to merge them to one mesh, then perhaps set 8 textures at once and expand the vertex structure to index each face to a texture. Im not sure about it though

 

doesn't sound too hard, except maybe getting 8 texture input channels, but that should be doable. in fact it could probably all be done with fixed function and d3dxmeshes, although i'm not so sure i'd recommend it.  <g>.

 

 

 


each weapon has a center, (0, 0, 0)

 

 


I have hundreds of weapons, shields, helms, armors, gloves, leggings and boots meshes each with their own texture. All of which fit together and are interchangable.

 

so the artists set the weapon bone of the first mesh, then set the origin of the first weapon to fit the first mesh, then use the first weapon to set the weapon bones of the remaining meshes. then subsequent weapons can be adjusted to the weapon bone of any mesh, and will fit with all meshes automatically.

 

so the weapon bone takes care of variations in the hand mesh size, and the weapon origin takes care of variations in the weapon grip size. each is adjusted once, then all mix and match correctly.

 

and its done in the modeling software, correct? max? maya? other?

 

actually that rings a bell. been doing too much rigid body stuff and not paying enough attention to skinned techniques.

 

the origin of my weapons is not centerd at the grip point, thus the code fixup required.

 

i've finished fixing the female first person animations. for the male animations, i plan to take copies of the male arms and scale them and adjust their origin in TrueSpace to match the female arms, then set the mesh ID based on the sex of the player's current character (the human player can control up to 10 player characters, and tab between them at any time).

 

for the remaining 120 3rd person animations, i'm thinking subtract the arm rotation and translation from the weapon rotation and translation in the first person ani's to get the rotation and translation of a weapon relative to the arm for 3rd person ani's, and do the fixup in code.  for future weapons, code will draw a weapon at a fixed point at the palm (the equivalent of the weapon bone location) and the origin of the new weapon model will be adjusted to fit, as is done with skinned meshes.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites
Norman Barrows    7179

wrap up / postmortem / for future reference:

 

for the male first person animations:

making copies of the male arm meshes, and scaling, rotating, and translating them to make them match the female arm meshes worked just fine.  the female arm mesh (left or right) was saved as an object, then loaded into the scene with the male arm mesh. this allowed side by side editing of the male arm mesh to match. then the female arm was deleted from the scene, and the male arm was saved as a .x file. then the code was modified to use the appropriate mesh, based on the sex pf the player's character. only took a few hours.

 

for 3rd person animations:

trying to solve for the weapon offset by using "1st person (wpn - hand) = 3rd person offset" did not work. the sequence of transformations was too different to easily determine the difference. this was due to the fact that the 1st person transformations were relative to an "estimated elbow position", while the 3rd person transformations were the usual nested rotations thing you get from a bones system. however, the "draw_object_at_right_hand" routine DID already include a transform from the elbow joint that was the equivalent of a weapon bone.

 

so first i adjusted the "weapon bone transform" to place it in the palm of a female model. then i adjusted the wood spear weapon to the female model. then i used the wood spear adjustments for the female model, and adjusted the male "weapon bone transform". this gave me properly positioned "weapon bones" for both male and female models. then i hooked up the in-game mesh / model manipulator to the code to draw an NPC weapon-in-hand, and added a couple testing hotkeys to change which weapon was drawn, and added one line of code to display the name of the weapon being drawn. then i went into the game, and started with the first weapon. for each weapon, i used the mesh / model manipulator to adjust the weapon to fit in the hand. the manipulator lets you edit floats used for scale, rotation, and translation of a mesh or model in real time. once the weapon was adjusted, i wrote down the rotations and translations. once i had the numbers for all the weapons, i quit the game, and added them to the database of object types. took maybe half a day to do it all. 53 weapon types, not including 6 types of missiles each for bows and atlatls.

 

i still have to make about half a dozen models for weapons that are drawn as individual meshes using code in the first person animations. things like flaming torches with animated textures. there the plan is to take the numbers from the code (scale, translation, mesh, texture, etc), and punch them into the modeler to create weapon models for the 3rd person animations. i also still have to add loaded missiles to the animations for bow, atlatl, and sling.

 

lessons learned:

1. weapon bone is definitely the way to go to connect multiple weapons to multiple character meshes.

2. a real time in-game editor (like the mesh / model manipulator) REALLY speeds up tweaking things.
3. its possible to scale, rotate, and translate different limb meshes (such as male and female arms) to match for interchangeable use.
4. trying to mathematically determine the difference between two dissimilar sequences of transformations can be difficult or practically impossible.
5. taking the time to setup in-game adjustment of all weapons at once was far better than tweaking each and recompiling or even soft coding the values. i set it up, compiled once, ran the game once, got all my hard coded values, put them in the code, compiled a second time. and that was it. now they all run as fast immediate reference instructions, as opposed to dereferenced soft coded variables, and i have no load time overhead for soft coded variables.   ; )
Edited by Norman Barrows

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this