UVWTag Manual

About

A UVWTag stores UVW coordinates for a (polygon) object. For each polygon a set of four UVW coordinates is stored (UVWStruct). The class UVWTag is based on VariableTag so the typical workflows on handling tags apply, see BaseTag and VariableTag Manual.

UVWTag objects are an instance of Tuvw.

Access

A UVWTag is typically attached to a polygon object.

Note
A polygon object can host multiple UVW tags.

Allocation/Deallocation

UVWTag instances are created with the usual tools.

A UVW tag with projection-based UVs can be created with:

// This example checks if the given object hosts a UVW tag.
// If not, a UVW tag is created.
BaseTag* const foundTag = object->GetTag(Tuvw);
UVWTag* uvwTag = static_cast<UVWTag*>(foundTag);
if (uvwTag == nullptr)
{
// check if the given object is a polygon object
if (object->IsInstanceOf(Opolygon))
{
PolygonObject* const polyObject = static_cast<PolygonObject*>(object);
const Int32 polyCount = polyObject->GetPolygonCount();
uvwTag = UVWTag::Alloc(polyCount);
if (uvwTag == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
polyObject->InsertTag(uvwTag);
}
}

Access Data

There are two ways to edit the data stored inside a UVWTag. The "slow" way is to access every set of UVW coordinate independently. The "fast" way works with a data handle that allows direct access to the internal memory.

Slow

The UVW coordinates stored in a UVWTag can be accessed with:

// This example loops through the UVW data stored in the given UVW tag.
const Int32 count = uvwTag->GetDataCount();
for (Int32 i = 0; i < count; ++i)
{
ApplicationOutput("UVW Polygon " + String::IntToString(i));
const UVWStruct uvwData = uvwTag->GetSlow(i);
}

Fast

The fast access to the UVW coordinates stored in the UVWTag is provided by a data handle and static functions:

// 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() is a custom function
CalculateUVCoordinates(a, uvwData.a);
CalculateUVCoordinates(b, uvwData.b);
CalculateUVCoordinates(c, uvwData.c);
CalculateUVCoordinates(d, uvwData.d);
UVWTag::Set(handle, i, uvwData);
}
polyObject->Message(MSG_UPDATE);

Further Reading