|
Loading Static and Dynamic Meshes
All meshes derive from IBaseMesh. All meshes is a bit of overkill, there are 2 mesh types - static( IMesh ) and dynamic( IAnimatedMesh ).
Here's sample code that shows how to load a mesh, detect which type of mesh it is by using getMeshType, and the load that mesh into the appropriate Scene Node for rendering by the Scene Manager.
scene::IBaseMesh* mesh = smgr->getMesh( "mesh.x" ); if( mesh ) { if( mesh->getMeshType() == scene::EMESHTYPE_STATIC ) { scene::IMesh* sMesh = (scene::IMesh*)mesh; sMesh->uploadMeshData( driver ); scene::IMeshSceneNode* node = smgr->addMeshSceneNode( sMesh ); } else { scene::IAnimatedMesh* aMesh = (scene::IAnimatedMesh*)mesh; aMesh->uploadMeshData( driver ); scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( aMesh ); } }
If you'd rather use RTTI and dynamic_cast, you could do the following :
scene::IBaseMesh* mesh = smgr->getMesh( "mesh.x" ); scene::IMesh* sMesh = dynamic_cast< scene::IMesh* >( mesh ); if( sMesh != NULL ) { sMesh->uploadMeshData( driver ); scene::IMeshSceneNode* node = smgr->addMeshSceneNode( sMesh ); } else { // We can safely assume the mesh is an Animated Mesh, since that's the only other possible class available. IAnimatedMesh* aMesh = (scene::IAnimatedMesh*)mesh; aMesh->uploadMeshData( driver ); scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( aMesh ); }
|