/// <summary> /// Sets the model that this object was instanced from /// </summary> public ModelInstance( Model source ) { m_Source = source; // Set up the animation layers if ( source.Animations == null ) { return; } m_Layers = new AnimationLayer[ ( int )ModelPart.NumParts ]; for ( int layerIndex = 0; layerIndex < ( int )ModelPart.NumParts; ++layerIndex ) { m_ReferencePoints[ layerIndex ] = new ReferencePoint( ( ModelPart )layerIndex ); ModelMesh partMesh = source.GetPartMesh( ( ModelPart )layerIndex ); if ( partMesh == null ) { continue; } if ( source.Animations != null ) { // TODO: This assigns the entire animation set to each layer, which isn't correct (although it'll work OK) m_Layers[ layerIndex ] = new AnimationLayer( source.Animations, ( ModelPart )layerIndex ); } } }
/// <summary> /// Nests one model part's mesh inside another, using a named tag as a transform /// </summary> private static void NestMesh( Model model, ModelPart parent, ModelPart child, string tagName ) { model.GetPartMesh( parent ).AddNestedPart( child, model.GetPartMesh( parent ).GetTagIndex( tagName ) ); }
private static void LoadNestedModel( Model model, ISource source, Matrix44 transform ) { // Run through all the parts for ( int partIndex = 0; partIndex < ( int )ModelPart.NumParts; ++partIndex ) { ModelPart curPart = ( ModelPart )partIndex; if ( curPart == ModelPart.Weapon ) { // The weapon does not have a related mesh, so just ignore... continue; } // Load the skin file for the current part IDictionary< string, ITexture2d > surfaceTextureTable = LoadSkin( source, DefaultSkinFile( source, curPart ) ); // Load the MD3 associated with the current part ModelMesh partMesh = LoadMd3( source, model, curPart, transform, MeshFile( source, curPart ), surfaceTextureTable ); model.SetPartMesh( curPart, partMesh ); } model.SetRootMesh( model.GetPartMesh( ModelPart.Lower ) ); NestMesh( model, ModelPart.Lower, ModelPart.Upper, "tag_torso" ); NestMesh( model, ModelPart.Upper, ModelPart.Head, "tag_head" ); NestMesh( model, ModelPart.Upper, ModelPart.Weapon, "tag_weapon" ); }