On 05/01/2014 at 11:51, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform: Windows ;
Language(s) : C++ ;
---------
Hi,
I'm trying to create a second UVW tag by allocating a brand new empty UVW tag instance.
Then looping through original one and copying the data over to the allocated one.
But I'm running into all kinds of strange problems.
First- I found a problem where a generated UWV tag has to be assigned some sort of projection (frontal, box, etc..) or else nothing will work at all properly.
Second - After I make sure to assign a frontal projection to my original UWV tag.
When I run my code to copy the data from the original to the allocated one. The original UVW tag gets deleted!!!
What the heck?
Third - C4D crashes (hangs) after that point
BaseObject *obj = doc->GetActiveObject();
Matrix mg = obj->GetMg();
BaseTag *srcTag = obj->GetTag(Tuvw, 0);
if( !srcTag ) return FALSE;
//Cast the active object to a polygon type so we can get it's poly count
PolygonObject *pobj = ToPoly(obj);
LONG numFaces = pobj->GetPolygonCount();
//Create a new empty UV tag in memory only at this point
AutoAlloc<UVWTag> newUVTag(numFaces);
if( !newUVTag ) return FALSE;
//Set this new tag's UVs to the same as the source tag's UVs
UVWTag *srcUVTag = (UVWTag* )srcTag; //Cast the BaseTag to a UVWTag type
for(LONG i=0; i<numFaces; i++)
{
srcUVTag->Copy(newUVTag, i, srcUVTag, i); //Copy the UV data to the new tag
}
//At this point the code deletes the existing UVW tag!!!
//Why on earth would it do that!?
obj->InsertTag(newUVTag); //<--- C4D hangs(crashes)
obj->Message(MSG_UPDATE);
Can anyone tell me how to do this properly?
-ScottA