From d1bebeba8ed7d05ce5ac459b7f93731d2db419e9 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Tue, 6 Apr 2010 00:34:23 +0000 Subject: [PATCH] remove dynamic_cast's from COB loader. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@655 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/COBLoader.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/code/COBLoader.cpp b/code/COBLoader.cpp index 677562150..bb71f90c3 100644 --- a/code/COBLoader.cpp +++ b/code/COBLoader.cpp @@ -152,22 +152,22 @@ void COBImporter::InternReadFile( const std::string& pFile, // sort faces by material indices for_each(boost::shared_ptr< Node >& n,scene.nodes) { - try { - Mesh& mesh = dynamic_cast(*n.get()); + if (n->type == Node::TYPE_MESH) { + Mesh& mesh = (Mesh&)(*n.get()); for_each(Face& f,mesh.faces) { mesh.temp_map[f.material].push_back(&f); } - } catch (std::bad_cast&) {} + } } // count meshes for_each(boost::shared_ptr< Node >& n,scene.nodes) { - try { - Mesh& mesh = dynamic_cast(*n.get()); + if (n->type == Node::TYPE_MESH) { + Mesh& mesh = (Mesh&)(*n.get()); if (mesh.vertex_positions.size() && mesh.texture_coords.size()) { pScene->mNumMeshes += mesh.temp_map.size(); } - } catch (std::bad_cast&) {} + } } pScene->mMeshes = new aiMesh*[pScene->mNumMeshes](); pScene->mMaterials = new aiMaterial*[pScene->mNumMeshes](); @@ -228,7 +228,7 @@ aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill // Note to everybody believing Voodoo is appropriate here: // I know polymorphism, run as fast as you can ;-) if (Node::TYPE_MESH == root.type) { - const Mesh& ndmesh = dynamic_cast(root); + const Mesh& ndmesh = (const Mesh&)(root); if (ndmesh.vertex_positions.size() && ndmesh.texture_coords.size()) { typedef std::pair Entry; @@ -349,7 +349,7 @@ aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill } } else if (Node::TYPE_LIGHT == root.type) { - const Light& ndlight = dynamic_cast(root); + const Light& ndlight = (const Light&)(root); aiLight* outlight = fill->mLights[fill->mNumLights++] = new aiLight(); outlight->mName.Set(ndlight.name); @@ -362,7 +362,7 @@ aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill outlight->mType = ndlight.ltype==Light::SPOT ? aiLightSource_SPOT : aiLightSource_DIRECTIONAL; } else if (Node::TYPE_CAMERA == root.type) { - const Camera& ndcam = dynamic_cast(root); + const Camera& ndcam = (const Camera&)(root); aiCamera* outcam = fill->mCameras[fill->mNumCameras++] = new aiCamera(); outcam->mName.Set(ndcam.name); @@ -659,7 +659,7 @@ void COBImporter::ReadLght_Ascii(Scene& out, LineSplitter& splitter, const Chunk } out.nodes.push_back(boost::shared_ptr(new Light())); - Light& msh = dynamic_cast(*out.nodes.back().get()); + Light& msh = (Light&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Ascii(msh,++splitter,nfo); @@ -715,7 +715,7 @@ void COBImporter::ReadCame_Ascii(Scene& out, LineSplitter& splitter, const Chunk } out.nodes.push_back(boost::shared_ptr(new Camera())); - Camera& msh = dynamic_cast(*out.nodes.back().get()); + Camera& msh = (Camera&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Ascii(msh,++splitter,nfo); @@ -733,7 +733,7 @@ void COBImporter::ReadBone_Ascii(Scene& out, LineSplitter& splitter, const Chunk } out.nodes.push_back(boost::shared_ptr(new Bone())); - Bone& msh = dynamic_cast(*out.nodes.back().get()); + Bone& msh = (Bone&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Ascii(msh,++splitter,nfo); @@ -749,7 +749,7 @@ void COBImporter::ReadGrou_Ascii(Scene& out, LineSplitter& splitter, const Chunk } out.nodes.push_back(boost::shared_ptr(new Group())); - Group& msh = dynamic_cast(*out.nodes.back().get()); + Group& msh = (Group&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Ascii(msh,++splitter,nfo); @@ -763,7 +763,7 @@ void COBImporter::ReadPolH_Ascii(Scene& out, LineSplitter& splitter, const Chunk } out.nodes.push_back(boost::shared_ptr(new Mesh())); - Mesh& msh = dynamic_cast(*out.nodes.back().get()); + Mesh& msh = (Mesh&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Ascii(msh,++splitter,nfo); @@ -1019,7 +1019,7 @@ void COBImporter::ReadPolH_Binary(COB::Scene& out, StreamReaderLE& reader, const const chunk_guard cn(nfo,reader); out.nodes.push_back(boost::shared_ptr(new Mesh())); - Mesh& msh = dynamic_cast(*out.nodes.back().get()); + Mesh& msh = (Mesh&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Binary(msh,reader,nfo); @@ -1209,7 +1209,7 @@ void COBImporter::ReadCame_Binary(COB::Scene& out, StreamReaderLE& reader, const const chunk_guard cn(nfo,reader); out.nodes.push_back(boost::shared_ptr(new Camera())); - Camera& msh = dynamic_cast(*out.nodes.back().get()); + Camera& msh = (Camera&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Binary(msh,reader,nfo); @@ -1232,7 +1232,7 @@ void COBImporter::ReadLght_Binary(COB::Scene& out, StreamReaderLE& reader, const const chunk_guard cn(nfo,reader); out.nodes.push_back(boost::shared_ptr(new Light())); - Light& msh = dynamic_cast(*out.nodes.back().get()); + Light& msh = (Light&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Binary(msh,reader,nfo); @@ -1248,7 +1248,7 @@ void COBImporter::ReadGrou_Binary(COB::Scene& out, StreamReaderLE& reader, const const chunk_guard cn(nfo,reader); out.nodes.push_back(boost::shared_ptr(new Group())); - Group& msh = dynamic_cast(*out.nodes.back().get()); + Group& msh = (Group&)(*out.nodes.back().get()); msh = nfo; ReadBasicNodeInfo_Binary(msh,reader,nfo);