ObjectPtr Copy_Object (ObjectPtr Old) { ObjectPtr New; if(Old == NULL) return NULL; New = Old->Copy(); /* * The following copying of OBJECT_FIELDS is redundant if Copy * did *New = *Old but we cannot assume it did. It is safe for * Copy to do *New = *Old but it should not otherwise * touch OBJECT_FIELDS. */ New->Type = Old->Type; New->Bound = Old->Bound; New->Clip = Old->Clip; New->BBox = Old->BBox; New->Flags = Old->Flags; New->Ph_Density = Old->Ph_Density; New->RadiosityImportance = Old->RadiosityImportance; // TODO FIXME - An explanation WHY this is important would be nice [CLi] New->LLights.clear(); // important New->Texture = Copy_Textures (Old->Texture); New->Interior_Texture = Copy_Textures (Old->Interior_Texture); if(Old->interior != NULL) New->interior = InteriorPtr(new Interior(*(Old->interior))); else New->interior.reset(); /* NK 1998 */ New->UV_Trans = Copy_Transform(Old->UV_Trans); /* NK ---- */ // TODO: we really ought to decide whether or not it's useful to maintain // the overhead of having multiple clip and bound objects ... it is // after all possible for the user to use CSG and give us one object // meaning we could use a plain pointer here. if (Old->Bound.empty() == false) New->Bound = Copy_Objects(Old->Bound); if (Old->Clip.empty() == false) { // note that in this case the objects are shared and should only be // destroyed the once !!! ... to be frank POV really needs a reference- // counted system for sharing objects with copy-on-write semantics. if(Old->Bound != Old->Clip) New->Clip = Copy_Objects(Old->Clip); else New->Clip = New->Bound; } return New; }
MATERIAL *Copy_Material(const MATERIAL *Old) { MATERIAL *New; if (Old != NULL) { New = Create_Material(); *New = *Old; New->Texture = Copy_Textures(Old->Texture); New->Interior_Texture = Copy_Textures(Old->Interior_Texture); if (Old->interior != NULL) New->interior = InteriorPtr(new Interior(*(Old->interior))); return(New); } else { return(NULL); } }