Jump to content
  • Advertisement
Sign in to follow this  
ManTis

Direct3d .x format

This topic is 5411 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to change parts of model at run-time, on joints? I'm thinking of 3d-robot game, with changable weapons, or armor look, adding some new weapons to weapon slots. The models should be non-biped. TIA for your help best regards, ManTis.

Share this post


Link to post
Share on other sites
Advertisement
You could bip a mech. But either way, you can swap body parts. When you load the x file in, you are directly placing each mesh somewhere in your body hierarchy. Just swap it with another. There's nothing special about skeletal meshes compared to static meshes. Actually, they are both indeed static meshes.

You will have to make sure the parts are orientated the same way. If your robot mesh has his left forearm facing direction 0.1, 0.7, 0.2 at location 29.402, 16.0, 4.0, then your swappable replacement forearm must be at that same rotation and position. You can always hack it, but it will work much easier if both are built in the same orientation and position.

Share this post


Link to post
Share on other sites
thank you.

and does that mean each .x file should have all possible body parts in it and they will just be made invisible or something?

update: and can you name any place in net where i can find some tutorial on this? If not, that's ok, I'll try to figure it out myself. just don't want to reinvent the wheel ;)

Share this post


Link to post
Share on other sites
You can put all of the body parts in the same scene. But you'll have to manually set which parts are default, to be rendered with the robot. And it will be a bad idea if you later decide to allow a certain arm to be used on more than one robot type.

If your robots will be totally replacable (every part can be swapped), my advice would be to create a single x file robot for each type. For example, create a "high alloy" model, and a "generic steel" model. So in-game, you could have your real robots just render a body part from those types. Just make sure they all use the same bone structure + same default pose.

Example:

struct RobotPart
{
RobotMesh *Mesh; // Mesh of a single body part
Texture *Tex; // Set Texture of the part
Matrix Transform; // Bone transform
};

class Robot
{
RobotPart Parts[PART_COUNT]; // All Current Parts
DefaultSetup(); // setup the default robot parts
Render(); // render the whole robot
};

Robot::DefaultSetup()
{
// Set Default Parts
Parts[PART_LEFTFOREARM].Mesh = GetSuit(SUIT_DEFAULT)->Parts[PART_LEFTFOREARM].Mesh;
Parts[PART_LEFTFOREARM].Tex = GetSuit(SUIT_DEFAULT)->Parts[PART_LEFTFOREARM].Tex;

Parts[PART_LEFTSHOULDER].Mesh = GetSuit(SUIT_DEFAULT)->Parts[PART_LEFTSHOULDER].Mesh;
Parts[PART_LEFTSHOULDER].Tex = GetSuit(SUIT_DEFAULT)->Parts[PART_LEFTSHOULDER].Tex;

// Set a custom part
Parts[PART_RIGHTSHOULDER].Mesh = GetSuit(SUIT_ALLOY)->Parts[PART_RIGHTSHOULDER].Mesh;
Parts[PART_RIGHTSHOULDER].Tex = GetSuit(SUIT_ALLOY)->Parts[PART_RIGHTSHOULDER].Tex;
}
Robot::Render()
{
for(int part=0; part<PART_COUNT; part++)
{
// Set bone transform for this part
SetWorldTransform(Parts[part].Transform);

// Set texture
SetTexture(Parts[part].Tex);

// Render this part
Parts[part].Mesh->Render();
}
}



In the example, each "suit" could be a robot itself, but containing the parts it loaded from file. Real in-game robots would never need to be loaded from file. Since all compatible robots use the same bone structure, you could also have the suits contain the bone hierarchy, and just let them compute the matrices for each bone.

My example is really only designed for replacing every part of the robot. If you just want to replace arms with specific guns, you might need to add / remove some stuff. For something like this, I would just make the gun arms seperate meshes (not part of any skeleton), and just apply the arm matrix when rendering.

I don't know of any tutorials specific to static mesh bone skeletons. Only some for skin meshes. And I really recommend not trying to learn about skinmeshes to make your robots. A robot type skeleton mesh is much simpler and requires virtually none of the complications of a skinmesh. If you can figure out how to load in the hierarchy, and how to determine which bone goes to which mesh part, the rest is pretty easy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!