simplex-solver 3.1.0__39-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. simplex_solver-3.1.0.dist-info/METADATA +90 -0
  2. simplex_solver-3.1.0.dist-info/RECORD +79 -0
  3. simplex_solver-3.1.0.dist-info/WHEEL +5 -0
  4. simplexui/__init__.py +53 -0
  5. simplexui/_version.py +1 -0
  6. simplexui/channelBox.py +858 -0
  7. simplexui/comboCheckDialog.py +343 -0
  8. simplexui/commands/__init__.py +16 -0
  9. simplexui/commands/alembicCommon.py +991 -0
  10. simplexui/commands/applyCorrectives.py +451 -0
  11. simplexui/commands/correctiveInterface.py +261 -0
  12. simplexui/commands/expandedExport.py +436 -0
  13. simplexui/commands/hdf5Convert.py +60 -0
  14. simplexui/commands/mayaCorrectiveInterface.py +161 -0
  15. simplexui/commands/mayatonumpy.py +375 -0
  16. simplexui/commands/mesh.py +1081 -0
  17. simplexui/commands/numpytoimath.py +319 -0
  18. simplexui/commands/poseblendlib.py +166 -0
  19. simplexui/commands/reorderSimplexPoints.py +102 -0
  20. simplexui/commands/rigidAlign.py +99 -0
  21. simplexui/commands/smpxBlend.py +629 -0
  22. simplexui/commands/unsubdivide.py +1227 -0
  23. simplexui/commands/uvTransfer.py +977 -0
  24. simplexui/dragFilter.py +299 -0
  25. simplexui/falloffDialog.py +471 -0
  26. simplexui/img/ChefHead.png +0 -0
  27. simplexui/img/frozen.png +0 -0
  28. simplexui/interface/__init__.py +28 -0
  29. simplexui/interface/dummyInterface.py +1585 -0
  30. simplexui/interface/mayaInterface.py +3271 -0
  31. simplexui/interfaceModel.py +1053 -0
  32. simplexui/interfaceModelTrees.py +441 -0
  33. simplexui/items/__init__.py +42 -0
  34. simplexui/items/accessor.py +213 -0
  35. simplexui/items/combo.py +852 -0
  36. simplexui/items/falloff.py +778 -0
  37. simplexui/items/group.py +297 -0
  38. simplexui/items/progression.py +743 -0
  39. simplexui/items/shape.py +443 -0
  40. simplexui/items/simplex.py +1764 -0
  41. simplexui/items/slider.py +738 -0
  42. simplexui/items/stack.py +154 -0
  43. simplexui/items/traversal.py +966 -0
  44. simplexui/main.pyw +22 -0
  45. simplexui/menu/__init__.py +69 -0
  46. simplexui/menu/dummyPlugins/__init__.py +16 -0
  47. simplexui/menu/genericPlugins/__init__.py +16 -0
  48. simplexui/menu/genericPlugins/_builtins.py +268 -0
  49. simplexui/menu/genericPlugins/checkPossibleCombos.py +45 -0
  50. simplexui/menu/genericPlugins/exportSplit.py +59 -0
  51. simplexui/menu/genericPlugins/showFalloffs.py +24 -0
  52. simplexui/menu/genericPlugins/showTraversals.py +24 -0
  53. simplexui/menu/genericPlugins/simplexUvTransfer.py +107 -0
  54. simplexui/menu/genericPlugins/unsubdivide.py +70 -0
  55. simplexui/menu/mayaPlugins/__init__.py +16 -0
  56. simplexui/menu/mayaPlugins/exportOther.py +43 -0
  57. simplexui/menu/mayaPlugins/extractProgressives.py +65 -0
  58. simplexui/menu/mayaPlugins/freezeCombo.py +245 -0
  59. simplexui/menu/mayaPlugins/generateShapeIncrementals.py +97 -0
  60. simplexui/menu/mayaPlugins/importObjs.py +193 -0
  61. simplexui/menu/mayaPlugins/linearizeTraversal.py +48 -0
  62. simplexui/menu/mayaPlugins/makeShelfBtn.py +65 -0
  63. simplexui/menu/mayaPlugins/relaxToSelection.py +75 -0
  64. simplexui/menu/mayaPlugins/reloadDefinition.py +33 -0
  65. simplexui/menu/mayaPlugins/snapToNeutral.py +72 -0
  66. simplexui/menu/mayaPlugins/softSelectToCluster.py +200 -0
  67. simplexui/menu/mayaPlugins/tweakMix.py +134 -0
  68. simplexui/menu/mayaPlugins/updateRestShape.py +105 -0
  69. simplexui/pysimplex.dll.a +0 -0
  70. simplexui/pysimplex.pyd +0 -0
  71. simplexui/simplexDialog.py +1454 -0
  72. simplexui/travCheckDialog.py +397 -0
  73. simplexui/traversalDialog.py +271 -0
  74. simplexui/ui/comboCheckDialog.ui +475 -0
  75. simplexui/ui/falloffDialog.ui +243 -0
  76. simplexui/ui/simplexDialog.ui +1458 -0
  77. simplexui/ui/travCheckDialog.ui +488 -0
  78. simplexui/ui/traversalDialog.ui +532 -0
  79. simplexui/utils.py +320 -0
