simplex-solver 3.0.18__37-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 (81) hide show
  1. pysimplex.pyd +0 -0
  2. simplex_solver-3.0.18.dist-info/METADATA +87 -0
  3. simplex_solver-3.0.18.dist-info/RECORD +81 -0
  4. simplex_solver-3.0.18.dist-info/WHEEL +5 -0
  5. simplex_solver-3.0.18.dist-info/licenses/LICENSE +165 -0
  6. simplexui/__init__.py +54 -0
  7. simplexui/channelBox.py +862 -0
  8. simplexui/comboCheckDialog.py +335 -0
  9. simplexui/commands/__init__.py +16 -0
  10. simplexui/commands/alembicCommon.py +1045 -0
  11. simplexui/commands/applyCorrectives.py +455 -0
  12. simplexui/commands/buildIceXML.py +443 -0
  13. simplexui/commands/correctiveInterface.py +271 -0
  14. simplexui/commands/expandedExport.py +435 -0
  15. simplexui/commands/hdf5Convert.py +62 -0
  16. simplexui/commands/mayaCorrectiveInterface.py +164 -0
  17. simplexui/commands/mesh.py +1086 -0
  18. simplexui/commands/reorderSimplexPoints.py +103 -0
  19. simplexui/commands/rigidAlign.py +103 -0
  20. simplexui/commands/setDelta.xsicompound +60 -0
  21. simplexui/commands/smpxBlend.py +634 -0
  22. simplexui/commands/unsubdivide.py +1232 -0
  23. simplexui/commands/uvTransfer.py +986 -0
  24. simplexui/commands/xsiCorrectiveInterface.py +136 -0
  25. simplexui/dragFilter.py +299 -0
  26. simplexui/falloffDialog.py +476 -0
  27. simplexui/img/ChefHead.png +0 -0
  28. simplexui/img/frozen.png +0 -0
  29. simplexui/interface/__init__.py +30 -0
  30. simplexui/interface/dummyInterface.py +1564 -0
  31. simplexui/interface/mayaInterface.py +3197 -0
  32. simplexui/interface/xsiInterface.py +2944 -0
  33. simplexui/interfaceModel.py +1040 -0
  34. simplexui/interfaceModelTrees.py +439 -0
  35. simplexui/interfaceModel_Test.py +259 -0
  36. simplexui/items/__init__.py +26 -0
  37. simplexui/items/accessor.py +217 -0
  38. simplexui/items/combo.py +855 -0
  39. simplexui/items/falloff.py +780 -0
  40. simplexui/items/group.py +295 -0
  41. simplexui/items/progression.py +745 -0
  42. simplexui/items/shape.py +444 -0
  43. simplexui/items/simplex.py +1747 -0
  44. simplexui/items/slider.py +741 -0
  45. simplexui/items/stack.py +156 -0
  46. simplexui/items/traversal.py +969 -0
  47. simplexui/main.pyw +22 -0
  48. simplexui/menu/__init__.py +73 -0
  49. simplexui/menu/dummyPlugins/__init__.py +16 -0
  50. simplexui/menu/genericPlugins/__init__.py +16 -0
  51. simplexui/menu/genericPlugins/_builtins.py +260 -0
  52. simplexui/menu/genericPlugins/checkPossibleCombos.py +47 -0
  53. simplexui/menu/genericPlugins/exportSplit.py +61 -0
  54. simplexui/menu/genericPlugins/showFalloffs.py +24 -0
  55. simplexui/menu/genericPlugins/showTraversals.py +24 -0
  56. simplexui/menu/genericPlugins/simplexUvTransfer.py +109 -0
  57. simplexui/menu/genericPlugins/unsubdivide.py +71 -0
  58. simplexui/menu/mayaPlugins/__init__.py +16 -0
  59. simplexui/menu/mayaPlugins/exportOther.py +45 -0
  60. simplexui/menu/mayaPlugins/extractProgressives.py +67 -0
  61. simplexui/menu/mayaPlugins/freezeCombo.py +251 -0
  62. simplexui/menu/mayaPlugins/generateShapeIncrementals.py +100 -0
  63. simplexui/menu/mayaPlugins/importObjs.py +196 -0
  64. simplexui/menu/mayaPlugins/linearizeTraversal.py +49 -0
  65. simplexui/menu/mayaPlugins/makeShelfBtn.py +69 -0
  66. simplexui/menu/mayaPlugins/relaxToSelection.py +77 -0
  67. simplexui/menu/mayaPlugins/reloadDefinition.py +34 -0
  68. simplexui/menu/mayaPlugins/snapToNeutral.py +74 -0
  69. simplexui/menu/mayaPlugins/softSelectToCluster.py +204 -0
  70. simplexui/menu/mayaPlugins/tweakMix.py +138 -0
  71. simplexui/menu/mayaPlugins/updateRestShape.py +107 -0
  72. simplexui/menu/xsiPlugins/__init__.py +16 -0
  73. simplexui/simplexDialog.py +1391 -0
  74. simplexui/travCheckDialog.py +393 -0
  75. simplexui/traversalDialog.py +277 -0
  76. simplexui/ui/comboCheckDialog.ui +475 -0
  77. simplexui/ui/falloffDialog.ui +243 -0
  78. simplexui/ui/simplexDialog.ui +1458 -0
  79. simplexui/ui/travCheckDialog.ui +488 -0
  80. simplexui/ui/traversalDialog.ui +532 -0
  81. simplexui/utils.py +320 -0
