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.
- simplex_solver-3.2.2.dist-info/DELVEWHEEL +2 -0
- simplex_solver-3.2.2.dist-info/METADATA +94 -0
- simplex_solver-3.2.2.dist-info/RECORD +84 -0
- simplex_solver-3.2.2.dist-info/WHEEL +5 -0
- simplex_solver.libs/.load-order-simplex_solver-3.2.2 +1 -0
- simplex_solver.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
- simplexui/__init__.py +86 -0
- simplexui/_version.py +1 -0
- simplexui/channelBox.py +867 -0
- simplexui/comboCheckDialog.py +396 -0
- simplexui/commands/__init__.py +16 -0
- simplexui/commands/alembicCommon.py +1148 -0
- simplexui/commands/alembic_walker.py +299 -0
- simplexui/commands/applyCorrectives.py +452 -0
- simplexui/commands/correctiveInterface.py +259 -0
- simplexui/commands/expandedExport.py +434 -0
- simplexui/commands/hdf5Convert.py +62 -0
- simplexui/commands/mayaCorrectiveInterface.py +159 -0
- simplexui/commands/mayatonumpy.py +416 -0
- simplexui/commands/mesh.py +1085 -0
- simplexui/commands/poseblendlib.py +168 -0
- simplexui/commands/reorderSimplexPoints.py +102 -0
- simplexui/commands/replaceDefinitionJson.py +74 -0
- simplexui/commands/rigidAlign.py +97 -0
- simplexui/commands/unsubdivide.py +1222 -0
- simplexui/commands/uvTransfer.py +976 -0
- simplexui/dragFilter.py +334 -0
- simplexui/falloffDialog.py +504 -0
- simplexui/img/ChefHead.png +0 -0
- simplexui/img/frozen.png +0 -0
- simplexui/interface/__init__.py +30 -0
- simplexui/interface/dummyInterface.py +1313 -0
- simplexui/interface/mayaInterface.py +2294 -0
- simplexui/interfaceModel.py +655 -0
- simplexui/interfaceModelTrees.py +456 -0
- simplexui/items/__init__.py +50 -0
- simplexui/items/accessor.py +145 -0
- simplexui/items/combo.py +645 -0
- simplexui/items/dragItem.py +44 -0
- simplexui/items/falloff.py +748 -0
- simplexui/items/group.py +267 -0
- simplexui/items/progression.py +613 -0
- simplexui/items/shape.py +384 -0
- simplexui/items/simplex.py +1734 -0
- simplexui/items/slider.py +632 -0
- simplexui/items/stack.py +147 -0
- simplexui/items/traversal.py +780 -0
- simplexui/items/treeItem.py +441 -0
- simplexui/main.pyw +22 -0
- simplexui/menu/__init__.py +73 -0
- simplexui/menu/dummyPlugins/__init__.py +16 -0
- simplexui/menu/genericPlugins/__init__.py +16 -0
- simplexui/menu/genericPlugins/_builtins.py +270 -0
- simplexui/menu/genericPlugins/checkPossibleCombos.py +48 -0
- simplexui/menu/genericPlugins/exportSplit.py +67 -0
- simplexui/menu/genericPlugins/showFalloffs.py +26 -0
- simplexui/menu/genericPlugins/showTraversals.py +26 -0
- simplexui/menu/genericPlugins/simplexUvTransfer.py +106 -0
- simplexui/menu/genericPlugins/unsubdivide.py +72 -0
- simplexui/menu/mayaPlugins/__init__.py +16 -0
- simplexui/menu/mayaPlugins/exportOther.py +53 -0
- simplexui/menu/mayaPlugins/extractProgressives.py +68 -0
- simplexui/menu/mayaPlugins/freezeCombo.py +247 -0
- simplexui/menu/mayaPlugins/generateShapeIncrementals.py +99 -0
- simplexui/menu/mayaPlugins/importObjs.py +199 -0
- simplexui/menu/mayaPlugins/linearizeTraversal.py +60 -0
- simplexui/menu/mayaPlugins/makeShelfBtn.py +67 -0
- simplexui/menu/mayaPlugins/relaxToSelection.py +76 -0
- simplexui/menu/mayaPlugins/reloadDefinition.py +44 -0
- simplexui/menu/mayaPlugins/snapToNeutral.py +71 -0
- simplexui/menu/mayaPlugins/softSelectToCluster.py +201 -0
- simplexui/menu/mayaPlugins/tweakMix.py +136 -0
- simplexui/menu/mayaPlugins/updateRestShape.py +113 -0
- simplexui/pysimplex.lib +0 -0
- simplexui/pysimplex.pyd +0 -0
- simplexui/simplexDialog.py +1547 -0
- simplexui/travCheckDialog.py +419 -0
- simplexui/traversalDialog.py +299 -0
- simplexui/ui/comboCheckDialog.ui +475 -0
- simplexui/ui/falloffDialog.ui +243 -0
- simplexui/ui/simplexDialog.ui +1458 -0
- simplexui/ui/travCheckDialog.ui +488 -0
- simplexui/ui/traversalDialog.ui +532 -0
- simplexui/utils.py +307 -0
|
@@ -0,0 +1,1222 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
from itertools import chain, zip_longest
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
from Qt.QtWidgets import QApplication
|
|
24
|
+
|
|
25
|
+
from .alembicCommon import buildSmpx, pbPrint, readSmpx
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def mergeCycles(groups):
|
|
29
|
+
"""Take a list of ordered items, and sort them so the last item of each list matches the first of the next list
|
|
30
|
+
|
|
31
|
+
Then return the groups of lists mashed together
|
|
32
|
+
For instance, with two cycles:
|
|
33
|
+
+---------+------------------------------------------------------------+
|
|
34
|
+
| input | [(1, 2), (11, 12), (3, 1), (10, 11), (2, 3), (12, 10)] |
|
|
35
|
+
+---------+------------------------------------------------------------+
|
|
36
|
+
| reorder | [[(1, 2), (2, 3), (3, 1)], [(10, 11), (11, 12), (12, 13)]] |
|
|
37
|
+
+---------+------------------------------------------------------------+
|
|
38
|
+
| output | [[1, 2, 3], [10, 11, 12, 13]] |
|
|
39
|
+
+---------+------------------------------------------------------------+
|
|
40
|
+
|
|
41
|
+
Also, return whether the cycles merged form a single closed group
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
groups : [(int, int), ...]
|
|
46
|
+
A list of pairs of integers
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
: [[int, ...], ...]
|
|
51
|
+
The ordered cycles
|
|
52
|
+
"""
|
|
53
|
+
groups = [list(g) for g in groups]
|
|
54
|
+
heads = {g[0]: g for g in groups}
|
|
55
|
+
tails = {g[-1]: g for g in groups}
|
|
56
|
+
|
|
57
|
+
headGetter = lambda x: heads.get(x[-1]) # noqa: E731
|
|
58
|
+
headSetter = lambda x, y: x + y[1:] # noqa: E731
|
|
59
|
+
|
|
60
|
+
tailGetter = lambda x: tails.get(x[0]) # noqa: E731
|
|
61
|
+
tailSetter = lambda x, y: y + x[1:] # noqa: E731
|
|
62
|
+
|
|
63
|
+
searches = ((headGetter, headSetter), (tailGetter, tailSetter))
|
|
64
|
+
|
|
65
|
+
out = []
|
|
66
|
+
cycles = []
|
|
67
|
+
while groups:
|
|
68
|
+
g = groups.pop()
|
|
69
|
+
del heads[g[0]]
|
|
70
|
+
del tails[g[-1]]
|
|
71
|
+
|
|
72
|
+
for getter, setter in searches:
|
|
73
|
+
while True:
|
|
74
|
+
adder = getter(g)
|
|
75
|
+
if adder is None:
|
|
76
|
+
break
|
|
77
|
+
g = setter(g, adder)
|
|
78
|
+
del heads[adder[0]]
|
|
79
|
+
del tails[adder[-1]]
|
|
80
|
+
adder[:] = []
|
|
81
|
+
groups = [x for x in groups if x]
|
|
82
|
+
|
|
83
|
+
cycle = False
|
|
84
|
+
if g[0] == g[-1]:
|
|
85
|
+
g.pop()
|
|
86
|
+
cycle = True
|
|
87
|
+
cycles.append(cycle)
|
|
88
|
+
out.append(g)
|
|
89
|
+
return out, cycles
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def grow(neigh, verts, exclude):
|
|
93
|
+
"""Grow the vertex set, also keeping track of which vertices to ignore for the next iteration
|
|
94
|
+
|
|
95
|
+
Parameters
|
|
96
|
+
----------
|
|
97
|
+
neigh : {int: [int, ...]}
|
|
98
|
+
A dict mapping a vert index to a list of neighbor vert indices
|
|
99
|
+
verts : set(int)
|
|
100
|
+
A set of vert indices to grow
|
|
101
|
+
exclude : set(int)
|
|
102
|
+
A set of vert indices to ignore
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
: set(int)
|
|
107
|
+
The newly grown vertices
|
|
108
|
+
: set(int)
|
|
109
|
+
``exclude`` combined with ``verts``
|
|
110
|
+
|
|
111
|
+
"""
|
|
112
|
+
grown = set()
|
|
113
|
+
growSet = verts - exclude
|
|
114
|
+
for v in growSet:
|
|
115
|
+
grown.update(neigh[v])
|
|
116
|
+
newGrown = grown - exclude
|
|
117
|
+
newExclude = exclude | growSet
|
|
118
|
+
return newGrown, newExclude
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def buildHint(island, neigh, borders):
|
|
122
|
+
"""Find star points that are an even number of grows from an edge
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
island : [int, ...]
|
|
127
|
+
A list of vertices as part of a mesh island
|
|
128
|
+
neigh : {int: [int, ...]}
|
|
129
|
+
The dictionary of vertex neighbors
|
|
130
|
+
borders : set(int)
|
|
131
|
+
A set of border vertices
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
: int
|
|
136
|
+
The first star point encountered at an even grow from the given borders
|
|
137
|
+
"""
|
|
138
|
+
borders = borders & island
|
|
139
|
+
if not borders:
|
|
140
|
+
# Well ... we don't have any good way of dealing with this
|
|
141
|
+
# Best thing I can do is search for a point with the least
|
|
142
|
+
# number of similar valences, and return that
|
|
143
|
+
d = {}
|
|
144
|
+
for v in island:
|
|
145
|
+
d.setdefault(len(neigh[v]), []).append(v)
|
|
146
|
+
|
|
147
|
+
dd = {}
|
|
148
|
+
for k, v in d.items():
|
|
149
|
+
dd.setdefault(len(v), []).append(k)
|
|
150
|
+
|
|
151
|
+
mkey = min(dd.keys())
|
|
152
|
+
return d[dd[mkey][0]][0]
|
|
153
|
+
|
|
154
|
+
exclude = set()
|
|
155
|
+
while borders:
|
|
156
|
+
borders, exclude = grow(neigh, borders, exclude)
|
|
157
|
+
borders, exclude = grow(neigh, borders, exclude)
|
|
158
|
+
for b in borders:
|
|
159
|
+
if len(neigh[b]) != 4:
|
|
160
|
+
return b
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def partitionIslands(faces, neigh, pBar=None):
|
|
165
|
+
"""Find all groups of connected verts
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
faces : [[int, ...], ...]
|
|
170
|
+
The list of lists of vertex indices making up faces
|
|
171
|
+
neigh : {int: [int, ...]}
|
|
172
|
+
The dict of vertex neighbors
|
|
173
|
+
pBar : QProgressDialog or None
|
|
174
|
+
An optional progress bar
|
|
175
|
+
|
|
176
|
+
Returns
|
|
177
|
+
-------
|
|
178
|
+
: [set(int), ...]
|
|
179
|
+
A list of sets of non-connected vertex islands
|
|
180
|
+
"""
|
|
181
|
+
allVerts = set(chain.from_iterable(faces))
|
|
182
|
+
islands = []
|
|
183
|
+
count = float(len(allVerts))
|
|
184
|
+
|
|
185
|
+
if pBar is not None:
|
|
186
|
+
pBar.setValue(0)
|
|
187
|
+
pBar.setMaximum(count)
|
|
188
|
+
QApplication.processEvents()
|
|
189
|
+
|
|
190
|
+
while allVerts:
|
|
191
|
+
verts = {allVerts.pop()}
|
|
192
|
+
exclude = set()
|
|
193
|
+
while verts:
|
|
194
|
+
verts, exclude = grow(neigh, verts, exclude)
|
|
195
|
+
islands.append(exclude)
|
|
196
|
+
allVerts.difference_update(exclude)
|
|
197
|
+
|
|
198
|
+
if pBar is not None:
|
|
199
|
+
pBar.setValue(count - len(allVerts))
|
|
200
|
+
QApplication.processEvents()
|
|
201
|
+
|
|
202
|
+
return islands
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def buildUnsubdivideHints(faces, neigh, borders, pBar=None):
|
|
206
|
+
"""Get one vertex per island that was part of the original mesh
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
faces : [[int, ...], ...]
|
|
211
|
+
The list of lists of vertex indices making up faces
|
|
212
|
+
neigh : {int: [int, ...]}
|
|
213
|
+
The dict of vertex neighbors
|
|
214
|
+
borders : set(int)
|
|
215
|
+
A set of border vertices
|
|
216
|
+
pBar : QProgressDialog or None
|
|
217
|
+
An optional progress bar
|
|
218
|
+
|
|
219
|
+
Returns
|
|
220
|
+
-------
|
|
221
|
+
: [int, ...]
|
|
222
|
+
A list of star-points (one per island) to un-subdivide from
|
|
223
|
+
"""
|
|
224
|
+
islands = partitionIslands(faces, neigh, pBar=pBar)
|
|
225
|
+
hints = []
|
|
226
|
+
|
|
227
|
+
if pBar is not None:
|
|
228
|
+
pBar.setValue(0)
|
|
229
|
+
pBar.setMaximum(len(islands))
|
|
230
|
+
QApplication.processEvents()
|
|
231
|
+
|
|
232
|
+
for i, isle in enumerate(islands):
|
|
233
|
+
if pBar is not None:
|
|
234
|
+
pBar.setValue(i)
|
|
235
|
+
QApplication.processEvents()
|
|
236
|
+
hints.append(buildHint(isle, neigh, borders))
|
|
237
|
+
|
|
238
|
+
hints = [h for h in hints if h is not None]
|
|
239
|
+
return hints
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def getFaceCenterDel(faces, eNeigh, hints, pBar=None):
|
|
243
|
+
"""Given a list of hint "keeper" points
|
|
244
|
+
|
|
245
|
+
Parameters
|
|
246
|
+
----------
|
|
247
|
+
faces : [[int, ...], ...]
|
|
248
|
+
The list of lists of vertex indices making up faces
|
|
249
|
+
eNeigh : {int: [int, ...]}
|
|
250
|
+
The dict of vertex neighbors
|
|
251
|
+
hints : [int, ...]
|
|
252
|
+
A list of star-points (one per island) to un-subdivide from
|
|
253
|
+
pBar : QProgressDialog or None
|
|
254
|
+
An optional progress bar
|
|
255
|
+
|
|
256
|
+
Returns
|
|
257
|
+
-------
|
|
258
|
+
: set(int)
|
|
259
|
+
Centers of the original faces during a subdivision
|
|
260
|
+
: bool
|
|
261
|
+
Whether the operation failed(True) or not(False)
|
|
262
|
+
"""
|
|
263
|
+
vertToFaces = {}
|
|
264
|
+
vc = set()
|
|
265
|
+
for i, face in enumerate(faces):
|
|
266
|
+
for f in face:
|
|
267
|
+
vertToFaces.setdefault(f, []).append(i)
|
|
268
|
+
vc.add(f)
|
|
269
|
+
|
|
270
|
+
count = len(vc)
|
|
271
|
+
centers = set()
|
|
272
|
+
midpoints = set()
|
|
273
|
+
originals = set(hints)
|
|
274
|
+
queue = set(hints)
|
|
275
|
+
|
|
276
|
+
if pBar is not None:
|
|
277
|
+
pBar.setValue(0)
|
|
278
|
+
pBar.setMaximum(count)
|
|
279
|
+
QApplication.processEvents()
|
|
280
|
+
|
|
281
|
+
i = 0
|
|
282
|
+
fail = False
|
|
283
|
+
while queue:
|
|
284
|
+
cur = queue.pop()
|
|
285
|
+
if cur in midpoints:
|
|
286
|
+
continue
|
|
287
|
+
|
|
288
|
+
if pBar is not None:
|
|
289
|
+
pBar.setValue(i)
|
|
290
|
+
QApplication.processEvents()
|
|
291
|
+
i += 2 # Add 2 because I *shouldn't* get any midpoints
|
|
292
|
+
|
|
293
|
+
midpoints.update(eNeigh[cur])
|
|
294
|
+
t = centers if cur in originals else originals
|
|
295
|
+
|
|
296
|
+
for f in vertToFaces[cur]:
|
|
297
|
+
nVerts = faces[f]
|
|
298
|
+
|
|
299
|
+
if len(nVerts) != 4:
|
|
300
|
+
fail = True
|
|
301
|
+
continue
|
|
302
|
+
|
|
303
|
+
curFaceIndex = nVerts.index(cur)
|
|
304
|
+
|
|
305
|
+
half = int(len(nVerts) / 2)
|
|
306
|
+
diag = nVerts[curFaceIndex - half]
|
|
307
|
+
|
|
308
|
+
isOrig = diag in originals
|
|
309
|
+
isCtr = diag in centers
|
|
310
|
+
if not isOrig and not isCtr:
|
|
311
|
+
t.add(diag)
|
|
312
|
+
queue.add(diag)
|
|
313
|
+
elif (
|
|
314
|
+
(isCtr and t is originals)
|
|
315
|
+
or (isOrig and t is centers)
|
|
316
|
+
or (diag in midpoints)
|
|
317
|
+
):
|
|
318
|
+
fail = True
|
|
319
|
+
|
|
320
|
+
return centers, fail
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def getBorders(faces):
|
|
324
|
+
"""Get the indices of verts along the borders of a mesh
|
|
325
|
+
|
|
326
|
+
Parameters
|
|
327
|
+
----------
|
|
328
|
+
faces : [[int, ...], ...]
|
|
329
|
+
The list of lists of vertex indices making up faces
|
|
330
|
+
|
|
331
|
+
Returns
|
|
332
|
+
-------
|
|
333
|
+
: set(int)
|
|
334
|
+
A set of border vertices
|
|
335
|
+
"""
|
|
336
|
+
edgePairs = set()
|
|
337
|
+
for face in faces:
|
|
338
|
+
for f in range(len(face)):
|
|
339
|
+
edgePairs.add((face[f], face[f - 1]))
|
|
340
|
+
borders = set()
|
|
341
|
+
for ep in edgePairs:
|
|
342
|
+
if (ep[1], ep[0]) not in edgePairs:
|
|
343
|
+
borders.update(ep)
|
|
344
|
+
return borders
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def buildEdgeDict(faces):
|
|
348
|
+
"""Build a dictionary of un-ordered neighboring vertices along edges
|
|
349
|
+
|
|
350
|
+
Parameters
|
|
351
|
+
----------
|
|
352
|
+
faces : [[int, ...], ...]
|
|
353
|
+
The list of lists of vertex indices making up faces
|
|
354
|
+
|
|
355
|
+
Returns
|
|
356
|
+
-------
|
|
357
|
+
: {int: set(int)}
|
|
358
|
+
A dictionary of neighboring vertices along edges
|
|
359
|
+
"""
|
|
360
|
+
edgeDict = {}
|
|
361
|
+
for face in faces:
|
|
362
|
+
for f in range(len(face)):
|
|
363
|
+
ff = edgeDict.setdefault(face[f - 1], set())
|
|
364
|
+
ff.add(face[f])
|
|
365
|
+
ff.add(face[f - 2])
|
|
366
|
+
return edgeDict
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def buildNeighborDict(faces):
|
|
370
|
+
"""Build a structure to ask for edge and face neighboring vertices
|
|
371
|
+
The returned neighbor list starts with an edge neighbor, and
|
|
372
|
+
proceeds counter clockwise, alternating between edge and face neighbors
|
|
373
|
+
Also, while I'm here, grab the border verts
|
|
374
|
+
|
|
375
|
+
Parameters
|
|
376
|
+
----------
|
|
377
|
+
faces : [[int, ...], ...]
|
|
378
|
+
The list of lists of vertex indices making up faces
|
|
379
|
+
|
|
380
|
+
Returns
|
|
381
|
+
-------
|
|
382
|
+
: {int: [[int, ...], ...]}
|
|
383
|
+
A dictionary keyed from a vert index whose
|
|
384
|
+
values are ordered cycles or fans
|
|
385
|
+
: set(int)
|
|
386
|
+
A set of vertices that are on the border
|
|
387
|
+
"""
|
|
388
|
+
fanDict = {}
|
|
389
|
+
edgeDict = {}
|
|
390
|
+
for face in faces:
|
|
391
|
+
for i in range(len(face)):
|
|
392
|
+
fanDict.setdefault(face[i], []).append(face[i + 1 :] + face[:i])
|
|
393
|
+
ff = edgeDict.setdefault(face[i - 1], set())
|
|
394
|
+
ff.add(face[i])
|
|
395
|
+
ff.add(face[i - 2])
|
|
396
|
+
|
|
397
|
+
borders = set()
|
|
398
|
+
out = {}
|
|
399
|
+
for k, v in fanDict.items():
|
|
400
|
+
fans, cycles = mergeCycles(v)
|
|
401
|
+
for f, c in zip(fans, cycles):
|
|
402
|
+
if not c:
|
|
403
|
+
borders.update((f[0], f[-1], k))
|
|
404
|
+
out[k] = fans
|
|
405
|
+
return out, edgeDict, borders
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _fanMatch(fan, uFan, dWings):
|
|
409
|
+
"""Twist a single fan so it matches the uFan if it can"""
|
|
410
|
+
uIdx = uFan[0]
|
|
411
|
+
for f, fIdx in enumerate(fan):
|
|
412
|
+
dw = dWings.get(fIdx, [])
|
|
413
|
+
if uIdx in dw:
|
|
414
|
+
return fan[f:] + fan[:f]
|
|
415
|
+
return None
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def _align(neigh, uNeigh, dWings):
|
|
419
|
+
"""Twist all the neighs so they match the uNeigh"""
|
|
420
|
+
out = []
|
|
421
|
+
for uFan in uNeigh:
|
|
422
|
+
for fan in neigh:
|
|
423
|
+
fm = _fanMatch(fan, uFan, dWings)
|
|
424
|
+
if fm is not None:
|
|
425
|
+
out.append(fm)
|
|
426
|
+
break
|
|
427
|
+
return out
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def buildLayeredNeighborDicts(faces, uFaces, dWings):
|
|
431
|
+
"""Build and align two neighbor dicts for both faces and uFaces
|
|
432
|
+
This guarantees that the neighbors at the same index are analogous
|
|
433
|
+
(ie. they go in the same direction)
|
|
434
|
+
|
|
435
|
+
Parameters
|
|
436
|
+
----------
|
|
437
|
+
faces : [[int, ...], ...]
|
|
438
|
+
The list of lists of vertex indices making up faces
|
|
439
|
+
uFaces : [[int, ...], ...]
|
|
440
|
+
The list of lists of vertex indices making up un-subdivided faces
|
|
441
|
+
dWings : ???
|
|
442
|
+
???
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
|
|
447
|
+
"""
|
|
448
|
+
neighDict, edgeDict, borders = buildNeighborDict(faces)
|
|
449
|
+
uNeighDict, uEdgeDict, uBorders = buildNeighborDict(uFaces)
|
|
450
|
+
|
|
451
|
+
assert (
|
|
452
|
+
borders >= uBorders
|
|
453
|
+
), "Somehow the unsubdivided borders contain different vIdxs"
|
|
454
|
+
|
|
455
|
+
for k, uNeigh in uNeighDict.items():
|
|
456
|
+
neighDict[k] = _align(neighDict[k], uNeigh, dWings)
|
|
457
|
+
|
|
458
|
+
return neighDict, uNeighDict, edgeDict, uEdgeDict, borders
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def _findOldPositionBorder(
|
|
462
|
+
faces,
|
|
463
|
+
uFaces,
|
|
464
|
+
verts,
|
|
465
|
+
uVerts,
|
|
466
|
+
neighDict,
|
|
467
|
+
uNeighDict,
|
|
468
|
+
edgeDict,
|
|
469
|
+
uEdgeDict,
|
|
470
|
+
borders,
|
|
471
|
+
vIdx,
|
|
472
|
+
computed,
|
|
473
|
+
) -> None:
|
|
474
|
+
"""Find the position of the un-subdivided mesh if the vertex was on the border"""
|
|
475
|
+
nei = neighDict[vIdx][0]
|
|
476
|
+
nei = [i for i in nei if i in borders]
|
|
477
|
+
assert len(nei) == 2, f"Found multi border, {nei}"
|
|
478
|
+
uVerts[vIdx] = 2 * verts[vIdx] - ((verts[nei[0]] + verts[nei[1]]) / 2)
|
|
479
|
+
computed.add(vIdx)
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def _findOldPositionSimple(
|
|
483
|
+
faces,
|
|
484
|
+
uFaces,
|
|
485
|
+
verts,
|
|
486
|
+
uVerts,
|
|
487
|
+
neighDict,
|
|
488
|
+
uNeighDict,
|
|
489
|
+
edgeDict,
|
|
490
|
+
uEdgeDict,
|
|
491
|
+
vIdx,
|
|
492
|
+
computed,
|
|
493
|
+
) -> None:
|
|
494
|
+
"""Find the position of the un-subdivided mesh if the vertex has at least 4 neighbors.
|
|
495
|
+
Updates uVerts in-place
|
|
496
|
+
"""
|
|
497
|
+
neigh = neighDict[vIdx][0]
|
|
498
|
+
|
|
499
|
+
eTest = edgeDict[vIdx]
|
|
500
|
+
e = [p for p in neigh if p in eTest]
|
|
501
|
+
f = [p for p in neigh if p not in eTest]
|
|
502
|
+
|
|
503
|
+
es = verts[e].sum(axis=0)
|
|
504
|
+
fs = verts[f].sum(axis=0)
|
|
505
|
+
|
|
506
|
+
n = len(e)
|
|
507
|
+
term1 = verts[vIdx] * (n / (n - 3.0))
|
|
508
|
+
term2 = es * (4 / (n * (n - 3.0)))
|
|
509
|
+
term3 = fs * (1 / (n * (n - 3.0)))
|
|
510
|
+
vk = term1 - term2 + term3
|
|
511
|
+
|
|
512
|
+
uVerts[vIdx] = vk
|
|
513
|
+
computed.add(vIdx)
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def _findOldPosition3Valence(
|
|
517
|
+
faces,
|
|
518
|
+
uFaces,
|
|
519
|
+
verts,
|
|
520
|
+
uVerts,
|
|
521
|
+
neighDict,
|
|
522
|
+
uNeighDict,
|
|
523
|
+
edgeDict,
|
|
524
|
+
uEdgeDict,
|
|
525
|
+
vIdx,
|
|
526
|
+
computed,
|
|
527
|
+
):
|
|
528
|
+
"""Find the position of the un-subdivided mesh if the vertex has exactly 3 neighbors
|
|
529
|
+
Updates uVerts in-place. It is possible for this to fail.
|
|
530
|
+
|
|
531
|
+
Returns
|
|
532
|
+
-------
|
|
533
|
+
: bool
|
|
534
|
+
Whether an update happened
|
|
535
|
+
"""
|
|
536
|
+
neigh = neighDict[vIdx][0]
|
|
537
|
+
uNeigh = uNeighDict[vIdx][0]
|
|
538
|
+
|
|
539
|
+
eTest = edgeDict[vIdx]
|
|
540
|
+
eNeigh = [n for n in neigh if n in eTest]
|
|
541
|
+
fNeigh = [n for n in neigh if n not in eTest]
|
|
542
|
+
|
|
543
|
+
ueTest = uEdgeDict[vIdx]
|
|
544
|
+
ueNeigh = [n for n in uNeigh if n in ueTest]
|
|
545
|
+
# ufNeigh = [n for n in uNeigh if n not in ueTest]
|
|
546
|
+
|
|
547
|
+
intr = computed.intersection(ueNeigh)
|
|
548
|
+
if intr:
|
|
549
|
+
# Easy valence 3 case. I only need
|
|
550
|
+
# The computed new neighbor
|
|
551
|
+
# The midpoint on the edge to that neighbor
|
|
552
|
+
# The "face" verts neighboring the midpoint
|
|
553
|
+
|
|
554
|
+
# Get the matching subbed an unsubbed neighbor indexes
|
|
555
|
+
uNIdx = intr.pop()
|
|
556
|
+
nIdx = eNeigh[ueNeigh.index(uNIdx)]
|
|
557
|
+
|
|
558
|
+
# Get the "face" verts next to the subbed neighbor
|
|
559
|
+
xx = neigh.index(nIdx)
|
|
560
|
+
fnIdxs = (neigh[xx - 1], neigh[(xx + 1) % len(neigh)])
|
|
561
|
+
|
|
562
|
+
# Then compute
|
|
563
|
+
# vk = 4*k1e - ke - k1fNs[0] - k1fNs[1]
|
|
564
|
+
vka = uVerts[uNIdx] + verts[fnIdxs[0]] + verts[fnIdxs[1]]
|
|
565
|
+
vkb = verts[nIdx] * 4
|
|
566
|
+
uVerts[vIdx] = vkb - vka
|
|
567
|
+
computed.add(vIdx)
|
|
568
|
+
return True
|
|
569
|
+
|
|
570
|
+
else:
|
|
571
|
+
# The Hard valence 3 case. Made even harder
|
|
572
|
+
# because the paper has a mistake in it
|
|
573
|
+
|
|
574
|
+
# vk = 4*ejk1 + 4*ejpk1 - fjnk1 - fjpk1 - 6*fjk1 + sum(fik)
|
|
575
|
+
# where k1 means subdivided mesh
|
|
576
|
+
# where j means an index, jn and jp are next/prev adjacents
|
|
577
|
+
# sum(fik) is the sum of all the points of the face that
|
|
578
|
+
# *aren't* the original, or edge-adjacent
|
|
579
|
+
# There could be more than 1 if an n-gon was subdivided
|
|
580
|
+
#
|
|
581
|
+
# I wonder: If it was a triangle that was subdivided, what
|
|
582
|
+
# would sum(fik) because there are no verts that fit that
|
|
583
|
+
# description. I think this is a degenerate case
|
|
584
|
+
|
|
585
|
+
# First, find an adjacent face on the unsub mesh that
|
|
586
|
+
# is only missing the neighbors of the vIdx
|
|
587
|
+
|
|
588
|
+
fnIdx = None
|
|
589
|
+
fik = None
|
|
590
|
+
fCtrIdx = None
|
|
591
|
+
for x, v in enumerate(fNeigh):
|
|
592
|
+
# working with neigh, but should only ever contain uNeigh indexes
|
|
593
|
+
eTest = edgeDict[vIdx]
|
|
594
|
+
origFace = {n for n in neighDict[v][0] if n not in eTest}
|
|
595
|
+
|
|
596
|
+
check = (origFace - set(ueNeigh)) - {vIdx}
|
|
597
|
+
if computed >= check:
|
|
598
|
+
fCtrIdx = v
|
|
599
|
+
fnIdx = x
|
|
600
|
+
fik = sorted(check)
|
|
601
|
+
break
|
|
602
|
+
|
|
603
|
+
if fnIdx is None:
|
|
604
|
+
# No possiblity found
|
|
605
|
+
return False
|
|
606
|
+
|
|
607
|
+
# Then apply the equation from above
|
|
608
|
+
neighIdx = neigh.index(fCtrIdx)
|
|
609
|
+
ejnk1 = neigh[(neighIdx + 1) % len(neigh)]
|
|
610
|
+
ejpk1 = neigh[neighIdx - 1]
|
|
611
|
+
fjnk1 = fNeigh[(fnIdx + 1) % len(fNeigh)]
|
|
612
|
+
fjpk1 = fNeigh[fnIdx - 1]
|
|
613
|
+
fjk1 = verts[fCtrIdx]
|
|
614
|
+
sumFik = uVerts[fik].sum(axis=0)
|
|
615
|
+
vk = 4 * ejnk1 + 4 * ejpk1 - fjnk1 - fjpk1 - 6 * fjk1 + sumFik
|
|
616
|
+
uVerts[vIdx] = vk
|
|
617
|
+
computed.add(vIdx)
|
|
618
|
+
return True
|
|
619
|
+
return False
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
def deleteCenters(meshFaces, uvFaces, centerDel, pBar=None):
|
|
623
|
+
"""Delete the given vertices and connected edges from a face representation
|
|
624
|
+
to give a new representation.
|
|
625
|
+
|
|
626
|
+
Parameters
|
|
627
|
+
----------
|
|
628
|
+
meshFaces : [[int, ...], ...]
|
|
629
|
+
The list of lists of vertex indices making up faces
|
|
630
|
+
centerDel : set(int)
|
|
631
|
+
A set of vertices to delete. These were the vertices added
|
|
632
|
+
to the centers of the faces when subdividing.
|
|
633
|
+
uvFaces : [[int, ...], ...]
|
|
634
|
+
The list of lists of uv indices making up uvFaces
|
|
635
|
+
pBar : QProgressDialog or None
|
|
636
|
+
An optional progress bar
|
|
637
|
+
|
|
638
|
+
Returns
|
|
639
|
+
-------
|
|
640
|
+
: [[int, ...], ...]
|
|
641
|
+
The new list of faces of the mesh
|
|
642
|
+
: [[int, ...], ...]
|
|
643
|
+
The new list of uvfaces of the mesh
|
|
644
|
+
: {int: (int, int)}
|
|
645
|
+
A dict of a deleted edge-midpoint to its two existing neighbor verts
|
|
646
|
+
: {int: (int, int)}
|
|
647
|
+
A dict of a deleted uv edge-midpoint to its two existing neighbor uvs
|
|
648
|
+
"""
|
|
649
|
+
# For each deleted index, grab the neighboring faces,
|
|
650
|
+
# and twist the faces so the deleted index is first
|
|
651
|
+
cds = set(centerDel)
|
|
652
|
+
faceDelDict = {}
|
|
653
|
+
uvDelDict = {}
|
|
654
|
+
uvFaces = uvFaces or []
|
|
655
|
+
for face, uvFace in zip_longest(meshFaces, uvFaces):
|
|
656
|
+
fi = cds.intersection(face)
|
|
657
|
+
# If we are a subdivided mesh, Then each face will have exactly one
|
|
658
|
+
# vertex that is part of the deletion set
|
|
659
|
+
if len(fi) != 1:
|
|
660
|
+
raise ValueError("Found a face with an unrecognized connectivity")
|
|
661
|
+
# Get that one vert
|
|
662
|
+
idx = fi.pop()
|
|
663
|
+
# Each face is a cycle. Rotate the cycle
|
|
664
|
+
# so that idx is first in the list
|
|
665
|
+
rv = face.index(idx)
|
|
666
|
+
rFace = face[rv:] + face[:rv]
|
|
667
|
+
faceDelDict.setdefault(idx, []).append(rFace)
|
|
668
|
+
|
|
669
|
+
if uvFace is not None:
|
|
670
|
+
rUVFace = uvFace[rv:] + uvFace[:rv]
|
|
671
|
+
uvDelDict.setdefault(idx, []).append(rUVFace)
|
|
672
|
+
|
|
673
|
+
newFaces = []
|
|
674
|
+
nUVFaces = []
|
|
675
|
+
wings = {}
|
|
676
|
+
uvWings = {}
|
|
677
|
+
|
|
678
|
+
if pBar is not None:
|
|
679
|
+
pBar.setValue(0)
|
|
680
|
+
pBar.setMaximum(len(faceDelDict))
|
|
681
|
+
|
|
682
|
+
chk = -1
|
|
683
|
+
for idx, rFaces in faceDelDict.items():
|
|
684
|
+
chk += 1
|
|
685
|
+
if pBar is not None:
|
|
686
|
+
pBar.setValue(chk)
|
|
687
|
+
QApplication.processEvents()
|
|
688
|
+
|
|
689
|
+
ruvFaces = uvDelDict.get(idx, [])
|
|
690
|
+
# The faces are guaranteed to be in a single loop cycle
|
|
691
|
+
# so I don't have to handle any annoying edge cases! Yay!
|
|
692
|
+
faceEnds = {
|
|
693
|
+
f[1]: (f[2], f[3], uvf) for f, uvf in zip_longest(rFaces, ruvFaces)
|
|
694
|
+
} # face ends
|
|
695
|
+
|
|
696
|
+
end = rFaces[-1][-1] # get an arbitrary face to start with
|
|
697
|
+
newFace = []
|
|
698
|
+
nUVFace = []
|
|
699
|
+
while faceEnds:
|
|
700
|
+
try:
|
|
701
|
+
diag, nxt, uvf = faceEnds.pop(end)
|
|
702
|
+
except KeyError:
|
|
703
|
+
print("rFaces", rFaces)
|
|
704
|
+
print("fe", faceEnds)
|
|
705
|
+
raise
|
|
706
|
+
if uvf is not None:
|
|
707
|
+
try:
|
|
708
|
+
nUVFace.append(uvf[2])
|
|
709
|
+
uvWings.setdefault(uvf[1], []).append(uvf[2])
|
|
710
|
+
uvWings.setdefault(uvf[3], []).append(uvf[2])
|
|
711
|
+
except IndexError:
|
|
712
|
+
print("UVF", uvf, chk)
|
|
713
|
+
raise
|
|
714
|
+
|
|
715
|
+
newFace.append(diag)
|
|
716
|
+
wings.setdefault(end, []).append(diag)
|
|
717
|
+
wings.setdefault(nxt, []).append(diag)
|
|
718
|
+
|
|
719
|
+
end = nxt
|
|
720
|
+
newFaces.append(newFace)
|
|
721
|
+
if nUVFace:
|
|
722
|
+
nUVFaces.append(nUVFace)
|
|
723
|
+
nUVFaces = nUVFaces or None
|
|
724
|
+
|
|
725
|
+
return newFaces, nUVFaces, wings, uvWings
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
def fixVerts(
|
|
729
|
+
faces,
|
|
730
|
+
uFaces,
|
|
731
|
+
verts,
|
|
732
|
+
neighDict,
|
|
733
|
+
uNeighDict,
|
|
734
|
+
edgeDict,
|
|
735
|
+
uEdgeDict,
|
|
736
|
+
borders,
|
|
737
|
+
pinned,
|
|
738
|
+
pBar=None,
|
|
739
|
+
):
|
|
740
|
+
"""Given the faces, vertex positions, and the point indices that
|
|
741
|
+
were created at the face centers for a subdivision step
|
|
742
|
+
Return the faces and verts of the mesh from before the
|
|
743
|
+
subdivision step. This algorithm doesn't handle UV's yet
|
|
744
|
+
|
|
745
|
+
Parameters
|
|
746
|
+
----------
|
|
747
|
+
faces : [[int, ...], ...]
|
|
748
|
+
The list of lists of vertex indices making up faces
|
|
749
|
+
verts : np.array
|
|
750
|
+
The Nx3 array of vertices
|
|
751
|
+
centerDel : set(int)
|
|
752
|
+
A set of vertices to delete
|
|
753
|
+
uFaces : [[int, ...], ...]
|
|
754
|
+
The list of lists of vertex indices making up the
|
|
755
|
+
un-subdivided faces. Not all numbers in the vert range are in this structure
|
|
756
|
+
neighDict : {int: [int, ...]}
|
|
757
|
+
The dictionary of vertex neighbors based on ``faces``
|
|
758
|
+
uNeighDict : {int: [int, ...]}
|
|
759
|
+
The dictionary of vertex neighbors based on ``uFaces``
|
|
760
|
+
edgeDict : TODO
|
|
761
|
+
Some kind of dictionary representing individual edges
|
|
762
|
+
uEdgeDict : TODO
|
|
763
|
+
Some kind of dictionary representing individual edges in the unsub mesh
|
|
764
|
+
borders : set(int)
|
|
765
|
+
The set of vertices along the borders
|
|
766
|
+
pinned : set(int)
|
|
767
|
+
The set of vertices that will not be moved by this process
|
|
768
|
+
pBar : QProgressDialog or None
|
|
769
|
+
An optional progress bar
|
|
770
|
+
|
|
771
|
+
Returns
|
|
772
|
+
-------
|
|
773
|
+
: np.array
|
|
774
|
+
An array of vertex positions
|
|
775
|
+
"""
|
|
776
|
+
uVerts = verts.copy()
|
|
777
|
+
uIdxs = sorted(set(chain.from_iterable(uFaces)))
|
|
778
|
+
|
|
779
|
+
v3Idxs = []
|
|
780
|
+
# bowtie verts are pinned
|
|
781
|
+
bowTieIdxs = []
|
|
782
|
+
computed = set()
|
|
783
|
+
i = 0
|
|
784
|
+
if pBar is not None:
|
|
785
|
+
pBar.setValue(0)
|
|
786
|
+
pBar.setMaximum(len(uIdxs))
|
|
787
|
+
|
|
788
|
+
for idx in uIdxs:
|
|
789
|
+
if pBar is not None:
|
|
790
|
+
pBar.setValue(i)
|
|
791
|
+
QApplication.processEvents()
|
|
792
|
+
if len(uNeighDict[idx]) > 1:
|
|
793
|
+
bowTieIdxs.append(idx)
|
|
794
|
+
i += 1
|
|
795
|
+
elif idx in pinned:
|
|
796
|
+
pass
|
|
797
|
+
elif idx in borders:
|
|
798
|
+
_findOldPositionBorder(
|
|
799
|
+
faces,
|
|
800
|
+
uFaces,
|
|
801
|
+
verts,
|
|
802
|
+
uVerts,
|
|
803
|
+
neighDict,
|
|
804
|
+
uNeighDict,
|
|
805
|
+
edgeDict,
|
|
806
|
+
uEdgeDict,
|
|
807
|
+
borders,
|
|
808
|
+
idx,
|
|
809
|
+
computed,
|
|
810
|
+
)
|
|
811
|
+
i += 1
|
|
812
|
+
elif sum(map(len, neighDict[idx])) > 6: # if valence > 3
|
|
813
|
+
_findOldPositionSimple(
|
|
814
|
+
faces,
|
|
815
|
+
uFaces,
|
|
816
|
+
verts,
|
|
817
|
+
uVerts,
|
|
818
|
+
neighDict,
|
|
819
|
+
uNeighDict,
|
|
820
|
+
edgeDict,
|
|
821
|
+
uEdgeDict,
|
|
822
|
+
idx,
|
|
823
|
+
computed,
|
|
824
|
+
)
|
|
825
|
+
i += 1
|
|
826
|
+
else:
|
|
827
|
+
v3Idxs.append(idx)
|
|
828
|
+
|
|
829
|
+
updated = True
|
|
830
|
+
while updated:
|
|
831
|
+
updated = False
|
|
832
|
+
rem = set()
|
|
833
|
+
for idx in v3Idxs:
|
|
834
|
+
up = _findOldPosition3Valence(
|
|
835
|
+
faces,
|
|
836
|
+
uFaces,
|
|
837
|
+
verts,
|
|
838
|
+
uVerts,
|
|
839
|
+
neighDict,
|
|
840
|
+
uNeighDict,
|
|
841
|
+
edgeDict,
|
|
842
|
+
uEdgeDict,
|
|
843
|
+
idx,
|
|
844
|
+
computed,
|
|
845
|
+
)
|
|
846
|
+
if not up:
|
|
847
|
+
continue
|
|
848
|
+
if pBar is not None:
|
|
849
|
+
pBar.setValue(i)
|
|
850
|
+
QApplication.processEvents()
|
|
851
|
+
i += 1
|
|
852
|
+
updated = True
|
|
853
|
+
rem.add(idx)
|
|
854
|
+
v3Idxs = list(set(v3Idxs) - rem)
|
|
855
|
+
|
|
856
|
+
return uVerts
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
def getUVPins(faces, borders, uvFaces, uvBorders, pinBorders: bool):
|
|
860
|
+
"""Find which uvBorders are also mesh borders
|
|
861
|
+
|
|
862
|
+
Parameters
|
|
863
|
+
----------
|
|
864
|
+
faces : [[int, ...], ...]
|
|
865
|
+
The list of lists of vertex indices making up faces
|
|
866
|
+
borders : set(int)
|
|
867
|
+
The set of vertices along the borders
|
|
868
|
+
uvFaces : [[int, ...], ...]
|
|
869
|
+
The list of lists of uv indices making up uvFaces
|
|
870
|
+
uvBorders : set(int)
|
|
871
|
+
The set of vertices along the borders of uvs
|
|
872
|
+
pinBorders : bool
|
|
873
|
+
Whether to just pin all uv borders
|
|
874
|
+
|
|
875
|
+
Returns
|
|
876
|
+
-------
|
|
877
|
+
: set(int)
|
|
878
|
+
The vertex indices to pin
|
|
879
|
+
"""
|
|
880
|
+
if uvFaces is None:
|
|
881
|
+
return set()
|
|
882
|
+
if pinBorders:
|
|
883
|
+
return set(uvBorders)
|
|
884
|
+
|
|
885
|
+
pinnit = set()
|
|
886
|
+
for face, uvFace in zip(faces, uvFaces):
|
|
887
|
+
for i in range(len(face)):
|
|
888
|
+
f = face[i]
|
|
889
|
+
pf = face[i - 1]
|
|
890
|
+
|
|
891
|
+
uv = uvFace[i]
|
|
892
|
+
puv = uvFace[i - 1]
|
|
893
|
+
|
|
894
|
+
if not (f in borders and pf in borders):
|
|
895
|
+
if uv in uvBorders and puv in uvBorders:
|
|
896
|
+
pinnit.add(puv)
|
|
897
|
+
pinnit.add(uv)
|
|
898
|
+
|
|
899
|
+
return uvBorders & pinnit
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
def collapse(faces, verts, uvFaces, uvs):
|
|
903
|
+
"""Take a mesh representation with unused vertex indices, and remove those vertices
|
|
904
|
+
|
|
905
|
+
Parameters
|
|
906
|
+
----------
|
|
907
|
+
faces : [[int, ...], ...]
|
|
908
|
+
The list of lists of vertex indices making up faces
|
|
909
|
+
The set of integers used here will be non-contiguous
|
|
910
|
+
verts : np.array
|
|
911
|
+
The N*3 array of vertices
|
|
912
|
+
uvFaces : [[int, ...], ...]
|
|
913
|
+
The list of lists of uv indices making up uvFaces
|
|
914
|
+
The set of integers used here will be non-contiguous
|
|
915
|
+
uvs : np.array
|
|
916
|
+
The N*2 array of uvs
|
|
917
|
+
|
|
918
|
+
Returns
|
|
919
|
+
-------
|
|
920
|
+
: [[int, ...], ...]
|
|
921
|
+
The list of lists of vertex indices making up faces
|
|
922
|
+
The set of integers used here will be contiguous
|
|
923
|
+
: np.array
|
|
924
|
+
The new N*3 array of vertices
|
|
925
|
+
: [[int, ...], ...]
|
|
926
|
+
The list of lists of uv indices making up uvFaces
|
|
927
|
+
The set of integers used here will be non-contiguous
|
|
928
|
+
: np.array
|
|
929
|
+
The new N*2 array of uvs
|
|
930
|
+
"""
|
|
931
|
+
vset = sorted(set(chain.from_iterable(faces)))
|
|
932
|
+
nVerts = verts[vset]
|
|
933
|
+
vDict = {v: i for i, v in enumerate(vset)}
|
|
934
|
+
nFaces = [[vDict[f] for f in face] for face in faces]
|
|
935
|
+
|
|
936
|
+
if uvFaces is not None:
|
|
937
|
+
uvset = sorted(set(chain.from_iterable(uvFaces)))
|
|
938
|
+
nUVs = uvs[uvset]
|
|
939
|
+
uvDict = {v: i for i, v in enumerate(uvset)}
|
|
940
|
+
nUVFaces = [[uvDict[f] for f in face] for face in uvFaces]
|
|
941
|
+
else:
|
|
942
|
+
nUVs = None
|
|
943
|
+
nUVFaces = None
|
|
944
|
+
|
|
945
|
+
return nFaces, nVerts, nUVFaces, nUVs
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
def getCenters(faces, hints=None, pBar=None):
|
|
949
|
+
"""Given a set of faces, find the face-center vertices from the subdivision
|
|
950
|
+
|
|
951
|
+
Parameters
|
|
952
|
+
----------
|
|
953
|
+
faces : [[int, ...], ...]
|
|
954
|
+
The list of lists of vertex indices making up faces
|
|
955
|
+
hints : set(int) or None
|
|
956
|
+
An optional list of star points that were part of the original un-subdivided mesh
|
|
957
|
+
pBar : QProgressDialog or None
|
|
958
|
+
An optional progress bar
|
|
959
|
+
|
|
960
|
+
Returns
|
|
961
|
+
-------
|
|
962
|
+
: set(int)
|
|
963
|
+
The vertices that were added to the centers of the faces as part of the subdivision process
|
|
964
|
+
"""
|
|
965
|
+
if pBar is not None:
|
|
966
|
+
pBar.setLabelText("Crawling Edges")
|
|
967
|
+
pBar.show()
|
|
968
|
+
QApplication.processEvents()
|
|
969
|
+
|
|
970
|
+
eNeigh = buildEdgeDict(faces)
|
|
971
|
+
if hints is None:
|
|
972
|
+
borders = getBorders(faces)
|
|
973
|
+
hints = buildUnsubdivideHints(
|
|
974
|
+
faces, eNeigh, borders, pBar=None
|
|
975
|
+
) # purposely no PBar
|
|
976
|
+
centerDel, fail = getFaceCenterDel(faces, eNeigh, hints, pBar=pBar)
|
|
977
|
+
assert not fail, "Could not detect subdivided topology with the provided hints"
|
|
978
|
+
|
|
979
|
+
if pBar is not None:
|
|
980
|
+
pBar.close()
|
|
981
|
+
|
|
982
|
+
return centerDel
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
def unSubdivide(
|
|
986
|
+
faces,
|
|
987
|
+
verts,
|
|
988
|
+
uvFaces,
|
|
989
|
+
uvs,
|
|
990
|
+
hints=None,
|
|
991
|
+
repositionVerts: bool = True,
|
|
992
|
+
pinBorders: bool = False,
|
|
993
|
+
pBar=None,
|
|
994
|
+
):
|
|
995
|
+
"""Given a mesh representation (faces and vertices) remove the edges added
|
|
996
|
+
by a subdivision, and optionally reposition the verts
|
|
997
|
+
|
|
998
|
+
Parameters
|
|
999
|
+
----------
|
|
1000
|
+
faces : [[int, ...], ...]
|
|
1001
|
+
The list of lists of vertex indices making up faces
|
|
1002
|
+
verts : np.array
|
|
1003
|
+
The N*3 array of vertices
|
|
1004
|
+
uvFaces : [[int, ...], ...]
|
|
1005
|
+
The list of lists of uv indices making up uvFaces
|
|
1006
|
+
uvs : np.array
|
|
1007
|
+
The N*2 array of uvs
|
|
1008
|
+
hints : set(int) or None
|
|
1009
|
+
An optional list of star points that were part of the original un-subdivided mesh
|
|
1010
|
+
repositionVerts : bool
|
|
1011
|
+
Whether to also estimate the positions of the un-subdivided verts. Defaults to True
|
|
1012
|
+
pinBorders : bool
|
|
1013
|
+
Whether or not to pin the border vertices. Defaults to False
|
|
1014
|
+
pBar : QProgressDialog or None
|
|
1015
|
+
An optional progress bar
|
|
1016
|
+
|
|
1017
|
+
Returns
|
|
1018
|
+
-------
|
|
1019
|
+
: [[vIdx ...], ...]
|
|
1020
|
+
The un-subdivided face structure
|
|
1021
|
+
: np.array
|
|
1022
|
+
The un-subdivided vertex positions
|
|
1023
|
+
: [[vIdx ...], ...] or None
|
|
1024
|
+
The un-subdivided uv-face structure if it exists
|
|
1025
|
+
: np.array or None
|
|
1026
|
+
The un-subdivided uvs if they exist
|
|
1027
|
+
"""
|
|
1028
|
+
if pBar is not None:
|
|
1029
|
+
pBar.show()
|
|
1030
|
+
pBar.setLabelText("Finding Neighbors")
|
|
1031
|
+
QApplication.processEvents()
|
|
1032
|
+
|
|
1033
|
+
eNeigh = buildEdgeDict(faces)
|
|
1034
|
+
|
|
1035
|
+
if hints is None:
|
|
1036
|
+
if pBar is not None:
|
|
1037
|
+
pBar.show()
|
|
1038
|
+
pBar.setLabelText("Getting Hints")
|
|
1039
|
+
QApplication.processEvents()
|
|
1040
|
+
borders = getBorders(faces)
|
|
1041
|
+
hints = buildUnsubdivideHints(
|
|
1042
|
+
faces, eNeigh, borders, pBar=None
|
|
1043
|
+
) # Purposely no PBar
|
|
1044
|
+
|
|
1045
|
+
if pBar is not None:
|
|
1046
|
+
pBar.setLabelText("Crawling Edges")
|
|
1047
|
+
QApplication.processEvents()
|
|
1048
|
+
centerDel, fail = getFaceCenterDel(faces, eNeigh, hints, pBar=pBar)
|
|
1049
|
+
assert not fail, "Could not detect subdivided topology with the provided hints"
|
|
1050
|
+
|
|
1051
|
+
if pBar is not None:
|
|
1052
|
+
pBar.setLabelText("Deleting Edges")
|
|
1053
|
+
QApplication.processEvents()
|
|
1054
|
+
uFaces, uUVFaces, dWings, uvDWings = deleteCenters(
|
|
1055
|
+
faces, uvFaces, centerDel, pBar=pBar
|
|
1056
|
+
)
|
|
1057
|
+
|
|
1058
|
+
uVerts = verts
|
|
1059
|
+
uUVs = uvs
|
|
1060
|
+
if repositionVerts:
|
|
1061
|
+
# Handle the verts
|
|
1062
|
+
if pBar is not None:
|
|
1063
|
+
pBar.setLabelText("Building Correspondences")
|
|
1064
|
+
QApplication.processEvents()
|
|
1065
|
+
neighDict, uNeighDict, edgeDict, uEdgeDict, borders = buildLayeredNeighborDicts(
|
|
1066
|
+
faces, uFaces, dWings
|
|
1067
|
+
)
|
|
1068
|
+
pinned = set(borders) if pinBorders else []
|
|
1069
|
+
if pBar is not None:
|
|
1070
|
+
pBar.setLabelText("Fixing Vert Positions")
|
|
1071
|
+
QApplication.processEvents()
|
|
1072
|
+
uVerts = fixVerts(
|
|
1073
|
+
faces,
|
|
1074
|
+
uFaces,
|
|
1075
|
+
verts,
|
|
1076
|
+
neighDict,
|
|
1077
|
+
uNeighDict,
|
|
1078
|
+
edgeDict,
|
|
1079
|
+
uEdgeDict,
|
|
1080
|
+
borders,
|
|
1081
|
+
pinned,
|
|
1082
|
+
pBar=pBar,
|
|
1083
|
+
)
|
|
1084
|
+
|
|
1085
|
+
# Handle the UVs
|
|
1086
|
+
if uvFaces is not None:
|
|
1087
|
+
(
|
|
1088
|
+
uvNeighDict,
|
|
1089
|
+
uUVNeighDict,
|
|
1090
|
+
uvEdgeDict,
|
|
1091
|
+
uvUEdgeDict,
|
|
1092
|
+
uvBorders,
|
|
1093
|
+
) = buildLayeredNeighborDicts(uvFaces, uUVFaces, uvDWings)
|
|
1094
|
+
uvPinned = getUVPins(faces, borders, uvFaces, uvBorders, pinBorders)
|
|
1095
|
+
if pBar is not None:
|
|
1096
|
+
pBar.setLabelText("Fixing UV Positions")
|
|
1097
|
+
QApplication.processEvents()
|
|
1098
|
+
uUVs = fixVerts(
|
|
1099
|
+
uvFaces,
|
|
1100
|
+
uUVFaces,
|
|
1101
|
+
uvs,
|
|
1102
|
+
uvNeighDict,
|
|
1103
|
+
uUVNeighDict,
|
|
1104
|
+
uvEdgeDict,
|
|
1105
|
+
uvUEdgeDict,
|
|
1106
|
+
uvBorders,
|
|
1107
|
+
uvPinned,
|
|
1108
|
+
pBar=pBar,
|
|
1109
|
+
)
|
|
1110
|
+
|
|
1111
|
+
rFaces, rVerts, rUVFaces, rUVs = collapse(uFaces, uVerts, uUVFaces, uUVs)
|
|
1112
|
+
|
|
1113
|
+
if pBar is not None:
|
|
1114
|
+
pBar.close()
|
|
1115
|
+
|
|
1116
|
+
return rFaces, rVerts, rUVFaces, rUVs
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
####################################################################
|
|
1120
|
+
# Handle .smpx files here #
|
|
1121
|
+
####################################################################
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
def _ussmpx(faces, verts, uvFaces, uvs, pBar=None):
|
|
1125
|
+
"""Unsubdivide a simplex"""
|
|
1126
|
+
pbPrint(pBar, message="Finding Neighbors")
|
|
1127
|
+
eNeigh = buildEdgeDict(faces)
|
|
1128
|
+
|
|
1129
|
+
pbPrint(pBar, message="Getting Hints")
|
|
1130
|
+
borders = getBorders(faces)
|
|
1131
|
+
hints = buildUnsubdivideHints(
|
|
1132
|
+
faces, eNeigh, borders, pBar=None
|
|
1133
|
+
) # Purposely no PBar
|
|
1134
|
+
|
|
1135
|
+
pbPrint(pBar, message="Crawling Edges")
|
|
1136
|
+
centerDel, fail = getFaceCenterDel(faces, eNeigh, hints, pBar=pBar)
|
|
1137
|
+
assert not fail, "Could not detect subdivided topology with the provided hints"
|
|
1138
|
+
|
|
1139
|
+
pbPrint(pBar, message="Deleting Edges")
|
|
1140
|
+
uFaces, uUVFaces, _, _ = deleteCenters(faces, uvFaces, centerDel, pBar=pBar)
|
|
1141
|
+
|
|
1142
|
+
pbPrint(pBar, message="Collapsing Indexes")
|
|
1143
|
+
uVerts = verts
|
|
1144
|
+
uUVs = uvs
|
|
1145
|
+
|
|
1146
|
+
rFaces, rVerts, rUVFaces, rUVs = collapse(uFaces, uVerts, uUVFaces, uUVs)
|
|
1147
|
+
|
|
1148
|
+
if pBar is not None:
|
|
1149
|
+
pBar.close()
|
|
1150
|
+
else:
|
|
1151
|
+
print("Done")
|
|
1152
|
+
|
|
1153
|
+
return rFaces, rVerts, rUVFaces, rUVs
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
def _applyShapePrefix(shapePrefix, jsString: str) -> str:
|
|
1157
|
+
"""Apply a prefix to the shape names.
|
|
1158
|
+
For XSI where shape names must be unique
|
|
1159
|
+
"""
|
|
1160
|
+
if shapePrefix is not None:
|
|
1161
|
+
d = json.loads(jsString)
|
|
1162
|
+
if d["encodingVersion"] > 1:
|
|
1163
|
+
for shape in d["shapes"]:
|
|
1164
|
+
shape["name"] = shapePrefix + shape["name"]
|
|
1165
|
+
else:
|
|
1166
|
+
d["shapes"] = [shapePrefix + i for i in d["shapes"]]
|
|
1167
|
+
jsString = json.dumps(d)
|
|
1168
|
+
return jsString
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
def _unflattenFaces(flatFaces, counts):
|
|
1172
|
+
faces = []
|
|
1173
|
+
ptr = 0
|
|
1174
|
+
for c in counts:
|
|
1175
|
+
faces.append(flatFaces[ptr : ptr + c].tolist())
|
|
1176
|
+
ptr += c
|
|
1177
|
+
return faces
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
def unsubdivideSimplex(inPath, outPath, shapePrefix=None, pBar=None) -> None:
|
|
1181
|
+
"""Unsubdivde a .smpx file on disk
|
|
1182
|
+
|
|
1183
|
+
Parameters
|
|
1184
|
+
----------
|
|
1185
|
+
inPath : str
|
|
1186
|
+
The input .smpx file path
|
|
1187
|
+
outPath : str
|
|
1188
|
+
The output .smpx file path
|
|
1189
|
+
shapePrefix : str or None
|
|
1190
|
+
An optional string to prefix the shape names with
|
|
1191
|
+
pBar : QProgressDialog or None
|
|
1192
|
+
An optional progress bar
|
|
1193
|
+
"""
|
|
1194
|
+
if np is None:
|
|
1195
|
+
raise RuntimeError("Un-Subdivide requires numpy, and it is not available here")
|
|
1196
|
+
|
|
1197
|
+
pbPrint(pBar, message="Loading smpx")
|
|
1198
|
+
jsString, counts, verts, flatFaces, uvs, flatUVFaces = readSmpx(inPath)
|
|
1199
|
+
jsString = _applyShapePrefix(shapePrefix, jsString)
|
|
1200
|
+
|
|
1201
|
+
js = json.loads(jsString)
|
|
1202
|
+
name = js["systemName"]
|
|
1203
|
+
|
|
1204
|
+
faces = _unflattenFaces(flatFaces, counts)
|
|
1205
|
+
uvFaces = None
|
|
1206
|
+
if flatUVFaces is not None:
|
|
1207
|
+
uvFaces = _unflattenFaces(flatUVFaces, counts)
|
|
1208
|
+
|
|
1209
|
+
pbPrint(pBar, message="Unsubdividing")
|
|
1210
|
+
verts = verts.swapaxes(0, 1)
|
|
1211
|
+
uFaces, uVerts, uUVFaces, uUVs = _ussmpx(faces, verts, uvFaces, uvs, pBar=pBar)
|
|
1212
|
+
|
|
1213
|
+
pbPrint(pBar, message="Exporting")
|
|
1214
|
+
buildSmpx(
|
|
1215
|
+
outPath,
|
|
1216
|
+
uVerts.swapaxes(0, 1),
|
|
1217
|
+
uFaces,
|
|
1218
|
+
jsString,
|
|
1219
|
+
name,
|
|
1220
|
+
uvs=uUVs,
|
|
1221
|
+
uvFaces=uUVFaces,
|
|
1222
|
+
)
|