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,780 @@
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
+ from enum import Enum
20
+ from typing import TYPE_CHECKING, Any
21
+
22
+ from .accessor import SimplexTreeAccessor
23
+ from .combo import Combo
24
+ from .dragItem import Draggable
25
+ from .group import Group
26
+ from .progression import Progression
27
+ from .slider import Slider
28
+ from .stack import stackable
29
+ from .treeItem import TreeItem
30
+
31
+ if TYPE_CHECKING:
32
+ from .progression import ProgPair
33
+ from .simplex import DCCObject, Simplex
34
+
35
+
36
+ class TravSide(Enum):
37
+ Start = "START"
38
+ End = "END"
39
+
40
+
41
+ class TravPair(SimplexTreeAccessor, Draggable):
42
+ classDepth: int = 4
43
+
44
+ def __init__(self, slider: Slider, value: float) -> None:
45
+ simplex = slider.simplex
46
+ super().__init__(simplex)
47
+ self.slider: Slider = slider
48
+ self._value: float = float(value)
49
+ self.minValue: float = -1.0
50
+ self.maxValue: float = 1.0
51
+ self._tickDelta: float = 0.0
52
+ self.travPoint: TravPoint | None = None
53
+
54
+ @property
55
+ def name(self) -> str:
56
+ return self.slider.name
57
+
58
+ @property
59
+ def value(self) -> float:
60
+ return self._value
61
+
62
+ @value.setter
63
+ @stackable
64
+ def value(self, val: float) -> None:
65
+ self._value = val
66
+
67
+ def buildDefinition(
68
+ self, simpDict: dict[str, Any], legacy: bool
69
+ ) -> tuple[int, float]:
70
+ sIdx = self.slider.buildDefinition(simpDict, legacy)
71
+ return sIdx, self.value
72
+
73
+ @stackable
74
+ def remove(self) -> None:
75
+ with self.removeItemManager(self):
76
+ if self.travPoint is not None:
77
+ self.travPoint.pairs.remove(self)
78
+ self.travPoint = None
79
+
80
+ @stackable
81
+ def delete(self) -> None:
82
+ if self.travPoint is not None:
83
+ if self.travPoint.traversal is not None:
84
+ self.travPoint.traversal.removePairs([self])
85
+
86
+ @staticmethod
87
+ def removeAll(pairs: list[TravPair]) -> None:
88
+ points = [i.travPoint for i in pairs if i.travPoint is not None]
89
+ travs = list({pp.traversal for pp in points})
90
+ for trav in travs:
91
+ if trav is not None:
92
+ trav.removePairs(pairs)
93
+
94
+ def treeRow(self) -> int:
95
+ if self.travPoint is None:
96
+ raise ValueError(
97
+ "Somehow you're trying to show a TravPair with no TravPoint"
98
+ )
99
+ return self.travPoint.pairs.index(self)
100
+
101
+ def treeParent(self) -> TreeItem:
102
+ if self.travPoint is None:
103
+ raise ValueError("")
104
+ return self.travPoint
105
+
106
+ def treeData(self, column: int) -> Any | None:
107
+ if column == 0:
108
+ return self.name
109
+ if column == 1:
110
+ return self.value
111
+ return None
112
+
113
+
114
+ class TravPoint(SimplexTreeAccessor):
115
+ classDepth: int = 3
116
+
117
+ def __init__(self, pairs: list[TravPair], side: TravSide) -> None:
118
+ if not pairs:
119
+ raise ValueError("Pairs must be provided for a TravPoint")
120
+ simplex = pairs[0].slider.simplex
121
+ super().__init__(simplex)
122
+
123
+ self.pairs = pairs
124
+ for pair in pairs:
125
+ pair.travPoint = self
126
+ self.side: TravSide = side
127
+ self.traversal: Traversal | None = None
128
+
129
+ def sliders(self) -> list[Slider]:
130
+ return [i.slider for i in self.pairs]
131
+
132
+ @staticmethod
133
+ def _wideCeiling(val: float, eps: float = 0.001) -> float:
134
+ if val > eps:
135
+ return 1.0
136
+ elif val < -eps:
137
+ return -1.0
138
+ return 0.0
139
+
140
+ @stackable
141
+ def addPair(self, pair: TravPair) -> None:
142
+ with self.insertItemManager(self):
143
+ self.pairs.append(pair)
144
+ pair.travPoint = self
145
+
146
+ def removePair(self, pair: TravPair) -> None:
147
+ pair.remove()
148
+
149
+ def addSlider(self, slider: Slider, val: float | None = None) -> None:
150
+ val = val if val is not None else slider.value
151
+ val = self._wideCeiling(val)
152
+ sliders = self.sliders()
153
+ try:
154
+ idx = sliders.index(slider)
155
+ except ValueError:
156
+ self.addPair(TravPair(slider, val))
157
+ else:
158
+ self.pairs[idx].value = val
159
+
160
+ def addItem(self, item: Slider | Combo) -> None:
161
+ if isinstance(item, Slider):
162
+ self.addSlider(item)
163
+ elif isinstance(item, Combo):
164
+ for cp in item.pairs:
165
+ self.addSlider(cp.slider, cp.value)
166
+
167
+ @property
168
+ def name(self) -> str:
169
+ return self.side.value
170
+
171
+ def buildDefinition(
172
+ self, simpDict: dict[str, Any], legacy: bool
173
+ ) -> list[tuple[int, float]]:
174
+ return [p.buildDefinition(simpDict, legacy) for p in self.pairs]
175
+
176
+ def getInputVector(self) -> list[float]:
177
+ """Get the input to the solver that would fully activate this point of the traversal
178
+
179
+ returns
180
+ -------
181
+ : [float, ...]
182
+ the ordered slider values
183
+ """
184
+ invec = [0.0] * len(self.simplex.sliders)
185
+ for cp in self.pairs:
186
+ invec[self.simplex.sliders.index(cp.slider)] = cp.value
187
+ return invec
188
+
189
+ def treeData(self, column: int) -> Any | None:
190
+ if column == 0:
191
+ return self.name
192
+ return None
193
+
194
+ def treeChild(self, row: int) -> TreeItem:
195
+ return self.pairs[row]
196
+
197
+ def treeRow(self) -> int:
198
+ if self.side == TravSide.Start:
199
+ return 0
200
+ return 1
201
+
202
+ def treeParent(self) -> TreeItem | None:
203
+ return self.traversal
204
+
205
+ def treeChildCount(self) -> int:
206
+ return len(self.pairs)
207
+
208
+
209
+ class Traversal(SimplexTreeAccessor):
210
+ """Traversals control a Progression based on any 2 points in the Solver space.
211
+
212
+ Traversals only make sense with intermediate shapes in the progression of the sliders
213
+ that control it.
214
+
215
+ Traversals should never have a shape at 100%. That shape should be handled by a Combo
216
+
217
+ First: A "point in solver space" just means a list of slider/value pairs.
218
+ The Slider/Value pairs that make a up a Combo are just a "Point in solver space" as well.
219
+ So technically Combos could be thought of as a special-case of Traversals. Combos control
220
+ a progression between the "Rest Point" where all sliders are at 0, and the Combo point
221
+
222
+ Outside of the context of Traversals, I just call solver space points "Combos", because
223
+ I don't need to be crazy specific like I do here.
224
+
225
+ The initial use-case for Traversals was dealing with eye combo shapes with incremental
226
+ Progressions. The eyeLookDown and the eyeClosed shapes both pull the upper lid down a great
227
+ deal, and the eyeClosed was a 4-shape progression. So, when transitioning from eyeLookDown
228
+ to eyeLookDown+eyeClosed, the deltas for all the progressive shapes were being triggered as
229
+ the combo was coming on, causing major wobbles in the eyelid. So we needed shapes that
230
+ countered those incrementals, but *only* on the transition from eyeLookDown to
231
+ eyeLookDown+eyeClosed (NOT on the transition from eyeClosed to eyeLookDown+eyeClosed)
232
+
233
+ Early setups used floating Combos, but those have linearinterpolation, and I wanted a
234
+ cleaner solution. That solution is the Traversal
235
+
236
+ Parameters
237
+ ----------
238
+ name : str
239
+ The name of this Combo
240
+ simplex : Simplex
241
+ The parent Simplex system
242
+ startPoint : TravPoint
243
+ A set of Slider/Value pairs where the Traversal solves to 0
244
+ endPoint : TravPoint
245
+ A set of Slider/Value pairs where the Traversal solves to 1
246
+ prog : Progression
247
+ The Progression that this Combo controls
248
+ group : Group
249
+ The Group to create this combo in
250
+ color : QColor
251
+ The color of this item in the UI
252
+ """
253
+
254
+ classDepth: int = 2
255
+
256
+ def __init__(
257
+ self,
258
+ name: str,
259
+ simplex: Simplex,
260
+ startPoint: TravPoint,
261
+ endPoint: TravPoint,
262
+ prog: Progression,
263
+ group: Group,
264
+ ) -> None:
265
+ super().__init__(simplex)
266
+ with self.stack.store(self):
267
+ if group.groupType is not type(self):
268
+ raise ValueError(
269
+ "Cannot add this Traversal to a group of a different type"
270
+ )
271
+ self._name: str = name
272
+ self.startPoint: TravPoint = startPoint
273
+ self.endPoint: TravPoint = endPoint
274
+ self.prog: Progression = prog
275
+ self.prog.controller = self
276
+ self._buildIdx: int | None = None
277
+ self._enabled: bool = True
278
+ self.startPoint.traversal = self
279
+ self.endPoint.traversal = self
280
+ self.simplex.traversals.append(self)
281
+
282
+ with self.insertItemManager(group):
283
+ self.group: Group = group
284
+ self.group.items.append(self)
285
+
286
+ @classmethod
287
+ def createTraversal(
288
+ cls,
289
+ name: str,
290
+ simplex: Simplex,
291
+ startPairs: list[tuple[Slider, float]],
292
+ endPairs: list[tuple[Slider, float]],
293
+ group: Group | None = None,
294
+ count: int = 4,
295
+ ) -> Traversal:
296
+ """Create a Traversal between two lists of pairs
297
+
298
+ Parameters
299
+ ----------
300
+ name : str
301
+ The name of this Combo
302
+ simplex : Simplex
303
+ The parent Simplex system
304
+ startPairs : [(Slider
305
+ A list of Slider/Value pairs to make the startPoint
306
+ endPairs : [(Slider
307
+ A list of Slider/Value pairs to make the endPoint
308
+ group : Group
309
+ The Group to create this combo in (Default value = None)
310
+ count : int
311
+ The number of incrementals to create (including the 100%) (Default value = 4)
312
+ """
313
+ if simplex.restShape is None:
314
+ raise RuntimeError("Simplex system is missing rest shape")
315
+
316
+ if group is None:
317
+ gname = "TRAVERSALS"
318
+ matches = [i for i in simplex.traversalGroups if i.name == gname]
319
+ if matches:
320
+ group = matches[0]
321
+ else:
322
+ group = Group(gname, simplex, Traversal)
323
+
324
+ startTPairs = [TravPair(p[0], p[1]) for p in startPairs]
325
+ endTPairs = [TravPair(p[0], p[1]) for p in endPairs]
326
+
327
+ startPoint = TravPoint(startTPairs, TravSide.Start)
328
+ endPoint = TravPoint(endTPairs, TravSide.End)
329
+
330
+ prog = Progression(name, simplex)
331
+ trav = cls(name, simplex, startPoint, endPoint, prog, group)
332
+
333
+ for c in reversed(list(range(count))):
334
+ val = (100 * (c + 1)) // count
335
+ pp = prog.createShape(f"{name}_{val}", val / 100.0)
336
+ simplex.DCC.zeroShape(pp.shape)
337
+ return trav
338
+
339
+ @property
340
+ def enabled(self) -> bool:
341
+ """Get whether this Traversal is evaluated in the solver"""
342
+ return self._enabled
343
+
344
+ @enabled.setter
345
+ @stackable
346
+ def enabled(self, value: bool) -> None:
347
+ """Set whether this Traversal is evaluated in the solver"""
348
+ self._enabled = value
349
+
350
+ @property
351
+ def name(self) -> str:
352
+ """Get the name of a Traversal"""
353
+ return self._name
354
+
355
+ @name.setter
356
+ @stackable
357
+ def name(self, value: str) -> None:
358
+ """Set the name of a Traversal"""
359
+ self._name = value
360
+ self.prog.name = value
361
+ # self.DCC.renameTraversal(self, value)
362
+
363
+ def allSliders(self) -> list[Slider]:
364
+ """Get the list of all Sliders that control this Traversal
365
+ Returns
366
+ -------
367
+ : [Slider, ...]
368
+ The list of all Sliders that control this Traversal
369
+ """
370
+ startSliders = [p.slider for p in self.startPoint.pairs]
371
+ endSliders = [
372
+ p.slider for p in self.endPoint.pairs if p.slider not in startSliders
373
+ ]
374
+ return startSliders + endSliders
375
+
376
+ def dynamicSliders(self) -> list[Slider]:
377
+ """Get a list of sliders that have different values at the start and end"""
378
+ return [sli for sli, rng in self.ranges().items() if rng[0] != rng[1]]
379
+
380
+ def staticSliders(self) -> list[Slider]:
381
+ """Get a list of sliders that have the same values at the start and end"""
382
+ return [sli for sli, rng in self.ranges().items() if rng[0] == rng[1]]
383
+
384
+ def ranges(self) -> dict[Slider, tuple[float, float]]:
385
+ """Get the range per Slider for this Traversal
386
+
387
+ Returns
388
+ -------
389
+ : type
390
+ (dict): A {Slider: range} dict
391
+ """
392
+ startDict = {p.slider: p.value for p in self.startPoint.pairs}
393
+ endDict = {p.slider: p.value for p in self.endPoint.pairs}
394
+ allSliders = startDict.keys() | endDict.keys()
395
+
396
+ rangeDict = {}
397
+ for sli in allSliders:
398
+ rangeDict[sli] = (startDict.get(sli, 0.0), endDict.get(sli, 0.0))
399
+ return rangeDict
400
+
401
+ @stackable
402
+ def setGroup(self, grp: Group) -> None:
403
+ """Set the Group for this Slider
404
+
405
+ Parameters
406
+ ----------
407
+ grp : Group
408
+ The Group to put this Slider under
409
+ """
410
+ if grp.groupType is None:
411
+ grp.groupType = type(self)
412
+
413
+ if not isinstance(self, grp.groupType):
414
+ raise ValueError(
415
+ f"All items in this group must be of type: {grp.groupType}"
416
+ )
417
+
418
+ if self.group:
419
+ self.group.items.remove(self)
420
+ grp.items.append(self)
421
+ self.group = grp
422
+
423
+ @staticmethod
424
+ def buildTraversalName(ranges: dict[Slider, tuple[float, float]]) -> str:
425
+ """Given the range dict (like from Traversal.ranges()) come up with a name
426
+
427
+ Parameters
428
+ ----------
429
+ ranges : dict
430
+ A {Slider: range} dict
431
+
432
+ Returns
433
+ -------
434
+ : str
435
+ The suggested Traversal name
436
+ """
437
+ static, dynamic = [], []
438
+ for sli, rng in ranges.items():
439
+ if rng[0] == rng[1]:
440
+ static.append(sli)
441
+ else:
442
+ dynamic.append(sli)
443
+
444
+ parts = []
445
+ for grp in static, dynamic:
446
+ for slider in sorted(grp, key=lambda x: x.name):
447
+ prefix = None
448
+ start, end = ranges[slider]
449
+ if start == end:
450
+ # prefix = 'St' # St for Static
451
+ if start == 0:
452
+ continue
453
+ shp = slider.prog.getShapeAtValue(start)
454
+ if shp is None:
455
+ continue
456
+ name = shp.strippedName()
457
+ else:
458
+ prefix = "Dy" # Dy for Dynamic
459
+ if start == 0:
460
+ shp = slider.prog.getShapeAtValue(end)
461
+ if shp is None:
462
+ continue
463
+ name = shp.strippedName()
464
+ elif end == 0:
465
+ shp = slider.prog.getShapeAtValue(start)
466
+ if shp is None:
467
+ continue
468
+ name = shp.strippedName()
469
+ else:
470
+ name = slider.name
471
+
472
+ if prefix is not None:
473
+ parts.append(prefix)
474
+ parts.append(name)
475
+
476
+ return "Tv_" + "_".join(parts)
477
+
478
+ def controllerNameLinks(self) -> list[bool]:
479
+ surr = f"_{self.name}_"
480
+ return [f"_{sli}_" in surr for sli in self.allSliders()]
481
+
482
+ def nameLinks(self) -> list[bool]:
483
+ # In this case, these names will *NOT* have the possibility of
484
+ # a pos/neg name. Only the traversal name, and possibly a percentage
485
+ shapeNames = []
486
+ shapes = [i.shape for i in self.prog.pairs]
487
+ for s in shapes:
488
+ x = s.name.rsplit("_", 1)
489
+ if len(x) == 2:
490
+ base, sfx = x
491
+ x = base if sfx.isdigit() else s.name
492
+ shapeNames.append(x)
493
+ return [i == self.name for i in shapeNames]
494
+
495
+ @stackable
496
+ def createShape(
497
+ self, shapeName: str | None = None, tVal: float | None = None
498
+ ) -> ProgPair:
499
+ """Create a shape and add it to a progression
500
+
501
+ Parameters
502
+ ----------
503
+ shapeName : str or None
504
+ The name of the shape to create.
505
+ If None, give it a default name
506
+ tVal : float or None
507
+ The progression value to set for the new Shape.
508
+ If None, it gets a "smart" default value
509
+ """
510
+ pp, idx = self.prog.newProgPair(shapeName, tVal)
511
+ with self.insertItemManager(self.prog, row=idx):
512
+ pp.prog = self.prog
513
+ self.prog.pairs.insert(idx, pp)
514
+ return pp
515
+
516
+ @classmethod
517
+ def loadV2(
518
+ cls, simplex: Simplex, progs: list[Progression], data: dict[str, Any]
519
+ ) -> Traversal:
520
+ """Load the data from a version2 formatted json dictionary
521
+
522
+ Parameters
523
+ ----------
524
+ simplex : Simplex
525
+ The Simplex system that's being built
526
+ progs : [Progression
527
+ The progressions that have already been built
528
+ data : dict
529
+ The chunk of the json dict used to build this object
530
+
531
+ Returns
532
+ -------
533
+ : Traversal
534
+ The specified Traversal
535
+ """
536
+ name = data["name"]
537
+ prog = progs[data["prog"]]
538
+ group = simplex.groups[data.get("group", 2)]
539
+
540
+ rangeDict = {} # slider: [startVal, endVal]
541
+
542
+ pFlip = -1.0 if data["progressFlip"] else 1.0
543
+ pcIdx = data["progressControl"]
544
+ if data["progressType"].lower() == "slider":
545
+ sli = simplex.sliders[pcIdx]
546
+ rangeDict[sli] = (0.0, pFlip)
547
+ else:
548
+ cmb = simplex.combos[pcIdx]
549
+ for cp in cmb.pairs:
550
+ rangeDict[cp.slider] = (0.0, cp.value)
551
+
552
+ mFlip = -1.0 if data["multiplierFlip"] else 1.0
553
+ mcIdx = data["multiplierControl"]
554
+ if data["multiplierType"].lower() == "slider":
555
+ sli = simplex.sliders[mcIdx]
556
+ rangeDict[sli] = (mFlip, mFlip)
557
+ else:
558
+ cmb = simplex.combos[mcIdx]
559
+ for cp in cmb.pairs:
560
+ rangeDict[cp.slider] = (cp.value, cp.value)
561
+
562
+ ssli = sorted((rangeDict.items()), key=lambda x: x[0].name)
563
+ startPairs, endPairs = [], []
564
+ for slider, (startVal, endVal) in ssli:
565
+ startPairs.append(TravPair(slider, startVal))
566
+ endPairs.append(TravPair(slider, endVal))
567
+
568
+ startPoint = TravPoint(startPairs, TravSide.Start)
569
+ endPoint = TravPoint(endPairs, TravSide.End)
570
+
571
+ return cls(name, simplex, startPoint, endPoint, prog, group)
572
+
573
+ @classmethod
574
+ def loadV3(
575
+ cls, simplex: Simplex, progs: list[Progression], data: dict[str, Any]
576
+ ) -> Traversal:
577
+ """Load the data from a version3 formatted json dictionary
578
+
579
+ Parameters
580
+ ----------
581
+ simplex : Simplex
582
+ The Simplex system that's being built
583
+ progs : [Progression
584
+ The progressions that have already been built
585
+ data : dict
586
+ The chunk of the json dict used to build this object
587
+
588
+ Returns
589
+ -------
590
+ : Traversal
591
+ The specified Traversal
592
+ """
593
+ name = data["name"]
594
+ prog = progs[data["prog"]]
595
+ group = simplex.groups[data.get("group", 2)]
596
+
597
+ startDict = dict(data["start"])
598
+ endDict = dict(data["end"])
599
+ sliIdxs = sorted(startDict.keys() | endDict.keys())
600
+ startPairs, endPairs = [], []
601
+ for idx in sliIdxs:
602
+ startPairs.append(TravPair(simplex.sliders[idx], startDict.get(idx, 0.0)))
603
+ endPairs.append(TravPair(simplex.sliders[idx], endDict.get(idx, 0.0)))
604
+ startPoint = TravPoint(startPairs, TravSide.Start)
605
+ endPoint = TravPoint(endPairs, TravSide.End)
606
+
607
+ return cls(name, simplex, startPoint, endPoint, prog, group)
608
+
609
+ def buildDefinition(self, simpDict: dict[str, Any], legacy: bool) -> int:
610
+ """Output a dictionary definition of this object
611
+
612
+ Parameters
613
+ ----------
614
+ simpDict : dict
615
+ The dictionary that is being built
616
+ legacy : bool
617
+ Whether to write out the legacy definition, or the newer one
618
+ This is ignored for Traversals. There is no legacy definition
619
+ """
620
+ if self._buildIdx is None:
621
+ self._buildIdx = len(simpDict["traversals"])
622
+ x = {
623
+ "name": self.name,
624
+ "prog": self.prog.buildDefinition(simpDict, legacy),
625
+ "start": self.startPoint.buildDefinition(simpDict, legacy),
626
+ "end": self.endPoint.buildDefinition(simpDict, legacy),
627
+ "group": self.group.buildDefinition(simpDict, legacy),
628
+ "enabled": self._enabled,
629
+ }
630
+ simpDict.setdefault("traversals", []).append(x)
631
+ return self._buildIdx
632
+
633
+ def clearBuildIndex(self) -> None:
634
+ """Clear the build index of this object
635
+
636
+ The buildIndex is stored when building a definition dictionary
637
+ that keeps track of its index for later referencing
638
+ """
639
+ self._buildIdx = None
640
+ self.prog.clearBuildIndex()
641
+ self.group.clearBuildIndex()
642
+
643
+ @stackable
644
+ def delete(self) -> None:
645
+ """Delete a traversal and any shapes it contains"""
646
+ with self.removeItemManager(self):
647
+ g = self.group
648
+ if self not in g.items:
649
+ return # Can happen when deleting multiple groups
650
+ g.items.remove(self)
651
+ self.group = None # type: ignore
652
+ self.simplex.traversals.remove(self)
653
+
654
+ pairs = self.prog.pairs[:] # gotta make a copy
655
+ for pp in pairs:
656
+ if not pp.shape.isRest:
657
+ self.simplex.shapes.remove(pp.shape)
658
+ self.DCC.deleteShape(pp.shape)
659
+
660
+ def extractShape(self, shape, live: bool = True, offset: float = 10.0) -> DCCObject:
661
+ """Extract a shape from a Traversal progression"""
662
+ return self.DCC.extractTraversalShape(self, shape, live, offset)
663
+
664
+ def addSlider(self, slider: Slider) -> None:
665
+ """Add a slider to both the startPoint and endPoint of this Traversal
666
+
667
+ Parameters
668
+ ----------
669
+ slider : Slider
670
+ The slider to add
671
+ """
672
+ self.startPoint.addSlider(slider, val=0.0)
673
+ self.endPoint.addSlider(slider)
674
+
675
+ def removePairs(self, pairs: list[TravPair]) -> None:
676
+ """Remove the given pairs from both the startPoint and endPoint of this Traversal
677
+
678
+ Parameters
679
+ ----------
680
+ pairs : [TravPair
681
+ The pairs to remove
682
+ """
683
+ # Get only the pairs that are a part of this traversal
684
+ sPairs = [i for i in self.startPoint.pairs if i in pairs]
685
+ ePairs = [i for i in self.endPoint.pairs if i in pairs]
686
+ pairs = sPairs + ePairs
687
+
688
+ # Get all the pairs that use the selected sliders
689
+ sliders = {p.slider for p in pairs}
690
+ sPairs = [i for i in self.startPoint.pairs if i.slider in sliders]
691
+ ePairs = [i for i in self.endPoint.pairs if i.slider in sliders]
692
+
693
+ # do the removal
694
+ for pair in sPairs:
695
+ pair.remove()
696
+
697
+ for pair in ePairs:
698
+ pair.remove()
699
+
700
+ @staticmethod
701
+ def traversalAlreadyExists(
702
+ simplex: Simplex, sliders: list[Slider], ranges: list[tuple[float, float]]
703
+ ) -> Traversal | None:
704
+ """In a given simplex syste, check if a traversal exists
705
+ with the given sliders and ranges
706
+ """
707
+ chk = dict(zip(sliders, ranges))
708
+ for trav in simplex.traversals:
709
+ if chk == trav.ranges():
710
+ return trav
711
+ return None
712
+
713
+ @staticmethod
714
+ def getCount(sliders: list[Slider], ranges: list[tuple[float, float]]) -> int:
715
+ """Get the count of shapes to create for a traversal with the given
716
+ sliders and ranges. It's the max number of shapes on a given side of 0
717
+ """
718
+ counts = []
719
+ for sli, rng in zip(sliders, ranges):
720
+ if rng[0] == rng[1]:
721
+ continue
722
+ vals = sli.prog.getValues()
723
+ if max(rng) == 0:
724
+ count = len([v for v in vals if v < 0])
725
+ else:
726
+ count = len([v for v in vals if v > 0])
727
+ counts.append(count)
728
+ if not counts:
729
+ return 0
730
+ return max(counts)
731
+
732
+ def getInputVector(self, value: float) -> list[float]:
733
+ """Get the input to the Solver that would set this traversal to
734
+ the given value
735
+
736
+ Parameters
737
+ ----------
738
+ value : float
739
+ The value to set the traversal to
740
+
741
+ Returns
742
+ -------
743
+ : [float, ...]
744
+ The ordered slider values
745
+ """
746
+ indexBySlider = {slider: idx for idx, slider in enumerate(self.simplex.sliders)}
747
+
748
+ fullStart = [0.0] * len(self.simplex.sliders)
749
+ for pair in self.startPoint.pairs:
750
+ fullStart[indexBySlider[pair.slider]] = pair.value
751
+
752
+ fullEnd = [0.0] * len(self.simplex.sliders)
753
+ for pair in self.endPoint.pairs:
754
+ fullEnd[indexBySlider[pair.slider]] = pair.value
755
+
756
+ def _lerp(s: float, e: float, v: float) -> float:
757
+ return s * (1 - v) + e * v
758
+
759
+ return [_lerp(fs, fe, value) for fs, fe in zip(fullStart, fullEnd)]
760
+
761
+ def treeChild(self, row: int) -> TreeItem:
762
+ if row == 0:
763
+ return self.startPoint
764
+ elif row == 1:
765
+ return self.endPoint
766
+ elif row == 2:
767
+ return self.prog
768
+ raise ValueError("Somehow have a Traversal item with more than 3 children")
769
+
770
+ def treeRow(self) -> int:
771
+ return self.group.items.index(self)
772
+
773
+ def treeParent(self) -> TreeItem:
774
+ return self.group
775
+
776
+ def treeChildCount(self) -> int:
777
+ return 3
778
+
779
+ def treeChecked(self) -> bool:
780
+ return self.enabled