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,436 @@
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 pysimplex import PySimplex
19
+
20
+ from ..interface.mayaInterface import DCC, disconnected
21
+ from ..items import Combo, Slider, Traversal, Simplex
22
+ from .alembicCommon import buildSmpx
23
+
24
+ try:
25
+ import numpy as np
26
+ except ImportError:
27
+ np = None
28
+
29
+
30
+ def _setSliders(ctrl, val, svs):
31
+ slis, vals = svs.setdefault(ctrl.simplex, ([], []))
32
+
33
+ if isinstance(ctrl, Slider):
34
+ slis.append(ctrl)
35
+ vals.append(val)
36
+ elif isinstance(ctrl, Combo):
37
+ for cp in ctrl.pairs:
38
+ slis.append(cp.slider)
39
+ vals.append(cp.value * abs(val))
40
+ elif isinstance(ctrl, Traversal):
41
+ # set the ctrl.multiplierCtrl.controller to 1
42
+ multCtrl = ctrl.multiplierCtrl.controller
43
+ multVal = ctrl.multiplierCtrl.value if val != 0.0 else 0.0
44
+ progCtrl = ctrl.progressCtrl.controller
45
+ _setSliders(multCtrl, multVal, svs)
46
+ _setSliders(progCtrl, val, svs)
47
+
48
+
49
+ def setSliderGroup(ctrls, val):
50
+ """Set a group of controls to a given value
51
+
52
+ Parameters
53
+ ----------
54
+ ctrls : [object, ...]
55
+ A list of simplex objects
56
+ val : float
57
+ The value to set
58
+
59
+ Returns
60
+ -------
61
+
62
+ """
63
+ svs = {}
64
+ for ctrl in ctrls:
65
+ _setSliders(ctrl, val, svs)
66
+
67
+ for smpx, (slis, vals) in svs.items():
68
+ smpx.setSlidersWeights(slis, vals)
69
+
70
+
71
+ def clientPartition(master, clients):
72
+ """
73
+
74
+ Parameters
75
+ ----------
76
+ master : Simplex
77
+ The master simplex system
78
+ clients : [Simplex, ...]
79
+ The client simplex systems
80
+
81
+ Returns
82
+ -------
83
+ : {str: [Slider, ...]}
84
+ Dictionary of name to slider
85
+ : {str: [Combo, ...]}
86
+ Dictionary of name to combo
87
+ : {str: [Traversal, ...]}
88
+ Dictionary of name to traversal
89
+
90
+ """
91
+ sliders, combos, traversals = {}, {}, {}
92
+ for cli in [master] + clients:
93
+ for sli in cli.sliders:
94
+ sliders.setdefault(sli.name, []).append(sli)
95
+
96
+ for com in cli.combos:
97
+ combos.setdefault(com.name, []).append(com)
98
+
99
+ for trav in cli.traversals:
100
+ traversals.setdefault(trav.name, []).append(trav)
101
+ return sliders, combos, traversals
102
+
103
+
104
+ def zeroAll(smpxs):
105
+ """Set all sliders on the given simplex systems to 0
106
+
107
+ Parameters
108
+ ----------
109
+ smpxs : [Simplex, ...]
110
+ A list of Simplex systems
111
+
112
+ Returns
113
+ -------
114
+
115
+ """
116
+ for smpx in smpxs:
117
+ smpx.setSlidersWeights(smpx.sliders, [0.0] * len(smpx.sliders))
118
+
119
+
120
+ def getExpandedData(master, clients, mesh):
121
+ """Get the fully expanded shape data for each slider, combo, and traversal
122
+ at each of its underlying shapes
123
+
124
+ Parameters
125
+ ----------
126
+ master : Simplex
127
+ The master simplex system
128
+ clients : [Simplex, ...]
129
+ The client simplex systems
130
+ mesh : str
131
+ The name of the maya shape node
132
+
133
+ Returns
134
+ -------
135
+ : np.array
136
+ The rest shape point positions
137
+ : np.array
138
+ The slider shape point positions
139
+ : np.array
140
+ The combo shape point positions
141
+ : np.array
142
+ The traversal shape point positions
143
+
144
+ """
145
+ # zero everything
146
+ zeroAll([master] + clients)
147
+ sliPart, cmbPart, travPart = clientPartition(master, clients)
148
+ sliderShapes = {}
149
+ for slider in master.sliders:
150
+ ss = {}
151
+ sliderShapes[slider] = ss
152
+ for pp in slider.prog.pairs:
153
+ if pp.shape.isRest:
154
+ continue
155
+ setSliderGroup(sliPart[slider.name], pp.value)
156
+ ss[pp] = DCC.getNumpyShape(mesh)
157
+ setSliderGroup(sliPart[slider.name], 0.0)
158
+
159
+ # Disable traversals
160
+ zeroAll([master] + clients)
161
+ travShapeThings = []
162
+ comboShapes = {}
163
+ for trav in master.traversals:
164
+ for pp in trav.prog.pairs:
165
+ if pp.shape.isRest:
166
+ continue
167
+ travShapeThings.append(pp.shape)
168
+ travShapeThings = [i.thing for i in travShapeThings]
169
+
170
+ # Get the combos with traversals disconnected
171
+ with disconnected(travShapeThings):
172
+ for combo in master.combos:
173
+ ss = {}
174
+ comboShapes[combo] = ss
175
+ for pp in combo.prog.pairs:
176
+ if pp.shape.isRest:
177
+ continue
178
+ setSliderGroup(cmbPart[combo.name], pp.value)
179
+ ss[pp] = DCC.getNumpyShape(mesh)
180
+ setSliderGroup(cmbPart[combo.name], 0.0)
181
+
182
+ zeroAll([master] + clients)
183
+ travShapes = {}
184
+ for trav in master.traversals:
185
+ ss = {}
186
+ travShapes[trav] = ss
187
+ progCtrl = trav.progressCtrl.controller
188
+ progVal = trav.progressCtrl.value
189
+ for pp in progCtrl.prog.pairs:
190
+ if pp.shape.isRest:
191
+ continue
192
+ if pp.value * progVal <= 0.0:
193
+ # Traversals only activate if the progression is in the same
194
+ # pos/neg direction as the value. Otherwise we just skip
195
+ continue
196
+
197
+ setSliderGroup(travPart[trav.name], pp.value)
198
+ ss[pp] = DCC.getNumpyShape(mesh)
199
+ setSliderGroup(travPart[trav.name], 0.0)
200
+
201
+ zeroAll([master] + clients)
202
+ restShape = DCC.getNumpyShape(mesh)
203
+
204
+ return restShape, sliderShapes, comboShapes, travShapes
205
+
206
+
207
+ def _setInputs(inVec, item, indexBySlider, value):
208
+ """Being clever
209
+ Sliders or Combos just set the value and return
210
+ Traversals recursively call this function with the controllers (that only either sliders or combos)
211
+ """
212
+ if isinstance(item, Slider):
213
+ inVec[indexBySlider[item]] = value
214
+ return inVec
215
+ elif isinstance(item, Combo):
216
+ for pair in item.pairs:
217
+ inVec[indexBySlider[pair.slider]] = pair.value * abs(value)
218
+ return inVec
219
+ elif isinstance(item, Traversal):
220
+ inVec = _setInputs(
221
+ inVec,
222
+ item.multiplierCtrl.controller,
223
+ indexBySlider,
224
+ item.multiplierCtrl.value,
225
+ )
226
+ inVec = _setInputs(
227
+ inVec,
228
+ item.progressCtrl.controller,
229
+ indexBySlider,
230
+ item.progressCtrl.value * value,
231
+ )
232
+ return inVec
233
+ raise ValueError(
234
+ "Not a Slider, Combo, or Traversal. Got type {0}: {1}".format(type(item), item)
235
+ )
236
+
237
+
238
+ def _buildSolverInputs(simplex, item, value, indexBySlider):
239
+ """Build an input vector for the solver that will
240
+ produce a required progression value on an item
241
+ """
242
+ inVec = [0.0] * len(simplex.sliders)
243
+ return _setInputs(inVec, item, indexBySlider, value)
244
+
245
+
246
+ def getTravDepth(trav):
247
+ """Get the depth of a traversal object
248
+
249
+ Parameters
250
+ ----------
251
+ trav : Traversal
252
+ The traversal object
253
+
254
+ Returns
255
+ -------
256
+ : int
257
+ The depth of the given Traversal
258
+
259
+ """
260
+ inputs = []
261
+ mult = trav.multiplierCtrl.controller
262
+ prog = trav.progressCtrl.controller
263
+ for item in (mult, prog):
264
+ if isinstance(item, Slider):
265
+ inputs.append(item)
266
+ elif isinstance(item, Combo):
267
+ for cp in item.pairs:
268
+ inputs.append(cp.slider)
269
+ return len(set(inputs))
270
+
271
+
272
+ def parseExpandedData(smpx, restShape, sliderShapes, comboShapes, travShapes):
273
+ """Turn the expanded data into shapeDeltas connected to the actual Shape objects
274
+
275
+ Parameters
276
+ ----------
277
+ smpx : Simplex
278
+ A simplex system
279
+ restShape : np.array
280
+ The rest point positions
281
+ sliderShapes : np.array
282
+ The slider shape point positions
283
+ comboShapes : np.array
284
+ The combo shape point positions
285
+ travShapes : np.array
286
+ The traversal shape point positions
287
+
288
+ Returns
289
+ -------
290
+ : np.array
291
+ The point positions for a new set of shapes
292
+
293
+ """
294
+ if np is None:
295
+ raise RuntimeError("Numpy is not available")
296
+
297
+ solver = PySimplex(smpx.dump())
298
+ shapeArray = np.zeros((len(smpx.shapes), len(restShape), 3))
299
+
300
+ indexBySlider = {s: i for i, s in enumerate(smpx.sliders)}
301
+ indexByShape = {s: i for i, s in enumerate(smpx.shapes)}
302
+
303
+ floatShapeSet = set(smpx.getFloatingShapes())
304
+ floatIdxs = sorted({indexByShape[s] for s in floatShapeSet})
305
+ travShapeSet = {pp.shape for t in smpx.traversals for pp in t.prog.pairs}
306
+ travIdxs = sorted({indexByShape[s] for s in travShapeSet})
307
+
308
+ # Sliders are simple, just set their shapes directly
309
+ for ppDict in sliderShapes.values():
310
+ for pp, shp in ppDict.items():
311
+ shapeArray[indexByShape[pp.shape]] = shp - restShape
312
+
313
+ # First sort the combos by depth
314
+ comboByDepth = {}
315
+ for combo in smpx.combos:
316
+ comboByDepth.setdefault(len(combo.pairs), []).append(combo)
317
+
318
+ for depth in sorted(comboByDepth.keys()):
319
+ for combo in comboByDepth[depth]:
320
+ for pp, shp in comboShapes[combo].items():
321
+ inVec = _buildSolverInputs(smpx, combo, pp.value, indexBySlider)
322
+ outVec = np.array(solver.solve(inVec))
323
+ outVec[np.where(np.isclose(outVec, 0.0))] = 0.0
324
+ outVec[np.where(np.isclose(outVec, 1.0))] = 1.0
325
+ outVec[indexByShape[pp.shape]] = 0.0
326
+
327
+ # ignore any traversals
328
+ outVec[travIdxs] = 0.0
329
+
330
+ # ignore floaters if we're not currently checking floaters
331
+ if pp.shape not in floatShapeSet:
332
+ outVec[floatIdxs] = 0.0
333
+
334
+ # set the shape delta to the output
335
+ baseShape = np.dot(outVec, shapeArray.swapaxes(0, 1))
336
+ shapeArray[indexByShape[pp.shape]] = shp - restShape - baseShape
337
+
338
+ # First the traversals by depth
339
+ travByDepth = {}
340
+ for trav in smpx.traversals:
341
+ travByDepth.setdefault(getTravDepth(trav), []).append(trav)
342
+
343
+ for depth in sorted(travByDepth.keys()):
344
+ for trav in travByDepth[depth]:
345
+ for pp, shp in travShapes[trav].items():
346
+ inVec = _buildSolverInputs(smpx, trav, pp.value, indexBySlider)
347
+ outVec = np.array(solver.solve(inVec))
348
+ outVec[np.where(np.isclose(outVec, 0.0))] = 0.0
349
+ outVec[np.where(np.isclose(outVec, 1.0))] = 1.0
350
+ outVec[indexByShape[pp.shape]] = 0.0
351
+
352
+ # set the shape delta to the output
353
+ baseShape = np.dot(outVec, shapeArray.swapaxes(0, 1))
354
+ shapeArray[indexByShape[pp.shape]] = shp - restShape - baseShape
355
+ return shapeArray
356
+
357
+
358
+ def buildShapeArray(mesh, master, clients):
359
+ """Build the outpu shape array
360
+
361
+ Parameters
362
+ ----------
363
+ mesh : str
364
+ The maya shape node name
365
+ master : Simplex
366
+ The master simplex system
367
+ clients :
368
+ The client simplex systems
369
+
370
+ Returns
371
+ -------
372
+ : np.array
373
+ The full output shape array
374
+
375
+ """
376
+ restShape, sliderShapes, comboShapes, travShapes = getExpandedData(
377
+ master, clients, mesh
378
+ )
379
+ shapeArray = parseExpandedData(
380
+ master, restShape, sliderShapes, comboShapes, travShapes
381
+ )
382
+ shapeArray += restShape[None, ...]
383
+ return shapeArray
384
+
385
+
386
+ def expandedExportAbc(path, mesh, master, clients=()):
387
+ """Export the alembic by re-building the deltas from all of the full shapes
388
+ This is required for delta-mushing a system, because the sum of mushed shapes
389
+ is not the same as the mushed sum-of-shapes
390
+
391
+ Parameters
392
+ ----------
393
+ path : str
394
+ Output path for the .smpx
395
+ mesh : str
396
+ The maya shape node name
397
+ master : Simplex
398
+ The master simplex system
399
+ clients : [Simplex, ...]
400
+ The client simplex systems
401
+
402
+ Returns
403
+ -------
404
+
405
+ """
406
+ # Convert clients to a list if need be
407
+ if not clients:
408
+ clients = []
409
+ elif not isinstance(clients, list):
410
+ if isinstance(clients, tuple):
411
+ clients = list(clients)
412
+ else:
413
+ clients = [clients]
414
+
415
+ faces, counts, uvs = DCC.getAbcFaces(mesh)
416
+ shapeArray = buildShapeArray(mesh, master, clients)
417
+ jsString = str(master.dump())
418
+
419
+ buildSmpx(
420
+ path,
421
+ shapeArray,
422
+ faces,
423
+ jsString,
424
+ master.name,
425
+ faceCounts=counts,
426
+ uvs=uvs,
427
+ )
428
+
429
+
430
+ if __name__ == "__main__":
431
+ # get the smpx from the UI
432
+
433
+ master = Simplex.buildSystemFromMesh("Face_SIMPLEX", "Face")
434
+ client = Simplex.buildSystemFromMesh("Face_SIMPLEX2", "Face2")
435
+ outPath = r"D:\Users\tyler\Desktop\TEST\expanded.smpx"
436
+ expandedExportAbc(outPath, "Face_SIMPLEX", master, client)
@@ -0,0 +1,60 @@
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 json
19
+
20
+ from .alembicCommon import buildSmpx, readSmpx
21
+
22
+
23
+ def hdf5Convert(inPath, outPath, ogawa=False):
24
+ """Load and parse all the data from a simplex file
25
+
26
+ Parameters
27
+ ----------
28
+ inPath : str
29
+ The input .smpx file path
30
+ outPath : str
31
+ The output .smpx file path
32
+ ogawa : bool
33
+ Whether to write out in Ogawa format. Defaults False
34
+
35
+ Returns
36
+ -------
37
+
38
+ """
39
+ jsString, counts, verts, faces, uvs, uvFaces = readSmpx(inPath)
40
+
41
+ js = json.loads(jsString)
42
+ name = js["systemName"]
43
+
44
+ buildSmpx(
45
+ outPath,
46
+ verts,
47
+ faces,
48
+ jsString,
49
+ name,
50
+ faceCounts=counts,
51
+ uvs=uvs,
52
+ uvFaces=uvFaces,
53
+ ogawa=ogawa,
54
+ )
55
+
56
+
57
+ if __name__ == "__main__":
58
+ inPath = r"D:\Users\tyler\Desktop\Head_Morphs_Main_Head-Face_v0010.smpx"
59
+ outPath = r"D:\Users\tyler\Desktop\Head_ogawa.smpx"
60
+ hdf5Convert(inPath, outPath, ogawa=True)
@@ -0,0 +1,161 @@
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
+ """Get the corrective deltas from a rig in Maya"""
19
+
20
+ from ctypes import c_float
21
+
22
+ from maya import OpenMaya as om
23
+ from maya import cmds
24
+
25
+ try:
26
+ import numpy as np
27
+ except ImportError:
28
+ pass
29
+
30
+
31
+ def setPose(pvp, multiplier):
32
+ """Set a percentage of a pose
33
+
34
+ Parameters
35
+ ----------
36
+ pvp : [(str, float), ...]
37
+ A list of property/value pairs
38
+ multiplier : float
39
+ The percentage multiplier of the pose
40
+ """
41
+ for prop, val in pvp:
42
+ cmds.setAttr(prop, val * multiplier)
43
+
44
+
45
+ def resetPose(pvp):
46
+ """Reset everything back to rest
47
+
48
+ Parameters
49
+ ----------
50
+ pvp : [(str, float), ...]
51
+ A list of property/value pairs
52
+ """
53
+ for prop, _val in pvp:
54
+ cmds.setAttr(prop, 0)
55
+
56
+
57
+ def _getDagPath(mesh):
58
+ sl = om.MSelectionList()
59
+ sl.add(mesh)
60
+ dagPath = om.MDagPath()
61
+ sl.getDagPath(0, dagPath)
62
+ return dagPath
63
+
64
+
65
+ def _getMayaPoints(meshFn):
66
+ rawPts = meshFn.getRawPoints()
67
+ ptCount = meshFn.numVertices()
68
+ cta = (c_float * 3 * ptCount).from_address(int(rawPts))
69
+ out = np.ctypeslib.as_array(cta)
70
+ out = np.copy(out)
71
+ out = out.reshape((-1, 3))
72
+ return out
73
+
74
+
75
+ def getDeformerChain(chkObj):
76
+ # Follow the deformer chain
77
+ memo = []
78
+ while chkObj and chkObj not in memo:
79
+ memo.append(chkObj)
80
+
81
+ typ = cmds.nodeType(chkObj)
82
+ if typ == "mesh":
83
+ cnx = cmds.listConnections(
84
+ chkObj + ".inMesh", destination=False, shapes=True
85
+ ) or [None]
86
+ chkObj = cnx[0]
87
+ elif typ == "groupParts":
88
+ cnx = cmds.listConnections(
89
+ chkObj + ".inputGeometry", destination=False, shapes=True
90
+ ) or [None]
91
+ chkObj = cnx[0]
92
+ elif typ == "polySoftEdge":
93
+ cnx = cmds.listConnections(
94
+ chkObj + ".inputPolymesh", destination=False, shapes=True
95
+ ) or [None]
96
+ chkObj = cnx[0]
97
+ elif typ == "AlembicNode":
98
+ # Alembic nodes aren't part of the deformer chain
99
+ # Cut it off, and return
100
+ return memo[:-1]
101
+ else:
102
+ cnx = cmds.ls(chkObj, type="geometryFilter") or [None]
103
+ chkObj = cnx[0]
104
+ if chkObj: # we have a deformer
105
+ # Get the mesh index of this deformer
106
+ cnx = cmds.listConnections(
107
+ chkObj, connections=True, plugs=True, source=False
108
+ )
109
+ prev = cmds.ls(memo[-2])[0] # Get the minimal unique name for testing
110
+ defIdx = 0
111
+ for i in range(0, len(cnx), 2):
112
+ if cnx[i + 1].startswith(prev):
113
+ defIdx = int(cnx[i].split("[")[-1][:-1])
114
+ break
115
+ # Use that mesh index to get the output
116
+ cnx = cmds.listConnections(
117
+ chkObj + ".input[{0}].inputGeometry".format(defIdx),
118
+ destination=False,
119
+ shapes=True,
120
+ ) or [None]
121
+ chkObj = cnx[0]
122
+
123
+ return memo
124
+
125
+
126
+ def getShiftValues(thing):
127
+ """Shift the vertices along each axis *before* the skinning
128
+ op in the deformer history
129
+
130
+ Parameters
131
+ ----------
132
+ mesh : str
133
+ The name of a mesh
134
+
135
+ Returns
136
+ -------
137
+ : [vert, ...]
138
+ A list of un-shifted vertices
139
+ : [vert, ...]
140
+ A list of vertices pre-shifted by 1 along the X axis
141
+ : [vert, ...]
142
+ A list of vertices pre-shifted by 1 along the Y axis
143
+ : [vert, ...]
144
+ A list of vertices pre-shifted by 1 along the Z axis
145
+ """
146
+ orig = getDeformerChain(thing)[-1]
147
+
148
+ dp = _getDagPath(thing)
149
+ meshFn = om.MFnMesh(dp)
150
+ allVerts = "{0}.vtx[*]".format(orig)
151
+
152
+ zero = _getMayaPoints(meshFn)
153
+ cmds.move(1, 0, 0, allVerts, relative=1, objectSpace=1)
154
+ oneX = _getMayaPoints(meshFn)
155
+ cmds.move(-1, 1, 0, allVerts, relative=1, objectSpace=1)
156
+ oneY = _getMayaPoints(meshFn)
157
+ cmds.move(0, -1, 1, allVerts, relative=1, objectSpace=1)
158
+ oneZ = _getMayaPoints(meshFn)
159
+ cmds.move(0, 0, -1, allVerts, relative=1, objectSpace=1)
160
+
161
+ return zero, oneX, oneY, oneZ