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