From 00fc110d3f9d33471af8e3f9f8a71c732e1a4bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Wed, 16 Jun 2021 09:39:26 +0200 Subject: 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. --- intern/cycles/render/alembic_read.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/intern/cycles/render/alembic_read.cpp b/intern/cycles/render/alembic_read.cpp index 33ce3502879..c53ec668938 100644 --- a/intern/cycles/render/alembic_read.cpp +++ b/intern/cycles/render/alembic_read.cpp @@ -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 *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); -- cgit v1.2.3