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++ ;---------
Hello.
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:
Hello,
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,
Sebastian -
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](https://developers.maxon.net/docs/cpp/2023_2/operatingsystem_8h.html#a808cc8f9935984021e65bec5d8564954) handle = uvwTag->[GetDataAddressW](https://developers.maxon.net/docs/cpp/2023_2/class_u_v_w_tag.html#af57f249e6e125ffac93441e0f0b5ef75)(); const [Int32](https://developers.maxon.net/docs/cpp/2023_2/ge__sys__math_8h.html#a958ae3b8c6dfd40570aeecfad51a2bff) count = uvwTag->[GetDataCount](https://developers.maxon.net/docs/cpp/2023_2/class_variable_tag.html#af2485ef86627c7525b86f83b831878d1)(); for ([Int32](https://developers.maxon.net/docs/cpp/2023_2/ge__sys__math_8h.html#a958ae3b8c6dfd40570aeecfad51a2bff) i = 0; i < count; ++i) { [UVWStruct](https://developers.maxon.net/docs/cpp/2023_2/struct_u_v_w_struct.html) uvwData; // get points in world space [CPolygon](https://developers.maxon.net/docs/cpp/2023_2/struct_c_polygon.html) polygon = polygons[i]; const [Vector](https://developers.maxon.net/docs/cpp/2023_2/struct_vector64.html) a = mg * points[polygon.[a](https://developers.maxon.net/docs/cpp/2023_2/struct_c_polygon.html#ac9e013f431fbd3e6d8f2906d22d341f1)]; const [Vector](https://developers.maxon.net/docs/cpp/2023_2/struct_vector64.html) b = mg * points[polygon.[b](https://developers.maxon.net/docs/cpp/2023_2/struct_c_polygon.html#a04308ac063738b8c0ff3bb2c7efcb298)]; const [Vector](https://developers.maxon.net/docs/cpp/2023_2/struct_vector64.html) c = mg * points[polygon.[c](https://developers.maxon.net/docs/cpp/2023_2/struct_c_polygon.html#aba426a3ffc4f9f0b041946f4b4d7cd09)]; const [Vector](https://developers.maxon.net/docs/cpp/2023_2/struct_vector64.html) d = mg * points[polygon.[d](https://developers.maxon.net/docs/cpp/2023_2/struct_c_polygon.html#a017e8eebe2e03bf7bb83298700654b3d)]; // define UV coordinates based on the world space position CalculateUVCoordinates(a, uvwData.[a](https://developers.maxon.net/docs/cpp/2023_2/struct_u_v_w_struct.html#a5955b5e71d8d50c4184e6747df745ce0)); CalculateUVCoordinates(b, uvwData.[b](https://developers.maxon.net/docs/cpp/2023_2/struct_u_v_w_struct.html#a440c0d32dcc99b0062316c68b3402026)); CalculateUVCoordinates(c, uvwData.[c](https://developers.maxon.net/docs/cpp/2023_2/struct_u_v_w_struct.html#a03d96ea4238f4d9528c9576e36a02c67)); CalculateUVCoordinates(d, uvwData.[d](https://developers.maxon.net/docs/cpp/2023_2/struct_u_v_w_struct.html#a6d2b168551b519faa7a499bdc8943031)); [UVWTag::Set](https://developers.maxon.net/docs/cpp/2023_2/class_u_v_w_tag.html#acf6734ae5a26959f75e5f5ceca10c5b4)(handle, i, uvwData); } polyObject->[Message](https://developers.maxon.net/docs/cpp/2023_2/class_c4_d_atom.html#a89b4a7026485f0a69fd6595623a491f6)([MSG_UPDATE](https://developers.maxon.net/docs/cpp/2023_2/group___m_s_g.html#ga135a2db08efb66a41df84586674dc0b0)); [EventAdd](https://developers.maxon.net/docs/cpp/2023_2/c4d__general_8h.html#a47d8b6918f07e855bcf82a6d671569ad)();
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:
Hello,
the "CalculateUVCoordinates()" function is just some custom dummy representing your own solution for this task.
best wishes,
Sebastian