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,319 @@
1
+ import imath
2
+ import ctypes
3
+ import numpy as np
4
+ from typing import TypeVar, Type
5
+
6
+
7
+ NTYPEDICT: dict[type, type] = {
8
+ ctypes.c_bool: bool,
9
+ ctypes.c_byte: np.int8,
10
+ ctypes.c_double: np.float64,
11
+ ctypes.c_float: np.float32,
12
+ ctypes.c_long: np.int32,
13
+ ctypes.c_short: np.int16,
14
+ ctypes.c_ubyte: np.uint8,
15
+ ctypes.c_ulong: np.uint32,
16
+ ctypes.c_ushort: np.uint16,
17
+ }
18
+
19
+ # fmt: off
20
+ TYPEDICT: dict[type, tuple[list[int], type, str]] = {
21
+ imath.BoolArray: ([], ctypes.c_bool, 'array'),
22
+ imath.DoubleArray: ([], ctypes.c_double, 'array'),
23
+ imath.FloatArray: ([], ctypes.c_float, 'array'),
24
+ imath.IntArray: ([], ctypes.c_long, 'array'),
25
+ imath.ShortArray: ([], ctypes.c_short, 'array'),
26
+ imath.SignedCharArray: ([], ctypes.c_byte, 'array'),
27
+ imath.UnsignedCharArray: ([], ctypes.c_ubyte, 'array'),
28
+ imath.UnsignedIntArray: ([], ctypes.c_ulong, 'array'),
29
+ imath.UnsignedShortArray: ([], ctypes.c_ushort, 'array'),
30
+
31
+ imath.Box2dArray: ([2, 2], ctypes.c_double, 'array'),
32
+ imath.Box2fArray: ([2, 2], ctypes.c_float, 'array'),
33
+ imath.Box2iArray: ([2, 2], ctypes.c_long, 'array'),
34
+ imath.Box2sArray: ([2, 2], ctypes.c_short, 'array'),
35
+ imath.Box3dArray: ([2, 3], ctypes.c_double, 'array'),
36
+ imath.Box3fArray: ([2, 3], ctypes.c_float, 'array'),
37
+ imath.Box3iArray: ([2, 3], ctypes.c_long, 'array'),
38
+ imath.Box3sArray: ([2, 3], ctypes.c_short, 'array'),
39
+ imath.C3cArray: ([3], ctypes.c_byte, 'array'),
40
+ imath.C3fArray: ([3], ctypes.c_float, 'array'),
41
+ imath.C4cArray: ([4], ctypes.c_byte, 'array'),
42
+ imath.C4fArray: ([4], ctypes.c_float, 'array'),
43
+ imath.M22dArray: ([2, 2], ctypes.c_double, 'array'),
44
+ imath.M22fArray: ([2, 2], ctypes.c_float, 'array'),
45
+ imath.M33dArray: ([3, 3], ctypes.c_double, 'array'),
46
+ imath.M33fArray: ([3, 3], ctypes.c_float, 'array'),
47
+ imath.M44dArray: ([4, 4], ctypes.c_double, 'array'),
48
+ imath.M44fArray: ([4, 4], ctypes.c_float, 'array'),
49
+ imath.QuatdArray: ([4], ctypes.c_double, 'array'),
50
+ imath.QuatfArray: ([4], ctypes.c_float, 'array'),
51
+ imath.V2dArray: ([2], ctypes.c_double, 'array'),
52
+ imath.V2fArray: ([2], ctypes.c_float, 'array'),
53
+ imath.V2iArray: ([2], ctypes.c_long, 'array'),
54
+ imath.V2sArray: ([2], ctypes.c_short, 'array'),
55
+ imath.V3dArray: ([3], ctypes.c_double, 'array'),
56
+ imath.V3fArray: ([3], ctypes.c_float, 'array'),
57
+ imath.V3iArray: ([3], ctypes.c_long, 'array'),
58
+ imath.V3sArray: ([3], ctypes.c_short, 'array'),
59
+ imath.V4dArray: ([4], ctypes.c_double, 'array'),
60
+ imath.V4fArray: ([4], ctypes.c_float, 'array'),
61
+ imath.V4iArray: ([4], ctypes.c_long, 'array'),
62
+ imath.V4sArray: ([4], ctypes.c_short, 'array'),
63
+
64
+ imath.Color4cArray2D: ([4], ctypes.c_byte, 'array2d'),
65
+ imath.Color4fArray2D: ([4], ctypes.c_float, 'array2d'),
66
+ imath.DoubleArray2D: ([], ctypes.c_double, 'array2d'),
67
+ imath.FloatArray2D: ([], ctypes.c_float, 'array2d'),
68
+ imath.IntArray2D: ([], ctypes.c_long, 'array2d'),
69
+
70
+ imath.DoubleMatrix: ([], ctypes.c_double, 'matrix'),
71
+ imath.FloatMatrix: ([], ctypes.c_float, 'matrix'),
72
+ imath.IntMatrix: ([], ctypes.c_long, 'matrix'),
73
+
74
+ imath.Box2d: ([2, 2], ctypes.c_double, 'box'),
75
+ imath.Box2f: ([2, 2], ctypes.c_float, 'box'),
76
+ imath.Box2i: ([2, 2], ctypes.c_long, 'box'),
77
+ imath.Box2s: ([2, 2], ctypes.c_short, 'box'),
78
+ imath.Box3d: ([2, 3], ctypes.c_double, 'box'),
79
+ imath.Box3f: ([2, 3], ctypes.c_float, 'box'),
80
+ imath.Box3i: ([2, 3], ctypes.c_long, 'box'),
81
+ imath.Box3s: ([2, 3], ctypes.c_short, 'box'),
82
+
83
+ imath.Line3d: ([2, 3], ctypes.c_double, 'line'),
84
+ imath.Line3f: ([2, 3], ctypes.c_float, 'line'),
85
+
86
+ imath.Color3c: ([3], ctypes.c_byte, ''),
87
+ imath.Color3f: ([3], ctypes.c_float, ''),
88
+ imath.Color4c: ([4], ctypes.c_byte, ''),
89
+ imath.Color4f: ([4], ctypes.c_float, ''),
90
+ imath.M22d: ([2, 2], ctypes.c_double, ''),
91
+ imath.M22dRow: ([2], ctypes.c_double, 'row'),
92
+ imath.M22f: ([2, 2], ctypes.c_float, ''),
93
+ imath.M22fRow: ([2], ctypes.c_float, 'row'),
94
+ imath.M33d: ([3, 3], ctypes.c_double, ''),
95
+ imath.M33dRow: ([3], ctypes.c_double, 'row'),
96
+ imath.M33f: ([3, 3], ctypes.c_float, ''),
97
+ imath.M33fRow: ([3], ctypes.c_float, 'row'),
98
+ imath.M44d: ([4, 4], ctypes.c_double, ''),
99
+ imath.M44dRow: ([4], ctypes.c_double, 'row'),
100
+ imath.M44f: ([4, 4], ctypes.c_float, ''),
101
+ imath.M44fRow: ([4], ctypes.c_float, 'row'),
102
+ imath.Quatd: ([4], ctypes.c_double, ''),
103
+ imath.Quatf: ([4], ctypes.c_float, ''),
104
+ imath.Shear6d: ([6], ctypes.c_double, ''),
105
+ imath.Shear6f: ([6], ctypes.c_float, ''),
106
+ imath.V2d: ([2], ctypes.c_double, ''),
107
+ imath.V2f: ([2], ctypes.c_float, ''),
108
+ imath.V2i: ([2], ctypes.c_long, ''),
109
+ imath.V2s: ([2], ctypes.c_short, ''),
110
+ imath.V3c: ([3], ctypes.c_byte, ''),
111
+ imath.V3d: ([3], ctypes.c_double, ''),
112
+ imath.V3f: ([3], ctypes.c_float, ''),
113
+ imath.V3i: ([3], ctypes.c_long, ''),
114
+ imath.V3s: ([3], ctypes.c_short, ''),
115
+ imath.V4c: ([4], ctypes.c_byte, ''),
116
+ imath.V4d: ([4], ctypes.c_double, ''),
117
+ imath.V4f: ([4], ctypes.c_float, ''),
118
+ imath.V4i: ([4], ctypes.c_long, ''),
119
+ imath.V4s: ([4], ctypes.c_short, ''),
120
+ }
121
+ # fmt: on
122
+
123
+ # Define the in-memory structures of the python objects
124
+ # I'm *GUESSING* on most of the types here, so they could be refined
125
+ # in the future if required
126
+
127
+ # Here's hoping these structs don't change with different versions
128
+ # of python or imath
129
+
130
+
131
+ class PyImoObj(ctypes.Structure):
132
+ _fields_ = [
133
+ ("refcount", ctypes.c_ssize_t), # from the PyObject c struct
134
+ ("typeptr", ctypes.c_void_p), # from the PyObject c struct
135
+ ("unknown1", ctypes.c_ssize_t), # Seems always -48 for some reason
136
+ ("unknown2", ctypes.c_ssize_t), # Seems always 0
137
+ ("unknown3", ctypes.c_ssize_t), # Seems always 0
138
+ ("dataptr", ctypes.c_void_p), # pointer to the PyImoDataObj
139
+ ]
140
+
141
+
142
+ class PyImoDataObj(ctypes.Structure):
143
+ _fields_ = [
144
+ ("magic", ctypes.c_ssize_t), # Some kind of type ID?
145
+ ("unknown1", ctypes.c_ssize_t), # Seems always 0
146
+ ("dataptr", ctypes.c_void_p), # Pointer to the allocated memory
147
+ # There's MORE data after this, like the row/column count
148
+ # and some other pointers. But I don't need them
149
+ # Plus, there are some edge cases with the different types
150
+ # like rows or bounding boxes
151
+ ]
152
+
153
+
154
+ PyImoObjPtr = ctypes.POINTER(PyImoObj)
155
+ PyImoDataObjPtr = ctypes.POINTER(PyImoDataObj)
156
+
157
+
158
+ def _getImoPointer(imo, extra: str) -> int:
159
+ """Get the memory address to the actual imath data
160
+
161
+ Args:
162
+ imo (imath object): The imath object to inspect
163
+ extra (str): The metadata of this current type
164
+
165
+ Returns:
166
+ int: The memory address to the actual data
167
+ """
168
+ # This is a scary function
169
+ # I found this stuff out by trial and error
170
+ pyStruct = ctypes.cast(id(imo), PyImoObjPtr).contents
171
+ if extra == "box":
172
+ # I'm guessing that since the bounding box data is a known
173
+ # size, they just put it directly into the structure
174
+ # And the data is stored where the dataptr would be.
175
+ # So I can just add the pyStruct.dataptr and the memory offset
176
+ # of the PyImoDataObj.dataptr to get memory address of the box
177
+ return pyStruct.dataptr + PyImoDataObj.dataptr.offset
178
+
179
+ pyImoStruct = ctypes.cast(pyStruct.dataptr, PyImoDataObjPtr).contents
180
+ return pyImoStruct.dataptr
181
+
182
+
183
+ def _link(imo) -> tuple[np.ndarray, int]:
184
+ """Build a numpy object that's referencing the same memory
185
+ as the given imath object
186
+
187
+ Args:
188
+ imo (imath object): The imath object to build a link to
189
+
190
+ Returns:
191
+ np.ndarray: The numpy array
192
+ int: The pointer to the memory address where the data lives
193
+ """
194
+ size, cdata, extra = TYPEDICT[type(imo)]
195
+ if extra == "array":
196
+ shape = [len(imo)] + size
197
+ elif extra == "array2d":
198
+ shape = list(imo.size()) + size
199
+ elif extra == "matrix":
200
+ shape = [imo.rows(), imo.columns()] + size
201
+ elif extra in ("box", "line"):
202
+ shape = size
203
+ else:
204
+ shape = [len(imo)]
205
+
206
+ for s in shape[::-1]:
207
+ cdata = cdata * s # type: ignore
208
+
209
+ ptr = _getImoPointer(imo, extra)
210
+ ctypearray = cdata.from_address(ptr)
211
+ nparray = np.ctypeslib.as_array(ctypearray)
212
+ return nparray, ptr
213
+
214
+
215
+ def imathToNumpy(imo) -> np.ndarray:
216
+ """Copy an imath object into a numpy array
217
+
218
+ Args:
219
+ imo (imath object): The imath object to convert
220
+
221
+ Returns:
222
+ np.ndarray: A copy of the imath object as a numpy array
223
+ """
224
+ gcarray, _ptr = _link(imo)
225
+ return np.copy(gcarray)
226
+
227
+
228
+ T = TypeVar("T")
229
+
230
+
231
+ def numpyToImath(npo: np.ndarray, imtype: Type[T]) -> T:
232
+ """Convert a numpy array to the given imath type
233
+
234
+ Args:
235
+ npo (array like): An object that can be cast to a numpy array
236
+ imtype (type): The imath type to convert to
237
+
238
+ Returns:
239
+ imathObj: An instantiated imtype object with the numpy data loaded into it
240
+ """
241
+ size, cdata, extra = TYPEDICT[imtype]
242
+ npo = np.asarray(npo, dtype=NTYPEDICT[cdata])
243
+ if extra == "array":
244
+ assert npo.ndim == len(size) + 1
245
+ imo = imtype(len(npo)) # type: ignore
246
+ elif extra in ("matrix", "array2d"):
247
+ assert npo.ndim == 2 + len(size)
248
+ imo = imtype(*npo.shape[:2])
249
+ else:
250
+ imo = imtype()
251
+
252
+ tret, _ptr = _link(imo)
253
+ np.copyto(tret, npo)
254
+ return imo
255
+
256
+
257
+ def _test():
258
+ """A quick test for all this crazy stuff"""
259
+
260
+ # By default the bounding box objects are set to
261
+ # The min/max for their types
262
+ box3dnp = np.empty((2, 3), dtype=np.float64)
263
+ box3dnp[0] = imath.DBL_MAX
264
+ box3dnp[1] = imath.DBL_MIN
265
+
266
+ box3fnp = np.empty((2, 3), dtype=np.float32)
267
+ box3fnp[0] = imath.FLT_MAX
268
+ box3fnp[1] = imath.FLT_MIN
269
+
270
+ box3fanp = np.empty((5, 2, 3), dtype=np.float32)
271
+ box3fanp[:] = box3fnp
272
+
273
+ # M44fArray
274
+ eyes = np.zeros((13, 4, 4), dtype=np.float32)
275
+ eyes[:] = np.eye(4, dtype=np.float32)
276
+
277
+ # Line3f
278
+ line = np.zeros((2, 3), dtype=np.float32)
279
+ line[1, 0] = 1.0
280
+
281
+ # M33fRow
282
+ im = imath.M33f()
283
+ nm = np.eye(3, dtype=np.float32)
284
+
285
+ # equivalent to an np.empty(3, 5)
286
+ # so I have to set the values manually
287
+ dubm = imath.DoubleMatrix(3, 5)
288
+ tt = 0.0
289
+ for i in range(3):
290
+ row = dubm[i]
291
+ for j in range(5):
292
+ row[j] = tt
293
+ tt += 1.0
294
+
295
+ # fmt: off
296
+ eqpairs = [
297
+ (imath.V3dArray(11), np.zeros((11, 3))),
298
+ (imath.M44fArray(13), eyes),
299
+ (imath.V3d(), np.zeros(3)),
300
+ (imath.Color4cArray2D(5, 7), np.zeros((5, 7, 4), dtype=np.int8)),
301
+ (imath.Box3fArray(5), box3fanp),
302
+ (imath.Box3d(), box3dnp),
303
+ (imath.Box3f(), box3fnp),
304
+ (imath.FloatArray(13), np.zeros((13), dtype=np.float32)),
305
+ (imath.Line3f(), line),
306
+ (im[1], nm[1]),
307
+ (dubm, np.arange(15, dtype=float).reshape((3, 5))),
308
+ ]
309
+ # fmt: on
310
+
311
+ for imo, chk in eqpairs:
312
+ nv = imathToNumpy(imo)
313
+ assert nv.dtype == chk.dtype
314
+ assert np.all(nv == chk)
315
+
316
+ imtype = type(imo)
317
+ _size, _cdata, extra = TYPEDICT[imtype]
318
+ if extra != "row": # Can't directly build row objects
319
+ _iv = numpyToImath(chk, imtype)
@@ -0,0 +1,166 @@
1
+ import numpy as np
2
+
3
+ # I could have used the Scipy rotations library, but it doeosn't deal
4
+ # with ndim arrays of quaternions.
5
+
6
+
7
+ def positive_scalar(q: np.ndarray) -> np.ndarray:
8
+ """Ensure the scalar value of an array of quaternions is positive"""
9
+ shape = q.shape
10
+ q = q.reshape((-1, 4))
11
+ q[q[:, 3] < 0] *= -1
12
+ return q.reshape(shape)
13
+
14
+
15
+ def outer(q: np.ndarray) -> np.ndarray:
16
+ """Do the outer product of an array of quaternions with itself"""
17
+ return q[..., None] * q[..., None, :] # broadcast to do the outer products
18
+
19
+
20
+ def inverse_quats(q: np.ndarray) -> np.ndarray:
21
+ """Get the inverses of the given unit quaternions"""
22
+ ret = q.copy()
23
+ ret[..., :-1] *= -1
24
+ return ret
25
+
26
+
27
+ def norm_quats(q: np.ndarray) -> np.ndarray:
28
+ """Normalize the given quaternions and flip any whose scalar component
29
+ is negative
30
+ """
31
+ return positive_scalar(q / np.linalg.norm(q, axis=-1, keepdims=True))
32
+
33
+
34
+ def mul_quats(q1, q2):
35
+ """Quaternion multiplication of two arrays
36
+
37
+ Follows the convention that the right hand is applied "first"
38
+ Like row-major transformation matrices
39
+ """
40
+ x1, y1, z1, w1 = q1[..., 0], q1[..., 1], q1[..., 2], q1[..., 3]
41
+ x2, y2, z2, w2 = q2[..., 0], q2[..., 1], q2[..., 2], q2[..., 3]
42
+
43
+ w = w2 * w1 - x2 * x1 - y2 * y1 - z2 * z1
44
+ x = w2 * x1 + x2 * w1 + y2 * z1 - z2 * y1
45
+ y = w2 * y1 - x2 * z1 + y2 * w1 + z2 * x1
46
+ z = w2 * z1 + x2 * y1 - y2 * x1 + z2 * w1
47
+
48
+ return np.stack((x, y, z, w), axis=-1)
49
+
50
+
51
+ def quaternion_pow(q: np.ndarray, n: np.ndarray):
52
+ """Exponentiate unit quaternions
53
+ Could also be thought of as slerping from the unit quaternion to the
54
+ given quaternions
55
+
56
+ Args:
57
+ q (np.array[..., 4]): An array of quaternions
58
+ n (np.array[..., 0]): An array of weights broadcastable to the shape
59
+ of the quaternion array
60
+
61
+ Returns:
62
+ np.array[..., 4]: An array of exponentiated quaternions
63
+ """
64
+ w = np.clip(q[..., -1], -1.0, 1.0)
65
+ v = q[..., :-1]
66
+
67
+ theta = np.arccos(w)
68
+ sin_theta = np.sin(theta)
69
+
70
+ # Broadcast n to shape of theta
71
+ n = np.broadcast_to(n, theta.shape)
72
+
73
+ # Scale the rotation angle
74
+ new_theta = n * theta
75
+ new_w = np.cos(new_theta)
76
+
77
+ # Fall back to a linear approximation for small angles
78
+ with np.errstate(divide="ignore", invalid="ignore"):
79
+ scale = np.where(sin_theta > 1e-8, np.sin(new_theta) / sin_theta, n)
80
+
81
+ new_v = v * scale[..., np.newaxis]
82
+
83
+ result = np.concatenate([new_v, new_w[..., np.newaxis]], axis=-1)
84
+ return result
85
+
86
+
87
+ def sum_weighted_quat_poses(
88
+ restPose: np.ndarray, # (N, 4) float
89
+ targets: np.ndarray, # (T, N, 4) float
90
+ weights: np.ndarray, # T float
91
+ levels: np.ndarray, # T int
92
+ ) -> np.ndarray: # (N, 4) float
93
+ """Perform a "weighted sum" of target poses of quaternions with multiple
94
+ levels. Each level is calculated individually, then multiplied in order
95
+ to get the final output.
96
+
97
+ This assumes Scalar (W) Last formatted quaternions
98
+
99
+ This uses some interesting math that I don't fully understand. But the idea
100
+ came from a NASA paper on the topic.
101
+
102
+ Apparently if you sum a bunch of the outer products of quaternions with
103
+ themselves, and then take the largest eigenvector of the resulting 4x4
104
+ matrix, that eigenvector is (in some sense) the average of those quaternions.
105
+
106
+ The naiive idea of an average is the sum divided by the count. So if you
107
+ multiply an average value by the count, you should get back the sum.
108
+
109
+ So if I take this "average" of quaternions and do a "multiplication" by the
110
+ count, I should get back something that looks like a "sum" of the quaternions
111
+
112
+ And to do "multiplication by the count", I just extrapolate the quaternion
113
+ by slerping it to that count.
114
+
115
+ This may not be "correct", but it sure seems to behave like I want it to.
116
+ And that's all that matters for this application.
117
+
118
+ Args:
119
+ restPose (np.array[N, 4]): An array of quaternions
120
+ targets (np.array[T, N, 4]): An array of target poses of quaternions
121
+ weights (np.array[T]): The weight of each target
122
+ levels (np.array[T]): The level of each target
123
+
124
+ Returns:
125
+ np.array[N, 4]: An array of quaternions
126
+ """
127
+ targets = norm_quats(targets)
128
+ restPose = norm_quats(restPose)
129
+
130
+ # Get the existing levels, and how many poses are at each level
131
+ exlev, counts = np.unique(levels, return_counts=True)
132
+ s_exlev = np.argsort(exlev)
133
+ exlev = exlev[s_exlev]
134
+ counts = counts[s_exlev]
135
+
136
+ # Get the targets in the space of the rest pose
137
+ restInv = inverse_quats(restPose)
138
+ relTargets = mul_quats(targets, restInv[None])
139
+
140
+ # Apply the weights to all the targets
141
+ slerped = quaternion_pow(relTargets, weights[..., None])
142
+
143
+ # Get the outer product of all the quaternions
144
+ # and sum them by level
145
+ outs = outer(slerped)
146
+ levelEigs = np.zeros((exlev[-1] + 1, len(restPose), 4, 4))
147
+ np.add.at(levelEigs, levels, outs)
148
+ levelEigs = levelEigs[exlev]
149
+
150
+ # Get largest eigenvalue for each matrix
151
+ # This represents the *average* of each level
152
+ evals, evecs = np.linalg.eig(levelEigs)
153
+ mvals = np.argmax(np.abs(evals), axis=-1)[..., None, None]
154
+ averages = np.take_along_axis(evecs, mvals, axis=evecs.ndim - 1).squeeze(axis=-1)
155
+ averages = norm_quats(averages)
156
+
157
+ # Take each level's pose to the power of its count
158
+ sums = quaternion_pow(averages, counts[:, None])
159
+ sums = norm_quats(sums)
160
+
161
+ # Finally multiply the poses together on top of the rest pose
162
+ qret = restPose.copy()
163
+ for x in sums:
164
+ qret = mul_quats(x, qret)
165
+
166
+ return qret
@@ -0,0 +1,102 @@
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
+ """Transfer shapes between mismatched models
19
+
20
+ Given a 1:1 point correspondence, transfer the shapes from one
21
+ geometry to another. Figuring out the correspondence is currently
22
+ outside the scope of this tool, though I may release one later.
23
+
24
+ The point correspondence should look like an unordered range, and
25
+ will be used as a numpy index to get the output values. It's also
26
+ possible to invert the range if you think you've got it backwards
27
+ """
28
+
29
+ # pylint:disable=wrong-import-position
30
+ import json
31
+
32
+ from .alembicCommon import buildSmpx, readSmpx
33
+
34
+ try:
35
+ import numpy as np
36
+ except ImportError:
37
+ pass
38
+
39
+
40
+ def reorderSimplexPoints(sourcePath, matchPath, outPath, invertMatch=False):
41
+ """Transfer shape data from the sourcePath using the numpy int array
42
+ at matchPath to make the final output at outPath
43
+
44
+ Parameters
45
+ ----------
46
+ sourcePath : str
47
+ The source .smpx file path
48
+ matchPath : str
49
+ The new vert order in numpy, or json format. The data should be an Nx2 array
50
+ of integers
51
+ outPath : str
52
+ The new output .smpx path
53
+ invertMatch : bool
54
+ Whether to directly apply the match from matchPath, or whether to invert it
55
+
56
+ Returns
57
+ -------
58
+
59
+ """
60
+ jsString, counts, verts, faces, uvs, uvFaces = readSmpx(sourcePath)
61
+
62
+ js = json.loads(jsString)
63
+ name = js["systemName"]
64
+
65
+ print("Loading Correspondence")
66
+ if matchPath.endswith(".json"):
67
+ with open(matchPath, "r") as f:
68
+ c = json.load(f)
69
+ c = np.array(c)
70
+ else:
71
+ c = np.load(matchPath)
72
+
73
+ c = c[c[:, 0].argsort()].T[1]
74
+ ci = c.argsort()
75
+ if invertMatch:
76
+ ci, c = c, ci
77
+
78
+ print("Reordering")
79
+ verts = verts[:, c, :]
80
+ faces = ci[faces]
81
+
82
+ buildSmpx(
83
+ outPath,
84
+ verts,
85
+ faces,
86
+ jsString,
87
+ name,
88
+ faceCounts=counts,
89
+ uvs=uvs,
90
+ uvFaces=uvFaces,
91
+ )
92
+
93
+
94
+ if __name__ == "__main__":
95
+ import os
96
+
97
+ base = r"K:\Departments\CharacterModeling\Library\Head\MaleHead_Standard\005"
98
+ _sourcePath = os.path.join(base, "HeadMaleStandard_High_Split_BadOrder.smpx")
99
+ _matchPath = os.path.join(base, "Reorder.np")
100
+ _outPath = os.path.join(base, "HeadMaleStandard_High_Split2.smpx")
101
+
102
+ reorderSimplexPoints(_sourcePath, _matchPath, _outPath)
@@ -0,0 +1,99 @@
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
+ try:
19
+ import numpy as np
20
+ except ImportError:
21
+ pass
22
+
23
+
24
+ def rigidAlign(P, Q, iters=10):
25
+ """Rigidly align meshes with matching vert order by a least-squares error.
26
+ Uses a variation of an algorithm by Umeyama
27
+ Relevant links:
28
+ * https://gist.github.com/nh2/bc4e2981b0e213fefd4aaa33edfb3893 (this code)
29
+ * http://stackoverflow.com/a/32244818/263061 (solution with scale)
30
+
31
+ Parameters
32
+ ----------
33
+ P : np.array
34
+ Static set of points
35
+ Q : np.array
36
+ Points to align with non-uniform scale
37
+ iters : int
38
+ The number of iterations (Defaults to 10)
39
+
40
+ Returns
41
+ -------
42
+ : np.array
43
+ The 4x4 transformation matrix that most closely aligns Q to P
44
+ """
45
+ # pylint:disable=invalid-name
46
+ assert P.shape == Q.shape
47
+
48
+ n, dim = P.shape
49
+ assert dim == 3
50
+
51
+ if iters <= 1:
52
+ raise ValueError("Must run at least 1 iteration")
53
+
54
+ # Get the centroid of each object
55
+ Qm = Q.mean(axis=0)
56
+ Pm = P.mean(axis=0)
57
+
58
+ # Subtract out the centroid to get the basic aligned mesh
59
+ cP = P - Pm # centeredP
60
+ cQRaw = Q - Qm # centeredQ
61
+
62
+ cQ = cQRaw.copy()
63
+ cumulation = np.eye(3) # build an accumulator for the rotation
64
+
65
+ # Here, we find an approximate rotation and scaling, but only
66
+ # keep track of the accumulated rotations.
67
+ # Then we apply the non-uniform scale by comparing bounding boxes
68
+ # This way we don't get any shear in our matrix, and we relatively
69
+ # quickly walk our way towards a minimum
70
+ for _ in range(iters):
71
+ # Magic?
72
+ C = np.dot(cP.T, cQ) / n
73
+ V, S, W = np.linalg.svd(C)
74
+
75
+ # Handle negative scaling
76
+ d = (np.linalg.det(V) * np.linalg.det(W)) < 0.0
77
+ if d:
78
+ S[-1] = -S[-1]
79
+ V[:, -1] = -V[:, -1]
80
+
81
+ # build the rotation matrix for this iteration
82
+ # and add it to the accumulation
83
+ R = np.dot(V, W)
84
+ cumulation = np.dot(cumulation, R.T)
85
+
86
+ # Now apply the accumulated rotation to the raw point positions
87
+ # Then grab the non-uniform scaling from the bounding box
88
+ # And set up cQ for the next iteration
89
+ cQ = np.dot(cQRaw, cumulation)
90
+ sf = (cP.max(axis=0) - cP.min(axis=0)) / (cQ.max(axis=0) - cQ.min(axis=0))
91
+ cQ = cQ * sf
92
+
93
+ # Build the final transformation
94
+ csf = cumulation * sf
95
+ tran = Pm - Qm.dot(csf)
96
+ outMat = np.eye(4)
97
+ outMat[:3, :3] = csf
98
+ outMat[3, :3] = tran
99
+ return outMat