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