On 15/03/2015 at 17:25, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C.O.F.F.E.E ;
---------
This article explains how to access a model's texture coordinates (this topic is quite poorly documented, and information is spread across code examples and forum threads).
1. Finding the tag
To find an object's UVW tag, you should iterate through all the object's tag until you find an instance of UVWTag.
Tags are stored in a linked list. To iterate through the tags, call BaseObject::GetFirstTag() to get the first element, then call BaseList2D::GetNext() until it returns NULL.
For our purpose, we stop when we find an instance of UVWTag:
for (tag = object->GetFirstTag();
tag != NULL && !instanceof(tag, UVWTag);
tag = tag->GetNext());
Keep in mind that at the end of this loop, tag will be NULL if the object doesn't have a UVW tag, make sure it is not before you use it.
2. Reading UVW data
Start by getting a reference to the UVW buffer:
var uvwData;
uvwData = tag->GetData();
uvwData is an array of 3D vectors.
The UVW coordinates for the v th point of the p th polygon is stored at index p * 4 + v .
This is because all polygons are made up of four points. This is also true for triangles, two of their points are at the same position.
If you end up with backwards UVs, try mirroring them ( p * 4 + (3 - v ) ).
Keep in mind that polygons and points are indexed from 0.
**3. Using UVW data
** As said above, the array returned by GetData() contains 3D vectors, you can access them in this fashion:
var u = uvwData[poly * 4 + point].x;
var v = uvwData[poly * 4 + point].y;
var w = uvwData[poly * 4 + point].z;