View Full Version : Modelling moving parts on models
Bubba
03-11-2008, 11:52 PM
Finally got farely decent at Blender and have quite a few nice looking ships. I would like to put some moving parts on them but I'm not sure how to do it. I know how to do it in code but I don't know how to go from editor to code.
I tried using bones but the influence of them is too large and I really do not need vertices to change position in the context of skinning. The parts on my ships are not skinned and do not affect any other portions of the model.
Since I'm currently using D3DXMesh one of my ideas is to make each moving part a subset of the mesh but I also need transformation information which I simply do not have in the standard x file format.
Any ideas?
Here is a pic of the model in the mesh viewer util. Still no textures since I really suck at making them.
Blender...
Not sure how to do it when you want to the relationship to carry over to .x files, but the normal way to do this would be by using groups (assuming you are trying to add rockets or something?)
BobMcGee123
03-12-2008, 07:34 AM
Wait I'm a little bit confused about what you are asking. This seems to be a Blender specific question, am I right?
but the normal way to do this would be by using groups (assuming you are trying to add rockets or something?)
I agree, for this is how I do this using Milkshape3D, e.g. a propeller, which spins depending on how fast the engine is going, moves separately from the rest of the vehicle. Each group ends up being its own mesh, and each mesh has its own local transformation matrix relative to the absolute transformation of the model.
Bubba
03-12-2008, 09:20 PM
Ok Bob so in your example you simply make the propeller a group of vertices in the model program? So I guess when you save the mesh the model program also saves the position of the propeller? So would you create a separate mesh called propeller and position it in the model program and then save the entire model? Or do you make the propeller a group of vertices within the entire model mesh?
I'll try this and see what happens. I'm eagerly awaiting a copy of 3DS Max so when I get it, it will help a lot.
BobMcGee123
03-13-2008, 04:51 AM
So would you create a separate mesh called propeller and position it in the model program and then save the entire model?
Yes, this is what I do.
BobMcGee123
03-13-2008, 05:01 AM
Here's a picture demonstrating this. The model is just hacked-together pieces from a jeep model I found online, I added the propeller, nothing fancy it's just to test functionality of the code. In terms of data structures this model is made up of 7 meshes, each of which has its own local transformation matrix. There is another matrix which contains the transformation of the entire model in absolute coordinates.
I also compute the radius, bounding box and center the mesh. The center is with respect to the center of the model in design coordinates (the center of the entire model is computed, and all vertices are adjusted such that in design coordinates the center is the origin). You must know the center of the mesh to have the propeller properly spin. According to matrix concatenations I have to translate the propeller back to the origin, rotate it about it's z axis based on angular velocity, then translate it back to its original position. When rendering the entire model there is a matrix for the entire model, and each mesh's local matrix is concatenated with that (by the OpenGL matrix stack...this could be the start of a basic scene graph). Here's the Render() hook for a Hovercraft (just hacked together for now), the hook meaning that nothing is actually rendered here, just the appropriate data is added to the renderer and held until the final rendering is done (all together).
Note that I use 'my own' file format. Milkshape3D (.ms3d) files are optimized for saving file space, whereas my files are optimized for rendering (tightly-packed data structures). My files are subsequently about %30 larger, and called .ntmdl (Nuclear Toaster Model).
void Hovertank::Render()
{
// DebugPrintFloat("inputs",this->inputs,gpTextManager);
// DebugPrintInt("prop index",this->pNTModel->GetMeshByGroupComment("propeller"),gpTextManager);
if(gpFrustum->SphereInFrustum(CurrentState.mPosition,mRadius))
{
Matrix4x4 final_render_mat;
final_render_mat = CurrentState.mMat_Orientation;
final_render_mat.SetTranslation(&CurrentState.mPosition);
Matrix4x4 rotation,translation_inverse,translation;
translation.SetTranslation(&prop->DEBUG_CENTER);
translation_inverse.SetTranslation( &(prop->DEBUG_CENTER *-1) );
rotation.InitFromAngles(0,0,this->propellor_angle);
prop->local_mat = translation * rotation * translation_inverse;
// DebugPrint4x4Matrix("prop_local",prop->local_mat,gpTextManager);
pNTModel->mat = final_render_mat;
gpGLRenderer->AddNTRenderModelToRenderer(*pNTModel);
}
}
Bubba
03-13-2008, 09:11 PM
Thanks all I'm gonna give it a go and try some stuff to see what happens. I was on the right track but just needed a nudge in the right direction.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.