Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I go back on unsolved question I asked about attaching two models together, could you give me some help on this ?

For example, If I want to attach together Model1 (= Main model) & Model2 ? I have to get the transformation matrix of Model1 and after get the Bone index on Model1 where I want to attach Model2 and then apply some transformation to attach Model2 to Model1

I wrote some code below about this, but It does not work at all !! (6th line of my code seems to be wrong !?)

Model1TransfoMatrix=New Matrix[Model1.Bones.Count];

Index=Model1.bone[x].Index;

foreach (ModelMesh mesh in Model2.Meshes)
{ 
  foreach(BasicEffect effect in mesh.effects)
  {
     matrix model2Transform = Matrix.CreateScale(0.1.0f)*Matrix.CreateFromYawPitchRoll(x,y,z);

     effect.World= model2Transform *Model1TransfoMatrix[Index];
     effect.view = camera.View;
     effect.Projection= camera.Projection;
   }
   mesh.draw();
}
share|improve this question
    
Can you clarify what you mean by attaching models together? I'm seeing two possibilities: an object 'held' by the first model, such as a sword, or an object that should be part of the first model, like a gun turret. Which is your intention? –  Fibericon Nov 12 '12 at 7:45

1 Answer 1

Your question is quite abstract.

I would suggest 2 methods.

  1. using 3d redactor such as 3dmax or blender or whatever.

  2. Draw second model using a SINGLE BONE absolute transform from model1.

It should look like:

Matrix[] Model1TransfoMatrix;
model1.CopyAbsoluteBoneTransformsTo(Model1TransfoMatrix);
foreach (ModelMesh mesh in Model2.Meshes)
{ 
  foreach(BasicEffect effect in mesh.effects)
  {
     matrix model2Transform = Matrix.CreateScale(0.1.0f)*Matrix.CreateFromYawPitchRoll(x,y,z);

     effect.World= model2Transform *Model1TransfoMatrix[0]; //root bone index
     effect.view = camera.View;
     effect.Projection= camera.Projection;
   }
   mesh.draw();
 }
share|improve this answer
    
please do you can answer this ? ^^ : gamedev.stackexchange.com/questions/45793/… –  Mehdi Bugnard Dec 18 '12 at 17:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.