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,451 @@
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
+ # pylint:disable=unused-variable
19
+ import itertools
20
+ import os
21
+
22
+ from pysimplex import PySimplex
23
+
24
+ from ..items import Combo, Simplex, Slider
25
+ from Qt.QtWidgets import QApplication
26
+ from .alembicCommon import (
27
+ buildSmpx,
28
+ getSmpxArchiveData,
29
+ getStaticMeshArrays,
30
+ getUvSample,
31
+ readSmpx,
32
+ )
33
+
34
+ try:
35
+ import numpy as np
36
+ except ImportError:
37
+ pass
38
+
39
+
40
+ def invertAll(matrixArray):
41
+ """Invert all the square sub-matrices in a numpy array
42
+
43
+ Parameters
44
+ ----------
45
+ matrixArray : np.array
46
+ An M*N*N numpy array
47
+
48
+ Returns
49
+ -------
50
+ : np.array
51
+ An M*N*N numpy array
52
+ """
53
+ # Look into numpy to see if there is a way to ignore
54
+ # all the repeated sanity checks, and do them ourselves, once
55
+ return np.array([np.linalg.inv(a) for a in matrixArray])
56
+
57
+
58
+ def applyReference(pts, restPts, restDelta, inv):
59
+ """Given a shape and an array of pre-inverted
60
+ per-point matrices return the deltas
61
+
62
+ Parameters
63
+ ----------
64
+ pts : np.array
65
+ Deformed point positions
66
+ restPts : np.array
67
+ Rest point positions
68
+ restDelta : np.array
69
+ The delta from rest
70
+ inv : np.array
71
+ An M*4*4 array of matrices
72
+
73
+ Returns
74
+ -------
75
+ : np.array
76
+ The new point positions
77
+
78
+ """
79
+ pts = pts + restPts + restDelta
80
+ preSize = pts.shape[-1]
81
+ if inv.shape[-2] > pts.shape[-1]:
82
+ oneShape = list(pts.shape)
83
+ oneShape[-1] = inv.shape[-2] - pts.shape[-1]
84
+ pts = np.concatenate((pts, np.ones(oneShape)), axis=-1)
85
+
86
+ # Return the 3d points
87
+ return np.einsum("ij,ijk->ik", pts, inv)[..., :preSize]
88
+
89
+
90
+ def loadSimplex(shapePath):
91
+ """Load and parse all the data from a simplex file
92
+
93
+ Parameters
94
+ ----------
95
+ shapePath : str
96
+ The path to the .smpx file
97
+
98
+ Returns
99
+ -------
100
+ : str
101
+ The simplex JSON string
102
+ : Simplex
103
+ The simplex system
104
+ : pySimplex
105
+ The instantiated simplex solver
106
+ : np.array
107
+ A Numpy array of the shape point positions
108
+ : np.array
109
+ A Numpy array of the rest pose of the system
110
+
111
+ """
112
+ if not os.path.isfile(str(shapePath)):
113
+ raise IOError("File does not exist: " + str(shapePath))
114
+
115
+ jsString, counts, verts, faces, uvs, uvFaces = readSmpx(shapePath)
116
+
117
+ simplex = Simplex.buildSystemFromJsonString(jsString, None, forceDummy=True)
118
+ solver = PySimplex(jsString)
119
+
120
+ # return as delta shapes
121
+ restIdx = simplex.shapes.index(simplex.restShape)
122
+ restPts = verts[restIdx]
123
+ verts = verts - restPts[None, ...] # reshape for broadcasting
124
+
125
+ return jsString, simplex, solver, verts, restPts
126
+
127
+
128
+ def writeSimplex(inPath, outPath, newShapes, name="Face", pBar=None):
129
+ """Write a simplex file with new shapes
130
+
131
+ Parameters
132
+ ----------
133
+ inPath : str
134
+ The input .smpx file path
135
+ outPath : str
136
+ The output .smpx file path
137
+ newShapes : np.array
138
+ A numpy array of shapes to write
139
+ name : str
140
+ The name of the new system
141
+ pBar : QProgressDialog, optional
142
+ An optional progress dialog
143
+
144
+ Returns
145
+ -------
146
+
147
+ """
148
+ if not os.path.isfile(str(inPath)):
149
+ raise IOError("File does not exist: " + str(inPath))
150
+
151
+ iarch, abcMesh, jsString = getSmpxArchiveData(inPath)
152
+ faces, counts = getStaticMeshArrays(abcMesh)
153
+ uvs = getUvSample(abcMesh)
154
+ del iarch, abcMesh
155
+
156
+ buildSmpx(
157
+ outPath,
158
+ newShapes,
159
+ faces,
160
+ jsString,
161
+ name,
162
+ faceCounts=counts,
163
+ uvs=uvs,
164
+ )
165
+
166
+
167
+ #########################################################################
168
+ #### Deform Reference ####
169
+ #########################################################################
170
+
171
+
172
+ def _buildSolverInputs(simplex, item, value, indexBySlider):
173
+ """Build an input vector for the solver that will
174
+ produce a required progression value on an item
175
+ """
176
+ inVec = [0.0] * len(simplex.sliders)
177
+ if isinstance(item, Slider):
178
+ inVec[indexBySlider[item]] = value
179
+ return inVec
180
+ elif isinstance(item, Combo):
181
+ for pair in item.pairs:
182
+ inVec[indexBySlider[pair.slider]] = pair.value * abs(value)
183
+ return inVec
184
+ else:
185
+ raise ValueError(
186
+ "Not a slider or combo. Got type {0}: {1}".format(type(item), item)
187
+ )
188
+
189
+
190
+ def buildFullShapes(simplex, shapeObjs, shapes, solver, pBar=None):
191
+ """Given shape inputs, build the full output shape from the deltas
192
+ We use shapes here because a shape implies both the progression
193
+ and the value of the inputs (with a little figuring)
194
+
195
+ Parameters
196
+ ----------
197
+ simplex : Simplex
198
+ A Simplex system
199
+ shapeObjs : [Shape, ...]
200
+ The Simplex system Shape objects
201
+ shapes : np.array
202
+ A numpy array of the shapes
203
+ solver : PySimplex
204
+ An instantiated simplex solver
205
+ pBar : QProgressDialog, optional
206
+ An optional progress dialog
207
+
208
+ Returns
209
+ -------
210
+ : {Shape: np.array, ...}
211
+ A dictionary of point positions indexed by the shape
212
+ : {Shape: [float, ...], ...}
213
+ A dictionary of solver inputs indexed by the shape
214
+ """
215
+ ###########################################
216
+ # Manipulate all the input lists and caches
217
+ indexBySlider = {s: i for i, s in enumerate(simplex.sliders)}
218
+ indexByShape = {s: i for i, s in enumerate(simplex.shapes)}
219
+ floaters = set(simplex.getFloatingShapes())
220
+ floatIdxs = {indexByShape[s] for s in floaters}
221
+
222
+ shapeDict = {}
223
+ for item in itertools.chain(simplex.sliders, simplex.combos):
224
+ for pair in item.prog.pairs:
225
+ if not pair.shape.isRest:
226
+ shapeDict[pair.shape] = (item, pair.value)
227
+
228
+ ######################
229
+ # Actually do the work
230
+ vecByShape = {} # store this for later use
231
+ ptsByShape = {}
232
+
233
+ if pBar is not None:
234
+ pBar.setMaximum(len(shapeObjs))
235
+ pBar.setValue(0)
236
+ QApplication.processEvents()
237
+
238
+ flatShapes = shapes.reshape((len(shapes), -1))
239
+ for i, shape in enumerate(shapeObjs):
240
+ if pBar is not None:
241
+ pBar.setValue(i)
242
+ QApplication.processEvents()
243
+ else:
244
+ print("Building {0} of {1}\r".format(i + 1, len(shapeObjs)), end=" ")
245
+
246
+ item, value = shapeDict[shape]
247
+ inVec = _buildSolverInputs(simplex, item, value, indexBySlider)
248
+ outVec = solver.solve(inVec)
249
+ if shape not in floaters:
250
+ for fi in floatIdxs:
251
+ outVec[fi] = 0.0
252
+ outVec = np.array(outVec)
253
+ outVec[np.where(np.isclose(outVec, 0))] = 0
254
+ outVec[np.where(np.isclose(outVec, 1))] = 1
255
+ vecByShape[shape] = outVec
256
+ pts = np.dot(outVec, flatShapes)
257
+ pts = pts.reshape((-1, 3))
258
+ ptsByShape[shape] = pts
259
+ if pBar is None:
260
+ print()
261
+
262
+ return ptsByShape, vecByShape
263
+
264
+
265
+ def collapseFullShapes(simplex, allPts, ptsByShape, vecByShape, pBar=None):
266
+ """Given a set of shapes that are full-on shapes (not just deltas)
267
+ Collapse them back into deltas in the simplex shape list
268
+
269
+ Parameters
270
+ ----------
271
+ simplex : Simplex
272
+ A simplex system
273
+ allPts : np.array
274
+ All the point positions
275
+ ptsByShape : {Shape: np.array, ...}
276
+ A dictionary of point positions indexed by the shape
277
+ vecByShape : {Shape: [float, ...], ...}
278
+ A dictionary of solver inputs indexed by the shape
279
+ pBar : QProgressDialog, optional
280
+ An optional progress dialog
281
+
282
+ Returns
283
+ -------
284
+ : np.array
285
+ The collapsed shapes
286
+
287
+ """
288
+ # Figure out what order to build the deltas
289
+ # so that the deltas exist when I try to combine them
290
+ ctrlOrder = simplex.controllersByDepth()
291
+ shapeOrder = [pp.shape for ctrl in ctrlOrder for pp in ctrl.prog.pairs]
292
+ shapeOrder = [i for i in shapeOrder if not i.isRest]
293
+
294
+ # Incrementally Build the numpy array of delta shapes
295
+ # build deltaShapeArray as a 2d array because numpy is like 10x faster on 2d arrays
296
+ indexByShape = {v: k for k, v in enumerate(simplex.shapes)}
297
+ deltaShapeArray = np.zeros((len(simplex.shapes), allPts.shape[1] * 3))
298
+
299
+ if pBar is not None:
300
+ pBar.setValue(0)
301
+ pBar.setMaximum(len(shapeOrder))
302
+ pBar.setLabelText("Building Corrected Deltas")
303
+ QApplication.processEvents()
304
+
305
+ for shpOrderIdx, shape in enumerate(shapeOrder):
306
+ if pBar is not None:
307
+ pBar.setValue(shpOrderIdx)
308
+ pBar.setLabelText("Building Corrected Deltas\n{}".format(shape.name))
309
+ QApplication.processEvents()
310
+ else:
311
+ print(
312
+ "Collapsing {0} of {1}\r".format(shpOrderIdx + 1, len(shapeOrder)),
313
+ end=" ",
314
+ )
315
+
316
+ shpIdx = indexByShape[shape]
317
+ if shape in ptsByShape:
318
+ base = np.dot(vecByShape[shape], deltaShapeArray)
319
+ deltaShapeArray[shpIdx] = (
320
+ ptsByShape[shape] - base.reshape((-1, 3))
321
+ ).flatten()
322
+ else:
323
+ deltaShapeArray[shpIdx] = allPts[shpIdx].flatten()
324
+
325
+ return deltaShapeArray.reshape((len(deltaShapeArray), -1, 3))
326
+
327
+
328
+ def applyCorrectives(
329
+ simplex, allShapePts, restPts, solver, shapes, refIdxs, references, pBar=None
330
+ ):
331
+ """Loop over the shapes and references, apply them, and return a new np.array
332
+ of shape points
333
+
334
+ Parameters
335
+ ----------
336
+ simplex : Simplex
337
+ Simplex system
338
+ allShapePts : np.array
339
+ deltas per shape
340
+ restPts : np.array
341
+ The rest point positions
342
+ solver : PySimplex
343
+ The Python Simplex solver object
344
+ shapes : [Shape, ...]
345
+ The simplex shape objects we care about
346
+ refIdxs : [int, ...]
347
+ The reference index per shape
348
+ references : np.array
349
+ A list of matrix-per-points
350
+ pBar : QProgressDialog, optional
351
+ An optional progress dialog
352
+
353
+ Returns
354
+ -------
355
+ : np.array
356
+ The new shape points with correctives applied
357
+
358
+ """
359
+ # The rule of thumb is "THE SHAPE IS ALWAYS A DELTA"
360
+
361
+ if pBar is not None:
362
+ pBar.setLabelText("Inverting References")
363
+ pBar.setValue(0)
364
+ pBar.setMaximum(len(references))
365
+ QApplication.processEvents()
366
+ else:
367
+ print("Inverting References")
368
+
369
+ # The initial reference is the rig rest shape
370
+ # This way we can handle a difference between
371
+ # The .smpx rest shape, and the rig rest shape
372
+
373
+ # shape 0, all points, the tranform row of the matrix, the first 3 values in that row
374
+ rigRest = references[0, :, 3, :3]
375
+ restDelta = rigRest - restPts
376
+
377
+ inverses = []
378
+ for i, r in enumerate(references):
379
+ if pBar is not None:
380
+ pBar.setValue(i)
381
+ QApplication.processEvents()
382
+ inverses.append(invertAll(r))
383
+
384
+ if pBar is not None:
385
+ pBar.setLabelText("Building Full Shapes")
386
+ QApplication.processEvents()
387
+ else:
388
+ print("Building Full Shapes")
389
+ ptsByShape, vecByShape = buildFullShapes(simplex, shapes, allShapePts, solver, pBar)
390
+
391
+ if pBar is not None:
392
+ pBar.setLabelText("Correcting Shapes")
393
+ pBar.setValue(0)
394
+ pBar.setMaximum(len(shapes))
395
+ newPtsByShape = {}
396
+ for i, (shape, refIdx) in enumerate(zip(shapes, refIdxs)):
397
+ if pBar is not None:
398
+ pBar.setValue(i)
399
+ QApplication.processEvents()
400
+ else:
401
+ print("Correcting {0} of {1}: {2}".format(i + 1, len(shapes), shape.name))
402
+
403
+ inv = inverses[refIdx]
404
+ pts = ptsByShape[shape]
405
+ newPts = applyReference(pts, restPts, restDelta, inv)
406
+ newPtsByShape[shape] = newPts
407
+
408
+ newShapePts = collapseFullShapes(
409
+ simplex, allShapePts, newPtsByShape, vecByShape, pBar
410
+ )
411
+ newShapePts = newShapePts + restPts[None, ...]
412
+
413
+ return newShapePts
414
+
415
+
416
+ def readAndApplyCorrectives(inPath, namePath, refPath, outPath, pBar=None):
417
+ """Read the provided files, apply the correctives, then output a new file
418
+
419
+ Parameters
420
+ ----------
421
+ inPath : str
422
+ The input path
423
+ namePath : str
424
+ A file correlating the shape names and indices
425
+ refPath : str
426
+ The reference matrices per point of deformation
427
+ outPath : str
428
+ The output path
429
+ pBar : QProgressDialog, optional
430
+ An optional progress dialog
431
+ """
432
+
433
+ if pBar is not None:
434
+ pBar.setLabelText("Reading reference data")
435
+ QApplication.processEvents()
436
+
437
+ jsString, simplex, solver, allShapePts, restPts = loadSimplex(inPath)
438
+ with open(namePath, "r") as f:
439
+ nr = f.read()
440
+ nr = [i.split(";") for i in nr.split("\n") if i]
441
+ nr = nr[1:] # ignore the rest shape for this stuff
442
+ names, refIdxs = list(zip(*nr))
443
+ refIdxs = list(map(int, refIdxs))
444
+ refs = np.load(refPath, allow_pickle=True)
445
+ shapeByName = {i.name: i for i in simplex.shapes}
446
+ shapes = [shapeByName[n] for n in names]
447
+ newPts = applyCorrectives(
448
+ simplex, allShapePts, restPts, solver, shapes, refIdxs, refs, pBar
449
+ )
450
+ writeSimplex(inPath, outPath, newPts, pBar=pBar)
451
+ print("DONE")
@@ -0,0 +1,261 @@
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 Qt.QtWidgets import QApplication
19
+
20
+ try:
21
+ import numpy as np
22
+ except ImportError:
23
+ pass
24
+
25
+ from .mayaCorrectiveInterface import getShiftValues, resetPose, setPose
26
+
27
+ dcc = "maya"
28
+
29
+
30
+ def getRefForPoses(mesh, poses, multipliers):
31
+ """Given a set of poses and a multiplier, get the reference
32
+
33
+ Parameters
34
+ ----------
35
+ mesh : object
36
+ The DCC object
37
+ poses : [[(str, float), ...], ...]
38
+ Property/value pairs for different rig poses
39
+ multiplier : float
40
+ The percent of the pose to apply
41
+
42
+ Returns
43
+ -------
44
+ : np.array
45
+ The point reference matrices in pose
46
+
47
+ """
48
+
49
+ for pose, mul in zip(poses, multipliers):
50
+ setPose(pose, mul)
51
+
52
+ ref = getDeformReference(mesh)
53
+
54
+ for pose in poses:
55
+ resetPose(pose)
56
+ return ref
57
+
58
+
59
+ def getDeformReference(mesh):
60
+ """Build the 4x4 deformation reference matrices given a mesh
61
+
62
+ Parameters
63
+ ----------
64
+ mesh : object
65
+ The DCC mesh object
66
+
67
+ Returns
68
+ -------
69
+ : np.array:
70
+ The point reference matrices in pose
71
+
72
+ """
73
+ zero, oneX, oneY, oneZ = getShiftValues(mesh)
74
+
75
+ zero = np.array(zero)
76
+ dx = np.array(oneX) - zero
77
+ dy = np.array(oneY) - zero
78
+ dz = np.array(oneZ) - zero
79
+
80
+ # Maya has numpy 1.09, but np.stack comes from 1.10
81
+ # mats = np.stack((dx, dy, dz, zero), axis=1)
82
+
83
+ # Make the new axis to concatenate on
84
+ zero = zero[:, None]
85
+ dx = dx[:, None]
86
+ dy = dy[:, None]
87
+ dz = dz[:, None]
88
+ mats = np.concatenate((dx, dy, dz, zero), axis=1)
89
+
90
+ # Turn the Nx4x3 matrix into a Nx4x4
91
+ zzz = np.zeros((len(mats), 4, 1))
92
+ zzz[:, 3] = 1.0
93
+ mats = np.concatenate((mats, zzz), axis=2)
94
+
95
+ return mats
96
+
97
+
98
+ def buildCorrectiveReferences(mesh, simplex, poses, sliders, pBar=None):
99
+ """Take correlated poses and sliders, and expand down the
100
+ simplex combo tree, building references for each required shape
101
+
102
+ Parameters
103
+ ----------
104
+ mesh : object
105
+ The DCC mesh object
106
+ simplex : Simplex
107
+ The Simplex system
108
+ poses : [[(str, float), ...], ...]
109
+ Property/value pairs for different rig poses
110
+ sliders : [Slider, ...]
111
+ Simplex slider objects that are controlled by the poses
112
+ pBar : QProgressDialog, optional
113
+ An optional progress dialog
114
+
115
+ Returns
116
+ -------
117
+ : np.array
118
+ The output matrix-per-point arrays
119
+ : [Shape, ...]
120
+ The shapes active
121
+ : [int, ...]
122
+ The Reference pose per shape
123
+ """
124
+ # cache the pose search
125
+
126
+ # Pre-cache the combo search
127
+ allCombosBySliderValue = {}
128
+ for c in simplex.combos:
129
+ for p in c.pairs:
130
+ allCombosBySliderValue.setdefault((p.slider, p.value), []).append(c)
131
+
132
+ # This is only my subset set of downstreams
133
+ # Get the downstreams by slider and value
134
+ sliderValuesByCombo = {}
135
+ for slider in sliders:
136
+ for p in slider.prog.pairs:
137
+ combos = allCombosBySliderValue.get((slider, p.value), [])
138
+ for combo in combos:
139
+ sliderValuesByCombo.setdefault(combo, []).append((slider, p.value))
140
+
141
+ # out = []
142
+ refCache = {}
143
+ refs, shapes, refIdxs = [], [], []
144
+
145
+ # get the slider outputs
146
+ if pBar is not None:
147
+ pBar.setLabelText("Building Shape References")
148
+ pBar.setValue(0)
149
+ mv = 0
150
+ for slider in sliders:
151
+ for p in slider.prog.pairs:
152
+ if not p.shape.isRest:
153
+ mv += 1
154
+ pBar.setMaximum(mv)
155
+ QApplication.processEvents()
156
+
157
+ # Make sure to export the rest reference first
158
+ ref = getRefForPoses(mesh, [], [])
159
+ refIdxs.append(len(refs))
160
+ cacheKey = frozenset([("", 0.0)])
161
+ refCache[cacheKey] = len(refs)
162
+ refs.append(ref)
163
+ shapes.append(simplex.restShape)
164
+
165
+ # Now export everything else
166
+ poseBySlider = {}
167
+ for slider, pose in zip(sliders, poses):
168
+ poseBySlider[slider] = pose
169
+ for p in slider.prog.pairs:
170
+ if not p.shape.isRest:
171
+ if pBar is not None:
172
+ pBar.setValue(pBar.value())
173
+ QApplication.processEvents()
174
+ cacheKey = frozenset([(slider, p.value)])
175
+ if cacheKey in refCache:
176
+ idx = refCache[cacheKey]
177
+ refIdxs.append(idx)
178
+ else:
179
+ ref = getRefForPoses(mesh, [pose], [p.value])
180
+ refIdxs.append(len(refs))
181
+ refCache[cacheKey] = len(refs)
182
+ refs.append(ref)
183
+ shapes.append(p.shape)
184
+
185
+ # Get the combo outputs
186
+ if pBar is not None:
187
+ pBar.setLabelText("Building Combo References")
188
+ pBar.setValue(0)
189
+ mv = 0
190
+ for combo in sliderValuesByCombo:
191
+ for p in combo.prog.pairs:
192
+ if not p.shape.isRest:
193
+ mv += 1
194
+ pBar.setMaximum(mv)
195
+ QApplication.processEvents()
196
+
197
+ for combo, sliderVals in sliderValuesByCombo.items():
198
+ # components = frozenset(sliderVals)
199
+ poses = [poseBySlider[s] for s, _ in sliderVals]
200
+ for p in combo.prog.pairs:
201
+ if not p.shape.isRest:
202
+ if pBar is not None:
203
+ pBar.setValue(pBar.value())
204
+ QApplication.processEvents()
205
+
206
+ cacheKey = frozenset(sliderVals)
207
+ if cacheKey in refCache:
208
+ idx = refCache[cacheKey]
209
+ refIdxs.append(idx)
210
+ else:
211
+ vals = [p.value * v[1] for v in sliderVals]
212
+ ref = getRefForPoses(mesh, poses, vals)
213
+ refIdxs.append(len(refs))
214
+ refCache[cacheKey] = len(refs)
215
+ refs.append(ref)
216
+ shapes.append(p.shape)
217
+
218
+ return np.array(refs), shapes, refIdxs
219
+
220
+
221
+ def outputCorrectiveReferences(
222
+ outNames, outRefs, simplex, mesh, poses, sliders, pBar=None
223
+ ):
224
+ """Output the proper files for an external corrective application
225
+
226
+ Parameters
227
+ ----------
228
+ outNames : str
229
+ The filepath for the output shape and reference indices
230
+ outRefs : str
231
+ The filepath for the deformation references
232
+ simplex : Simplex
233
+ A simplex system
234
+ mesh : object
235
+ The mesh object to deform
236
+ poses : [[(str, float), ...], ...]
237
+ Lists of parameter
238
+ sliders : [Slider, ...]
239
+ The simplex sliders that correspond to the poses
240
+ pBar : QProgressDialog, optional
241
+ An optional progress dialog
242
+
243
+ Returns
244
+ -------
245
+
246
+ """
247
+ refs, shapes, refIdxs = buildCorrectiveReferences(
248
+ mesh, simplex, poses, sliders, pBar
249
+ )
250
+
251
+ if pBar is not None:
252
+ pBar.setLabelText("Writing Names")
253
+ QApplication.processEvents()
254
+ nameWrite = ["{};{}".format(s.name, r) for s, r in zip(shapes, refIdxs)]
255
+ with open(outNames, "w") as f:
256
+ f.write("\n".join(nameWrite))
257
+
258
+ if pBar is not None:
259
+ pBar.setLabelText("Writing References")
260
+ QApplication.processEvents()
261
+ refs.dump(outRefs)