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()) {
pxr::GfMatrix4d bind_xf;
if (skel_api.GetGeomBindTransformAttr().Get(&bind_xf)) {
/* Assume that if a bind transform is defined, then the
* transform is constant. */
/* The USD bind transform is a matrix of doubles,
* 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);
}
else {

View File

@ -110,7 +110,7 @@ class USDMeshReader : public USDGeomReader {
* Override transform computation to account for the binding
* 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

View File

@ -350,25 +350,28 @@ void USDStageReader::process_armature_modifiers() const
if (!reader->object()) {
continue;
}
if (const USDMeshReader *mesh_reader = dynamic_cast<const USDMeshReader *>(reader)) {
/* Check if the mesh object has an armature modifier. */
ModifierData *md = BKE_modifiers_findby_type(reader->object(), eModifierType_Armature);
if (!md) {
continue;
}
ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md);
/* Assign the armature based on the bound USD skeleton path of the skinned mesh. */
std::string skel_path = mesh_reader->get_skeleton_path();
std::map<std::string, Object *>::const_iterator it = usd_path_to_armature.find(skel_path);
if (it == usd_path_to_armature.end()) {
WM_reportf(RPT_WARNING,
"%s: Couldn't find armature object corresponding to USD skeleton %s",
__func__,
skel_path.c_str());
}
amd->object = it->second;
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. */
ModifierData *md = BKE_modifiers_findby_type(reader->object(), eModifierType_Armature);
if (!md) {
continue;
}
ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md);
/* Assign the armature based on the bound USD skeleton path of the skinned mesh. */
std::string skel_path = mesh_reader->get_skeleton_path();
std::map<std::string, Object *>::const_iterator it = usd_path_to_armature.find(skel_path);
if (it == usd_path_to_armature.end()) {
WM_reportf(RPT_WARNING,
"%s: Couldn't find armature object corresponding to USD skeleton %s",
__func__,
skel_path.c_str());
}
amd->object = it->second;
}
}

View File

@ -12,6 +12,8 @@
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>;
class USDXformReader : public USDPrimReader {
@ -63,7 +65,7 @@ class USDXformReader : public USDPrimReader {
* - A boolean flag indicating whether the matrix
* 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