| 48 | } |
| 49 | |
| 50 | void ExtMeshCache::DefineExtMesh(ExtMesh *mesh) { |
| 51 | const string &meshName = mesh->GetName(); |
| 52 | |
| 53 | if (!meshes.IsObjDefined(meshName)) { |
| 54 | // It is a new mesh |
| 55 | meshes.DefineObj(mesh); |
| 56 | } else { |
| 57 | // Check if the meshes are of the same type |
| 58 | const ExtMesh *meshToReplace = static_cast<const ExtMesh *>(meshes.GetObj(meshName)); |
| 59 | if (meshToReplace->GetType() != mesh->GetType()) |
| 60 | throw runtime_error("Mesh " + meshName + " of type " + ToString(mesh->GetType()) + |
| 61 | " can not replace a mesh of type " + ToString(meshToReplace->GetType()) + ". Delete the old mesh first."); |
| 62 | |
| 63 | // Replace an old mesh |
| 64 | ExtMesh *oldMesh = static_cast<ExtMesh *>(meshes.DefineObj(mesh)); |
| 65 | |
| 66 | if (oldMesh->GetType() == TYPE_EXT_TRIANGLE) { |
| 67 | // I have also to check/update all instances and motion blur meshes for |
| 68 | // reference to the old mesh |
| 69 | ExtTriangleMesh *om = static_cast<ExtTriangleMesh *>(oldMesh); |
| 70 | ExtTriangleMesh *nm = static_cast<ExtTriangleMesh *>(mesh); |
| 71 | |
| 72 | BOOST_FOREACH(NamedObject *no, meshes.GetObjs()) { |
| 73 | ExtMesh *mesh = static_cast<ExtMesh *>(no); |
| 74 | |
| 75 | switch (mesh->GetType()) { |
| 76 | case TYPE_EXT_TRIANGLE_INSTANCE: |
| 77 | static_cast<ExtInstanceTriangleMesh *>(mesh)->UpdateMeshReferences(om, nm); |
| 78 | break; |
| 79 | case TYPE_EXT_TRIANGLE_MOTION: |
| 80 | static_cast<ExtMotionTriangleMesh *>(mesh)->UpdateMeshReferences(om, nm); |
| 81 | break; |
| 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (deleteMeshData) |
| 89 | oldMesh->Delete(); |
| 90 | delete oldMesh; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void ExtMeshCache::DeleteExtMesh(const string &meshName) { |
| 95 | if (deleteMeshData) { |
no test coverage detected