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
This commit is contained in:
Cody Winchester 2021-11-05 14:59:03 +01:00 committed by Sybren A. Stüvel
parent 6b0a6c2ca9
commit 4e2478940e
Notes: blender-bot 2023-02-13 18:45:50 +01:00
Referenced by issue #88074, Alembic: export animated vertex colors
3 changed files with 42 additions and 16 deletions

View File

@ -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;
}

View File

@ -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);
}
}
}
OC4fGeomParam param(prop, name, true, kFacevaryingScope, 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;
}
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)

View File

@ -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),