@@ -0,0 +1,193 @@
1
+ import os
2
+ from functools import partial
3
+
4
+ import maya.cmds as cmds
5
+
6
+ from ...items import Combo, Slider, Traversal
7
+ from Qt.QtWidgets import (
8
+ QAction,
9
+ QApplication,
10
+ QFileDialog,
11
+ QMessageBox,
12
+ QProgressDialog,
13
+ )
14
+
15
+ try:
16
+ import numpy as np
17
+ except ImportError:
18
+ np = None
19
+
20
+ try:
21
+ from MeshCrawler.commands import setAllVerts
22
+ from MeshCrawler.mesh import Mesh
23
+ from MeshCrawler.meshcrawlerGen import autoCrawlMeshes
24
+ except ImportError:
25
+ autoCrawlMeshes = None
26
+
27
+
28
+ def buildMesh(simplex, mesh):
29
+ topo = simplex.DCC.getMeshTopology(mesh)
30
+ faceIdxs, counts = topo[1], topo[2]
31
+ faces = []
32
+ ptr = 0
33
+ for c in counts:
34
+ faces.append(tuple(faceIdxs[ptr : ptr + c]))
35
+ ptr += c
36
+ return Mesh(topo[0], tuple(faces))
37
+
38
+
39
+ def importSimpleObjs(simplex, orders, pBar):
40
+ for shapeName, ctrl, shape, path in orders:
41
+ pBar.setValue(pBar.value() + 1)
42
+ pBar.setLabelText("Loading Obj :\n{0}".format(shapeName))
43
+ QApplication.processEvents()
44
+ if pBar.wasCanceled():
45
+ return
46
+
47
+ mesh = simplex.DCC.importObj(path)
48
+
49
+ if isinstance(ctrl, Slider):
50
+ simplex.DCC.connectShape(shape, mesh=mesh, live=False, delete=True)
51
+ elif isinstance(ctrl, Combo):
52
+ simplex.DCC.connectComboShape(
53
+ ctrl, shape, mesh=mesh, live=False, delete=True
54
+ )
55
+ elif isinstance(ctrl, Traversal):
56
+ simplex.DCC.connectTraversalShape(
57
+ ctrl, shape, mesh=mesh, live=False, delete=True
58
+ )
59
+
60
+
61
+ def importReorderObjs(simplex, orders, pBar):
62
+ reoMesh = simplex.DCC.extractShape(simplex.restShape, live=False)
63
+ orderMesh = buildMesh(simplex, reoMesh)
64
+
65
+ memo = {}
66
+
67
+ for shapeName, ctrl, shape, path in orders:
68
+ pBar.setValue(pBar.value() + 1)
69
+ pBar.setLabelText("Loading Obj :\n{0}".format(shapeName))
70
+ QApplication.processEvents()
71
+ if pBar.wasCanceled():
72
+ return
73
+
74
+ impMesh = simplex.DCC.importObj(path)
75
+ objMesh = buildMesh(simplex, impMesh)
76
+ reo = memo.setdefault(
77
+ objMesh.faceVertArray, autoCrawlMeshes(orderMesh, objMesh)
78
+ )
79
+ verts = simplex.DCC.getNumpyShape(impMesh)
80
+
81
+ setAllVerts(reoMesh, verts[reo])
82
+
83
+ if isinstance(ctrl, Slider):
84
+ simplex.DCC.connectShape(shape, mesh=reoMesh, live=False, delete=False)
85
+ elif isinstance(ctrl, Combo):
86
+ simplex.DCC.connectComboShape(
87
+ ctrl, shape, mesh=reoMesh, live=False, delete=False
88
+ )
89
+ elif isinstance(ctrl, Traversal):
90
+ simplex.DCC.connectTraversalShape(
91
+ ctrl, shape, mesh=reoMesh, live=False, delete=False
92
+ )
93
+
94
+ cmds.delete(reoMesh)
95
+
96
+
97
+ def importObjList(simplex, paths, pBar, reorder=True):
98
+ """Import all given .obj files
99
+
100
+ Parameters
101
+ ----------
102
+ paths : list
103
+ The list of .obj files to import
104
+ """
105
+ shapeDict = {shape.name: shape for shape in simplex.shapes}
106
+
107
+ inPairs = {}
108
+ for path in paths:
109
+ shapeName = os.path.splitext(os.path.basename(path))[0]
110
+ shape = shapeDict.get(shapeName)
111
+ if shape is not None:
112
+ inPairs[shapeName] = path
113
+ else:
114
+ sfx = "_Extract"
115
+ if shapeName.endswith(sfx):
116
+ shapeName = shapeName[: -len(sfx)]
117
+ shape = shapeDict.get(shapeName)
118
+ if shape is not None:
119
+ inPairs[shapeName] = path
120
+
121
+ sliderMasters, comboMasters, travMasters = {}, {}, {}
122
+ for masters in [simplex.sliders, simplex.combos, simplex.traversals]:
123
+ for master in masters:
124
+ for pp in master.prog.pairs:
125
+ shape = shapeDict.get(pp.shape.name)
126
+ if shape is not None:
127
+ if shape.name in inPairs:
128
+ if isinstance(master, Slider):
129
+ sliderMasters[shape.name] = master
130
+ elif isinstance(master, Combo):
131
+ comboMasters[shape.name] = master
132
+ elif isinstance(master, Traversal):
133
+ travMasters[shape.name] = master
134
+
135
+ comboDepth = {}
136
+ for k, v in comboMasters.items():
137
+ depth = len(v.pairs)
138
+ comboDepth.setdefault(depth, {})[k] = v
139
+
140
+ importOrder = []
141
+ for shapeName, slider in sliderMasters.items():
142
+ importOrder.append(
143
+ (shapeName, slider, shapeDict[shapeName], inPairs[shapeName])
144
+ )
145
+
146
+ for depth in sorted(comboDepth.keys()):
147
+ for shapeName, combo in comboDepth[depth].items():
148
+ importOrder.append(
149
+ (shapeName, combo, shapeDict[shapeName], inPairs[shapeName])
150
+ )
151
+
152
+ for shapeName, trav in travMasters.items():
153
+ importOrder.append((shapeName, trav, shapeDict[shapeName], inPairs[shapeName]))
154
+
155
+ if pBar is not None:
156
+ pBar.setMaximum(len(sliderMasters) + len(comboMasters) + len(travMasters))
157
+
158
+ if reorder:
159
+ importReorderObjs(simplex, importOrder, pBar)
160
+ else:
161
+ importSimpleObjs(simplex, importOrder, pBar)
162
+
163
+ pBar.close()
164
+
165
+
166
+ def registerTool(window, menu):
167
+ importObjsACT = QAction("Import Obj Folder", window)
168
+ menu.addAction(importObjsACT)
169
+ importObjsACT.triggered.connect(partial(importObjsInterface, window))
170
+
171
+
172
+ def importObjsInterface(window):
173
+ reorder = True
174
+ if np is None or autoCrawlMeshes is None:
175
+ reorder = False
176
+
177
+ folder = QFileDialog.getExistingDirectory(window, "Import Obj Folder", "")
178
+
179
+ if not os.path.isdir(folder):
180
+ QMessageBox.warning(window, "Warning", "Folder does not exist")
181
+ return
182
+
183
+ paths = os.listdir(folder)
184
+ paths = [i for i in paths if i.endswith((".obj", ".OBJ"))]
185
+ if not paths:
186
+ QMessageBox.warning(window, "Warning", "Folder does not contain any .obj files")
187
+ return
188
+ paths = [os.path.join(folder, p) for p in paths]
189
+
190
+ pBar = QProgressDialog("Loading from Mesh", "Cancel", 0, 100, window)
191
+ pBar.show()
192
+
193
+ importObjList(window.simplex, paths, pBar=pBar, reorder=reorder)
@@ -0,0 +1,48 @@
1
+ # Copyright 2016, Blur Studio
2
+ #
3
+ # This file is part of Simplex.
4
+ #
5
+ # Simplex is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Simplex is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ from functools import partial
19
+ import maya.cmds as cmds
20
+ from Qt.QtWidgets import QAction
21
+
22
+
23
+ def registerTool(window, menu):
24
+ lineTravACT = QAction("Linearize Traversal", window)
25
+ menu.addAction(lineTravACT)
26
+ lineTravACT.triggered.connect(partial(lineTrav, window))
27
+
28
+
29
+ def lineTrav(window):
30
+ simplex = window.simplex
31
+ travDialog = window.travDialog
32
+ sel = travDialog.uiTraversalTREE.getSelectedIndexes()
33
+ travIdx = sel[0]
34
+ trav = travIdx.model().itemFromIndex(travIdx)
35
+ extracted = window.shapeIndexExtract([travIdx])
36
+ rest = simplex.DCC.extractTraversalShape(trav, simplex.restShape, live=False)
37
+
38
+ end = extracted[-1]
39
+ val = len(extracted)
40
+ for i, mesh in enumerate(extracted[:-1]):
41
+ startDup = cmds.duplicate(rest, name="startDup")[0]
42
+ absBlend = cmds.blendShape(end, startDup)
43
+ cmds.blendShape(absBlend, edit=True, weight=((0, (i + 1.0) / val)))
44
+
45
+ finBlend = cmds.blendShape(startDup, mesh)
46
+ cmds.blendShape(finBlend, edit=True, weight=((0, 1)))
47
+ cmds.delete(startDup)
48
+ cmds.delete(rest)
@@ -0,0 +1,65 @@
1
+ # Copyright 2016, Blur Studio
2
+ #
3
+ # This file is part of Simplex.
4
+ #
5
+ # Simplex is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Simplex is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ import os
19
+
20
+ from Qt.QtWidgets import QAction
21
+
22
+ dn = os.path.dirname
23
+ SHELF_DEV_BUTTON = """
24
+ import os, sys
25
+
26
+ path = r'{0}'
27
+ path = os.path.normcase(os.path.normpath(path))
28
+ if sys.path[0] != path:
29
+ sys.path.insert(0, path)
30
+
31
+ import simplexui
32
+ if simplexui.SIMPLEX_UI is not None:
33
+ try:
34
+ simplexui.SIMPLEX_UI.close()
35
+ except RuntimeError:
36
+ # In case I closed it myself
37
+ pass
38
+ del simplexui
39
+
40
+ for key, value in sys.modules.items():
41
+ try:
42
+ packPath = value.__file__
43
+ except AttributeError:
44
+ continue
45
+
46
+ packPath = os.path.normcase(os.path.normpath(packPath))
47
+ if packPath.startswith(path):
48
+ sys.modules.pop(key)
49
+
50
+ import simplexui
51
+ simplexui.runSimplexUI()
52
+
53
+ sys.path.pop(0)
54
+ """.format(dn(dn(dn(dn(__file__)))))
55
+
56
+
57
+ def registerTool(window, menu):
58
+ makeShelfBtnACT = QAction("Make Shelf Button", window)
59
+ menu.addAction(makeShelfBtnACT)
60
+ makeShelfBtnACT.triggered.connect(makeShelfButton)
61
+
62
+
63
+ def makeShelfButton():
64
+ pass
65
+ # TODO: Actually, ya know, Add the button to the shelf
@@ -0,0 +1,75 @@
1
+ # Copyright 2016, Blur Studio
2
+ #
3
+ # This file is part of Simplex.
4
+ #
5
+ # Simplex is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Simplex is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ import maya.cmds as cmds
19
+
20
+ from Qt.QtWidgets import QAction
21
+
22
+
23
+ def registerTool(window, menu):
24
+ relaxToSelectionACT = QAction("Relax To Selection", window)
25
+ menu.addAction(relaxToSelectionACT)
26
+ relaxToSelectionACT.triggered.connect(relaxToSelectionInterface)
27
+
28
+
29
+ def relaxToSelectionInterface():
30
+ sel = cmds.ls(sl=True)
31
+ if len(sel) >= 2:
32
+ relaxToSelection(sel[0], sel[1])
33
+
34
+
35
+ def relaxToSelection(source, target):
36
+ """
37
+ Transfer high-frequency sculpts (like wrinkles) from one shape to another
38
+
39
+ This sets up a delta mush on a detailed mesh (source) before blending to a
40
+ less detailed shape (target). Turning up the deltaMush re-applies the
41
+ high-resolution deltas to that less detailed shape so then blend it back
42
+ into the target
43
+ """
44
+ sourceDup = cmds.duplicate(source, name="deltaMushMesh")[0]
45
+ targetDup = cmds.duplicate(target, name="targetDup")[0]
46
+ deltaMushRelax = cmds.group(sourceDup, name="deltaMushRelax")
47
+ cmds.hide([sourceDup, targetDup, deltaMushRelax])
48
+
49
+ cmds.addAttr(
50
+ deltaMushRelax,
51
+ longName="smooth_iter",
52
+ attributeType="long",
53
+ minValue=0,
54
+ maxValue=100,
55
+ defaultValue=10,
56
+ )
57
+ smoothIter = "{0}.smooth_iter".format(deltaMushRelax)
58
+ cmds.setAttr(smoothIter, edit=True, keyable=True)
59
+
60
+ blender = cmds.blendShape(targetDup, sourceDup)
61
+ deltaMush = cmds.deltaMush(
62
+ sourceDup,
63
+ smoothingIterations=10,
64
+ smoothingStep=0.5,
65
+ pinBorderVertices=1,
66
+ envelope=1,
67
+ )[0]
68
+ cmds.connectAttr(smoothIter, deltaMush + ".smoothingIterations", force=True)
69
+
70
+ cmds.delete(targetDup)
71
+ finalBlend = cmds.blendShape(sourceDup, target)
72
+ cmds.blendShape(finalBlend, edit=True, weight=((0, 1)))
73
+ cmds.blendShape(blender, edit=True, weight=((0, 1)))
74
+
75
+ cmds.select(deltaMushRelax)
@@ -0,0 +1,33 @@
1
+ # Copyright 2016, Blur Studio
2
+ #
3
+ # This file is part of Simplex.
4
+ #
5
+ # Simplex is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Simplex is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ from functools import partial
19
+ from Qt.QtWidgets import QAction
20
+
21
+
22
+ def registerTool(window, menu):
23
+ reloadDefinitionACT = QAction("Reload Definition", window)
24
+ menu.addAction(reloadDefinitionACT)
25
+ reloadDefinitionACT.triggered.connect(partial(reloadDefinitionInterface, window))
26
+
27
+
28
+ def reloadDefinitionInterface(window):
29
+ reloadDefinition(window.simplex)
30
+
31
+
32
+ def reloadDefinition(simplex):
33
+ simplex.DCC.setSimplexString(simplex.DCC.op, simplex.dump())
@@ -0,0 +1,72 @@
1
+ # Copyright 2016, Blur Studio
2
+ #
3
+ # This file is part of Simplex.
4
+ #
5
+ # Simplex is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Simplex is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ from functools import partial
19
+
20
+ import maya.cmds as cmds
21
+
22
+ from Qt.QtWidgets import QAction
23
+
24
+
25
+ def registerTool(window, menu):
26
+ snapShapeToNeutralACT = QAction("Snap Shape To Neutral", window)
27
+ menu.addAction(snapShapeToNeutralACT)
28
+ snapShapeToNeutralACT.triggered.connect(
29
+ partial(snapShapeToNeutralInterface, window)
30
+ )
31
+
32
+
33
+ def snapShapeToNeutralInterface(window):
34
+ sel = cmds.ls(sl=True)
35
+ if len(sel) >= 2:
36
+ snapShapeToNeutral(sel[0], sel[1])
37
+ elif len(sel) == 1:
38
+ rest = window.simplex.extractRestShape()
39
+ snapShapeToNeutral(sel[0], rest)
40
+ cmds.delete(rest)
41
+
42
+
43
+ def snapShapeToNeutral(source, target):
44
+ """
45
+ Take a mesh, and find the closest location on the target head, and snap to that
46
+ Then set up a blendShape so the artist can "paint" in the snapping behavior
47
+ """
48
+ # Make a duplicate of the source and snap it to the target
49
+ snapShape = cmds.duplicate(source, name="snp")
50
+ cmds.transferAttributes(
51
+ target,
52
+ snapShape,
53
+ transferPositions=1,
54
+ sampleSpace=1, # 0=World, 1=Local, 3=UV
55
+ searchMethod=0, # 0=Along Normal, 1=Closest Location
56
+ )
57
+
58
+ # Then delete history
59
+ cmds.delete(snapShape, constructionHistory=True)
60
+ cmds.hide(snapShape)
61
+
62
+ # Blend the source to the snappedShape
63
+ bs = cmds.blendShape(snapShape, source)[0]
64
+ cmds.blendShape(bs, edit=True, weight=((0, 1)))
65
+
66
+ # But set the weights back to 0.0 for painting
67
+ numVerts = cmds.polyEvaluate(source, vertex=1)
68
+ setter = "{0}.inputTarget[0].inputTargetGroup[0].targetWeights[0:{1}]".format(
69
+ bs, numVerts - 1
70
+ )
71
+ weights = [0.0] * numVerts
72
+ cmds.setAttr(setter, *weights, size=numVerts)
@@ -0,0 +1,200 @@
1
+ # Copyright 2016, Blur Studio
2
+ #
3
+ # This file is part of Simplex.
4
+ #
5
+ # Simplex is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Simplex is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ import maya.cmds as cmds
19
+ import maya.OpenMaya as om
20
+
21
+ from Qt.QtWidgets import QAction
22
+
23
+
24
+ def registerTool(window, menu):
25
+ softSelectToClusterACT = QAction("Soft Select To Cluster", window)
26
+ menu.addAction(softSelectToClusterACT)
27
+ softSelectToClusterACT.triggered.connect(softSelectToClusterInterface)
28
+
29
+
30
+ def softSelectToClusterInterface():
31
+ sel = cmds.ls(sl=True, objectsOnly=True)
32
+ if sel:
33
+ name = sel[0].split("|")[-1]
34
+ softSelectToCluster(sel[0], "{0}_Soft".format(name))
35
+
36
+
37
+ def getSoftSelectionValues(myNode, returnSimpleIndices=True):
38
+ """Get the current soft selection values"""
39
+ softOn = cmds.softSelect(query=True, softSelectEnabled=True)
40
+ richSelList = om.MSelectionList()
41
+
42
+ if softOn:
43
+ richSel = om.MRichSelection()
44
+ try:
45
+ om.MGlobal.getRichSelection(richSel)
46
+ except RuntimeError:
47
+ return []
48
+ richSel.getSelection(richSelList)
49
+ else:
50
+ om.MGlobal.getActiveSelectionList(richSelList)
51
+ toReturn = {}
52
+ if richSelList.isEmpty():
53
+ return toReturn
54
+
55
+ uVal = om.MScriptUtil()
56
+ uVal.createFromInt(0)
57
+ ptru = uVal.asIntPtr()
58
+
59
+ vVal = om.MScriptUtil()
60
+ vVal.createFromInt(0)
61
+ ptrv = vVal.asIntPtr()
62
+
63
+ wVal = om.MScriptUtil()
64
+ wVal.createFromInt(0)
65
+ ptrw = wVal.asIntPtr()
66
+
67
+ iterSel = om.MItSelectionList(richSelList)
68
+
69
+ while not iterSel.isDone():
70
+ component = om.MObject()
71
+ dagPath = om.MDagPath()
72
+ try:
73
+ iterSel.getDagPath(dagPath, component)
74
+ except Exception:
75
+ iterSel.next()
76
+ continue
77
+
78
+ depNode_name = dagPath.fullPathName()
79
+
80
+ # hack in a quick check so it only works with
81
+ # shapes under the given transform
82
+ if not depNode_name.startswith(myNode):
83
+ iterSel.next()
84
+ continue
85
+
86
+ elementIndices = []
87
+ elementWeights = []
88
+
89
+ if component.isNull():
90
+ toReturn[depNode_name] = (elementIndices, elementWeights)
91
+ continue
92
+
93
+ componentFn = om.MFnComponent(component)
94
+ count = componentFn.elementCount()
95
+ ctyp = componentFn.componentType()
96
+
97
+ if ctyp == om.MFn.kMeshPolygonComponent:
98
+ polyIter = om.MItMeshPolygon(dagPath, component)
99
+ setOfVerts = set()
100
+ while not polyIter.isDone():
101
+ connectedVertices = om.MIntArray()
102
+ polyIter.getVertices(connectedVertices)
103
+ for j in range(connectedVertices.length()):
104
+ setOfVerts.add(connectedVertices[j])
105
+ polyIter.next()
106
+ lstVerts = list(setOfVerts)
107
+ lstVerts.sort()
108
+ for vtx in lstVerts:
109
+ elementIndices.append(vtx)
110
+ elementWeights.append(1)
111
+ elif ctyp == om.MFn.kMeshEdgeComponent:
112
+ edgeIter = om.MItMeshEdge(dagPath, component)
113
+ setOfVerts = set()
114
+ while not edgeIter.isDone():
115
+ setOfVerts.add(edgeIter.index(0))
116
+ setOfVerts.add(edgeIter.index(1))
117
+ edgeIter.next()
118
+ lstVerts = list(setOfVerts)
119
+ lstVerts.sort()
120
+ for vtx in lstVerts:
121
+ elementIndices.append(vtx)
122
+ elementWeights.append(1)
123
+ elif ctyp in (om.MFn.kCurveCVComponent, om.MFn.kMeshVertComponent):
124
+ singleFn = om.MFnSingleIndexedComponent(component)
125
+ for i in range(count):
126
+ weight = componentFn.weight(i).influence() if softOn else 1
127
+ elementIndices.append(singleFn.element(i))
128
+ elementWeights.append(weight)
129
+ elif ctyp == om.MFn.kSurfaceCVComponent:
130
+ spansV = cmds.getAttr(depNode_name + ".spansV")
131
+ degreesV = cmds.getAttr(depNode_name + ".degreeV")
132
+ numCVsInV_ = spansV + degreesV
133
+
134
+ doubleFn = om.MFnDoubleIndexedComponent(component)
135
+ for i in range(count):
136
+ weight = componentFn.weight(i).influence() if softOn else 1
137
+ doubleFn.getElement(i, ptru, ptrv)
138
+ u = uVal.getInt(ptru)
139
+ v = vVal.getInt(ptrv)
140
+ if returnSimpleIndices:
141
+ elementIndices.append(numCVsInV_ * u + v)
142
+ else:
143
+ elementIndices.append((u, v))
144
+ elementWeights.append(weight)
145
+ elif ctyp == om.MFn.kLatticeComponent:
146
+ div_s = cmds.getAttr(depNode_name + ".sDivisions")
147
+ div_t = cmds.getAttr(depNode_name + ".tDivisions")
148
+ # div_u = cmds.getAttr(depNode_name + ".uDivisions")
149
+
150
+ tripleFn = om.MFnTripleIndexedComponent(component)
151
+ for i in range(count):
152
+ tripleFn.getElement(i, ptru, ptrv, ptrw)
153
+ s = uVal.getInt(ptru)
154
+ t = vVal.getInt(ptrv)
155
+ u = wVal.getInt(ptrw)
156
+ weight = componentFn.weight(i).influence() if softOn else 1
157
+
158
+ if returnSimpleIndices:
159
+ simpleIndex = (u * div_s * div_t) + (t * div_s) + s
160
+ elementIndices.append(simpleIndex)
161
+ else:
162
+ elementIndices.append((s, t, u))
163
+ elementWeights.append(weight)
164
+
165
+ toReturn[depNode_name] = (elementIndices, elementWeights)
166
+ iterSel.next()
167
+ return toReturn
168
+
169
+
170
+ def softSelectToCluster(tfm, name):
171
+ # Get the manipulator position for the selection
172
+ cmds.setToolTo("Move")
173
+ currentMoveMode = cmds.manipMoveContext("Move", query=True, mode=True)
174
+ cmds.manipMoveContext("Move", edit=True, mode=0) # set to the correct mode
175
+ pos = cmds.manipMoveContext("Move", query=True, position=True) # get the position
176
+ cmds.manipMoveContext("Move", edit=True, mode=currentMoveMode) # and reset
177
+
178
+ tfm = cmds.ls(tfm, long=True)[0]
179
+ vnum = cmds.polyEvaluate(tfm, vertex=True)
180
+ softSelDict = getSoftSelectionValues(tfm)
181
+
182
+ shapes = [k for k in softSelDict if k.startswith(tfm)]
183
+ if not shapes:
184
+ print("No selection found on the given mesh: {0}".format(tfm))
185
+ return
186
+
187
+ elementIndices, elementWeights = softSelDict[shapes[0]]
188
+ weightDict = dict(zip(elementIndices, elementWeights))
189
+ weights = [weightDict.get(i, 0.0) for i in range(vnum)]
190
+
191
+ # Build the Cluster and set the weights
192
+ # Currently this part is polymesh specific
193
+ clusterNode, clusterHandle = cmds.cluster(tfm, name=name)
194
+ attr = "{0}.weightList[0].weights[0:{1}]".format(clusterNode, vnum - 1)
195
+ cmds.setAttr(attr, *weights, size=vnum)
196
+
197
+ # Reposition the cluster
198
+ cmds.xform(clusterHandle, absolute=True, worldSpace=True, pivots=pos)
199
+ clusterShape = cmds.listRelatives(clusterHandle, children=True, shapes=True)
200
+ cmds.setAttr(clusterShape[0] + ".origin", *pos)