simplex-solver 3.2.2__cp39-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. simplex_solver-3.2.2.dist-info/DELVEWHEEL +2 -0
  2. simplex_solver-3.2.2.dist-info/METADATA +94 -0
  3. simplex_solver-3.2.2.dist-info/RECORD +84 -0
  4. simplex_solver-3.2.2.dist-info/WHEEL +5 -0
  5. simplex_solver.libs/.load-order-simplex_solver-3.2.2 +1 -0
  6. simplex_solver.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
  7. simplexui/__init__.py +86 -0
  8. simplexui/_version.py +1 -0
  9. simplexui/channelBox.py +867 -0
  10. simplexui/comboCheckDialog.py +396 -0
  11. simplexui/commands/__init__.py +16 -0
  12. simplexui/commands/alembicCommon.py +1148 -0
  13. simplexui/commands/alembic_walker.py +299 -0
  14. simplexui/commands/applyCorrectives.py +452 -0
  15. simplexui/commands/correctiveInterface.py +259 -0
  16. simplexui/commands/expandedExport.py +434 -0
  17. simplexui/commands/hdf5Convert.py +62 -0
  18. simplexui/commands/mayaCorrectiveInterface.py +159 -0
  19. simplexui/commands/mayatonumpy.py +416 -0
  20. simplexui/commands/mesh.py +1085 -0
  21. simplexui/commands/poseblendlib.py +168 -0
  22. simplexui/commands/reorderSimplexPoints.py +102 -0
  23. simplexui/commands/replaceDefinitionJson.py +74 -0
  24. simplexui/commands/rigidAlign.py +97 -0
  25. simplexui/commands/unsubdivide.py +1222 -0
  26. simplexui/commands/uvTransfer.py +976 -0
  27. simplexui/dragFilter.py +334 -0
  28. simplexui/falloffDialog.py +504 -0
  29. simplexui/img/ChefHead.png +0 -0
  30. simplexui/img/frozen.png +0 -0
  31. simplexui/interface/__init__.py +30 -0
  32. simplexui/interface/dummyInterface.py +1313 -0
  33. simplexui/interface/mayaInterface.py +2294 -0
  34. simplexui/interfaceModel.py +655 -0
  35. simplexui/interfaceModelTrees.py +456 -0
  36. simplexui/items/__init__.py +50 -0
  37. simplexui/items/accessor.py +145 -0
  38. simplexui/items/combo.py +645 -0
  39. simplexui/items/dragItem.py +44 -0
  40. simplexui/items/falloff.py +748 -0
  41. simplexui/items/group.py +267 -0
  42. simplexui/items/progression.py +613 -0
  43. simplexui/items/shape.py +384 -0
  44. simplexui/items/simplex.py +1734 -0
  45. simplexui/items/slider.py +632 -0
  46. simplexui/items/stack.py +147 -0
  47. simplexui/items/traversal.py +780 -0
  48. simplexui/items/treeItem.py +441 -0
  49. simplexui/main.pyw +22 -0
  50. simplexui/menu/__init__.py +73 -0
  51. simplexui/menu/dummyPlugins/__init__.py +16 -0
  52. simplexui/menu/genericPlugins/__init__.py +16 -0
  53. simplexui/menu/genericPlugins/_builtins.py +270 -0
  54. simplexui/menu/genericPlugins/checkPossibleCombos.py +48 -0
  55. simplexui/menu/genericPlugins/exportSplit.py +67 -0
  56. simplexui/menu/genericPlugins/showFalloffs.py +26 -0
  57. simplexui/menu/genericPlugins/showTraversals.py +26 -0
  58. simplexui/menu/genericPlugins/simplexUvTransfer.py +106 -0
  59. simplexui/menu/genericPlugins/unsubdivide.py +72 -0
  60. simplexui/menu/mayaPlugins/__init__.py +16 -0
  61. simplexui/menu/mayaPlugins/exportOther.py +53 -0
  62. simplexui/menu/mayaPlugins/extractProgressives.py +68 -0
  63. simplexui/menu/mayaPlugins/freezeCombo.py +247 -0
  64. simplexui/menu/mayaPlugins/generateShapeIncrementals.py +99 -0
  65. simplexui/menu/mayaPlugins/importObjs.py +199 -0
  66. simplexui/menu/mayaPlugins/linearizeTraversal.py +60 -0
  67. simplexui/menu/mayaPlugins/makeShelfBtn.py +67 -0
  68. simplexui/menu/mayaPlugins/relaxToSelection.py +76 -0
  69. simplexui/menu/mayaPlugins/reloadDefinition.py +44 -0
  70. simplexui/menu/mayaPlugins/snapToNeutral.py +71 -0
  71. simplexui/menu/mayaPlugins/softSelectToCluster.py +201 -0
  72. simplexui/menu/mayaPlugins/tweakMix.py +136 -0
  73. simplexui/menu/mayaPlugins/updateRestShape.py +113 -0
  74. simplexui/pysimplex.lib +0 -0
  75. simplexui/pysimplex.pyd +0 -0
  76. simplexui/simplexDialog.py +1547 -0
  77. simplexui/travCheckDialog.py +419 -0
  78. simplexui/traversalDialog.py +299 -0
  79. simplexui/ui/comboCheckDialog.ui +475 -0
  80. simplexui/ui/falloffDialog.ui +243 -0
  81. simplexui/ui/simplexDialog.ui +1458 -0
  82. simplexui/ui/travCheckDialog.ui +488 -0
  83. simplexui/ui/traversalDialog.ui +532 -0
  84. simplexui/utils.py +307 -0
