Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Winchester <CodyWinch>2021-11-05 16:59:03 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-11-09 12:54:13 +0300
commit4e2478940eb8803f28bfd7361ea3ff7dd83cd247 (patch)
treedcdfa6438c8b461c67fbb7e09cef76f04b614172 /source/blender/io
parent6b0a6c2ca96df219ac057bd781f38bdd24b23963 (diff)
Alembic: Allow exporting of animated vertex colors
Allow exporting of animated vertex colors to Alembic. The changes are made to be in line with the way the UV Maps are written. Each vertex color gets a OC4fGeomParam created and mapped into the CDStreamConfig to avoid recreating the Param on each frame. The time sample index is also stored in the config now and set onto the UV and Vertex Color params each frame. Without this the exports would get inconsistent timing results where animated UV maps and Vertex Colors were not playing back at the original speed. Reviewed By: sybren Maniphest Tasks: T88074 Differential Revision: https://developer.blender.org/D11278
Diffstat (limited to 'source/blender/io')
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_mesh.cc3
-rw-r--r--source/blender/io/alembic/intern/abc_customdata.cc51
-rw-r--r--source/blender/io/alembic/intern/abc_customdata.h4
3 files changed, 42 insertions, 16 deletions
diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
index 442ab6afcd0..7275d0addf0 100644
--- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
@@ -190,6 +190,7 @@ void ABCGenericMeshWriter::do_write(HierarchyContext &context)
m_custom_data_config.totpoly = mesh->totpoly;
m_custom_data_config.totloop = mesh->totloop;
m_custom_data_config.totvert = mesh->totvert;
+ m_custom_data_config.timesample_index = timesample_index_;
try {
if (is_subd_) {
@@ -351,7 +352,7 @@ void ABCGenericMeshWriter::write_face_sets(Object *object, struct Mesh *mesh, Sc
void ABCGenericMeshWriter::write_arb_geo_params(struct Mesh *me)
{
- if (frame_has_been_written_ || !args_.export_params->vcolors) {
+ if (!args_.export_params->vcolors) {
return;
}
diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc
index 087d60f8896..188e8daac8f 100644
--- a/source/blender/io/alembic/intern/abc_customdata.cc
+++ b/source/blender/io/alembic/intern/abc_customdata.cc
@@ -176,29 +176,23 @@ static void write_uv(const OCompoundProperty &prop,
UInt32ArraySample(&indices.front(), indices.size()),
kFacevaryingScope);
param.set(sample);
+ param.setTimeSampling(config.timesample_index);
config.abc_uv_maps[uv_map_name] = param;
}
-/* Convention to write Vertex Colors:
- * - C3fGeomParam/C4fGeomParam on the arbGeomParam
- * - set scope as vertex varying
- */
-static void write_mcol(const OCompoundProperty &prop,
- const CDStreamConfig &config,
- void *data,
- const char *name)
+static void get_cols(const CDStreamConfig &config,
+ std::vector<Imath::C4f> &buffer,
+ std::vector<uint32_t> &uvidx,
+ void *cd_data)
{
const float cscale = 1.0f / 255.0f;
MPoly *polys = config.mpoly;
MLoop *mloops = config.mloop;
- MCol *cfaces = static_cast<MCol *>(data);
-
- std::vector<Imath::C4f> buffer;
- std::vector<uint32_t> indices;
+ MCol *cfaces = static_cast<MCol *>(cd_data);
buffer.reserve(config.totvert);
- indices.reserve(config.totvert);
+ uvidx.reserve(config.totvert);
Imath::C4f col;
@@ -217,17 +211,44 @@ static void write_mcol(const OCompoundProperty &prop,
col[3] = cface->b * cscale;
buffer.push_back(col);
- indices.push_back(buffer.size() - 1);
+ uvidx.push_back(buffer.size() - 1);
}
}
+}
+
+/* Convention to write Vertex Colors:
+ * - C3fGeomParam/C4fGeomParam on the arbGeomParam
+ * - set scope as vertex varying
+ */
+static void write_mcol(const OCompoundProperty &prop,
+ CDStreamConfig &config,
+ void *data,
+ const char *name)
+{
+ std::vector<uint32_t> indices;
+ std::vector<Imath::C4f> buffer;
+
+ get_cols(config, buffer, indices, data);
+
+ if (indices.empty() || buffer.empty()) {
+ return;
+ }
- OC4fGeomParam param(prop, name, true, kFacevaryingScope, 1);
+ std::string vcol_name(name);
+ OC4fGeomParam param = config.abc_vertex_colors[vcol_name];
+
+ if (!param.valid()) {
+ param = OC4fGeomParam(prop, name, true, kFacevaryingScope, 1);
+ }
OC4fGeomParam::Sample sample(C4fArraySample(&buffer.front(), buffer.size()),
UInt32ArraySample(&indices.front(), indices.size()),
kVertexScope);
param.set(sample);
+ param.setTimeSampling(config.timesample_index);
+
+ config.abc_vertex_colors[vcol_name] = param;
}
void write_generated_coordinates(const OCompoundProperty &prop, CDStreamConfig &config)
diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h
index 03e6f697f0c..5eae6307474 100644
--- a/source/blender/io/alembic/intern/abc_customdata.h
+++ b/source/blender/io/alembic/intern/abc_customdata.h
@@ -66,6 +66,7 @@ struct CDStreamConfig {
float weight;
float time;
+ int timesample_index;
bool use_vertex_interpolation;
Alembic::AbcGeom::index_t index;
Alembic::AbcGeom::index_t ceil_index;
@@ -82,6 +83,9 @@ struct CDStreamConfig {
/* ORCO coordinates, aka Generated Coordinates. */
Alembic::AbcGeom::OV3fGeomParam abc_orco;
+ /* Mapping from vertex color layer name to its Alembic color data. */
+ std::map<std::string, Alembic::AbcGeom::OC4fGeomParam> abc_vertex_colors;
+
CDStreamConfig()
: mloop(NULL),
totloop(0),