1
1

Alembic procedural: support reading per-vertex UV sets

This adds support for importing UV sets which are defined per vertex,
instead of per face corners. Such UV sets can be generated when the
mesh is split according to UV islands, or when there is only one UV
island, in which cases only a single UV value can be stored per
vertex since vertices will never be on a seam.
This commit is contained in:
2021-06-16 09:39:26 +02:00
parent 1c0a490d0e
commit 00fc110d3f

View File

@@ -736,13 +736,14 @@ static void process_uvs(CachedData &cache,
const IV2fGeomParam::Sample &sample,
double time)
{
if (scope != kFacevaryingScope) {
if (scope != kFacevaryingScope && scope != kVaryingScope && scope != kVertexScope) {
return;
}
const array<int> *uv_loops = cache.uv_loops.data_for_time_no_check(time).get_data_or_null();
if (!uv_loops) {
/* It's ok to not have loop indices, as long as the scope is not face-varying. */
if (!uv_loops && scope == kFacevaryingScope) {
return;
}
@@ -766,9 +767,27 @@ static void process_uvs(CachedData &cache,
const uint32_t *indices = sample.getIndices()->get();
const V2f *values = sample.getVals()->get();
for (const int uv_loop_index : *uv_loops) {
const uint32_t index = indices[uv_loop_index];
*data_float2++ = make_float2(values[index][0], values[index][1]);
if (scope == kFacevaryingScope) {
for (const int uv_loop_index : *uv_loops) {
const uint32_t index = indices[uv_loop_index];
*data_float2++ = make_float2(values[index][0], values[index][1]);
}
}
else if (scope == kVaryingScope || scope == kVertexScope) {
if (triangles) {
for (size_t i = 0; i < triangles->size(); i++) {
const int3 t = (*triangles)[i];
*data_float2++ = make_float2(values[t.x][0], values[t.x][1]);
*data_float2++ = make_float2(values[t.y][0], values[t.y][1]);
*data_float2++ = make_float2(values[t.z][0], values[t.z][1]);
}
}
else if (corners) {
for (size_t i = 0; i < corners->size(); i++) {
const int c = (*corners)[i];
*data_float2++ = make_float2(values[c][0], values[c][1]);
}
}
}
attribute.data.add_data(data, time);