USD: Skeleton and blend shape import #110912

Merged
Michael Kowalski merged 38 commits from makowalski/blender:usdskel_import into main 2023-08-17 20:11:58 +02:00
4 changed files with 29 additions and 22 deletions
Showing only changes of commit 8d67a3a9b4 - Show all commits

View File

@ -1144,8 +1144,10 @@ std::optional<XformResult> USDMeshReader::get_local_usd_xform(const float time)
if (skel_api.GetGeomBindTransformAttr().HasAuthoredValue()) { if (skel_api.GetGeomBindTransformAttr().HasAuthoredValue()) {
pxr::GfMatrix4d bind_xf; pxr::GfMatrix4d bind_xf;
if (skel_api.GetGeomBindTransformAttr().Get(&bind_xf)) { if (skel_api.GetGeomBindTransformAttr().Get(&bind_xf)) {
/* Assume that if a bind transform is defined, then the /* The USD bind transform is a matrix of doubles,
* transform is constant. */ * but we cast it to GfMatrix4f because Blender expects
* a matrix of floats. Also, we assume the transform
* is constant over time. */
return XformResult(pxr::GfMatrix4f(bind_xf), true); return XformResult(pxr::GfMatrix4f(bind_xf), true);
} }
else { else {

View File

@ -110,7 +110,7 @@ class USDMeshReader : public USDGeomReader {
* Override transform computation to account for the binding * Override transform computation to account for the binding
* transformation for skinned meshes. * transformation for skinned meshes.
*/ */
std::optional<XformResult> get_local_usd_xform(const float time) const override; std::optional<XformResult> get_local_usd_xform(float time) const override;
makowalski marked this conversation as resolved Outdated

Remove the const from const float time, in the declaration it has no meaning. See the C/C++ style guide for more info.

Remove the `const` from `const float time`, in the declaration it has no meaning. See the C/C++ style guide for more info.
}; };
} // namespace blender::io::usd } // namespace blender::io::usd

View File

@ -350,12 +350,16 @@ void USDStageReader::process_armature_modifiers() const
if (!reader->object()) { if (!reader->object()) {
continue; continue;
} }
if (const USDMeshReader *mesh_reader = dynamic_cast<const USDMeshReader *>(reader)) { const USDMeshReader *mesh_reader = dynamic_cast<const USDMeshReader *>(reader);
makowalski marked this conversation as resolved Outdated

Swap the condition and continue here as well. That wayall the precondition checks use the same logic, and the main path of the for-body can be followed vertically.

Swap the condition and `continue` here as well. That wayall the precondition checks use the same logic, and the main path of the for-body can be followed vertically.
if (!mesh_reader) {
continue;
}
/* Check if the mesh object has an armature modifier. */ /* Check if the mesh object has an armature modifier. */
ModifierData *md = BKE_modifiers_findby_type(reader->object(), eModifierType_Armature); ModifierData *md = BKE_modifiers_findby_type(reader->object(), eModifierType_Armature);
if (!md) { if (!md) {
continue; continue;
} }
ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md); ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md);
/* Assign the armature based on the bound USD skeleton path of the skinned mesh. */ /* Assign the armature based on the bound USD skeleton path of the skinned mesh. */
@ -370,7 +374,6 @@ void USDStageReader::process_armature_modifiers() const
amd->object = it->second; amd->object = it->second;
} }
} }
}
void USDStageReader::import_all_materials(Main *bmain) void USDStageReader::import_all_materials(Main *bmain)
{ {

View File

@ -12,6 +12,8 @@
namespace blender::io::usd { namespace blender::io::usd {
/** A transformation matrix and a boolean indicating
makowalski marked this conversation as resolved Outdated

Document what the boolean means.

Document what the boolean means.
* whether the matrix is constant over time. */
using XformResult = std::tuple<pxr::GfMatrix4f, bool>; using XformResult = std::tuple<pxr::GfMatrix4f, bool>;
class USDXformReader : public USDPrimReader { class USDXformReader : public USDPrimReader {
@ -63,7 +65,7 @@ class USDXformReader : public USDPrimReader {
* - A boolean flag indicating whether the matrix * - A boolean flag indicating whether the matrix
* is constant over time. * is constant over time.
*/ */
virtual std::optional<XformResult> get_local_usd_xform(const float time) const; virtual std::optional<XformResult> get_local_usd_xform(float time) const;
}; };
} // namespace blender::io::usd } // namespace blender::io::usd