USD: Correctly write out and read Mesh velocity data #120771

Merged
Jesse Yurkovich merged 4 commits from deadpin/blender:usd-duplicatevel into main 2024-04-23 20:44:44 +02:00
3 changed files with 27 additions and 5 deletions

View File

@ -737,6 +737,23 @@ void USDMeshReader::read_vertex_creases(Mesh *mesh, const double motionSampleTim
creases.finish();
}
void USDMeshReader::read_velocities(Mesh *mesh, const double motionSampleTime)
{
pxr::VtVec3fArray velocities;
mesh_prim_.GetVelocitiesAttr().Get(&velocities, motionSampleTime);
if (!velocities.empty()) {
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
bke::GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
"velocity", bke::AttrDomain::Point, CD_PROP_FLOAT3);
Span<pxr::GfVec3f> usd_data(velocities.data(), velocities.size());
attribute.span.typed<float3>().copy_from(usd_data.cast<float3>());
attribute.finish();
}
}
void USDMeshReader::process_normals_vertex_varying(Mesh *mesh)
{
if (!mesh) {
@ -868,6 +885,7 @@ void USDMeshReader::read_mesh_sample(ImportSettings *settings,
(settings->read_flag & MOD_MESHSEQ_READ_COLOR) ||
(settings->read_flag & MOD_MESHSEQ_READ_ATTRIBUTES))
{
read_velocities(mesh, motionSampleTime);
read_custom_data(settings, mesh, motionSampleTime, new_mesh);
}
}
@ -913,6 +931,11 @@ void USDMeshReader::read_custom_data(const ImportSettings *settings,
continue;
}
/* We handle the non-standard primvar:velocity elsewhere. */
if (ELEM(name, "velocity")) {
continue;
}
if (ELEM(type,
pxr::SdfValueTypeNames->StringArray,
pxr::SdfValueTypeNames->QuatfArray,

View File

@ -78,6 +78,7 @@ class USDMeshReader : public USDGeomReader {
void read_mpolys(Mesh *mesh);
void read_vertex_creases(Mesh *mesh, double motionSampleTime);
void read_velocities(Mesh *mesh, double motionSampleTime);
void read_mesh_sample(ImportSettings *settings,
Mesh *mesh,

View File

@ -135,13 +135,11 @@ void USDGenericMeshWriter::write_custom_data(const Object *obj,
attributes.for_all(
[&](const bke::AttributeIDRef &attribute_id, const bke::AttributeMetaData &meta_data) {
/* Skipping "internal" Blender properties. Skipping
* material_index as it's dealt with elsewhere. Skipping
* edge domain because USD doesn't have a good
* conversion for them. */
/* Skip "internal" Blender properties and attributes processed elsewhere.
* Skip edge domain because USD doesn't have a good conversion for them. */
if (attribute_id.name()[0] == '.' || attribute_id.is_anonymous() ||
meta_data.domain == bke::AttrDomain::Edge ||
ELEM(attribute_id.name(), "position", "material_index"))
ELEM(attribute_id.name(), "position", "material_index", "velocity"))
{
return true;
}