5
\$\begingroup\$

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();
}
\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – Fibericon Nov 12 '12 at 7:45
1
\$\begingroup\$

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();
 }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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