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,70 @@
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
+ from functools import partial
20
+
21
+ from ...commands.unsubdivide import unsubdivideSimplex
22
+ from Qt import QtCompat
23
+ from Qt.QtWidgets import QAction, QMessageBox, QProgressDialog
24
+
25
+
26
+ try:
27
+ from ..commands.numpytoimath import numpyToImath
28
+ except ImportError:
29
+ numpyToImath = None
30
+
31
+
32
+ def registerTool(window, menu):
33
+ if numpyToImath is not None:
34
+ exportUnsubACT = QAction("Un Subdivide Smpx ...", window)
35
+ menu.addAction(exportUnsubACT)
36
+ exportUnsubACT.triggered.connect(partial(exportUnsubInterface, window))
37
+
38
+
39
+ def exportUnsubInterface(window):
40
+ if numpyToImath is None:
41
+ QMessageBox.warning(
42
+ window,
43
+ "No ImathToNumpy",
44
+ "ImathToNumpy is not available here, and it is required to unsubdivide a system",
45
+ )
46
+ return
47
+
48
+ path, _filter = QtCompat.QFileDialog.getOpenFileName(
49
+ window, "Un Subdivide", "", "Simplex (*.smpx)"
50
+ )
51
+
52
+ if not path:
53
+ return
54
+
55
+ outPath = path.replace(".smpx", "_UNSUB.smpx")
56
+ if path == outPath:
57
+ QMessageBox.warning(window, "Unable to rename smpx file: {}".format(path))
58
+ return
59
+
60
+ if os.path.isfile(outPath):
61
+ btns = QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel
62
+ msg = "Unsub file already exists.\n{0}\nOverwrite?".format(outPath)
63
+ response = QMessageBox.question(window, "File already exists", msg, btns)
64
+ if not response & QMessageBox.StandardButton.Ok:
65
+ return
66
+
67
+ pBar = QProgressDialog("Exporting Unsubdivided smpx File", "Cancel", 0, 100, window)
68
+ pBar.show()
69
+ unsubdivideSimplex(path, outPath, pBar=pBar)
70
+ pBar.close()
@@ -0,0 +1,16 @@
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/>.
@@ -0,0 +1,43 @@
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 import QtCompat
23
+ from Qt.QtWidgets import QAction, QProgressDialog
24
+
25
+
26
+ def registerTool(window, menu):
27
+ exportOtherACT = QAction("Export Other", window)
28
+ menu.addAction(exportOtherACT)
29
+ exportOtherACT.triggered.connect(partial(exportOtherInterface, window))
30
+
31
+
32
+ def exportOtherInterface(window):
33
+ sel = cmds.ls(sl=True)
34
+ path, _filter = QtCompat.QFileDialog.getSaveFileName(
35
+ window, "Export Other", "", "Simplex (*.smpx)"
36
+ )
37
+
38
+ pBar = QProgressDialog(
39
+ "Exporting Simplex from Other Mesh", "Cancel", 0, 100, window
40
+ )
41
+ if sel and path:
42
+ window.simplex.exportOther(path, sel[0], world=True, pBar=pBar)
43
+ pBar.close()
@@ -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
+ from functools import partial
19
+
20
+ from ...interfaceModel import coerceIndexToType
21
+ from ...items import Slider
22
+ from Qt.QtWidgets import QAction
23
+
24
+
25
+ def registerTool(window, menu):
26
+ extractProgressivesACT = QAction("Extract Progressive", window)
27
+ menu.addAction(extractProgressivesACT)
28
+ extractProgressivesACT.triggered.connect(
29
+ partial(extractProgressivesInterface, window)
30
+ )
31
+
32
+
33
+ def registerContext(tree, clickIdx, indexes, menu):
34
+ window = tree.window()
35
+ live = window.uiLiveShapeConnectionACT.isChecked()
36
+ sliders = coerceIndexToType(indexes, Slider)
37
+
38
+ multis = []
39
+ for slidx in sliders:
40
+ slider = slidx.model().itemFromIndex(slidx)
41
+ if len(slider.prog.pairs) > 2:
42
+ multis.append(slidx)
43
+
44
+ if multis:
45
+ extractACT = menu.addAction("Extract Progressive")
46
+ extractACT.triggered.connect(partial(extractProgressivesContext, multis, live))
47
+ return True
48
+ return False
49
+
50
+
51
+ def extractProgressivesContext(indexes, live):
52
+ sliders = [idx.model().itemFromIndex(idx) for idx in indexes]
53
+ sliders = list(set(sliders))
54
+ for sli in sliders:
55
+ sli.extractProgressive(live=live)
56
+
57
+
58
+ def extractProgressivesInterface(window):
59
+ live = window.uiLiveShapeConnectionACT.isChecked()
60
+ indexes = window.uiSliderTREE.getSelectedIndexes()
61
+ indexes = coerceIndexToType(indexes, Slider)
62
+ sliders = [idx.model().itemFromIndex(idx) for idx in indexes]
63
+ sliders = list(set(sliders))
64
+ for sli in sliders:
65
+ sli.extractProgressive(live=live)
@@ -0,0 +1,245 @@
1
+ # This file is part of Simplex.
2
+ #
3
+ # Simplex is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # Simplex is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Simplex. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ from functools import partial
17
+
18
+ from maya import cmds
19
+
20
+ from ...interface.mayaInterface import disconnected
21
+ from ...interfaceModel import coerceIndexToType
22
+ from ...items import Combo
23
+
24
+
25
+ # UI stuff
26
+ def registerContext(tree, clickIdx, indexes, menu):
27
+ # The basicBlendshape deformer is included in simplex_maya
28
+ if not cmds.pluginInfo("simplex_maya", query=True, loaded=True):
29
+ try:
30
+ cmds.loadPlugin("simplex_maya")
31
+ except RuntimeError:
32
+ return False
33
+
34
+ comboIdxs = coerceIndexToType(indexes, Combo)
35
+ combos = [cidx.model().itemFromIndex(cidx) for cidx in comboIdxs]
36
+
37
+ if combos:
38
+ freezeAct = menu.addAction("Freeze Combos")
39
+ unfreezeAct = menu.addAction("Un-Freeze Combos")
40
+ freezeAct.triggered.connect(partial(freezeCombosContext, combos, tree, True))
41
+ unfreezeAct.triggered.connect(partial(freezeCombosContext, combos, tree, False))
42
+ return True
43
+ return False
44
+
45
+
46
+ def freezeCombosContext(combos, tree, doFreeze):
47
+ if doFreeze:
48
+ for combo in combos:
49
+ if not combo.frozen:
50
+ freezeCombo(combo)
51
+ else:
52
+ for combo in combos:
53
+ if combo.frozen:
54
+ unfreezeCombo(combo)
55
+
56
+ tree.update()
57
+
58
+
59
+ def freezeCombo(combo):
60
+ """Freeze a combo so you can change the upstream combos and shapes
61
+ without affecting the result that you sculpted for the given combo
62
+
63
+ In practice, this snapshots the combo, then live-reads the upstream
64
+ shapes from the main blendshape and builds an up-to-date combo. The
65
+ difference between these two meshes is added back into the combo shape
66
+ """
67
+ simplex = combo.simplex
68
+
69
+ tweakShapeGroups = []
70
+ fullGeos = []
71
+ ppFilter = []
72
+ freezeShapes = []
73
+
74
+ # disconnect the controller from the operator
75
+ with disconnected(simplex.DCC.op) as sliderCnx:
76
+ for _shapeIdx, pp in enumerate(combo.prog.pairs):
77
+ tVal = pp.value
78
+ freezeShape = pp.shape
79
+ if freezeShape.isRest:
80
+ continue
81
+
82
+ freezeShapes.append(freezeShape)
83
+ # zero all the sliders
84
+ cnx = sliderCnx[simplex.DCC.op]
85
+ for a in cnx.values():
86
+ cmds.setAttr(a, 0.0)
87
+
88
+ # set the combo values
89
+ for pair in combo.pairs:
90
+ cmds.setAttr(cnx[pair.slider.thing], pair.value * tVal)
91
+
92
+ tweakPairs = []
93
+ for shape in simplex.shapes[1:]: # skip the restShape
94
+ shapeVal = cmds.getAttr(shape.thing)
95
+ if abs(shapeVal) > 0.0001:
96
+ tweakPairs.append((shape, shapeVal))
97
+
98
+ # Extract this fully-on shape
99
+ fullGeo = cmds.duplicate(
100
+ simplex.DCC.mesh, name="{0}_Freeze".format(freezeShape.name)
101
+ )[0]
102
+ fullGeos.append(fullGeo)
103
+
104
+ # Clean any orig shapes for now
105
+ interObjs = cmds.ls(
106
+ cmds.listRelatives(fullGeo, shapes=True), intermediateObjects=True
107
+ )
108
+ cmds.delete(interObjs)
109
+
110
+ tweakShapeGroups.append(tweakPairs)
111
+ ppFilter.append(pp)
112
+
113
+ simplex.DCC.primeShapes(combo)
114
+
115
+ shapePlugFmt = (
116
+ ".inputTarget[{meshIdx}].inputTargetGroup[{shapeIdx}].inputTargetItem[6000]"
117
+ )
118
+ endPlugs = [
119
+ ".inputRelativePointsTarget",
120
+ ".inputRelativeComponentsTarget",
121
+ ".inputPointsTarget",
122
+ ".inputComponentsTarget",
123
+ "",
124
+ ]
125
+ shapeNode = simplex.DCC.shapeNode
126
+ helpers = []
127
+ for geo, tweakPairs, pp, freezeShape in zip(
128
+ fullGeos, tweakShapeGroups, ppFilter, freezeShapes
129
+ ):
130
+ # build the basicBS node
131
+ bbs = cmds.deformer(geo, type="basicBlendShape")[0]
132
+ helpers.append(bbs)
133
+ idx = 0
134
+
135
+ for shape, val in tweakPairs:
136
+ if shape == freezeShape:
137
+ continue
138
+ # connect the output shape.thing to the basicBS
139
+
140
+ # Create an empty shape. Do it like this to get the automated renaming stuff
141
+ gDup = cmds.duplicate(geo, name="{0}_DeltaCnx".format(shape.name))[0]
142
+ # The 4th value must be 1.0 so the blendshape auto-names
143
+ cmds.blendShape(bbs, edit=True, target=(geo, idx, gDup, 1.0))
144
+ cmds.blendShape(bbs, edit=True, weight=(idx, -val))
145
+ cmds.delete(gDup)
146
+
147
+ # Connect the shape plugs
148
+ inPlug = bbs + shapePlugFmt
149
+ inPlug = inPlug.format(meshIdx=0, shapeIdx=idx)
150
+
151
+ shapeIdx = simplex.DCC.getShapeIndex(shape)
152
+ outPlug = shapeNode + shapePlugFmt
153
+ outPlug = outPlug.format(meshIdx=0, shapeIdx=shapeIdx)
154
+
155
+ # Must connect the individual child plugs rather than the top
156
+ # because otherwise the input geometry plug overrides these deltas
157
+ for ep in endPlugs:
158
+ cmds.connectAttr(outPlug + ep, inPlug + ep)
159
+
160
+ idx += 1
161
+
162
+ # Connect the basicBS back into freezeShape
163
+ freezeShapeIdx = simplex.DCC.getShapeIndex(pp.shape)
164
+ freezeShapeTarget = shapeNode + shapePlugFmt + ".inputGeomTarget"
165
+ freezeShapeTarget = freezeShapeTarget.format(meshIdx=0, shapeIdx=freezeShapeIdx)
166
+ cmds.connectAttr(geo + ".outMesh", freezeShapeTarget)
167
+
168
+ gShapes = cmds.listRelatives(geo, shapes=True)
169
+ if True:
170
+ # Hide the frozen shapenode under the ctrl as an intermediate shape
171
+ for gs in gShapes:
172
+ cmds.setAttr(gs + ".intermediateObject", 1)
173
+ nn = cmds.parent(gs, simplex.DCC.ctrl, shape=True, relative=True)
174
+ helpers.extend(nn)
175
+
176
+ # Get rid of the extra transform object
177
+ cmds.delete(geo)
178
+ else:
179
+ helpers.extend(cmds.listRelatives(geo, shapes=True))
180
+
181
+ # keep track of the shapes under the ctrl object
182
+ combo.freezeThing = helpers
183
+
184
+
185
+ def unfreezeCombo(combo):
186
+ if combo.freezeThing:
187
+ cmds.delete(combo.freezeThing)
188
+ combo.freezeThing = []
189
+
190
+
191
+ def _getDeformerChain(chkObj):
192
+ # Get a deformer chain
193
+ memo = []
194
+ while chkObj and chkObj not in memo:
195
+ memo.append(chkObj)
196
+
197
+ typ = cmds.nodeType(chkObj)
198
+ if typ == "mesh":
199
+ cnx = cmds.listConnections(chkObj + ".inMesh") or [None]
200
+ chkObj = cnx[0]
201
+ elif typ == "groupParts":
202
+ cnx = cmds.listConnections(
203
+ chkObj + ".inputGeometry", destination=False, shapes=True
204
+ ) or [None]
205
+ chkObj = cnx[0]
206
+ else:
207
+ cnx = cmds.ls(chkObj, type="geometryFilter") or [None]
208
+ chkObj = cnx[0]
209
+ if chkObj: # we have a deformer
210
+ cnx = cmds.listConnections(chkObj + ".input[0].inputGeometry") or [None]
211
+ chkObj = cnx[0]
212
+ return memo
213
+
214
+
215
+ def checkFrozen(combo):
216
+ # If the blendshape shape has an incoming connection whose shape name
217
+ # ends with 'FreezeShape' and the shape's parent is the ctrl
218
+ #
219
+ simplex = combo.simplex
220
+
221
+ ret = []
222
+ shapes = combo.prog.getShapes()
223
+ shapes = [i for i in shapes if not i.isRest]
224
+
225
+ shapePlugFmt = (
226
+ ".inputTarget[{meshIdx}].inputTargetGroup[{shapeIdx}].inputTargetItem[6000]"
227
+ )
228
+
229
+ for shape in shapes:
230
+ shpIdx = simplex.DCC.getShapeIndex(shape)
231
+ shpPlug = (
232
+ simplex.DCC.shapeNode
233
+ + shapePlugFmt.format(meshIdx=0, shapeIdx=shpIdx)
234
+ + ".inputGeomTarget"
235
+ )
236
+
237
+ cnx = cmds.listConnections(shpPlug, shapes=True, destination=False) or []
238
+ for cc in cnx:
239
+ if not cc.endswith("FreezeShape"):
240
+ continue
241
+ par = cmds.listRelatives(cc, parent=True)
242
+ if par and par[0] == simplex.DCC.ctrl:
243
+ # Can't use list history to get the chain because it's a pseudo-cycle
244
+ ret.extend(_getDeformerChain(cc))
245
+ return ret
@@ -0,0 +1,97 @@
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 ...interfaceModel import coerceIndexToType
23
+ from ...items import Combo, Slider
24
+ from Qt.QtWidgets import QInputDialog, QMessageBox
25
+
26
+
27
+ def registerContext(tree, clickIdx, indexes, menu):
28
+ window = tree.window()
29
+ sliders = coerceIndexToType(indexes, Slider)
30
+ combos = coerceIndexToType(indexes, Combo)
31
+ multis = []
32
+ for grp in [sliders, combos]:
33
+ for idx in grp:
34
+ item = idx.model().itemFromIndex(idx)
35
+ if len(item.prog.pairs) == 2:
36
+ multis.append(idx)
37
+
38
+ if not multis:
39
+ return False
40
+
41
+ extractACT = menu.addAction("Generate Incrementals ...")
42
+ extractACT.triggered.connect(
43
+ partial(generateShapeIncrementalsContext, multis, window)
44
+ )
45
+ return True
46
+
47
+
48
+ def generateShapeIncrementalsContext(indexes, window):
49
+ idx = indexes[0] # Only on the click index
50
+ slider = idx.model().itemFromIndex(idx)
51
+ if len(slider.prog.pairs) > 2:
52
+ QMessageBox.warning(window, "Warning", "Slider already has incrementals")
53
+ return
54
+
55
+ increments, good = QInputDialog.getInt(
56
+ window, "Increments", "Number of Increments", 4, 1, 100
57
+ )
58
+ if not good:
59
+ return
60
+
61
+ rest = None
62
+ target = None
63
+ maxval = -1.0
64
+
65
+ for pp in slider.prog.pairs:
66
+ if pp.shape.isRest:
67
+ rest = pp.shape
68
+ elif abs(pp.value) > maxval:
69
+ target = pp.shape
70
+
71
+ target.name = target.name + "_100"
72
+
73
+ startObj = slider.extractShape(rest, live=False)
74
+ endObj = slider.extractShape(target)
75
+ shapeDup = cmds.duplicate(endObj, name="shapeDup")[0]
76
+
77
+ bs = cmds.blendShape(startObj, shapeDup)
78
+
79
+ incs = []
80
+ for i in range(1, increments):
81
+ val = float(increments - i) / increments
82
+ percent = int(float(i) * 100 / increments)
83
+ cmds.blendShape(bs, edit=True, weight=((0, val)))
84
+
85
+ nne = endObj.replace("_100_", "_{0}_".format(percent))
86
+ nn = nne.replace("_Extract", "")
87
+ inc = cmds.duplicate(shapeDup, name=nne)
88
+ incs.append((percent, nn, nne))
89
+
90
+ for perc, inc, ince in incs:
91
+ pp = slider.createShape(shapeName=inc, tVal=perc / 100.0)
92
+ pp.shape.connectShape(mesh=ince, live=True)
93
+
94
+ window.uiSliderTREE.model().invalidateFilter()
95
+
96
+ cmds.delete((shapeDup, startObj))
97
+ cmds.select(endObj)