@@ -0,0 +1,455 @@
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
+ from __future__ import absolute_import, print_function
20
+
21
+ import itertools
22
+ import os
23
+
24
+ from pysimplex import PySimplex
25
+ from six.moves import map, zip
26
+
27
+ from ..items import Combo, Simplex, Slider
28
+ from Qt.QtWidgets import QApplication
29
+ from .alembicCommon import (
30
+ buildSmpx,
31
+ getSmpxArchiveData,
32
+ getStaticMeshArrays,
33
+ getUvSample,
34
+ readSmpx,
35
+ )
36
+
37
+ try:
38
+ import numpy as np
39
+ except ImportError:
40
+ pass
41
+
42
+
43
+ def invertAll(matrixArray):
44
+ """Invert all the square sub-matrices in a numpy array
45
+
46
+ Parameters
47
+ ----------
48
+ matrixArray : np.array
49
+ An M*N*N numpy array
50
+
51
+ Returns
52
+ -------
53
+ : np.array
54
+ An M*N*N numpy array
55
+ """
56
+ # Look into numpy to see if there is a way to ignore
57
+ # all the repeated sanity checks, and do them ourselves, once
58
+ return np.array([np.linalg.inv(a) for a in matrixArray])
59
+
60
+
61
+ def applyReference(pts, restPts, restDelta, inv):
62
+ """Given a shape and an array of pre-inverted
63
+ per-point matrices return the deltas
64
+
65
+ Parameters
66
+ ----------
67
+ pts : np.array
68
+ Deformed point positions
69
+ restPts : np.array
70
+ Rest point positions
71
+ restDelta : np.array
72
+ The delta from rest
73
+ inv : np.array
74
+ An M*4*4 array of matrices
75
+
76
+ Returns
77
+ -------
78
+ : np.array
79
+ The new point positions
80
+
81
+ """
82
+ pts = pts + restPts + restDelta
83
+ preSize = pts.shape[-1]
84
+ if inv.shape[-2] > pts.shape[-1]:
85
+ oneShape = list(pts.shape)
86
+ oneShape[-1] = inv.shape[-2] - pts.shape[-1]
87
+ pts = np.concatenate((pts, np.ones(oneShape)), axis=-1)
88
+
89
+ # Return the 3d points
90
+ return np.einsum("ij,ijk->ik", pts, inv)[..., :preSize]
91
+
92
+
93
+ def loadSimplex(shapePath):
94
+ """Load and parse all the data from a simplex file
95
+
96
+ Parameters
97
+ ----------
98
+ shapePath : str
99
+ The path to the .smpx file
100
+
101
+ Returns
102
+ -------
103
+ : str
104
+ The simplex JSON string
105
+ : Simplex
106
+ The simplex system
107
+ : pySimplex
108
+ The instantiated simplex solver
109
+ : np.array
110
+ A Numpy array of the shape point positions
111
+ : np.array
112
+ A Numpy array of the rest pose of the system
113
+
114
+ """
115
+ if not os.path.isfile(str(shapePath)):
116
+ raise IOError("File does not exist: " + str(shapePath))
117
+
118
+ jsString, counts, verts, faces, uvs, uvFaces = readSmpx(shapePath)
119
+
120
+ simplex = Simplex.buildSystemFromJsonString(jsString, None, forceDummy=True)
121
+ solver = PySimplex(jsString)
122
+
123
+ # return as delta shapes
124
+ restIdx = simplex.shapes.index(simplex.restShape)
125
+ restPts = verts[restIdx]
126
+ verts = verts - restPts[None, ...] # reshape for broadcasting
127
+
128
+ return jsString, simplex, solver, verts, restPts
129
+
130
+
131
+ def writeSimplex(inPath, outPath, newShapes, name="Face", pBar=None):
132
+ """Write a simplex file with new shapes
133
+
134
+ Parameters
135
+ ----------
136
+ inPath : str
137
+ The input .smpx file path
138
+ outPath : str
139
+ The output .smpx file path
140
+ newShapes : np.array
141
+ A numpy array of shapes to write
142
+ name : str
143
+ The name of the new system
144
+ pBar : QProgressDialog, optional
145
+ An optional progress dialog
146
+
147
+ Returns
148
+ -------
149
+
150
+ """
151
+ if not os.path.isfile(str(inPath)):
152
+ raise IOError("File does not exist: " + str(inPath))
153
+
154
+ iarch, abcMesh, jsString = getSmpxArchiveData(inPath)
155
+ faces, counts = getStaticMeshArrays(abcMesh)
156
+ uvs = getUvSample(abcMesh)
157
+ del iarch, abcMesh
158
+
159
+ buildSmpx(
160
+ outPath,
161
+ newShapes,
162
+ faces,
163
+ jsString,
164
+ name,
165
+ faceCounts=counts,
166
+ uvs=uvs,
167
+ )
168
+
169
+
170
+ #########################################################################
171
+ #### Deform Reference ####
172
+ #########################################################################
173
+
174
+
175
+ def _buildSolverInputs(simplex, item, value, indexBySlider):
176
+ """Build an input vector for the solver that will
177
+ produce a required progression value on an item
178
+ """
179
+ inVec = [0.0] * len(simplex.sliders)
180
+ if isinstance(item, Slider):
181
+ inVec[indexBySlider[item]] = value
182
+ return inVec
183
+ elif isinstance(item, Combo):
184
+ for pair in item.pairs:
185
+ inVec[indexBySlider[pair.slider]] = pair.value * abs(value)
186
+ return inVec
187
+ else:
188
+ raise ValueError(
189
+ "Not a slider or combo. Got type {0}: {1}".format(type(item), item)
190
+ )
191
+
192
+
193
+ def buildFullShapes(simplex, shapeObjs, shapes, solver, pBar=None):
194
+ """Given shape inputs, build the full output shape from the deltas
195
+ We use shapes here because a shape implies both the progression
196
+ and the value of the inputs (with a little figuring)
197
+
198
+ Parameters
199
+ ----------
200
+ simplex : Simplex
201
+ A Simplex system
202
+ shapeObjs : [Shape, ...]
203
+ The Simplex system Shape objects
204
+ shapes : np.array
205
+ A numpy array of the shapes
206
+ solver : PySimplex
207
+ An instantiated simplex solver
208
+ pBar : QProgressDialog, optional
209
+ An optional progress dialog
210
+
211
+ Returns
212
+ -------
213
+ : {Shape: np.array, ...}
214
+ A dictionary of point positions indexed by the shape
215
+ : {Shape: [float, ...], ...}
216
+ A dictionary of solver inputs indexed by the shape
217
+ """
218
+ ###########################################
219
+ # Manipulate all the input lists and caches
220
+ indexBySlider = {s: i for i, s in enumerate(simplex.sliders)}
221
+ indexByShape = {s: i for i, s in enumerate(simplex.shapes)}
222
+ floaters = set(simplex.getFloatingShapes())
223
+ floatIdxs = set([indexByShape[s] for s in floaters])
224
+
225
+ shapeDict = {}
226
+ for item in itertools.chain(simplex.sliders, simplex.combos):
227
+ for pair in item.prog.pairs:
228
+ if not pair.shape.isRest:
229
+ shapeDict[pair.shape] = (item, pair.value)
230
+
231
+ ######################
232
+ # Actually do the work
233
+ vecByShape = {} # store this for later use
234
+ ptsByShape = {}
235
+
236
+ if pBar is not None:
237
+ pBar.setMaximum(len(shapeObjs))
238
+ pBar.setValue(0)
239
+ QApplication.processEvents()
240
+
241
+ flatShapes = shapes.reshape((len(shapes), -1))
242
+ for i, shape in enumerate(shapeObjs):
243
+ if pBar is not None:
244
+ pBar.setValue(i)
245
+ QApplication.processEvents()
246
+ else:
247
+ print("Building {0} of {1}\r".format(i + 1, len(shapeObjs)), end=" ")
248
+
249
+ item, value = shapeDict[shape]
250
+ inVec = _buildSolverInputs(simplex, item, value, indexBySlider)
251
+ outVec = solver.solve(inVec)
252
+ if shape not in floaters:
253
+ for fi in floatIdxs:
254
+ outVec[fi] = 0.0
255
+ outVec = np.array(outVec)
256
+ outVec[np.where(np.isclose(outVec, 0))] = 0
257
+ outVec[np.where(np.isclose(outVec, 1))] = 1
258
+ vecByShape[shape] = outVec
259
+ pts = np.dot(outVec, flatShapes)
260
+ pts = pts.reshape((-1, 3))
261
+ ptsByShape[shape] = pts
262
+ if pBar is None:
263
+ print()
264
+
265
+ return ptsByShape, vecByShape
266
+
267
+
268
+ def collapseFullShapes(simplex, allPts, ptsByShape, vecByShape, pBar=None):
269
+ """Given a set of shapes that are full-on shapes (not just deltas)
270
+ Collapse them back into deltas in the simplex shape list
271
+
272
+ Parameters
273
+ ----------
274
+ simplex : Simplex
275
+ A simplex system
276
+ allPts : np.array
277
+ All the point positions
278
+ ptsByShape : {Shape: np.array, ...}
279
+ A dictionary of point positions indexed by the shape
280
+ vecByShape : {Shape: [float, ...], ...}
281
+ A dictionary of solver inputs indexed by the shape
282
+ pBar : QProgressDialog, optional
283
+ An optional progress dialog
284
+
285
+ Returns
286
+ -------
287
+ : np.array
288
+ The collapsed shapes
289
+
290
+ """
291
+ # Figure out what order to build the deltas
292
+ # so that the deltas exist when I try to combine them
293
+ ctrlOrder = simplex.controllersByDepth()
294
+ shapeOrder = [pp.shape for ctrl in ctrlOrder for pp in ctrl.prog.pairs]
295
+ shapeOrder = [i for i in shapeOrder if not i.isRest]
296
+
297
+ # Incrementally Build the numpy array of delta shapes
298
+ # build deltaShapeArray as a 2d array because numpy is like 10x faster on 2d arrays
299
+ indexByShape = {v: k for k, v in enumerate(simplex.shapes)}
300
+ deltaShapeArray = np.zeros((len(simplex.shapes), allPts.shape[1] * 3))
301
+
302
+ if pBar is not None:
303
+ pBar.setValue(0)
304
+ pBar.setMaximum(len(shapeOrder))
305
+ pBar.setLabelText("Building Corrected Deltas")
306
+ QApplication.processEvents()
307
+
308
+ for shpOrderIdx, shape in enumerate(shapeOrder):
309
+
310
+ if pBar is not None:
311
+ pBar.setValue(shpOrderIdx)
312
+ pBar.setLabelText("Building Corrected Deltas\n{}".format(shape.name))
313
+ QApplication.processEvents()
314
+ else:
315
+ print(
316
+ "Collapsing {0} of {1}\r".format(shpOrderIdx + 1, len(shapeOrder)),
317
+ end=" ",
318
+ )
319
+
320
+ shpIdx = indexByShape[shape]
321
+ if shape in ptsByShape:
322
+ base = np.dot(vecByShape[shape], deltaShapeArray)
323
+ deltaShapeArray[shpIdx] = (
324
+ ptsByShape[shape] - base.reshape((-1, 3))
325
+ ).flatten()
326
+ else:
327
+ deltaShapeArray[shpIdx] = allPts[shpIdx].flatten()
328
+
329
+ return deltaShapeArray.reshape((len(deltaShapeArray), -1, 3))
330
+
331
+
332
+ def applyCorrectives(
333
+ simplex, allShapePts, restPts, solver, shapes, refIdxs, references, pBar=None
334
+ ):
335
+ """Loop over the shapes and references, apply them, and return a new np.array
336
+ of shape points
337
+
338
+ Parameters
339
+ ----------
340
+ simplex : Simplex
341
+ Simplex system
342
+ allShapePts : np.array
343
+ deltas per shape
344
+ restPts : np.array
345
+ The rest point positions
346
+ solver : PySimplex
347
+ The Python Simplex solver object
348
+ shapes : [Shape, ...]
349
+ The simplex shape objects we care about
350
+ refIdxs : [int, ...]
351
+ The reference index per shape
352
+ references : np.array
353
+ A list of matrix-per-points
354
+ pBar : QProgressDialog, optional
355
+ An optional progress dialog
356
+
357
+ Returns
358
+ -------
359
+ : np.array
360
+ The new shape points with correctives applied
361
+
362
+ """
363
+ # The rule of thumb is "THE SHAPE IS ALWAYS A DELTA"
364
+
365
+ if pBar is not None:
366
+ pBar.setLabelText("Inverting References")
367
+ pBar.setValue(0)
368
+ pBar.setMaximum(len(references))
369
+ QApplication.processEvents()
370
+ else:
371
+ print("Inverting References")
372
+
373
+ # The initial reference is the rig rest shape
374
+ # This way we can handle a difference between
375
+ # The .smpx rest shape, and the rig rest shape
376
+
377
+ # shape 0, all points, the tranform row of the matrix, the first 3 values in that row
378
+ rigRest = references[0, :, 3, :3]
379
+ restDelta = rigRest - restPts
380
+
381
+ inverses = []
382
+ for i, r in enumerate(references):
383
+ if pBar is not None:
384
+ pBar.setValue(i)
385
+ QApplication.processEvents()
386
+ inverses.append(invertAll(r))
387
+
388
+ if pBar is not None:
389
+ pBar.setLabelText("Building Full Shapes")
390
+ QApplication.processEvents()
391
+ else:
392
+ print("Building Full Shapes")
393
+ ptsByShape, vecByShape = buildFullShapes(simplex, shapes, allShapePts, solver, pBar)
394
+
395
+ if pBar is not None:
396
+ pBar.setLabelText("Correcting Shapes")
397
+ pBar.setValue(0)
398
+ pBar.setMaximum(len(shapes))
399
+ newPtsByShape = {}
400
+ for i, (shape, refIdx) in enumerate(zip(shapes, refIdxs)):
401
+ if pBar is not None:
402
+ pBar.setValue(i)
403
+ QApplication.processEvents()
404
+ else:
405
+ print("Correcting {0} of {1}: {2}".format(i + 1, len(shapes), shape.name))
406
+
407
+ inv = inverses[refIdx]
408
+ pts = ptsByShape[shape]
409
+ newPts = applyReference(pts, restPts, restDelta, inv)
410
+ newPtsByShape[shape] = newPts
411
+
412
+ newShapePts = collapseFullShapes(
413
+ simplex, allShapePts, newPtsByShape, vecByShape, pBar
414
+ )
415
+ newShapePts = newShapePts + restPts[None, ...]
416
+
417
+ return newShapePts
418
+
419
+
420
+ def readAndApplyCorrectives(inPath, namePath, refPath, outPath, pBar=None):
421
+ """Read the provided files, apply the correctives, then output a new file
422
+
423
+ Parameters
424
+ ----------
425
+ inPath : str
426
+ The input path
427
+ namePath : str
428
+ A file correlating the shape names and indices
429
+ refPath : str
430
+ The reference matrices per point of deformation
431
+ outPath : str
432
+ The output path
433
+ pBar : QProgressDialog, optional
434
+ An optional progress dialog
435
+ """
436
+
437
+ if pBar is not None:
438
+ pBar.setLabelText("Reading reference data")
439
+ QApplication.processEvents()
440
+
441
+ jsString, simplex, solver, allShapePts, restPts = loadSimplex(inPath)
442
+ with open(namePath, "r") as f:
443
+ nr = f.read()
444
+ nr = [i.split(";") for i in nr.split("\n") if i]
445
+ nr = nr[1:] # ignore the rest shape for this stuff
446
+ names, refIdxs = list(zip(*nr))
447
+ refIdxs = list(map(int, refIdxs))
448
+ refs = np.load(refPath, allow_pickle=True)
449
+ shapeByName = {i.name: i for i in simplex.shapes}
450
+ shapes = [shapeByName[n] for n in names]
451
+ newPts = applyCorrectives(
452
+ simplex, allShapePts, restPts, solver, shapes, refIdxs, refs, pBar
453
+ )
454
+ writeSimplex(inPath, outPath, newPts, pBar=pBar)
455
+ print("DONE")