@@ -0,0 +1,748 @@
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 copy
20
+ import math
21
+ from typing import TYPE_CHECKING, Any
22
+
23
+ import numpy as np
24
+ from numpy import typing as npt
25
+
26
+ from .accessor import SimplexAccessor
27
+ from .stack import stackable
28
+
29
+ if TYPE_CHECKING:
30
+ from .progression import Progression
31
+ from .shape import Shape
32
+ from .simplex import DCCObject, Simplex
33
+
34
+
35
+ class SplitDefinition:
36
+ """A class defining how splits are applied to a system"""
37
+
38
+ LEFTSIDE: str = "L"
39
+ RIGHTSIDE: str = "R"
40
+ TOPSIDE: str = "U"
41
+ BOTTOMSIDE: str = "D"
42
+ FRONTSIDE: str = "F"
43
+ BACKSIDE: str = "B"
44
+ ALLSIDES: str = LEFTSIDE + RIGHTSIDE + TOPSIDE + BOTTOMSIDE + FRONTSIDE + BACKSIDE
45
+
46
+ CENTERS: str = "MC"
47
+
48
+ VERTICAL_SPLIT: str = "V"
49
+ VERTICAL_RESULTS: str = TOPSIDE + BOTTOMSIDE
50
+ VERTICAL_AXIS: str = "Y"
51
+ VERTICAL_AXISINDEX: int = 1
52
+
53
+ HORIZONTAL_SPLIT: str = "X"
54
+ HORIZONTAL_RESULTS: str = LEFTSIDE + RIGHTSIDE
55
+ HORIZONTAL_AXIS: str = "X"
56
+ HORIZONTAL_AXISINDEX: int = 0
57
+
58
+ DEPTH_SPLIT: str = "Z"
59
+ DEPTH_RESULTS: str = FRONTSIDE + BACKSIDE
60
+ DEPTH_AXIS: str = "Z"
61
+ DEPTH_AXISINDEX: int = 2
62
+
63
+ RESTNAME: str = "Rest"
64
+ SEP: str = "_"
65
+
66
+ def getComponentIndex(self, axis: str) -> int:
67
+ """Get the axis index. Usually x->1 y->2 z->3"""
68
+ axis = axis.lower()
69
+ if axis == self.HORIZONTAL_AXIS.lower():
70
+ return self.HORIZONTAL_AXISINDEX
71
+ elif axis == self.VERTICAL_AXIS.lower():
72
+ return self.VERTICAL_AXISINDEX
73
+ elif axis == self.DEPTH_AXIS.lower():
74
+ return self.DEPTH_AXISINDEX
75
+ raise ValueError(f"Invalid Axis: {axis}")
76
+
77
+ def getSearchRep(self, axis: str) -> tuple[str, str]:
78
+ if axis.lower() == self.HORIZONTAL_AXIS.lower():
79
+ return self.HORIZONTAL_SPLIT, self.HORIZONTAL_RESULTS
80
+ elif axis.lower() == self.VERTICAL_AXIS.lower():
81
+ return self.VERTICAL_SPLIT, self.VERTICAL_RESULTS
82
+ elif axis.lower() == self.DEPTH_AXIS.lower():
83
+ return self.DEPTH_SPLIT, self.DEPTH_RESULTS
84
+ raise ValueError(f"Invalid Axis: {axis}")
85
+
86
+
87
+ class Falloff(SimplexAccessor):
88
+ """Falloffs define how shapes are split left/right, front/back, top/bottom, or however else
89
+
90
+ Falloffs are the core of the splitting algorithm built into Simplex.
91
+ When splitting, they define how shapes are duplicated and renamed, as well as
92
+ how the deltas are multiplied.
93
+
94
+ Currently only axis-aligned planar falloffs are fully defined and supported, but there are plans
95
+ for per-point falloffs (weightmap), oriented planes, and other implicit geometric shapes.
96
+
97
+ A planar falloff is a worldspace value field where any point past falloff min has the min value,
98
+ any point past the max has the max value, and any point in between is defined by user-controlled curve
99
+ Maya users might think of this as a planar projection of a ramp.
100
+
101
+ A group of static variables controls how splits are detected and renamed. Names are split by
102
+ Falloff.SEP and the split chunks are matched to the items below. In some cases, rather than
103
+ lists of characters, I just use a string.
104
+
105
+ These define the strings identifying their eponymous sides:
106
+ LEFTSIDE, RIGHTSIDE, TOPSIDE, BOTTOMSIDE, FRONTSIDE, BACKSIDE
107
+
108
+ This is a character list definint the single-character values that define centered shapes:
109
+ CENTERS
110
+
111
+ These define the strings that are detected to find splits.
112
+ For instance, if HORIZONTAL_SPLIT="X", then cornerPuller_X would split across the X axis,
113
+ and the new items would be given names
114
+
115
+ ::
116
+ "cornerPuller_{}".format(LEFTSIDE)
117
+ "cornerPuller_{}".format(RIGHTSIDE)
118
+
119
+ VERTICAL_SPLIT, VERTICAL_AXIS, VERTICAL_AXISINDEX
120
+ HORIZONTAL_SPLIT, HORIZONTAL_AXIS, HORIZONTAL_AXISINDEX
121
+ DEPTH_SPLIT, DEPTH_AXIS, DEPTH_AXISINDEX,
122
+
123
+ Parameters
124
+ ----------
125
+ name : str
126
+ The name of the falloff
127
+ simplex : Simplex
128
+ The Simplex system
129
+ *data : list
130
+ The data used to build this falloff.
131
+ You should use one of the classmethod like Falloff.createPlanar or Falloff.createMap instead
132
+ """
133
+ splitType = None
134
+
135
+ def __init__(self, name: str, simplex: Simplex, axis: str) -> None:
136
+ super().__init__(simplex)
137
+ with self.stack.store(self):
138
+ self._search: str | None = None
139
+ self._rep: str | None = None
140
+ self._weights: npt.NDArray | None = None
141
+ self._verts: npt.NDArray | None = None
142
+ self._thing: DCCObject | None = None
143
+ self._thingRepr: str | None = None
144
+
145
+ self._axis: str = axis
146
+ self._name: str = name
147
+ self.children: list[Progression] = []
148
+ self._buildIdx: int | None = None
149
+ self.simplex.falloffs.append(self)
150
+
151
+ @property
152
+ def name(self) -> str:
153
+ """Get the name of a Falloff"""
154
+ return self._name
155
+
156
+ @name.setter
157
+ @stackable
158
+ def name(self, value: str) -> None:
159
+ """Set the name of a Falloff"""
160
+ self._name = value
161
+
162
+ @classmethod
163
+ def createMap(
164
+ cls, name: str, simplex: Simplex, mapName: str, axis: str
165
+ ) -> MapFalloff:
166
+ # Note that MapName and Axis are swapped
167
+ # This is to provide backward compatibility.
168
+ # You should just make the MapFalloff object directly
169
+ assert len(axis) == 1, "Looks like you got mapName and axis swapped"
170
+ return MapFalloff(name, simplex, axis, mapName)
171
+
172
+ @classmethod
173
+ def createPlanar(
174
+ cls,
175
+ name: str,
176
+ simplex: Simplex,
177
+ axis: str,
178
+ maxVal: float,
179
+ maxHandle: float,
180
+ minHandle: float,
181
+ minVal: float,
182
+ ) -> PlanarFalloff:
183
+ return PlanarFalloff(
184
+ name,
185
+ simplex,
186
+ axis,
187
+ maxVal,
188
+ maxHandle,
189
+ minHandle,
190
+ minVal,
191
+ )
192
+
193
+ @classmethod
194
+ def loadV2(cls, simplex: Simplex, data: dict[str, Any]) -> Falloff:
195
+ """Load the falloff from the version 2 json specification
196
+
197
+ Parameters
198
+ ----------
199
+ simplex : Simplex
200
+ The Simplex system
201
+ data : dict
202
+ The data to load
203
+
204
+ Returns
205
+ -------
206
+ : Falloff
207
+ The specified Falloff
208
+ """
209
+ tpe = data["type"]
210
+ name = data["name"]
211
+ axis = data["axis"]
212
+ if tpe == "map":
213
+ return MapFalloff.createMap(name, simplex, data["mapName"], axis)
214
+ elif tpe == "planar":
215
+ maxVal = data["maxVal"]
216
+ maxHandle = data["maxHandle"]
217
+ minHandle = data["minHandle"]
218
+ minVal = data["minVal"]
219
+ return PlanarFalloff.createPlanar(
220
+ name, simplex, axis, maxVal, maxHandle, minHandle, minVal
221
+ )
222
+
223
+ raise ValueError("Bad data passed to Falloff creation")
224
+
225
+ def buildDefinition(self, simpDict: dict[str, Any], legacy: bool) -> int:
226
+ """Output a dictionary definition of this object
227
+
228
+ Parameters
229
+ ----------
230
+ simpDict : dict
231
+ The dictionary that is being built
232
+ legacy : bool
233
+ Whether to write out the legacy definition, or the newer one
234
+ """
235
+ raise NotImplementedError("Can't build definition on an untyped falloff")
236
+
237
+ def clearBuildIndex(self) -> None:
238
+ """Clear the build index of this object
239
+
240
+ The buildIndex is stored when building a definition dictionary
241
+ that keeps track of its index for later referencing
242
+ """
243
+ self._buildIdx = None
244
+
245
+ @stackable
246
+ def duplicate(self, newName: str) -> Falloff:
247
+ """Duplicate a Falloff with a new name
248
+
249
+ Parameters
250
+ ----------
251
+ newName : str
252
+ The name to give the new Falloff
253
+
254
+ Returns
255
+ -------
256
+ : Falloff
257
+ The newly duplicated Falloff
258
+ """
259
+ nf = copy.copy(self)
260
+ nf.name = newName
261
+ nf.children = []
262
+ nf.clearBuildIndex()
263
+ self.simplex.falloffs.append(nf)
264
+ self.DCC.duplicateFalloff(self, nf)
265
+ return nf
266
+
267
+ @stackable
268
+ def delete(self) -> None:
269
+ """Delete the Falloff"""
270
+ fIdx = self.simplex.falloffs.index(self)
271
+ for child in self.children:
272
+ child.removeFalloff(self)
273
+
274
+ self.simplex.falloffs.pop(fIdx)
275
+ self.DCC.deleteFalloff(self)
276
+
277
+ @property
278
+ def axis(self) -> str:
279
+ return self._axis
280
+
281
+ @axis.setter
282
+ @stackable
283
+ def axis(self, value: str) -> None:
284
+ self._axis = value
285
+ # TODO: Does this need to update the dcc??
286
+
287
+ @property
288
+ def verts(self) -> npt.NDArray | None:
289
+ """Get the stored vertex values"""
290
+ return self._verts
291
+
292
+ @verts.setter
293
+ def verts(self, vals: npt.NDArray) -> None:
294
+ """Input the vertices into this falloff and compute the weights
295
+
296
+ Parameters
297
+ ----------
298
+ vals : np.array
299
+ A (Nx3) numpy array of vertices
300
+ """
301
+ self._verts = vals
302
+
303
+ @property
304
+ def weights(self) -> npt.NDArray | None:
305
+ """Get the per-vertex weight values"""
306
+ return self._weights
307
+
308
+ @weights.setter
309
+ def weights(self, val: npt.ArrayLike) -> None:
310
+ """Set the per-vertex weight values
311
+
312
+ Parameters
313
+ ----------
314
+ val : A list or numpy array of values between 0 and 1
315
+ """
316
+ self._weights = np.asarray(val)
317
+
318
+ def getSidedName(self, name: str, sIdx: int) -> str:
319
+ """Take name to split along some axis, and replace the fields based on the index
320
+ For instance, this could take cp_X and return cp_L for sIdx=1 and cp_R for sIdx=2
321
+
322
+ Parameters
323
+ ----------
324
+ name : str
325
+ The name to "split" with this falloff
326
+ sIdx : int
327
+ The index of the replacement value
328
+
329
+ Returns
330
+ -------
331
+ : str
332
+ The newly sided name
333
+ """
334
+ sdef = self.simplex.sdef
335
+ search, replaces = sdef.getSearchRep(self.axis)
336
+ replace = replaces[sIdx]
337
+
338
+ nn = name
339
+ s = f"{sdef.SEP}{search}{sdef.SEP}"
340
+ r = f"{sdef.SEP}{replace}{sdef.SEP}"
341
+ nn = nn.replace(s, r)
342
+
343
+ s = f"{sdef.SEP}{search}" # handle Postfix
344
+ r = f"{sdef.SEP}{replace}"
345
+ if nn.endswith(s):
346
+ nn = r.join(nn.rsplit(s, 1))
347
+
348
+ s = f"{search}{sdef.SEP}" # handle Prefix
349
+ r = f"{replace}{sdef.SEP}"
350
+ if nn.startswith(s):
351
+ nn = nn.replace(s, r, 1)
352
+ return nn
353
+
354
+ def canRename(self, item: SimplexAccessor) -> bool:
355
+ """Check if the item can be renamed by this Falloff
356
+
357
+ Parameters
358
+ ----------
359
+ item : object
360
+ The named simplex object to check
361
+
362
+ Returns
363
+ -------
364
+ : bool
365
+ Whether this object can be renamed
366
+ """
367
+ nn = self.getSidedName(item.name, 0)
368
+ return nn != item.name
369
+
370
+ def splitRename(self, item: SimplexAccessor, sIdx: int) -> None:
371
+ """Actually run the rename for a particular item
372
+
373
+ Parameters
374
+ ----------
375
+ item : object
376
+ The named Simplex Item
377
+ sIdx : int
378
+ The replacement index
379
+ """
380
+ from .combo import Combo
381
+ from .shape import Shape
382
+ from .slider import Slider
383
+ from .traversal import Traversal
384
+
385
+ if isinstance(item, (Shape, Slider, Combo, Traversal)):
386
+ item.name = self.getSidedName(item.name, sIdx)
387
+
388
+ def applyFalloff(self, shape: Shape, sIdx: int) -> None:
389
+ """Apply the falloff to the vertices of a shape
390
+
391
+ Parameters
392
+ ----------
393
+ shape : Shape
394
+ The shape to apply to
395
+ sIdx : int
396
+ The replacement index
397
+ """
398
+ rest = self.simplex.restShape
399
+ if rest is None:
400
+ raise ValueError("Trying to apply a falloff on system with no rest shape")
401
+ if rest.verts is None:
402
+ raise ValueError(
403
+ "Trying to apply a falloff to a shape with unset rest verts"
404
+ )
405
+ weights = self.weights
406
+ if weights is None:
407
+ raise ValueError("Weights are not properly set for this falloff")
408
+
409
+ if sIdx == 1:
410
+ weights = 1 - weights
411
+
412
+ if shape.verts is None:
413
+ raise ValueError("Trying to apply a falloff to a shape with unset verts")
414
+
415
+ weightedDeltas = (shape.verts - rest.verts) * weights[:, None]
416
+
417
+ shape.verts = weightedDeltas + rest.verts
418
+
419
+
420
+ class PlanarFalloff(Falloff):
421
+ splitType: str = "planar"
422
+
423
+ def __init__(
424
+ self,
425
+ name: str,
426
+ simplex: Simplex,
427
+ axis: str,
428
+ maxVal: float,
429
+ maxHandle: float,
430
+ minHandle: float,
431
+ minVal: float,
432
+ ) -> None:
433
+ self._maxVal = maxVal
434
+ self._maxHandle = maxHandle
435
+ self._minHandle = minHandle
436
+ self._minVal = minVal
437
+ self._bezier = None
438
+ super().__init__(name, simplex, axis)
439
+
440
+ @stackable
441
+ def setPlanarData(
442
+ self,
443
+ axis: str,
444
+ minVal: float,
445
+ minHandle: float,
446
+ maxHandle: float,
447
+ maxVal: float,
448
+ ) -> None:
449
+ """Set the type/data for a planar Falloff
450
+
451
+ Parameters
452
+ ----------
453
+ axis : str
454
+ The axis to align the falloff to. X, Y, or Z
455
+ maxVal : float
456
+ The value past which the falloff is 1.0
457
+ maxHandle : float
458
+ The (0, 1) range of the max cubic falloff handle
459
+ minHandle : float
460
+ The (0, 1) range of the min cubic falloff handle
461
+ minVal : float
462
+ The value past which the falloff is 0.0
463
+ """
464
+ self.axis = axis
465
+ self.minVal = minVal
466
+ self.minHandle = minHandle
467
+ self.maxHandle = maxHandle
468
+ self.maxVal = maxVal
469
+ self._updateDCC()
470
+
471
+ @property
472
+ def maxVal(self) -> float:
473
+ return self._maxVal
474
+
475
+ @maxVal.setter
476
+ @stackable
477
+ def maxVal(self, value: float) -> None:
478
+ self._maxVal = value
479
+ self._updateDCC()
480
+
481
+ @property
482
+ def maxHandle(self) -> float:
483
+ return self._maxHandle
484
+
485
+ @maxHandle.setter
486
+ @stackable
487
+ def maxHandle(self, value: float) -> None:
488
+ self._maxHandle = value
489
+ self._updateDCC()
490
+
491
+ @property
492
+ def minHandle(self) -> float:
493
+ return self._minHandle
494
+
495
+ @minHandle.setter
496
+ @stackable
497
+ def minHandle(self, value: float) -> None:
498
+ self._minHandle = value
499
+ self._updateDCC()
500
+
501
+ @property
502
+ def minVal(self) -> float:
503
+ return self._minVal
504
+
505
+ @minVal.setter
506
+ @stackable
507
+ def minVal(self, value: float) -> None:
508
+ self._minVal = value
509
+ self._updateDCC()
510
+
511
+ @property
512
+ def verts(self) -> npt.NDArray | None:
513
+ """Get the stored vertex values"""
514
+ return self._verts
515
+
516
+ @verts.setter
517
+ def verts(self, vals: npt.NDArray) -> None:
518
+ """Input the vertices into this falloff and compute the weights
519
+
520
+ Parameters
521
+ ----------
522
+ vals : np.array
523
+ A (Nx3) numpy array of vertices
524
+ """
525
+ # Clear out the weights since they're calculated
526
+ self._weights = None
527
+ self._verts = vals
528
+
529
+ def _updateDCC(self) -> None:
530
+ """ """
531
+ # TODO: Separate Map and Planar falloff data
532
+ self.DCC.setFalloffData(
533
+ self,
534
+ 'planar',
535
+ self.axis,
536
+ self.minVal,
537
+ self.minHandle,
538
+ self.maxHandle,
539
+ self.maxVal,
540
+ None,
541
+ )
542
+
543
+ @property
544
+ def bezier(self) -> tuple[float, float, float, float]:
545
+ """Pre-build a factorization of the cubic bezier curve that is being used for a falloff
546
+ Based on method described at https://pomax.github.io/bezierinfo/#yforx
547
+ """
548
+ if self._bezier is None:
549
+ p0x = 0.0
550
+ p1x = self.minHandle
551
+ p2x = self.maxHandle
552
+ p3x = 1.0
553
+
554
+ f = p1x - p0x
555
+ g = p3x - p2x
556
+ d = 3 * f + 3 * g - 2
557
+ n = 2 * f + g - 1
558
+ r = (n * n - f * d) / (d * d)
559
+ qq = (3 * f * d * n - 2 * n * n * n) / (d * d * d)
560
+ self._bezier = (qq, r, d, n)
561
+ return self._bezier
562
+
563
+ # Split code
564
+ def getMultiplier(self, xVal: float) -> float:
565
+ """Get the weight value for the given X
566
+
567
+ Parameters
568
+ ----------
569
+ xVal : float
570
+ The value to get the weight for
571
+
572
+ Returns
573
+ -------
574
+ : float
575
+ The weight
576
+ """
577
+ # Vertices are assumed to be at (0,0) and (1,1)
578
+ if xVal <= self.minVal:
579
+ return 0.0
580
+ if xVal >= self.maxVal:
581
+ return 1.0
582
+
583
+ tVal = float(xVal - self.minVal) / float(self.maxVal - self.minVal)
584
+ qq, r, d, n = self.bezier
585
+ q = qq - tVal / d
586
+ discriminant = q * q - 4 * r * r * r
587
+ if discriminant >= 0:
588
+ pm = (discriminant**0.5) / 2
589
+ w = (-q / 2 + pm) ** (1 / 3.0)
590
+ u = w + r / w
591
+ else:
592
+ theta = math.acos(-q / (2 * r ** (3 / 2.0)))
593
+ phi = theta / 3 + 4 * math.pi / 3
594
+ u = 2 * r ** (0.5) * math.cos(phi)
595
+ t = u + n / d
596
+ t1 = 1 - t
597
+ return 3 * t1 * t**2 * 1 + t**3 * 1
598
+
599
+ @property
600
+ def weights(self) -> npt.NDArray:
601
+ """Get the per-vertex weight values"""
602
+
603
+ if self._weights is None:
604
+ if self._verts is None:
605
+ raise ValueError(
606
+ f"Attempted to auto-compute weights of a procedural falloff without setting verts: {self.name}"
607
+ )
608
+ component = self.simplex.sdef.getComponentIndex(self.axis)
609
+ self._weights = np.array(
610
+ [self.getMultiplier(v[component]) for v in self._verts]
611
+ )
612
+
613
+ return self._weights
614
+
615
+ @weights.setter
616
+ def weights(self, val: npt.ArrayLike) -> None:
617
+ """Set the per-vertex weight values
618
+
619
+ Parameters
620
+ ----------
621
+ val : A list or numpy array of values between 0 and 1
622
+ """
623
+ self._weights = np.asarray(val)
624
+
625
+ def buildDefinition(self, simpDict: dict[str, Any], legacy: bool) -> int:
626
+ """Output a dictionary definition of this object
627
+
628
+ Parameters
629
+ ----------
630
+ simpDict : dict
631
+ The dictionary that is being built
632
+ legacy : bool
633
+ Whether to write out the legacy definition, or the newer one
634
+ """
635
+ if self._buildIdx is None:
636
+ self._buildIdx = len(simpDict["falloffs"])
637
+ if legacy:
638
+ line = [
639
+ "planar",
640
+ self.axis,
641
+ self.maxVal,
642
+ self.maxHandle,
643
+ self.minHandle,
644
+ self.minVal,
645
+ ]
646
+ simpDict.setdefault("falloffs", []).append([self.name] + line)
647
+ else:
648
+ x = {
649
+ "name": self.name,
650
+ "type": "planar",
651
+ "axis": self.axis,
652
+ "maxVal": self.maxVal,
653
+ "maxHandle": self.maxHandle,
654
+ "minHandle": self.minHandle,
655
+ "minVal": self.minVal,
656
+ }
657
+ simpDict.setdefault("falloffs", []).append(x)
658
+ return self._buildIdx
659
+
660
+
661
+ class MapFalloff(Falloff):
662
+ splitType: str = "map"
663
+
664
+ def __init__(self, name: str, simplex: Simplex, axis: str, mapName: str) -> None:
665
+ self._mapName = mapName
666
+ super().__init__(name, simplex, axis)
667
+
668
+ @stackable
669
+ def setMapData(self, axis: str, mapName: str) -> None:
670
+ """Set the type/data for a map Falloff
671
+
672
+ Parameters
673
+ ----------
674
+ mapName : str
675
+ The name of the weightmap
676
+ """
677
+ self.axis = axis
678
+ self.mapName = mapName
679
+ self._updateDCC()
680
+
681
+ @property
682
+ def mapName(self) -> str:
683
+ return self._mapName
684
+
685
+ @mapName.setter
686
+ @stackable
687
+ def mapName(self, value: str) -> None:
688
+ self._mapName = value
689
+ self._updateDCC()
690
+
691
+ def _updateDCC(self) -> None:
692
+ """ """
693
+ # TODO: Separate Map and Planar falloff data
694
+ self.DCC.setFalloffData(
695
+ self,
696
+ "map",
697
+ self.axis,
698
+ None,
699
+ None,
700
+ None,
701
+ None,
702
+ self.mapName,
703
+ )
704
+
705
+ @property
706
+ def weights(self) -> npt.NDArray:
707
+ """Get the per-vertex weight values"""
708
+
709
+ if self._weights is None:
710
+ raise ValueError(
711
+ f"Attempted to auto-compute weights of a map falloff: {self.name}"
712
+ )
713
+ return self._weights
714
+
715
+ @weights.setter
716
+ def weights(self, val: npt.ArrayLike) -> None:
717
+ """Set the per-vertex weight values
718
+
719
+ Parameters
720
+ ----------
721
+ val : A list or numpy array of values between 0 and 1
722
+ """
723
+ self._weights = np.asarray(val)
724
+
725
+ def buildDefinition(self, simpDict: dict[str, Any], legacy: bool) -> int:
726
+ """Output a dictionary definition of this object
727
+
728
+ Parameters
729
+ ----------
730
+ simpDict : dict
731
+ The dictionary that is being built
732
+ legacy : bool
733
+ Whether to write out the legacy definition, or the newer one
734
+ """
735
+ if self._buildIdx is None:
736
+ self._buildIdx = len(simpDict["falloffs"])
737
+ if legacy:
738
+ line = ["map", self.axis, self.mapName] # Just default it to x axis
739
+ simpDict.setdefault("falloffs", []).append([self.name] + line)
740
+ else:
741
+ x = {
742
+ "name": self.name,
743
+ "type": "map",
744
+ "axis": self.axis,
745
+ "mapName": self.mapName,
746
+ }
747
+ simpDict.setdefault("falloffs", []).append(x)
748
+ return self._buildIdx