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