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