| 179 | |
| 180 | |
| 181 | void Scene::DuplicateObject(const std::string &srcObjName, const std::string &dstObjName, |
| 182 | const luxrays::Transform &trans, const u_int dstObjID) { |
| 183 | const SceneObject *srcObj = objDefs.GetSceneObject(srcObjName); |
| 184 | |
| 185 | // Check the type of mesh |
| 186 | ExtMesh *newMesh; |
| 187 | const ExtMesh *srcMesh = srcObj->GetExtMesh(); |
| 188 | switch (srcMesh->GetType()) { |
| 189 | case TYPE_EXT_TRIANGLE: { |
| 190 | // Create an instance of the mesh |
| 191 | const string instanceShapeName = "InstanceMesh-" + dstObjName; |
| 192 | DefineMesh(instanceShapeName, srcMesh->GetName(), trans); |
| 193 | |
| 194 | newMesh = extMeshCache.GetExtMesh(instanceShapeName); |
| 195 | break; |
| 196 | } |
| 197 | case TYPE_EXT_TRIANGLE_INSTANCE: { |
| 198 | // Get the instanced mesh |
| 199 | const ExtInstanceTriangleMesh *srcInstanceMesh = static_cast<const ExtInstanceTriangleMesh *>(srcMesh); |
| 200 | const ExtTriangleMesh *baseMesh = static_cast<const ExtTriangleMesh *>(srcInstanceMesh->GetTriangleMesh()); |
| 201 | |
| 202 | // Create the new instance of the base mesh |
| 203 | const string instanceShapeName = "InstanceMesh-" + dstObjName; |
| 204 | DefineMesh(instanceShapeName, baseMesh->GetName(), trans); |
| 205 | |
| 206 | newMesh = extMeshCache.GetExtMesh(instanceShapeName); |
| 207 | break; |
| 208 | } |
| 209 | case TYPE_EXT_TRIANGLE_MOTION: { |
| 210 | // Get the motion mesh |
| 211 | const ExtMotionTriangleMesh *srcMotionMesh = static_cast<const ExtMotionTriangleMesh *>(srcMesh); |
| 212 | const ExtTriangleMesh *baseMesh = static_cast<const ExtTriangleMesh *>(srcMotionMesh->GetTriangleMesh()); |
| 213 | |
| 214 | // Create the new instance of the base mesh |
| 215 | const string instanceShapeName = "InstanceMesh-" + dstObjName; |
| 216 | DefineMesh(instanceShapeName, baseMesh->GetName(), trans); |
| 217 | |
| 218 | newMesh = extMeshCache.GetExtMesh(instanceShapeName); |
| 219 | break; |
| 220 | } |
| 221 | default: |
| 222 | throw runtime_error("Unknown mesh type in Scene::DuplicateObject(): " + ToString(srcMesh->GetType())); |
| 223 | } |
| 224 | |
| 225 | // If the Null index was passed as ID, copy the ID of the source object |
| 226 | const u_int objID = (dstObjID == 0xffffffff) ? srcObj->GetID() : dstObjID; |
| 227 | |
| 228 | SceneObject *dstObj = new SceneObject(newMesh, srcObj->GetMaterial(), objID, |
| 229 | srcObj->IsCameraInvisible()); |
| 230 | dstObj->SetName(dstObjName); |
| 231 | objDefs.DefineSceneObject(dstObj); |
| 232 | |
| 233 | // Check if it is a light source |
| 234 | const Material *mat = dstObj->GetMaterial(); |
| 235 | if (mat->IsLightSource()) { |
| 236 | SDL_LOG("The " << dstObjName << " object is a light sources with " << dstObj->GetExtMesh()->GetTotalTriangleCount() << " triangles"); |
| 237 | |
| 238 | objDefs.DefineIntersectableLights(lightDefs, dstObj); |
nothing calls this directly
no test coverage detected