Map UV of input object to generated object

On 11/11/2016 at 01:40, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   17 
Platform:   Windows  ;   
Language(s) :     C++  ;

In an object generator plugin, there's an input polygonal object as geometry, and an output generated object. The constraint is that the input and output are topologically identical. 
The general case for my problem is exemplified with the Catmull-Clark Subdivision. The initial vertices of the un-sybdivided object remain, being simply translated to a new position. 
How would one in C4D sdk set the uvs of the subdivided object such that there is a topologically identical uv mapping? In other words the uv parameters of the initial verices stay the same, and the generated points have interpolated parameters.

I hope the attached image makes it clear. Left is input, right is output. Notice how the mapping preserves the uvs at he corners and at midpoints. 

Thanks in advance!

On 12/11/2016 at 00:18, xxxxxxxx wrote:

I was hoping there was an easier, predefined method. 😕

But here's what i have so far, seems to work. I'll expose the general framework. Here the assumtion is that you want to generate from the input an output that is topologically identical, and has the same number polygons.

        //first get the UVW tag from op (this is the input)
UVWTag * opUVWtag = (UVWTag* )op->GetTag(Tuvw);
       //create the UVW tag for pp (output object) and get the pointer
pp->MakeVariableTag(Tuvw, mesh.faces.GetCount()*4);
UVWTag * ppUVWtag = (UVWTag* )pp->GetTag(Tuvw);
       //for each polygon i  of op get the UVWStruct and set it to pp (assumes topological identity)
UVWStruct * faceUVW = opUVWtag -> GetSlow (i)
ppUVWtag->SetSlow(i, faceUVW)

for the subdivision surfaces, each input quad polygon generates four other quad polygons. So you would get the UVWStruct for the input quad and generate four other UVWStructs for the output quads.

Hope this is of some help to someone someday. 
Cheers! adl

On 14/11/2016 at 01:41, xxxxxxxx wrote:


there is no build-in method handling such a scenario. You can find examples on how to read and write data of the UVWTag in the UVWTag Manual.

best wishes,

On 15/11/2016 at 00:01, xxxxxxxx wrote:

Hi Sebastian,
The manual has the following example

// This example calculates UVW coordinates based on the polygon's world space position.
[UVWHandle]( handle = uvwTag->[GetDataAddressW](;
const [Int32]( count = uvwTag->[GetDataCount](;
for ([Int32]( i = 0; i < count; ++i)
[UVWStruct]( uvwData;
// get points in world space
[CPolygon]( polygon = polygons[i];
const [Vector]( a = mg * points[polygon.[a](];
const [Vector]( b = mg * points[polygon.[b](];
const [Vector]( c = mg * points[polygon.[c](];
const [Vector]( d = mg * points[polygon.[d](];
// define UV coordinates based on the world space position
CalculateUVCoordinates(a, uvwData.[a](;
CalculateUVCoordinates(b, uvwData.[b](;
CalculateUVCoordinates(c, uvwData.[c](;
CalculateUVCoordinates(d, uvwData.[d](;
[UVWTag::Set](, i, uvwData);

but the fuction "CalculateUVCoordinates()" doesn't seem to be part of the SDK. It would have been extremely useful though.

On 15/11/2016 at 02:09, xxxxxxxx wrote:


the "CalculateUVCoordinates()" function is just some custom dummy representing your own solution for this task.

best wishes,