From a1c9d425844c5c2299daf9a89438d164f605407c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 26 May 2020 16:38:47 +0200 Subject: Fix T77021: Alembic export of animated mesh with multiple UV maps fails This was caused by a side-effect of our exporting code's memory management (Alembic considers data "written" and "final" when its C++ objects go out of scope) in combination with my change in rB65574463fa2d. I removed an "only export UVs on the first frame" clause because it was unclear why this restriction was there. As it turns out, it breaks the export of the 2nd and subsequent UV maps on an animated mesh. Effectively, on every frame the Alembic library thought we want to create a new UV map, instead of continuing to write a new frame of data to the existing one. This is resolved by keeping a reference to the C++ objects for the UV maps in memory while the exporter is running. --- source/blender/io/alembic/intern/abc_customdata.cc | 13 +++++++++---- source/blender/io/alembic/intern/abc_customdata.h | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'source/blender/io') diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index c5f60ac3e29..b769d00cd9c 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -146,7 +146,7 @@ const char *get_uv_sample(UVSample &sample, const CDStreamConfig &config, Custom * - (optional due to its behavior) tag as UV using Alembic::AbcGeom::SetIsUV */ static void write_uv(const OCompoundProperty &prop, - const CDStreamConfig &config, + CDStreamConfig &config, void *data, const char *name) { @@ -159,13 +159,18 @@ static void write_uv(const OCompoundProperty &prop, return; } - OV2fGeomParam param(prop, name, true, kFacevaryingScope, 1); + std::string uv_map_name(name); + OV2fGeomParam param = config.abc_uv_maps[uv_map_name]; + if (!param.valid()) { + param = OV2fGeomParam(prop, name, true, kFacevaryingScope, 1); + } OV2fGeomParam::Sample sample(V2fArraySample(&uvs.front(), uvs.size()), UInt32ArraySample(&indices.front(), indices.size()), kFacevaryingScope); - param.set(sample); + + config.abc_uv_maps[uv_map_name] = param; } /* Convention to write Vertex Colors: @@ -219,7 +224,7 @@ static void write_mcol(const OCompoundProperty &prop, } void write_custom_data(const OCompoundProperty &prop, - const CDStreamConfig &config, + CDStreamConfig &config, CustomData *data, int data_type) { diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h index 11b005eb66a..5e9300b0db6 100644 --- a/source/blender/io/alembic/intern/abc_customdata.h +++ b/source/blender/io/alembic/intern/abc_customdata.h @@ -27,6 +27,8 @@ #include #include +#include + struct CustomData; struct MLoop; struct MLoopUV; @@ -70,6 +72,12 @@ struct CDStreamConfig { const char **modifier_error_message; + /* Alembic needs Blender to keep references to C++ objects (the destructors + * finalise the writing to ABC). This map stores OV2fGeomParam objects for the + * 2nd and subsequent UV maps; the primary UV map is kept alive by the Alembic + * mesh sample itself. */ + std::map abc_uv_maps; + CDStreamConfig() : mloop(NULL), totloop(0), @@ -95,7 +103,7 @@ struct CDStreamConfig { const char *get_uv_sample(UVSample &sample, const CDStreamConfig &config, CustomData *data); void write_custom_data(const OCompoundProperty &prop, - const CDStreamConfig &config, + CDStreamConfig &config, CustomData *data, int data_type); -- cgit v1.2.3