Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check skin cluster weights #2971

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/mayaUsd/fileio/utils/jointWriteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,27 @@ int UsdMayaJointUtil::getCompressedSkinWeights(
unsigned int numInfluences;
skinCluster.getWeights(outputDagPath, components.object(), weights, numInfluences);

if (numInfluences <= 0) {
MString msg("No influences found for skinCluster ");
msg += skinCluster.name();
MGlobal::displayError(msg);
throw std::runtime_error(msg.asChar());
}

if (weights.length() < numVertices * numInfluences) {
MString msg("The number of vertices on the exported mesh ");
msg += outputDagPath.partialPathName();
msg += "(";
msg += numVertices;

msg += ") do not match the number of vertices where the skinCluster was applied (";
msg += weights.length() / numInfluences;
msg += "). Remove any nodes that change mesh topology after the skinCluster.";

MGlobal::displayError(msg);
throw std::runtime_error(msg.asChar());
}

// Determine how many influence/weight "slots" we actually need per point.
// For example, if there are the joints /a, /a/b, and /a/c, but each point
// only has non-zero weighting for a single joint, then we only need one
Expand Down Expand Up @@ -463,4 +484,4 @@ MObject UsdMayaJointUtil::writeSkinningData(
return inMeshObj;
}

PXR_NAMESPACE_CLOSE_SCOPE
PXR_NAMESPACE_CLOSE_SCOPE
1 change: 1 addition & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(TEST_SCRIPT_FILES
testUsdExportSelection.py
testUsdExportSelectionHierarchy.py
testUsdExportSkeleton.py
testUsdExportSkin.py
testUsdExportStripNamespaces.py
testUsdExportStroke.py
testUsdExportUserTaggedAttributes.py
Expand Down
61 changes: 61 additions & 0 deletions test/lib/usd/translators/testUsdExportSkin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env mayapy
#
# Copyright 2023 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import unittest

from maya import cmds
from maya import standalone
from maya.api import OpenMaya as OM

from pxr import Gf, Sdf, Tf, Usd, UsdGeom, UsdSkel, UsdUtils, Vt

import fixturesUtils


def build_scene():
"""Set up simple skinCluster, add a polyReduce after"""
cmds.file(f=1, new=1)
root = cmds.joint()
cmds.joint()
sphere = cmds.polySphere()
cmds.select(root, add=1)
group = cmds.group()

cmds.skinCluster(root, sphere[0])
cmds.select(sphere[0])

cmds.polyReduce(p=50)
return group

class TestUsdExportSkin(unittest.TestCase):
@classmethod
def setUpClass(cls):
inputPath = fixturesUtils.setUpClass(__file__)
# cls.outFile = os.path.join

@classmethod
def tearDownClass(cls):
standalone.uninitialize()

def test_exportSkinDifferingTopology(self):
"""Raise a runtime error if the topology has changed downstream from the skinCluster"""
grp = build_scene()
self.assertRaises(RuntimeError, cmds.mayaUSDExport, file="Does_not_export.usdc", skn="auto", skl="auto")


if __name__ == '__main__':
unittest.main(verbosity=2)