Skip to content

Commit 931ee12

Browse files
committed
Allow for loading a simplex system onto a node with multiple shapes in Maya
1 parent 9a40f1f commit 931ee12

File tree

7 files changed

+282
-196
lines changed

7 files changed

+282
-196
lines changed

simplexui/commands/uvTransfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def uvTransferLoad(
906906
The target uv faces
907907
908908
"""
909-
import .alembicCommon as abc
909+
from . import alembicCommon as abc
910910
from .mesh import Mesh
911911

912912
if srcPath.endswith(".abc") or srcPath.endswith(".smpx"):
@@ -978,7 +978,7 @@ def uvTransferFiles(
978978
-------
979979
980980
"""
981-
import .alembicCommon as abc
981+
from . import alembicCommon as abc
982982

983983
tarVerts, tarFaces, tarUvs, tarUvFaces = uvTransferLoad(
984984
srcPath, tarPath, srcUvSet=srcUvSet, tarUvSet=tarUvSet, tol=tol, pBar=pBar

simplexui/interface/dummyInterface.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ def postLoad(self, simp, preRet):
275275
"""
276276
pass
277277

278+
def checkForErrors(self, window):
279+
""" Check for any DCC specific errors
280+
281+
Parameters
282+
----------
283+
window : QMainWindow
284+
The simplex window
285+
"""
286+
pass
287+
278288
# System IO
279289
@undoable
280290
def loadNodes(self, simp, thing, create=True, pBar=None):

simplexui/interface/mayaInterface.py

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,23 @@ def _checkAllShapeValidity(self, shapeNames):
274274
missingNames.append(shapeName)
275275
return missingNames, len(attrs)
276276

277+
278+
@classmethod
279+
def _removeExtraShapeNodes(cls, tfm):
280+
shapeNodes = cmds.listRelatives(tfm, shapes=True, noIntermediate=True)
281+
if len(shapeNodes) > 1:
282+
keeper = None
283+
todel = []
284+
for sn in shapeNodes:
285+
tfmChk = ''.join(sn.rsplit('Shape', 1))
286+
if tfmChk == tfm:
287+
keeper = sn
288+
else:
289+
todel.append(sn)
290+
if keeper is not None:
291+
cmds.delete(todel)
292+
293+
277294
def preLoad(self, simp, simpDict, create=True, pBar=None):
278295
"""
279296
@@ -293,21 +310,24 @@ def preLoad(self, simp, simpDict, create=True, pBar=None):
293310
294311
"""
295312
cmds.undoInfo(state=False)
296-
if pBar is not None:
297-
pBar.setLabelText("Loading Connections")
298-
QApplication.processEvents()
299-
ev = simpDict["encodingVersion"]
313+
try:
314+
if pBar is not None:
315+
pBar.setLabelText("Loading Connections")
316+
QApplication.processEvents()
317+
ev = simpDict["encodingVersion"]
300318

301-
shapeNames = simpDict.get("shapes")
302-
if not shapeNames:
303-
return
319+
shapeNames = simpDict.get("shapes")
320+
if not shapeNames:
321+
return
304322

305-
if ev > 1:
306-
shapeNames = [i["name"] for i in shapeNames]
323+
if ev > 1:
324+
shapeNames = [i["name"] for i in shapeNames]
325+
326+
toMake, nextIndex = self._checkAllShapeValidity(shapeNames)
307327

308-
toMake, nextIndex = self._checkAllShapeValidity(shapeNames)
328+
if not toMake:
329+
return
309330

310-
if toMake:
311331
if not create:
312332
if pBar is not None:
313333
msg = "\n".join(
@@ -332,24 +352,33 @@ def preLoad(self, simp, simpDict, create=True, pBar=None):
332352
pBar.setValue(0)
333353
QApplication.processEvents()
334354

355+
baseShape = cmds.duplicate(self.mesh)[0]
356+
cmds.delete(baseShape, constructionHistory=True)
357+
self._removeExtraShapeNodes(baseShape)
358+
335359
for i, shapeName in enumerate(toMake):
336360
if pBar is not None:
337361
pBar.setLabelText("Creating Empty Shape:\n{0}".format(shapeName))
338362
pBar.setValue(i)
339363
QApplication.processEvents()
340364

341-
newShape = cmds.duplicate(self.mesh, name=shapeName)[0]
342-
cmds.delete(newShape, constructionHistory=True)
365+
baseShape = cmds.rename(baseShape, shapeName)
366+
343367
index = self._firstAvailableIndex()
344368
cmds.blendShape(
345-
self.shapeNode, edit=True, target=(self.mesh, index, newShape, 1.0)
369+
self.shapeNode, edit=True, target=(self.mesh, index, baseShape, 1.0)
346370
)
347371
weightAttr = "{0}.weight[{1}]".format(self.shapeNode, index)
348372
thing = cmds.ls(weightAttr)[0]
373+
349374
cmds.connectAttr("{0}.weights[{1}]".format(self.op, nextIndex), thing)
350-
cmds.delete(newShape)
351375
nextIndex += 1
352-
return None
376+
377+
cmds.delete(baseShape)
378+
except Exception:
379+
cmds.undoInfo(state=True)
380+
raise
381+
353382

354383
def postLoad(self, simp, preRet):
355384
"""
@@ -366,6 +395,23 @@ def postLoad(self, simp, preRet):
366395
"""
367396
cmds.undoInfo(state=True)
368397

398+
def checkForErrors(self, window):
399+
""" Check for any DCC specific errors
400+
401+
Parameters
402+
----------
403+
window : QMainWindow
404+
The simplex window
405+
"""
406+
shapeNodes = cmds.listRelatives(self.mesh, shapes=True, noIntermediate=True)
407+
if len(shapeNodes) > 1:
408+
msg = (
409+
"The current mesh has multiple shape nodes.",
410+
"The UI will still mostly work, but extracting/connecting shapes"
411+
"may fail in unexpected ways."
412+
)
413+
QMessageBox.warning(window, "Multiple Shape Nodes", '\n'.join(msg))
414+
369415
# System IO
370416
@undoable
371417
def loadNodes(self, simp, thing, create=True, pBar=None):
@@ -655,18 +701,18 @@ def loadAbc(self, abcMesh, js, pBar=None):
655701
cmds.polyEvaluate(importHead, vertex=True) # Force a refresh
656702
cmds.disconnectAttr(abcNode + ".outPolyMesh[0]", importHeadShape + ".inMesh")
657703

658-
importBS = cmds.blendShape(self.mesh, importHead)[0]
704+
importRest = cmds.duplicate(self.mesh, name="importRest")[0]
705+
cmds.delete(importRest, constructionHistory=True)
706+
self._removeExtraShapeNodes(importRest)
707+
708+
importBS = cmds.blendShape(importRest, importHead)[0]
659709
cmds.blendShape(importBS, edit=True, weight=[(0, 1.0)])
660710
# Maybe get shapeNode from self.mesh??
661-
inTarget = (
662-
importBS
663-
+ ".inputTarget[0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget"
664-
)
665-
cmds.disconnectAttr(self.mesh + ".worldMesh[0]", inTarget)
666711
importOrig = [
667712
i for i in cmds.listRelatives(importHead, shapes=True) if i.endswith("Orig")
668713
][0]
669714
cmds.connectAttr(abcNode + ".outPolyMesh[0]", importOrig + ".inMesh")
715+
cmds.delete(importRest)
670716

671717
if pBar is not None:
672718
pBar.show()
@@ -1239,6 +1285,15 @@ def renameSystem(self, name):
12391285
-------
12401286
12411287
"""
1288+
if (
1289+
self.mesh is None
1290+
or self.ctrl is None
1291+
or self.shapeNode is None
1292+
or self.op is None
1293+
or self.simplex is None
1294+
):
1295+
raise ValueError("System is not set up. Cannot rename")
1296+
12421297
nn = self.mesh.replace(self.name, name)
12431298
self.mesh = cmds.rename(self.mesh, nn)
12441299

simplexui/interface/xsiInterface.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ def postLoad(self, simp, preRet):
364364
self.recreateShapeNode()
365365
self.updateSlidersRange(simp.sliders)
366366

367+
def checkForErrors(self, window):
368+
""" Check for any DCC specific errors
369+
370+
Parameters
371+
----------
372+
window : QMainWindow
373+
The simplex window
374+
"""
375+
pass
376+
367377
# System IO
368378
@undoable
369379
def loadNodes(self, simp, thing, create=True, pBar=None):

0 commit comments

Comments
 (0)