Commit: 19fa05d37c0fc27b79baa195a6f2cf72aee621fc
Author: Michael Kowalski
Date:   Fri Sep 2 18:51:55 2022 -0400
Branches: universal-scene-description
https://developer.blender.org/rB19fa05d37c0fc27b79baa195a6f2cf72aee621fc

USD skel export fixes.

Fixed error in USDSkinnedMeshWriter which was causing
the mesh to be written more than once when exporting
blendshapes is disabled.  Also removed unnecessary
warnings when the mesh has deform groups that don't
match any bones.

Updated USDBlendShapeMeshWriter to skip creating a
blendshape neutral mesh if exporting blendshapes is
disabled.

Added more descriptive error message when the shape key
offset count doesn't match the mesh vertex count.  Now
exporting the default mesh when this size mismatch is
detected.

===================================================================

M       source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc
M       source/blender/io/usd/intern/usd_writer_skinned_mesh.cc

===================================================================

diff --git a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc 
b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc
index 6f6a78f9974..44c2d1947f4 100644
--- a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc
@@ -39,6 +39,9 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_meta_types.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
 #include <string>
 
 namespace usdtokens {
@@ -144,18 +147,28 @@ void 
USDBlendShapeMeshWriter::write_blendshape(HierarchyContext &context) const
     return;
   }
 
-  pxr::UsdSkelSkeleton skel = get_skeleton(context);
+  const Key *key = get_shape_key(context.object);
 
-  if (!skel) {
-    printf("WARNING: couldn't get skeleton for blendshape mesh prim %s\n",
-           this->usd_export_context_.usd_path.GetString().c_str());
+  if (!key || !key->block.first) {
+    WM_reportf(RPT_WARNING,
+               "WARNING: couldn't get shape key for blendshape mesh prim %s",
+               usd_export_context_.usd_path.GetString().c_str());
     return;
   }
 
-  const Key *key = get_shape_key(context.object);
+  /* Validate the offset counts. */
+  Mesh *src_mesh = static_cast<Mesh *>(context.object->data);
+  KeyBlock *basis = reinterpret_cast<KeyBlock *>(src_mesh->key->block.first);
+  if (src_mesh->totvert != basis->totelem) {
+    /* No need for a warning, as we would have warned about
+     * the vert count mismatch when creating the mesh. */
+    return;
+  }
 
-  if (!key) {
-    printf("WARNING: couldn't get shape key for blendshape mesh prim %s\n",
+  pxr::UsdSkelSkeleton skel = get_skeleton(context);
+
+  if (!skel) {
+    printf("WARNING: couldn't get skeleton for blendshape mesh prim %s\n",
            this->usd_export_context_.usd_path.GetString().c_str());
     return;
   }
@@ -331,7 +344,10 @@ pxr::UsdSkelSkeleton 
USDBlendShapeMeshWriter::get_skeleton(const HierarchyContex
 
 Mesh *USDBlendShapeMeshWriter::get_export_mesh(Object *object_eval, bool 
&r_needsfree)
 {
-  if (!is_blendshape_mesh(object_eval)) {
+  /* We must check if blendshapes are enabled before attempting to create the
+   * blendshape mesh. */
+  if (!(usd_export_context_.export_params.export_blendshapes && 
is_blendshape_mesh(object_eval))) {
+    /* Get the default mesh.  */
     return USDMeshWriter::get_export_mesh(object_eval, r_needsfree);
   }
 
@@ -348,10 +364,15 @@ Mesh *USDBlendShapeMeshWriter::get_export_mesh(Object 
*object_eval, bool &r_need
   KeyBlock *basis = reinterpret_cast<KeyBlock *>(src_mesh->key->block.first);
 
   if (src_mesh->totvert != basis->totelem) {
-    printf("WARNING: shape vert count %d doesn't match shape key number of 
elements %d\n",
-           src_mesh->totvert,
-           basis->totelem);
-    return nullptr;
+    WM_reportf(RPT_WARNING,
+               "USD Export: mesh %s can't be exported as a blendshape because 
the mesh vertex count %d "
+               "doesn't match shape key number of elements %d'.  This may be 
because the mesh topology was "
+               "changed by a modifier.  Exporting meshes with modifiers as 
blendshapes isn't currently supported",
+               object_eval->id.name + 2,
+               src_mesh->totvert,
+               basis->totelem);
+
+    return USDMeshWriter::get_export_mesh(object_eval, r_needsfree);
   }
 
   Mesh *temp_mesh = reinterpret_cast<Mesh *>(
diff --git a/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc 
b/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc
index a79b0dd42fe..320cd41b1ae 100644
--- a/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc
@@ -78,9 +78,11 @@ USDSkinnedMeshWriter::USDSkinnedMeshWriter(const 
USDExporterContext &ctx)
 
 void USDSkinnedMeshWriter::do_write(HierarchyContext &context)
 {
-  if (this->frame_has_been_written_ && 
usd_export_context_.export_params.export_blendshapes) {
+  if (this->frame_has_been_written_) {
     /* Only blendshapes may be animated on skinned meshes. */
-    write_blendshape(context);
+    if (usd_export_context_.export_params.export_blendshapes) {
+      write_blendshape(context);
+    }
     return;
   }
 
@@ -214,12 +216,6 @@ void USDSkinnedMeshWriter::write_weights(const Object *ob,
       }
     }
 
-    if (bone_idx == -1) {
-      printf("WARNING: deform group %s in skinned mesh %s doesn't match any 
bones\n",
-             def->name,
-             this->usd_export_context_.usd_path.GetString().c_str());
-    }
-
     group_to_bone_idx.push_back(bone_idx);
   }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to