Archived

This topic is now archived and is closed to further replies.

Raloth

handling customizable body parts

Recommended Posts

I''m working on a mech type game, just the map editor right now, and I''m thinking ahead a little. I want to have customizable body parts. For example, pick the legs off one mech and arms off another. How would I go about handling meshes this way? Since I''m using DirectX the logical path would be skinned meshes, but I don''t know if it would be so easy to stick my own parts on it. The only idea I''ve come up with is a .X file that contains nothing but the keyframe animation data and naming different bones with things like "larm" "rarm" "torso" etc. This would allow me to attach static mesh files to it, and also optimize things by storing multiple meshes in the same vertex buffer. Would this be the way to go?

Share this post


Link to post
Share on other sites
Having never done this myself, i''m only theorising... (is that a word yet?)

What you could do is have an object class which is like a linked list or such
then derive each part from it, making the body the root node so you would have

BODY (root)
|
|
->RightArm(node)->LeftArm(node)->RLeg(node)->LLeg(node)

if you want you could then attach things to these like

BODY (root)
|
|
->RightArm(node)->LeftArm(node)->RLeg(node)->LLeg(node)
|
->Weapon(node)

and so on. then you can define anchor points for the the nodes to each parent, where they shoul dbe attached, relative to the parent mesh. The you''d just draw the body and iterate through its child nodes to render these.

you''d obviously need untility fucntions (add, attach(to), remove etc) this should also let you dynamically attach/remove arms/legs/weapons whenever...

hope that helped a little, or at least gave you some other ideas.

-----------------------
"Without a sense of humour we couldn''t react to a lot of things"

Share this post


Link to post
Share on other sites
There is a game that I played - the name of which has totally escaped me at present - which had something similar to this. The way it worked was that each of several body areas - front, back, left arm, right arm, etc - had a number of storage spaces and the equipment had a specific size. Then you simply had to fill slots with equipment in any layout that you wanted. It didn''t put restrictions on having to put weapons on the arms and engines on the legs, for example, but it did restrict you in that you had to have certain equipment for the bot to work, and for some other equipments to work...

Share this post


Link to post
Share on other sites
jhavna, that''s kind of what I was thinking . I''m just not sure how to store all of that data along with animation, and be able to support limbs of different sizes and things.

Share this post


Link to post
Share on other sites
well, in reply to your last question, the storage is quite simple. You''d have a class called bodypart/bodypart_mesh or whatever, which is derived from node and holds the vertex data for that part. The node class stores the pointers to parent node, child node, prev and next node. The pointers are of type node. So you add the body, which is the parent/root and it has no children, no parent and no next or previous nodes (yet).
then add a child. So call body->attach_child(left_arm) which will:
set the body as the parent to arm (i.e. set parent pointer to body node), and set the rest of the pointers to NULL.
Then adding a sibling (you cannot have more than one child per parent in this version) you would
left_arm->attach_sibling(right_arm) which then:
sets the next pointer of left_arm to the new node. The new node will point to parent (body) and the previous will point to left_arm.
Note: although each child node points to a parent, a parent can only point to one child, unless you somehow dynmically update a list of pointers when you add another child.
The list can then be traversed from the root to left most child, and the through it''s siblings...

I suggest reading up on abstract data types (linked lists, trees etc) one good book is "Data structures and other objects using C++" by Main&Savitch (i hope that''s the right title!) or doing a few searches on the net.

as for animation, well each part will then also have an onDraw fucntion, which is called every frame (if it is active and attached to the tree) so when you get a new frame just call onDraw on the root, which will then call onDraw of its child, which in turn will call onDraw of its sibling and so forth. Of course, you might want to call it onUpdate or whatever suits you.and when you no longer need a part (i.e. it got shot off or dropped) simply call a kill, which marks the part as inactive, and cause it to be removed from the tree at the next update (the nodes will check a boolean to see if any nodes need killing)


voila. a object driven data tree of meshes

-----------------------
"Without a sense of humour we couldn''t react to a lot of things"

Share this post


Link to post
Share on other sites
I do something along those veins in a game i'm currently making; my game "Attaches" .X files to one another in a pretty unspectacular way. For instance, each character wears the same backpack. Rather than model the backpack on each character I just put a matrix with nothing in it on each character's back and name it "ATTACH_backpack". Then, when I load each character model I check the name of each matrix and if it has "ATTACH_***" then I load "***.x" too and keep handy a pointer to that matrix. When I render, I set the animation time for each character and render the character, then I set the animation time on each of their attached models, set the "ATTACH_***" matrix as the current matrix, and render the attached piece. This way, the backpack adopts any of the matrix's position/scale/rotation data as it changes with animation. If the player ducks than the backpack's matrix moves along with the player's back; if the player shrinks the backpack shrinks along with him; just like it belongs there.

So, naming a matrix in the model to designate what goes where solves the animation / resizing issue

Concerning animation time for each piece you could do that through "AnimationSet"s in .X. Microsoft's Maya exporter doesn't export different AnimationSets though so I can't share any experience with them.

[edited by - monkeyography on July 30, 2003 2:30:44 AM]

Share this post


Link to post
Share on other sites