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,1085 @@
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
+ """
19
+ This library will try to provide mesh access to and from every DCC
20
+
21
+ The Mesh object itself will try to provide an efficient way to run algorithms on
22
+ 3d mesh data
23
+
24
+ There are also convenience classes that act as function sets for mesh object components
25
+ Verts and Faces are the most common convenience classes and give access to adjacency
26
+ data (for backwards compatibility)
27
+
28
+ VertSet and FaceSet classes are just sets that also contain references back to the mesh
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ from types import NotImplementedType
34
+
35
+
36
+ class Mesh:
37
+ """
38
+ The inputs to this mesh object are inspired by the .obj file format
39
+
40
+ Parameters
41
+ ----------
42
+ verts : [(float, float, float), ...]
43
+ 3d Point positions
44
+ faces : [[int, ...], ...]
45
+ List of lists of vertex indices
46
+ uvs : [(float, float), ...]
47
+ 2d UV positions
48
+ uvFaces : [[int, ...], ...]
49
+ Face representations used for UVs
50
+ uvMap : {str: ((float, float), ...), ...}
51
+ Dictionary of named uv sets
52
+ uvFaceMap : {str: [[int, ...], ...], ...}
53
+ Dictionary of named uv faces
54
+ ensureWinding : boole
55
+ Ensure that neighbor operations return items in order
56
+
57
+ Faces are ccw wound
58
+
59
+ The idea for this data structure is to keep all the data in one place and have the
60
+ individual convenience objects reference back to it. Storing in one place means I
61
+ can store it efficiently, and allow for efficient editing and querying. The
62
+ convenience layer on top means you can get "good enough" performance for high-level
63
+ tasks without having to directly manipulate the underlying data.
64
+
65
+ This will error out with non-manifold geometry. This is a feature not a bug ;)
66
+
67
+ The only strange property is "Edge Adjacency", and this borrows some data from
68
+ the winged edge structure. Given two neighboring vertices, return the bordering
69
+ faces. The first face contains the vertices wound backwards (clockwise),
70
+ the second face contains the vertices wound forwards (counter clockwise)
71
+ For instance, we could pass the vert indices (0, 1), and get back (10, 13) where
72
+ faces[10].verts is (1, 0, 2) and faces[13].verts is (0, 1, 3).
73
+
74
+ UV's have a default mapping as part of class. However, named UV sets are supported
75
+ through the uvMap and uvFaceMap arguments. The default mapping is automatically
76
+ given the name 'default'. Partial uv sets are not handled
77
+
78
+ Float Data:
79
+ vertArray : array of 3d floats
80
+ uvMap : map of d[name] => array of 2d floats
81
+
82
+ Face Data:
83
+ faceVertArray : 2d array of vertex indices per face
84
+ uvFaceMap : map of d[name] => 2d array of UV indices per face
85
+
86
+ Vert Data:
87
+ vertToFaces : 2d array of face indices per vert
88
+ vertNeighbors : 2d array of vert indices per vert
89
+ vertWindingPairs : map of vertIdx => [(ccw Vert Pair), ...]
90
+
91
+ Edge Adjacency:
92
+ faceEdgeAdjacency : map of d[(vert1, vert2)] => (order, reverse) face indices
93
+ where `order` contains (vert1, vert2) in the winding order
94
+ and `reverse` contains (vert2, vert1) in the winding order
95
+ """
96
+
97
+ def __init__(
98
+ self,
99
+ verts,
100
+ faces,
101
+ uvs=None,
102
+ uvFaces=None,
103
+ uvMap=None,
104
+ uvFaceMap=None,
105
+ ensureWinding=False,
106
+ ) -> None:
107
+ self._verts = None
108
+ self._faces = None
109
+ self._uvs = {}
110
+ self._uvFaces = {}
111
+ self._wound = ensureWinding
112
+
113
+ self.children = []
114
+ # load the float data
115
+ self.vertArray = verts
116
+ self.uvMap = uvMap or {}
117
+ if uvs is not None:
118
+ self.uvMap["default"] = uvs
119
+
120
+ # build the empty face data
121
+ self.faceVertArray = faces
122
+ self.uvFaceMap = uvFaceMap or {}
123
+ if uvFaces:
124
+ self.uvFaceMap["default"] = uvFaces
125
+
126
+ vertToFaces = {}
127
+ neighborDict = {}
128
+ hedgeCCWDict = {}
129
+ hedgeCWDict = {}
130
+ self.vertWindingPairs = {}
131
+ for f, face in enumerate(self.faceVertArray):
132
+ for v, vert in enumerate(face):
133
+ vertToFaces.setdefault(vert, []).append(f)
134
+ self.vertWindingPairs.setdefault(face[v - 1], []).append(
135
+ (face[v - 2], face[v])
136
+ )
137
+ neighborDict.setdefault(face[v - 1], []).append(face[v])
138
+ neighborDict.setdefault(face[v - 1], []).append(face[v - 2])
139
+ hedgeCCWDict[(face[v - 1], face[v])] = f
140
+ hedgeCWDict[(face[v], face[v - 1])] = f
141
+
142
+ vertCount = len(self.vertArray)
143
+ if ensureWinding:
144
+ self.vertNeighbors = [
145
+ self._linkPairs(self.vertWindingPairs[i]) for i in range(vertCount)
146
+ ]
147
+ else:
148
+ vn = []
149
+ for i in range(vertCount):
150
+ vnv = []
151
+ for n in neighborDict[i]:
152
+ if n not in vnv:
153
+ vnv.append(n)
154
+ vn.append(vnv)
155
+ self.vertNeighbors = vn
156
+
157
+ self.faceEdgeAdjacency = {}
158
+ for i in range(vertCount):
159
+ for j in self.vertNeighbors[i]:
160
+ pair = (i, j)
161
+ ccw = hedgeCCWDict.get(pair, None)
162
+ cw = hedgeCWDict.get(pair, None)
163
+ self.faceEdgeAdjacency[pair] = (ccw, cw)
164
+
165
+ if ensureWinding:
166
+ self.vertToFaces = []
167
+ for i in range(vertCount):
168
+ wings = [self.faceEdgeAdjacency[(i, j)] for j in self.vertNeighbors[i]]
169
+ wings = [i for i in wings if None not in i]
170
+ self.vertToFaces.append(self._linkPairs(wings))
171
+ else:
172
+ self.vertToFaces = [vertToFaces[i] for i in range(vertCount)]
173
+
174
+ def ensureWinding(self) -> None:
175
+ """Ensure the winding of the mesh after-the-fact"""
176
+ if self._wound:
177
+ return
178
+ self._wound = True
179
+ self.vertNeighbors = [
180
+ self._linkPairs(self.vertWindingPairs[i]) for i in range(self.vertCount())
181
+ ]
182
+
183
+ self.vertToFaces = []
184
+ for i in range(self.vertCount()):
185
+ wings = [self.faceEdgeAdjacency[(i, j)] for j in self.vertNeighbors[i]]
186
+ wings = [i for i in wings if None not in i]
187
+ self.vertToFaces.append(self._linkPairs(wings))
188
+
189
+ @classmethod
190
+ def loadObj(cls, path, ensureWinding: bool = True) -> Mesh:
191
+ """Read a .obj file and produce a Mesh object
192
+
193
+ Parameters
194
+ ----------
195
+ path
196
+ The path to the .obj formatted file
197
+
198
+ Returns
199
+ -------
200
+ : Mesh
201
+ Mesh object containing lists of linked vertices, edges, and faces
202
+
203
+ Raises
204
+ ------
205
+ IOError
206
+ If the file cannot be opened
207
+ """
208
+ vertices = []
209
+ faces = []
210
+ uvs = []
211
+ uvIdxs = []
212
+ nIdxs = []
213
+
214
+ with open(path, "r") as inFile:
215
+ lines = inFile.readlines()
216
+
217
+ for line in lines:
218
+ sp = line.split()
219
+ if sp == []:
220
+ pass
221
+ elif sp[0] == "v":
222
+ v = [float(i) for i in sp[1:4]]
223
+ vertices.append(v)
224
+
225
+ elif sp[0] == "vt":
226
+ uv = [float(i) for i in sp[1:3]]
227
+ uvs.append(uv)
228
+
229
+ elif sp[0] == "f":
230
+ face = []
231
+ for s in sp[1:]:
232
+ vt = [int(i) - 1 if i else None for i in s.split("/")]
233
+ # Pad out the face vert/uv/normal triples
234
+ face.append(vt + [None] * 3)
235
+ # Then cut them back to 3
236
+ # Still doing this even though I'm ignoring normals
237
+ face = [i[:3] for i in face]
238
+ f, u, n = list(zip(*face))
239
+ faces.append(f[::-1])
240
+ if any(u):
241
+ uvIdxs.append(list(u[::-1]))
242
+ if any(n):
243
+ nIdxs.append(list(n[::-1]))
244
+
245
+ return cls(
246
+ vertices, faces, uvs=uvs, uvFaces=uvIdxs, ensureWinding=ensureWinding
247
+ )
248
+
249
+ @classmethod
250
+ def loadAbc(cls, path, meshName=None, ensureWinding: bool = True) -> Mesh:
251
+ """Read a .abc file and produce a Mesh object
252
+
253
+ Parameters
254
+ ----------
255
+ path: str
256
+ The path to the .abc formatted file
257
+
258
+ Returns
259
+ -------
260
+ : Mesh
261
+ Mesh object containing lists of linked vertices, edges, and faces
262
+
263
+ Raises
264
+ ------
265
+ IOError
266
+ If the file cannot be opened
267
+ """
268
+ from alembic.Abc import IArchive
269
+ from alembic.AbcGeom import IPolyMesh
270
+
271
+ from .alembicCommon import findAlembicObject
272
+
273
+ iarch = IArchive(str(path)) # because alembic hates unicode
274
+ mesh = findAlembicObject(iarch.getTop(), abcType=IPolyMesh, name=meshName)
275
+ sch = mesh.getSchema()
276
+ rawVerts = sch.getPositionsProperty().samples[0]
277
+ rawFaces = sch.getFaceIndicesProperty().samples[0]
278
+ rawCounts = sch.getFaceCountsProperty().samples[0]
279
+ iuvs = sch.getUVsParam()
280
+
281
+ faces = []
282
+ faceCounter = 0
283
+ for count in rawCounts:
284
+ faces.append(list(rawFaces[faceCounter : faceCounter + count]))
285
+ faceCounter += count
286
+
287
+ uvs = None
288
+ uvFaces = None
289
+ if iuvs.valid():
290
+ uvValue = iuvs.getValueProperty().getValue()
291
+ uvs = list(zip(uvValue.x, uvValue.y))
292
+ if iuvs.isIndexed():
293
+ idxs = list(iuvs.getIndexProperty().getValue())
294
+ uvFaces = []
295
+ uvCounter = 0
296
+ for count in rawCounts:
297
+ uvFaces.append(list(idxs[uvCounter : uvCounter + count]))
298
+ uvCounter += count
299
+
300
+ verts = []
301
+ for v in rawVerts:
302
+ verts.append(list(v))
303
+
304
+ return cls(verts, faces, uvs=uvs, uvFaces=uvFaces, ensureWinding=ensureWinding)
305
+
306
+ @classmethod
307
+ def loadPrimitive(cls, prim, channelName=None, ensureWinding: bool = True) -> Mesh:
308
+ """Read the vertex and face data from a cross3d primitive
309
+
310
+ Parameters
311
+ ----------
312
+ prim : Cross3d.Primitive
313
+ The cross3d primitive
314
+ channelName : str
315
+ The name of the UV channel to load
316
+
317
+ Returns
318
+ -------
319
+ : Mesh
320
+ Mesh object containing lists of linked vertices, edges, and faces
321
+
322
+ Raises
323
+ ------
324
+ ValueError
325
+ If the primitive is not a mesh
326
+ """
327
+ verts = prim.vertexPositions()
328
+ faces = prim.faces()
329
+ if channelName:
330
+ uvs = prim.uvPositions(channelName)
331
+ uvFaces = prim.uvFaces(channelName)
332
+ return cls(verts, faces, uvs, uvFaces, ensureWinding=ensureWinding)
333
+ return cls(verts, faces, ensureWinding=ensureWinding)
334
+
335
+ @staticmethod
336
+ def _linkPairs(pairs):
337
+ """
338
+ Take a list of paired items, and order them so the
339
+ second item of a pair matches the first of the next pair
340
+ Then return the first item of each pair for each cycle.
341
+ for instance, with two cycles:
342
+ input: [(1, 2), (11, 12), (3, 1), (10, 11), (2, 3), (12, 10)]
343
+ reorder: [[(1, 2), (2, 3), (3, 1)], [(10, 11), (11, 12), (12, 10)]]
344
+ output: [1, 2, 3, 10, 11, 12]
345
+ """
346
+ fwPairs = dict(pairs)
347
+ out = []
348
+ while fwPairs:
349
+ linked = []
350
+ # pick a random start from whatever's left
351
+ nxt = next(fwPairs.keys())
352
+ while nxt is not None:
353
+ # Follow the pairs around until I cant find more
354
+ nnxt = fwPairs.pop(nxt, None)
355
+ linked.append((nxt, nnxt))
356
+ nxt = nnxt
357
+
358
+ if fwPairs and linked[0][0] != linked[-1][0]:
359
+ # if there's still some left and we didn't find a cycle
360
+ # then search backwards
361
+ bkPairs = {j: i for i, j in fwPairs.items()}
362
+ inv = []
363
+ nxt = linked[0][0]
364
+ while nxt is not None:
365
+ # Follow the pairs around until I cant find more
366
+ nnxt = bkPairs.pop(nxt, None)
367
+ inv.append((nnxt, nxt))
368
+ nxt = nnxt
369
+ # reverse and remove the extra (idx, None) pair
370
+ linked = inv[-2::-1] + linked
371
+ # Rebuild what's left into a new dict for the next group
372
+ fwPairs = {j: i for i, j in bkPairs.items()}
373
+
374
+ # Parse the final output
375
+ fin = [i for i, _ in linked]
376
+ if fin[0] == fin[-1]:
377
+ # Get rid of the doubled values when finding cycles
378
+ fin = fin[:-1]
379
+ out.extend(fin)
380
+ return out
381
+
382
+ def adjacentFacesByEdge(self, faceIdx):
383
+ """Get all faces that share an edge with the given face
384
+ Winding Guaranteed Counterclockwise
385
+
386
+ Parameters
387
+ ----------
388
+ faceIdx : int
389
+ The face Index
390
+
391
+ Returns
392
+ -------
393
+ : [int, ...]
394
+ List of faces indices that share an edge with the input
395
+
396
+ Raises
397
+ ------
398
+ IndexError
399
+ The input is out of range
400
+ """
401
+ verts = self.faceVertArray[faceIdx]
402
+ out = []
403
+ for i in range(verts):
404
+ edge = (verts[i - 1], verts[i])
405
+ _, rev = self.faceEdgeAdjacency.get(edge, (None, None))
406
+ out.append(rev)
407
+ return out
408
+
409
+ def adjacentFacesByVert(self, faceIdx):
410
+ """Get all faces that share a vert with the given face
411
+ Winding Not Guaranteed
412
+
413
+ Parameters
414
+ ----------
415
+ faceIdx : int
416
+ The face Index
417
+
418
+ Returns
419
+ -------
420
+ : [int, ...]
421
+ List of faces indices that share an edge with the input
422
+
423
+ Raises
424
+ ------
425
+ IndexError
426
+ The input is out of range
427
+ """
428
+ out = set()
429
+ verts = self.faceVertArray[faceIdx]
430
+ for v in verts:
431
+ out.update(self.vertToFaces[v])
432
+ return list(out)
433
+
434
+ def adjacentVertsByFace(self, vertIdx):
435
+ """Get all verts that share a face with the given vert
436
+ Winding Not Guaranteed
437
+
438
+ Parameters
439
+ ----------
440
+ vertIdx : int
441
+ Vertex Index
442
+
443
+ Returns
444
+ -------
445
+ : [int, ...]
446
+ List of vertex indices that share a face with the input
447
+
448
+ Raises
449
+ ------
450
+ IndexError
451
+ The input is out of range
452
+ """
453
+ faces = self.vertToFaces[vertIdx]
454
+ out = set()
455
+ for f in faces:
456
+ out.update(self.faceVertArray[f])
457
+ return list(out)
458
+
459
+ def adjacentVertsByEdge(self, vertIdx):
460
+ """Get all verts that share an edge with the given vert
461
+ Winding Guaranteed Counterclockwise
462
+
463
+ Parameters
464
+ ----------
465
+ vertIdx : int
466
+ Vertex Index
467
+
468
+ Returns
469
+ -------
470
+ : [int, ...]
471
+ List of vertex indices that share an edge with the input
472
+
473
+ Raises
474
+ ------
475
+ IndexError
476
+ The input is out of range
477
+ """
478
+ return self.vertNeighbors[vertIdx]
479
+
480
+ def vertCount(self) -> int:
481
+ """Get the number of vertices in this mesh"""
482
+ return len(self.vertArray)
483
+
484
+ def faceCount(self) -> int:
485
+ """Get the number of faces in this mesh"""
486
+ return len(self.faceVertArray)
487
+
488
+ def verts(self):
489
+ """Get all vertex convenience objects
490
+
491
+ Returns
492
+ -------
493
+ : [Vertex, ...]
494
+ List of vertex objects
495
+ """
496
+ if self._verts is None:
497
+ self._verts = [Vert(self, i) for i in range(len(self.vertArray))]
498
+ return self._verts
499
+
500
+ def faces(self):
501
+ """Get all face convenience objects
502
+
503
+ Returns
504
+ -------
505
+ : [Face, ...]
506
+ List of face objects
507
+ """
508
+ if self._faces is None:
509
+ self._faces = [Face(self, i) for i in range(len(self.faceVertArray))]
510
+ return self._faces
511
+
512
+ def vertSet(self) -> VertSet:
513
+ """Get a vertex set containing the whole mesh
514
+
515
+ Returns
516
+ -------
517
+ : VertSet
518
+ A vertex set containing the whole mesh
519
+ """
520
+ ret = VertSet(self, [])
521
+ ret.update(list(range(len(self.vertArray))))
522
+ return ret
523
+
524
+ def faceSet(self) -> FaceSet:
525
+ """Get a face set containing the whole mesh
526
+
527
+ Returns
528
+ -------
529
+ : FaceSet
530
+ A face set containing the whole mesh
531
+ """
532
+ ret = FaceSet(self, [])
533
+ ret.update(list(range(len(self.faceVertArray))))
534
+ return ret
535
+
536
+ def uvs(self, channelName: str = "default"):
537
+ """Get all UV convenience objects
538
+
539
+ Returns
540
+ -------
541
+ : [UV, ...]
542
+ List of UV objects
543
+ """
544
+ if channelName not in self._uvs:
545
+ uvm = self.uvMap.get(channelName)
546
+ if uvm is not None:
547
+ self._uvs[channelName] = [UV(self, channelName, i) for i in uvm]
548
+ return self._uvs.get(channelName)
549
+
550
+ def uvFaces(self, channelName: str = "default"):
551
+ """Get all UV convenience objects
552
+
553
+ Returns
554
+ -------
555
+ : [UV, ...]
556
+ List of UV objects
557
+ """
558
+ if channelName not in self._uvFaces:
559
+ uvfm = self.uvFaceMap.get(channelName, [])
560
+ if uvfm is not None:
561
+ self._uvFaces[channelName] = [
562
+ UVFace(self, channelName, i) for i in uvfm
563
+ ]
564
+ return self._uvFaces.get(channelName)
565
+
566
+ def isBorderVert(self, vertIdx) -> bool:
567
+ """Check if the given vertex index is along a border
568
+
569
+ Returns
570
+ -------
571
+ : bool
572
+ Whether the given vertex index is along a border
573
+ """
574
+
575
+ neighbors = self.vertNeighbors[vertIdx]
576
+ for n in neighbors:
577
+ if None in self.faceEdgeAdjacency[(vertIdx, n)]:
578
+ return True
579
+ return False
580
+
581
+ def getBorderVerts(self) -> VertSet:
582
+ """Get a vertex set of the border vertices
583
+
584
+ Returns
585
+ -------
586
+ : VertSet
587
+ VertSet of border vertices
588
+ """
589
+ out = VertSet(self)
590
+ for edge, adj in self.faceEdgeAdjacency.items():
591
+ if None in adj:
592
+ out.update(edge)
593
+ return out
594
+
595
+ def clearCache(self) -> None:
596
+ """Clear all cached convenience classes"""
597
+ self._verts = None
598
+ self._faces = None
599
+ self._uvs = {}
600
+ self._uvFaces = {}
601
+ self.children = []
602
+
603
+
604
+ #######################################################################################
605
+
606
+
607
+ class MeshComponent:
608
+ """Base class for all mesh components
609
+ Handles keeping track of the mesh and index
610
+
611
+ Parameters
612
+ ----------
613
+ mesh : Mesh
614
+ The mesh object that this is a component of
615
+ index : int
616
+ The index of this component
617
+ """
618
+
619
+ __slot__ = "mesh", "index"
620
+
621
+ def __init__(self, mesh: Mesh, index) -> None:
622
+ self.mesh = mesh
623
+ self.index = index
624
+ self.mesh.children.append(self)
625
+
626
+ def __int__(self):
627
+ return self.index
628
+
629
+ def clear(self) -> None:
630
+ """Remove all reference data from this object"""
631
+ self.mesh = None
632
+ self.mesh.children.remove(self)
633
+
634
+ def value(self):
635
+ """Return the value of the object"""
636
+ raise NotImplementedError
637
+
638
+ def __eq__(self, other):
639
+ if isinstance(other, type(self)):
640
+ if self.mesh is other.mesh:
641
+ return self.index == other.index
642
+ # Not worrying about floating point equality
643
+ return self.value() == other.value()
644
+ return NotImplemented
645
+
646
+ def __hash__(self):
647
+ return self.index
648
+
649
+
650
+ class Vert(MeshComponent):
651
+ """A convenience class for accessing and manipulating vertices"""
652
+
653
+ def adjacentVertsByEdge(self):
654
+ """Get all verts that share an edge with the given vert
655
+
656
+ Returns
657
+ -------
658
+ : list
659
+ List of verts that share an edge with the input
660
+ """
661
+ idxs = self.mesh.adjacentVertsByEdge(self.index)
662
+ verts = self.mesh.verts()
663
+ return [verts[i] for i in idxs]
664
+
665
+ def adjacentVertsByFace(self):
666
+ """Get all verts that share a face with the given vert
667
+
668
+ Returns
669
+ -------
670
+ : list
671
+ List of verts that share a face with the input
672
+ """
673
+ idxs = self.mesh.adjacentVertsByFace(self.index)
674
+ verts = self.mesh.verts()
675
+ return [verts[i] for i in idxs]
676
+
677
+ def adjacentFaces(self):
678
+ """Get all faces that use this vertex
679
+
680
+ Returns
681
+ -------
682
+ : list
683
+ List of faces that use this vertex
684
+ """
685
+ idxs = self.mesh.vertToFaces[self.index]
686
+ faces = self.mesh.faces()
687
+ return [faces[i] for i in idxs]
688
+
689
+ def value(self):
690
+ """Get the vertex's position
691
+
692
+ Returns
693
+ -------
694
+ : tuple
695
+ (x, y, z) vertex position
696
+ """
697
+ return self.mesh.vertArray[self.index]
698
+
699
+ def setValue(self, pos) -> None:
700
+ """Set the vertex position
701
+
702
+ Parameters
703
+ ----------
704
+ pos : tuple
705
+ (x, y, z) vertex position
706
+ """
707
+ t = tuple(pos)
708
+ assert len(t) == 3
709
+ self.mesh.vertArray[self.index] = t
710
+
711
+
712
+ class Face(MeshComponent):
713
+ """A convenience class for accessing and manipulating faces"""
714
+
715
+ def adjacentFacesByEdge(self):
716
+ """Get all faces that share an edge with the given face
717
+
718
+ Returns
719
+ -------
720
+ : list
721
+ List of faces that share an edge with the input
722
+ """
723
+ idxs = self.mesh.adjacentFacesByEdge(self.index)
724
+ faces = self.mesh.faces()
725
+ return [faces[i] for i in idxs]
726
+
727
+ def adjacentFacesByVert(self):
728
+ """Get all faces that share a vert with the given face
729
+
730
+ Returns
731
+ -------
732
+ : list
733
+ List of faces that share a vert with the input
734
+ """
735
+ idxs = self.mesh.adjacentFacesByVert(self.index)
736
+ faces = self.mesh.faces()
737
+ return [faces[i] for i in idxs]
738
+
739
+ def __eq__(self, other) -> NotImplementedType | bool:
740
+ if isinstance(other, Face):
741
+ return set(self.verts()) == set(other.verts())
742
+ return NotImplemented
743
+
744
+ def __hash__(self) -> int:
745
+ return hash(self.verts())
746
+
747
+ def verts(self):
748
+ """Get all verts that make up this face
749
+
750
+ Returns
751
+ -------
752
+ : list
753
+ List of vertexes that make up this face
754
+ """
755
+ idxs = self.mesh.faceVertArray[self.index]
756
+ verts = self.mesh.verts()
757
+ return [verts[i] for i in idxs]
758
+
759
+ def uvs(self, name: str = "default"):
760
+ """Get all uvs that make up this face
761
+
762
+ Returns
763
+ -------
764
+ : list
765
+ List of uvs that make up this face
766
+ """
767
+ idxs = self.mesh.faceUVArray[name][self.index]
768
+ uvs = self.mesh.uvs(name)
769
+ return [uvs[i] for i in idxs]
770
+
771
+ def value(self):
772
+ """Get the face's index
773
+
774
+ Returns
775
+ -------
776
+ : int
777
+ The face's index
778
+ """
779
+ return self.index
780
+
781
+
782
+ class UV(MeshComponent):
783
+ """A convenience class for accessing and manipulating uvs"""
784
+
785
+ __slot__ = "mesh", "index", "name"
786
+
787
+ def __init__(self, mesh: Mesh, name: str, index) -> None:
788
+ self.name = name
789
+ super().__init__(mesh, index)
790
+
791
+ def value(self):
792
+ """Get the uv's position
793
+
794
+ Returns
795
+ -------
796
+ : tuple
797
+ (u, v) position
798
+ """
799
+ return self.mesh.uvMap[self.name][self.index]
800
+
801
+ def setValue(self, pos) -> None:
802
+ """Set the uv's position
803
+
804
+ Parameters
805
+ ----------
806
+ pos : tuple
807
+ (u, v) position
808
+ """
809
+ t = tuple(pos)
810
+ assert len(t) == 2
811
+ self.mesh.uvMap[self.name][self.index] = t
812
+
813
+ def __hash__(self) -> int:
814
+ return hash(self.name, self.index)
815
+
816
+
817
+ class UVFace(MeshComponent):
818
+ """A convenience class for accessing and manipulating faces"""
819
+
820
+ __slot__ = "mesh", "index", "name"
821
+
822
+ def __init__(self, mesh: Mesh, name: str, index) -> None:
823
+ self.name = name
824
+ super().__init__(mesh, index)
825
+
826
+ def __eq__(self, other) -> NotImplementedType | bool:
827
+ if isinstance(other, UVFace):
828
+ return set(self.uvs()) == set(other.uvs())
829
+ return NotImplemented
830
+
831
+ def __hash__(self) -> int:
832
+ return hash(self.verts())
833
+
834
+ def verts(self):
835
+ """Get all verts that make up this UVFace
836
+
837
+ Returns
838
+ -------
839
+ : list
840
+ List of vertexes that make up this face
841
+ """
842
+ idxs = self.mesh.faceVertArray[self.index]
843
+ verts = self.mesh.verts()
844
+ return [verts[i] for i in idxs]
845
+
846
+ def uvs(self, name: str = "default"):
847
+ """Get all uvs that make up this UVFace
848
+
849
+ Returns
850
+ -------
851
+ : list
852
+ List of uvs that make up this face
853
+ """
854
+ idxs = self.mesh.uvFaceMap[name][self.index]
855
+ uvs = self.mesh.uvs(name)
856
+ return [uvs[i] for i in idxs]
857
+
858
+ def value(self):
859
+ """Get the uvFace's index
860
+
861
+ Returns
862
+ -------
863
+ : int
864
+ The uvFace's index
865
+ """
866
+ return self.index
867
+
868
+
869
+ #######################################################################################
870
+
871
+
872
+ class MeshSetMeta(type):
873
+ """Wraps the magic methods to ensure that a reference to the mesh is kept"""
874
+
875
+ def __new__(mcs, clsName, bases, dct):
876
+ names = [
877
+ "__and__",
878
+ "__or__",
879
+ "__sub__",
880
+ "__xor__",
881
+ "copy",
882
+ "difference",
883
+ "intersection",
884
+ "union",
885
+ "symmetric_difference",
886
+ ]
887
+
888
+ rnames = ["__rand__", "__ror__", "__rsub__", "__rxor__"]
889
+
890
+ def wrap_closure(name: str, right: bool):
891
+ def inner(self, *args):
892
+ result = getattr(set, name)(self, *args)
893
+ if not hasattr(result, "mesh"):
894
+ if right:
895
+ # Gotta special-case the __r*__ methods
896
+ # because they get the mesh from the args
897
+ result.mesh = args[0].mesh
898
+ else:
899
+ result.mesh = self.mesh
900
+ return result
901
+
902
+ inner.fn_name = name
903
+ inner.__name__ = name
904
+ return inner
905
+
906
+ if set in bases:
907
+ for attr in names:
908
+ dct[attr] = wrap_closure(attr, False)
909
+ for attr in rnames:
910
+ dct[attr] = wrap_closure(attr, True)
911
+
912
+ return super().__new__(mcs, clsName, bases, dct)
913
+
914
+
915
+ class MeshSet(set, metaclass=MeshSetMeta):
916
+ """An set-like object that deals with geometry"""
917
+
918
+ def __init__(self, mesh: Mesh, indices=None) -> None:
919
+ idxs = [] if indices is None else [int(i) for i in indices]
920
+ super().__init__(idxs)
921
+ self.mesh = mesh
922
+ self.mesh.children.append(self)
923
+
924
+ def grow(self, growMethod, exclude=None, track=False):
925
+ """Add adjacent objects as determined by the growMethod, and
926
+ keep track of the previous growth for optimization purposes
927
+
928
+ Parameters
929
+ ----------
930
+ growMethod : function
931
+ A function that returns the neighbors
932
+ for each object index
933
+ exclude : MeshSet
934
+ A set of objects to exclude from growth
935
+ track : bool
936
+ Whether to keep track of the exclude input as well
937
+
938
+ Returns
939
+ -------
940
+ : MeshSet
941
+ An updated MeshSet
942
+ : MeshSet (Only if track=True)
943
+ The updated exclude set
944
+ """
945
+ if not isinstance(exclude, type(self)):
946
+ exclude = exclude or []
947
+ exclude = type(self)(self.mesh, exclude)
948
+
949
+ grown = type(self)(self.mesh)
950
+ growSet = self - exclude
951
+
952
+ for vert in growSet:
953
+ grown.update(growMethod(vert))
954
+
955
+ newGrown = grown - exclude
956
+ if track:
957
+ newExclude = exclude | growSet
958
+ return newGrown, newExclude
959
+ else:
960
+ return newGrown
961
+
962
+ def _partitionIslands(self, growMethod):
963
+ """Separate the current set into sets of neighboring objects
964
+
965
+ Parameters
966
+ ----------
967
+ growMethod : function
968
+ A function that returns the neighbors for each object index
969
+
970
+ Returns
971
+ -------
972
+ : [MeshSet, ...]
973
+ A list of interconnected object sets
974
+ """
975
+ myType = type(self)
976
+ allVerts = myType(self.mesh, [])
977
+ allVerts.update(self)
978
+ islands = []
979
+
980
+ while allVerts:
981
+ seed = myType(self.mesh, [allVerts.pop()])
982
+ island = myType(self.mesh, [])
983
+ while seed:
984
+ grown = myType(self.mesh, [])
985
+ for vert in seed:
986
+ grown.update(growMethod(vert))
987
+ newIsland = (island | seed) & self
988
+ seed = (grown - island) & self
989
+ island = newIsland
990
+
991
+ islands.append(island)
992
+ allVerts.difference_update(island)
993
+ return islands
994
+
995
+
996
+ class VertSet(MeshSet):
997
+ """A set-like object that deals with vertices"""
998
+
999
+ def growByEdge(self, exclude=None, track: bool = False):
1000
+ """Add verts that share edges with the current set
1001
+ Parameters
1002
+ ----------
1003
+ exclude : VertSet
1004
+ A set of vertices to exclude from growth
1005
+ track : bool
1006
+ Whether to keep track of the exclude input as well
1007
+
1008
+ Returns
1009
+ -------
1010
+ : VertSet
1011
+ An updated vertex set
1012
+ """
1013
+ return self.grow(self.mesh.adjacentVertsByEdge, exclude=exclude, track=track)
1014
+
1015
+ def growByFace(self, exclude=None, track: bool = False):
1016
+ """Add verts that share faces with the current set
1017
+ Parameters
1018
+ ----------
1019
+ exclude : VertSet
1020
+ A set of vertices to exclude from growth
1021
+ track : bool
1022
+ Whether to keep track of the exclude input as well
1023
+
1024
+ Returns
1025
+ -------
1026
+ : VertSet
1027
+ An updated vertex set
1028
+ """
1029
+ return self.grow(self.mesh.adjacentVertsByFace, exclude=exclude, track=track)
1030
+
1031
+ def partitionIslands(self):
1032
+ """Separate the current set into sets of neighboring objects
1033
+
1034
+ Returns
1035
+ -------
1036
+ : [VertSet, ...]
1037
+ A list of interconnected object sets
1038
+ """
1039
+ return super()._partitionIslands(self.mesh.adjacentVertsByFace)
1040
+
1041
+
1042
+ class FaceSet(MeshSet):
1043
+ """A set-like object that deals with faces"""
1044
+
1045
+ def growByEdge(self, exclude=None, track: bool = False):
1046
+ """Add faces that share edges with the current set
1047
+ Parameters
1048
+ ----------
1049
+ exclude : FaceSet
1050
+ A set of faces to exclude from growth
1051
+ track : bool
1052
+ Whether to keep track of the exclude input as well
1053
+
1054
+ Returns
1055
+ -------
1056
+ : FaceSet
1057
+ An updated face set
1058
+ """
1059
+ return self.grow(self.mesh.adjacentFacesByEdge, exclude=exclude, track=track)
1060
+
1061
+ def growByVert(self, exclude=None, track: bool = False):
1062
+ """Add faces that share verts with the current set
1063
+ Parameters
1064
+ ----------
1065
+ exclude : FaceSet
1066
+ A set of faces to exclude from growth
1067
+ track : bool
1068
+ Whether to keep track of the exclude input as well
1069
+
1070
+ Returns
1071
+ -------
1072
+ : FaceSet
1073
+ An updated face set
1074
+ """
1075
+ return self.grow(self.mesh.adjacentFacesByVert, exclude=exclude, track=track)
1076
+
1077
+ def partitionIslands(self):
1078
+ """Separate the current set into sets of neighboring objects
1079
+
1080
+ Returns
1081
+ -------
1082
+ : [FaceSet, ...]
1083
+ A list of interconnected object sets
1084
+ """
1085
+ return super()._partitionIslands(self.mesh.adjacentFacesByVert)