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.
- pysimplex.pyd +0 -0
- simplex_solver-3.0.18.dist-info/METADATA +87 -0
- simplex_solver-3.0.18.dist-info/RECORD +81 -0
- simplex_solver-3.0.18.dist-info/WHEEL +5 -0
- simplex_solver-3.0.18.dist-info/licenses/LICENSE +165 -0
- simplexui/__init__.py +54 -0
- simplexui/channelBox.py +862 -0
- simplexui/comboCheckDialog.py +335 -0
- simplexui/commands/__init__.py +16 -0
- simplexui/commands/alembicCommon.py +1045 -0
- simplexui/commands/applyCorrectives.py +455 -0
- simplexui/commands/buildIceXML.py +443 -0
- simplexui/commands/correctiveInterface.py +271 -0
- simplexui/commands/expandedExport.py +435 -0
- simplexui/commands/hdf5Convert.py +62 -0
- simplexui/commands/mayaCorrectiveInterface.py +164 -0
- simplexui/commands/mesh.py +1086 -0
- simplexui/commands/reorderSimplexPoints.py +103 -0
- simplexui/commands/rigidAlign.py +103 -0
- simplexui/commands/setDelta.xsicompound +60 -0
- simplexui/commands/smpxBlend.py +634 -0
- simplexui/commands/unsubdivide.py +1232 -0
- simplexui/commands/uvTransfer.py +986 -0
- simplexui/commands/xsiCorrectiveInterface.py +136 -0
- simplexui/dragFilter.py +299 -0
- simplexui/falloffDialog.py +476 -0
- simplexui/img/ChefHead.png +0 -0
- simplexui/img/frozen.png +0 -0
- simplexui/interface/__init__.py +30 -0
- simplexui/interface/dummyInterface.py +1564 -0
- simplexui/interface/mayaInterface.py +3197 -0
- simplexui/interface/xsiInterface.py +2944 -0
- simplexui/interfaceModel.py +1040 -0
- simplexui/interfaceModelTrees.py +439 -0
- simplexui/interfaceModel_Test.py +259 -0
- simplexui/items/__init__.py +26 -0
- simplexui/items/accessor.py +217 -0
- simplexui/items/combo.py +855 -0
- simplexui/items/falloff.py +780 -0
- simplexui/items/group.py +295 -0
- simplexui/items/progression.py +745 -0
- simplexui/items/shape.py +444 -0
- simplexui/items/simplex.py +1747 -0
- simplexui/items/slider.py +741 -0
- simplexui/items/stack.py +156 -0
- simplexui/items/traversal.py +969 -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 +260 -0
- simplexui/menu/genericPlugins/checkPossibleCombos.py +47 -0
- simplexui/menu/genericPlugins/exportSplit.py +61 -0
- simplexui/menu/genericPlugins/showFalloffs.py +24 -0
- simplexui/menu/genericPlugins/showTraversals.py +24 -0
- simplexui/menu/genericPlugins/simplexUvTransfer.py +109 -0
- simplexui/menu/genericPlugins/unsubdivide.py +71 -0
- simplexui/menu/mayaPlugins/__init__.py +16 -0
- simplexui/menu/mayaPlugins/exportOther.py +45 -0
- simplexui/menu/mayaPlugins/extractProgressives.py +67 -0
- simplexui/menu/mayaPlugins/freezeCombo.py +251 -0
- simplexui/menu/mayaPlugins/generateShapeIncrementals.py +100 -0
- simplexui/menu/mayaPlugins/importObjs.py +196 -0
- simplexui/menu/mayaPlugins/linearizeTraversal.py +49 -0
- simplexui/menu/mayaPlugins/makeShelfBtn.py +69 -0
- simplexui/menu/mayaPlugins/relaxToSelection.py +77 -0
- simplexui/menu/mayaPlugins/reloadDefinition.py +34 -0
- simplexui/menu/mayaPlugins/snapToNeutral.py +74 -0
- simplexui/menu/mayaPlugins/softSelectToCluster.py +204 -0
- simplexui/menu/mayaPlugins/tweakMix.py +138 -0
- simplexui/menu/mayaPlugins/updateRestShape.py +107 -0
- simplexui/menu/xsiPlugins/__init__.py +16 -0
- simplexui/simplexDialog.py +1391 -0
- simplexui/travCheckDialog.py +393 -0
- simplexui/traversalDialog.py +277 -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 +320 -0
|
@@ -0,0 +1,1045 @@
|
|
|
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
|
+
""" Alembic files can be difficult to work with, and can be *very* slow in Python
|
|
19
|
+
This is a library of convenience functions with the numpy speed optimizations
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import absolute_import, print_function
|
|
22
|
+
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
import six
|
|
26
|
+
from alembic.Abc import IArchive, OArchive, OStringProperty
|
|
27
|
+
from alembic.AbcGeom import (
|
|
28
|
+
GeometryScope,
|
|
29
|
+
IPolyMesh,
|
|
30
|
+
IXform,
|
|
31
|
+
ON3fGeomParamSample,
|
|
32
|
+
OPolyMesh,
|
|
33
|
+
OPolyMeshSchemaSample,
|
|
34
|
+
OV2fGeomParamSample,
|
|
35
|
+
OXform,
|
|
36
|
+
)
|
|
37
|
+
from imath import IntArray, UnsignedIntArray, V2f, V2fArray, V3fArray
|
|
38
|
+
from six.moves import range, zip
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
import numpy as np
|
|
42
|
+
except ImportError:
|
|
43
|
+
np = None
|
|
44
|
+
arrayToNumpy = None
|
|
45
|
+
else:
|
|
46
|
+
try:
|
|
47
|
+
from imathnumpy import arrayToNumpy # pylint:disable=no-name-in-module
|
|
48
|
+
except ImportError:
|
|
49
|
+
arrayToNumpy = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def pbPrint(pBar, message=None, val=None, maxVal=None, _pbPrintLastComma=[]):
|
|
53
|
+
"""A function that handles displaying messages in a QProgressDialog or printing to stdout
|
|
54
|
+
|
|
55
|
+
Don't forget to call QApplication.processEvents() after using this function
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
pBar : QProgressDialog or None
|
|
60
|
+
An optional progress bar
|
|
61
|
+
message : str or None
|
|
62
|
+
An optional message to display
|
|
63
|
+
val : int or None
|
|
64
|
+
An optional progress value to display
|
|
65
|
+
maxVal : int or None
|
|
66
|
+
An optional maximum value to display
|
|
67
|
+
_pbPrintLastComma: object
|
|
68
|
+
INTERNAL USE ONLY
|
|
69
|
+
"""
|
|
70
|
+
if pBar is not None:
|
|
71
|
+
if val is not None:
|
|
72
|
+
pBar.setValue(val)
|
|
73
|
+
if message is not None:
|
|
74
|
+
pBar.setLabelText(message)
|
|
75
|
+
else:
|
|
76
|
+
if message is not None:
|
|
77
|
+
if val is not None:
|
|
78
|
+
if maxVal is not None:
|
|
79
|
+
print(
|
|
80
|
+
message, "{0: <4} of {1: <4}\r".format(val + 1, maxVal), end=" "
|
|
81
|
+
)
|
|
82
|
+
else:
|
|
83
|
+
print(message, "{0: <4}\r".format(val + 1), end=" ")
|
|
84
|
+
# This is the ugliest, most terrible thing I think I've ever written
|
|
85
|
+
# Abusing the static default object to check if the last time
|
|
86
|
+
# this function was used, there was a trailing comma
|
|
87
|
+
# But damn if it doesn't make me laugh
|
|
88
|
+
if not _pbPrintLastComma:
|
|
89
|
+
_pbPrintLastComma.append("")
|
|
90
|
+
else:
|
|
91
|
+
if _pbPrintLastComma:
|
|
92
|
+
print(_pbPrintLastComma.pop())
|
|
93
|
+
print(message)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def mkArray(aType, iList):
|
|
97
|
+
"""Makes the alembic-usable c++ typed 2-d arrays
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
aType : imath type
|
|
102
|
+
The type of the output array
|
|
103
|
+
iList : list or np.array
|
|
104
|
+
The input iterable.
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
: aType
|
|
109
|
+
The input list translated into an aType array
|
|
110
|
+
"""
|
|
111
|
+
if isinstance(iList, aType):
|
|
112
|
+
return iList
|
|
113
|
+
|
|
114
|
+
if np is None:
|
|
115
|
+
array = aType(len(iList))
|
|
116
|
+
for i in range(len(iList)):
|
|
117
|
+
array[i] = tuple(iList[i])
|
|
118
|
+
return array
|
|
119
|
+
elif arrayToNumpy is None:
|
|
120
|
+
array = aType(len(iList))
|
|
121
|
+
for i in range(len(iList)):
|
|
122
|
+
array[i] = tuple(iList[i].tolist())
|
|
123
|
+
return array
|
|
124
|
+
else:
|
|
125
|
+
iList = np.array(iList)
|
|
126
|
+
array = aType(len(iList))
|
|
127
|
+
memView = arrayToNumpy(array)
|
|
128
|
+
np.copyto(memView, iList)
|
|
129
|
+
return array
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def mk1dArray(aType, iList):
|
|
133
|
+
"""Makes the alembic-usable c++ typed 1-d arrays
|
|
134
|
+
|
|
135
|
+
Parameters
|
|
136
|
+
----------
|
|
137
|
+
aType : imath type
|
|
138
|
+
The type of the output array
|
|
139
|
+
iList : list or np.array
|
|
140
|
+
The input iterable.
|
|
141
|
+
|
|
142
|
+
Returns
|
|
143
|
+
-------
|
|
144
|
+
: aType
|
|
145
|
+
The input list translated into an aType array
|
|
146
|
+
"""
|
|
147
|
+
if isinstance(iList, aType):
|
|
148
|
+
return iList
|
|
149
|
+
if np is None or arrayToNumpy is None or aType is UnsignedIntArray:
|
|
150
|
+
array = aType(len(iList))
|
|
151
|
+
for i in range(len(iList)):
|
|
152
|
+
# Gotta cast to int because an "int" from numpy has
|
|
153
|
+
# the type np.int32, which makes this conversion angry
|
|
154
|
+
array[i] = int(iList[i])
|
|
155
|
+
return array
|
|
156
|
+
else:
|
|
157
|
+
iList = np.array(iList)
|
|
158
|
+
array = aType(len(iList))
|
|
159
|
+
memView = arrayToNumpy(array)
|
|
160
|
+
np.copyto(memView, iList)
|
|
161
|
+
return array
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def mkSampleVertexPoints(pts):
|
|
165
|
+
"""Make an imath array of vertices
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
pts : list or np.array
|
|
170
|
+
The input points
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
: V3fArray
|
|
175
|
+
The output list
|
|
176
|
+
"""
|
|
177
|
+
return mkArray(V3fArray, pts)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def mkSampleIntArray(vals):
|
|
181
|
+
"""Make an imath array of integers
|
|
182
|
+
|
|
183
|
+
Parameters
|
|
184
|
+
----------
|
|
185
|
+
pts : list or np.array
|
|
186
|
+
The input integers
|
|
187
|
+
|
|
188
|
+
Returns
|
|
189
|
+
-------
|
|
190
|
+
: IntArray
|
|
191
|
+
The output list
|
|
192
|
+
"""
|
|
193
|
+
return mk1dArray(IntArray, vals)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def mkSampleUIntArray(vals):
|
|
197
|
+
"""Make an imath array of unsigned integers
|
|
198
|
+
|
|
199
|
+
Parameters
|
|
200
|
+
----------
|
|
201
|
+
pts : list or np.array
|
|
202
|
+
The input unsigned integers
|
|
203
|
+
|
|
204
|
+
Returns
|
|
205
|
+
-------
|
|
206
|
+
: UnsignedIntArray
|
|
207
|
+
The output list
|
|
208
|
+
"""
|
|
209
|
+
return mk1dArray(UnsignedIntArray, vals)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def mkSampleUvArray(uvs):
|
|
213
|
+
"""Make an imath array of uvs
|
|
214
|
+
|
|
215
|
+
Parameters
|
|
216
|
+
----------
|
|
217
|
+
uvs : list or np.array
|
|
218
|
+
The input uvs
|
|
219
|
+
|
|
220
|
+
Returns
|
|
221
|
+
-------
|
|
222
|
+
: V2fArray
|
|
223
|
+
The output list
|
|
224
|
+
"""
|
|
225
|
+
array = V2fArray(len(uvs))
|
|
226
|
+
setter = V2f(0, 0)
|
|
227
|
+
for i in range(len(uvs)):
|
|
228
|
+
setter.setValue(float(uvs[i][0]), float(uvs[i][1]))
|
|
229
|
+
array[i] = setter
|
|
230
|
+
return array
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def mkUvSample(uvs, indexes=None):
|
|
234
|
+
"""Take an array, and make a poly mesh sample of the uvs
|
|
235
|
+
|
|
236
|
+
Parameters
|
|
237
|
+
----------
|
|
238
|
+
uvs : list or np.array
|
|
239
|
+
The input uvs
|
|
240
|
+
indexes : list or np.array or None
|
|
241
|
+
The optional face indices of the uvs
|
|
242
|
+
|
|
243
|
+
Returns
|
|
244
|
+
-------
|
|
245
|
+
: OV2fGeomParamSample
|
|
246
|
+
The UV sample
|
|
247
|
+
"""
|
|
248
|
+
ary = mkSampleUvArray(uvs)
|
|
249
|
+
if indexes is None:
|
|
250
|
+
return OV2fGeomParamSample(ary, GeometryScope.kFacevaryingScope)
|
|
251
|
+
idxs = mkSampleUIntArray(indexes)
|
|
252
|
+
return OV2fGeomParamSample(ary, idxs, GeometryScope.kFacevaryingScope)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def mkNormalSample(norms, indexes=None):
|
|
256
|
+
"""Take an array, and make a poly mesh sample of the normals
|
|
257
|
+
|
|
258
|
+
Parameters
|
|
259
|
+
----------
|
|
260
|
+
norms : list or np.array
|
|
261
|
+
The input normals
|
|
262
|
+
indexes : list or np.array or None
|
|
263
|
+
The optional face indices of the normals
|
|
264
|
+
|
|
265
|
+
Returns
|
|
266
|
+
-------
|
|
267
|
+
: ON3fGeomParamSample
|
|
268
|
+
The Normal sample
|
|
269
|
+
"""
|
|
270
|
+
ary = mkArray(V3fArray, norms)
|
|
271
|
+
if indexes is None:
|
|
272
|
+
return ON3fGeomParamSample(ary, GeometryScope.kFacevaryingScope)
|
|
273
|
+
idxs = mkSampleUIntArray(indexes)
|
|
274
|
+
return ON3fGeomParamSample(ary, idxs, GeometryScope.kFacevaryingScope)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def setAlembicSample(
|
|
278
|
+
omeshSch, points, faceCount, faceIndex, bounds=None, uvs=None, normals=None
|
|
279
|
+
):
|
|
280
|
+
"""Set an alembic sample to the output mesh with the given properties"""
|
|
281
|
+
# Do it this way because the defaults for these arguments are some value other than None
|
|
282
|
+
kwargs = {}
|
|
283
|
+
if uvs is not None:
|
|
284
|
+
kwargs["iUVs"] = uvs
|
|
285
|
+
if normals is not None:
|
|
286
|
+
kwargs["iNormals"] = normals
|
|
287
|
+
|
|
288
|
+
s = OPolyMeshSchemaSample(points, faceIndex, faceCount, **kwargs)
|
|
289
|
+
if bounds is not None:
|
|
290
|
+
omeshSch.getChildBoundsProperty().setValue(bounds)
|
|
291
|
+
omeshSch.set(s)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def getSampleArray(imesh, pBar=None):
|
|
295
|
+
"""Get the per-frame vertex positions for a mesh
|
|
296
|
+
|
|
297
|
+
Parameters
|
|
298
|
+
----------
|
|
299
|
+
imesh : IPolyMesh
|
|
300
|
+
The input alembic mesh object
|
|
301
|
+
|
|
302
|
+
Returns
|
|
303
|
+
-------
|
|
304
|
+
: np.array or list
|
|
305
|
+
The per-frame vertex positions
|
|
306
|
+
"""
|
|
307
|
+
meshSchema = imesh.getSchema()
|
|
308
|
+
posProp = meshSchema.getPositionsProperty()
|
|
309
|
+
numShapes = len(posProp.samples)
|
|
310
|
+
if arrayToNumpy is not None:
|
|
311
|
+
shapes = np.empty((len(posProp.samples), len(posProp.samples[0]), 3))
|
|
312
|
+
for i, s in enumerate(posProp.samples):
|
|
313
|
+
pbPrint(pBar, message="Reading Shape", val=i, maxVal=numShapes)
|
|
314
|
+
shapes[i] = arrayToNumpy(s)
|
|
315
|
+
elif np is not None:
|
|
316
|
+
shapes = []
|
|
317
|
+
for i, s in enumerate(posProp.samples):
|
|
318
|
+
pbPrint(pBar, message="Reading Shape", val=i, maxVal=numShapes)
|
|
319
|
+
shapes.append((list(s.x), list(s.y), list(s.z)))
|
|
320
|
+
shapes = np.array(shapes)
|
|
321
|
+
shapes = shapes.transpose((0, 2, 1))
|
|
322
|
+
else:
|
|
323
|
+
shapes = []
|
|
324
|
+
for i, s in enumerate(posProp.samples):
|
|
325
|
+
pbPrint(pBar, message="Reading Shape", val=i, maxVal=numShapes)
|
|
326
|
+
shapes.append(s)
|
|
327
|
+
pbPrint(pBar, message="Done Reading")
|
|
328
|
+
return shapes
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def getStaticMeshData(imesh):
|
|
332
|
+
"""Get all the generally non-changing data for a mesh
|
|
333
|
+
|
|
334
|
+
Parameters
|
|
335
|
+
----------
|
|
336
|
+
imesh : IPolyMesh
|
|
337
|
+
The input alembic mesh object
|
|
338
|
+
|
|
339
|
+
Returns
|
|
340
|
+
-------
|
|
341
|
+
: IntArray
|
|
342
|
+
A flat alembic array of vertex indices for the faces
|
|
343
|
+
: IntArray
|
|
344
|
+
The number of vertices per face
|
|
345
|
+
"""
|
|
346
|
+
sch = imesh.getSchema()
|
|
347
|
+
faces = sch.getFaceIndicesProperty().samples[0]
|
|
348
|
+
counts = sch.getFaceCountsProperty().samples[0]
|
|
349
|
+
return faces, counts
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def getStaticMeshArrays(imesh):
|
|
353
|
+
"""Get all the generally non-changing data for a mesh as numpy arrays
|
|
354
|
+
|
|
355
|
+
Parameters
|
|
356
|
+
----------
|
|
357
|
+
imesh : IPolyMesh
|
|
358
|
+
The input alembic mesh object
|
|
359
|
+
|
|
360
|
+
Returns
|
|
361
|
+
-------
|
|
362
|
+
: np.array or list
|
|
363
|
+
A flat of vertex indices for the faces as np.array if possible
|
|
364
|
+
: np.array or list
|
|
365
|
+
The number of vertices per face as np.array if possible
|
|
366
|
+
"""
|
|
367
|
+
faces, counts = getStaticMeshData(imesh)
|
|
368
|
+
if arrayToNumpy is not None:
|
|
369
|
+
faces = arrayToNumpy(faces).copy()
|
|
370
|
+
counts = arrayToNumpy(counts).copy()
|
|
371
|
+
elif np is not None:
|
|
372
|
+
faces, counts = np.array(faces), np.array(counts)
|
|
373
|
+
else:
|
|
374
|
+
faces, counts = list(faces), list(counts)
|
|
375
|
+
return faces, counts
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def getUvSample(imesh):
|
|
379
|
+
"""Get the UV's for a mesh
|
|
380
|
+
|
|
381
|
+
Parameters
|
|
382
|
+
----------
|
|
383
|
+
imesh : IPolyMesh
|
|
384
|
+
The input alembic mesh object
|
|
385
|
+
|
|
386
|
+
Returns
|
|
387
|
+
-------
|
|
388
|
+
: OV2fGeomParamSample
|
|
389
|
+
The UV Sample
|
|
390
|
+
"""
|
|
391
|
+
imeshsch = imesh.getSchema()
|
|
392
|
+
uvParam = imeshsch.getUVsParam()
|
|
393
|
+
|
|
394
|
+
if not uvParam.valid():
|
|
395
|
+
return None
|
|
396
|
+
|
|
397
|
+
uvValue = uvParam.getValueProperty().getValue()
|
|
398
|
+
if uvParam.isIndexed():
|
|
399
|
+
idxValue = uvParam.getIndexProperty().getValue()
|
|
400
|
+
uv = OV2fGeomParamSample(uvValue, idxValue, GeometryScope.kFacevaryingScope)
|
|
401
|
+
else:
|
|
402
|
+
uv = OV2fGeomParamSample(uvValue, GeometryScope.kFacevaryingScope)
|
|
403
|
+
return uv
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def getUvArray(imesh):
|
|
407
|
+
"""Get the uv positions for a mesh
|
|
408
|
+
|
|
409
|
+
Parameters
|
|
410
|
+
----------
|
|
411
|
+
imesh : IPolyMesh
|
|
412
|
+
The input alembic mesh object
|
|
413
|
+
|
|
414
|
+
Returns
|
|
415
|
+
-------
|
|
416
|
+
: list or np.array or None
|
|
417
|
+
The UVs if they exist as a numpy array if possible
|
|
418
|
+
"""
|
|
419
|
+
imeshsch = imesh.getSchema()
|
|
420
|
+
uvParam = imeshsch.getUVsParam()
|
|
421
|
+
if uvParam.valid():
|
|
422
|
+
uvProp = uvParam.getValueProperty()
|
|
423
|
+
uvVals = uvProp.getValue()
|
|
424
|
+
# imathNumpy doesn't work on V2f arrays
|
|
425
|
+
# so I have to use one of the slow ways
|
|
426
|
+
uv = list(zip(uvVals.x, uvVals.y))
|
|
427
|
+
if np is not None:
|
|
428
|
+
uv = np.array(uv)
|
|
429
|
+
else:
|
|
430
|
+
uv = None
|
|
431
|
+
return uv
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def getFlatUvFaces(imesh):
|
|
435
|
+
"""Get the UV structure for a mesh if it's indexed. If un-indexed, return None
|
|
436
|
+
This means that if we have valid UVs, but invalid uvFaces, then we're un-indexed
|
|
437
|
+
and can handle the data appropriately for export without keeping track of index-ness
|
|
438
|
+
|
|
439
|
+
Parameters
|
|
440
|
+
----------
|
|
441
|
+
imesh : IPolyMesh
|
|
442
|
+
The input alembic mesh object
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
: [int, ...] or np.array
|
|
447
|
+
The UVFace structure
|
|
448
|
+
: bool
|
|
449
|
+
Whether we share uvs between uvFaces (True), or we have a uv per face-vertex (False)
|
|
450
|
+
"""
|
|
451
|
+
sch = imesh.getSchema()
|
|
452
|
+
iuvs = sch.getUVsParam()
|
|
453
|
+
idxs = None
|
|
454
|
+
indexed = None
|
|
455
|
+
if iuvs.valid():
|
|
456
|
+
if iuvs.isIndexed():
|
|
457
|
+
indexed = True
|
|
458
|
+
idxs = iuvs.getIndexProperty().getValue()
|
|
459
|
+
# if arrayToNumpy is not None:
|
|
460
|
+
# idxs = arrayToNumpy(idxs).copy()
|
|
461
|
+
# elif np is not None:
|
|
462
|
+
if np is not None:
|
|
463
|
+
idxs = np.array(idxs)
|
|
464
|
+
else:
|
|
465
|
+
idxs = list(idxs)
|
|
466
|
+
else:
|
|
467
|
+
indexed = False
|
|
468
|
+
rawCount = sum(list(sch.getFaceCountsProperty().samples[0]))
|
|
469
|
+
if np is not None:
|
|
470
|
+
idxs = np.arange(rawCount)
|
|
471
|
+
else:
|
|
472
|
+
idxs = list(range(rawCount))
|
|
473
|
+
|
|
474
|
+
return idxs, indexed
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
def getUvFaces(imesh):
|
|
478
|
+
"""Get the UV structure for a mesh if it's indexed. If un-indexed, return None
|
|
479
|
+
This means that if we have valid UVs, but invalid uvFaces, then we're un-indexed
|
|
480
|
+
and can handle the data appropriately for export without keeping track of index-ness
|
|
481
|
+
|
|
482
|
+
Parameters
|
|
483
|
+
----------
|
|
484
|
+
imesh : IPolyMesh
|
|
485
|
+
The input alembic mesh object
|
|
486
|
+
|
|
487
|
+
Returns
|
|
488
|
+
-------
|
|
489
|
+
: [[int, ...], ...]
|
|
490
|
+
The UVFace structure
|
|
491
|
+
"""
|
|
492
|
+
sch = imesh.getSchema()
|
|
493
|
+
rawCounts = sch.getFaceCountsProperty().samples[0]
|
|
494
|
+
iuvs = sch.getUVsParam()
|
|
495
|
+
uvFaces = None
|
|
496
|
+
if iuvs.valid():
|
|
497
|
+
uvFaces = []
|
|
498
|
+
uvCounter = 0
|
|
499
|
+
if iuvs.isIndexed():
|
|
500
|
+
idxs = list(iuvs.getIndexProperty().getValue())
|
|
501
|
+
for count in rawCounts:
|
|
502
|
+
uvFaces.append(list(idxs[uvCounter : uvCounter + count]))
|
|
503
|
+
uvCounter += count
|
|
504
|
+
return uvFaces
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def getMeshFaces(imesh):
|
|
508
|
+
"""Get The vertex indices used per face
|
|
509
|
+
|
|
510
|
+
Parameters
|
|
511
|
+
----------
|
|
512
|
+
imesh : IPolyMesh
|
|
513
|
+
The input alembic mesh object
|
|
514
|
+
|
|
515
|
+
Returns
|
|
516
|
+
-------
|
|
517
|
+
: [[int, ...], ...]
|
|
518
|
+
The UVFace structure
|
|
519
|
+
"""
|
|
520
|
+
rawFaces, rawCounts = getStaticMeshData(imesh)
|
|
521
|
+
faces = []
|
|
522
|
+
ptr = 0
|
|
523
|
+
for count in rawCounts:
|
|
524
|
+
faces.append(list(rawFaces[ptr : ptr + count]))
|
|
525
|
+
ptr += count
|
|
526
|
+
return faces
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def getPointCount(imesh):
|
|
530
|
+
"""Get the number of vertices in a mesh
|
|
531
|
+
|
|
532
|
+
Parameters
|
|
533
|
+
----------
|
|
534
|
+
imesh : IPolyMesh
|
|
535
|
+
The input alembic mesh object
|
|
536
|
+
|
|
537
|
+
Returns
|
|
538
|
+
-------
|
|
539
|
+
: int
|
|
540
|
+
The number of vertices in the mesh
|
|
541
|
+
"""
|
|
542
|
+
meshSchema = imesh.getSchema()
|
|
543
|
+
posProp = meshSchema.getPositionsProperty()
|
|
544
|
+
return len(posProp.samples[0])
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
def findAlembicObject(obj, abcType=None, name=None):
|
|
548
|
+
"""
|
|
549
|
+
Finds a single object in an alembic archive by name and/or type
|
|
550
|
+
If only type is specified, then the first object of that type
|
|
551
|
+
encountered will be returned
|
|
552
|
+
"""
|
|
553
|
+
md = obj.getMetaData()
|
|
554
|
+
if abcType is None:
|
|
555
|
+
if name is None or obj.getName() == name:
|
|
556
|
+
return obj
|
|
557
|
+
elif abcType.matches(md):
|
|
558
|
+
if name is None or obj.getName() == name:
|
|
559
|
+
return abcType(obj.getParent(), obj.getName())
|
|
560
|
+
for child in obj.children:
|
|
561
|
+
out = findAlembicObject(child, abcType, name)
|
|
562
|
+
if out is not None:
|
|
563
|
+
return out
|
|
564
|
+
return None
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def findAllAlembicObjects(obj, abcType=None, out=None):
|
|
568
|
+
"""Finds all objects of a type in an alembic archive"""
|
|
569
|
+
md = obj.getMetaData()
|
|
570
|
+
out = [] if out is None else out
|
|
571
|
+
if abcType is None:
|
|
572
|
+
out.append(obj)
|
|
573
|
+
elif abcType.matches(md):
|
|
574
|
+
out.append(abcType(obj.getParent(), obj.getName()))
|
|
575
|
+
for child in obj.children:
|
|
576
|
+
findAllAlembicObjects(child, abcType, out)
|
|
577
|
+
return out
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def getTypedIObject(obj):
|
|
581
|
+
from alembic.AbcGeom import (
|
|
582
|
+
ICamera,
|
|
583
|
+
ICurves,
|
|
584
|
+
ILight,
|
|
585
|
+
INuPatch,
|
|
586
|
+
IPoints,
|
|
587
|
+
IPolyMesh,
|
|
588
|
+
ISubD,
|
|
589
|
+
IXform,
|
|
590
|
+
)
|
|
591
|
+
|
|
592
|
+
md = obj.getMetaData()
|
|
593
|
+
for abcType in (
|
|
594
|
+
IXform,
|
|
595
|
+
IPolyMesh,
|
|
596
|
+
ICamera,
|
|
597
|
+
ICurves,
|
|
598
|
+
ILight,
|
|
599
|
+
INuPatch,
|
|
600
|
+
IPoints,
|
|
601
|
+
ISubD,
|
|
602
|
+
):
|
|
603
|
+
if abcType.matches(md):
|
|
604
|
+
return abcType(obj.getParent(), obj.getName())
|
|
605
|
+
return None
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def getMesh(infile):
|
|
609
|
+
"""Get the first found mesh object from the alembic filepath"""
|
|
610
|
+
iarch = IArchive(infile)
|
|
611
|
+
ipolymsh = findAlembicObject(iarch.getTop(), abcType=IPolyMesh)
|
|
612
|
+
return ipolymsh
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def writeStringProperty(props, key, value, ogawa=True):
|
|
616
|
+
"""Write the definition string to an alembic OObject
|
|
617
|
+
|
|
618
|
+
HDF5 (which we must still support) has a character limit
|
|
619
|
+
to string properties. Splitting the string must be handled
|
|
620
|
+
in a uniform way, so this function must be used
|
|
621
|
+
|
|
622
|
+
Parameters
|
|
623
|
+
----------
|
|
624
|
+
props : OCompoundProperty
|
|
625
|
+
The alembic OObject properties
|
|
626
|
+
value : str
|
|
627
|
+
The simplex definition string
|
|
628
|
+
ogawa : bool
|
|
629
|
+
If the output is ogawa
|
|
630
|
+
|
|
631
|
+
"""
|
|
632
|
+
if len(value) > 65000 and not ogawa:
|
|
633
|
+
value = str(value)
|
|
634
|
+
numChunks = (len(value) // 65000) + 1
|
|
635
|
+
chunkSize = (len(value) // numChunks) + 1
|
|
636
|
+
for c in range(numChunks):
|
|
637
|
+
prop = OStringProperty(props, "{0}{1}".format(key, c))
|
|
638
|
+
prop.setValue(value[chunkSize * c : chunkSize * (c + 1)])
|
|
639
|
+
else:
|
|
640
|
+
prop = OStringProperty(props, str(key))
|
|
641
|
+
prop.setValue(str(value))
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
def readStringProperty(props, key):
|
|
645
|
+
"""Read the definition string from an alembic OObject
|
|
646
|
+
|
|
647
|
+
HDF5 (which we must still support) has a character limit
|
|
648
|
+
to string properties. Splitting the string must be handled
|
|
649
|
+
in a uniform way, so this function must be used
|
|
650
|
+
|
|
651
|
+
Parameters
|
|
652
|
+
----------
|
|
653
|
+
props : ICompoundProperty
|
|
654
|
+
The alembic IObject properties
|
|
655
|
+
|
|
656
|
+
Returns
|
|
657
|
+
-------
|
|
658
|
+
: str
|
|
659
|
+
The simplex definition string
|
|
660
|
+
"""
|
|
661
|
+
if not props.valid():
|
|
662
|
+
raise ValueError(".smpx file is missing the alembic user properties")
|
|
663
|
+
|
|
664
|
+
try:
|
|
665
|
+
prop = props.getProperty(key)
|
|
666
|
+
except KeyError:
|
|
667
|
+
parts = []
|
|
668
|
+
for c in range(10):
|
|
669
|
+
try:
|
|
670
|
+
prop = props.getProperty("{0}{1}".format(key, c))
|
|
671
|
+
except KeyError:
|
|
672
|
+
if c == 0:
|
|
673
|
+
raise
|
|
674
|
+
break
|
|
675
|
+
else:
|
|
676
|
+
parts.append(prop.getValue())
|
|
677
|
+
else:
|
|
678
|
+
raise ValueError("That is a HELL of a long simplex definition")
|
|
679
|
+
jsString = "".join(parts)
|
|
680
|
+
else:
|
|
681
|
+
jsString = prop.getValue()
|
|
682
|
+
|
|
683
|
+
return jsString
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def flattenFaces(faces):
|
|
687
|
+
"""Take a nested list representation of faces
|
|
688
|
+
and turn it into a flat face/count representation
|
|
689
|
+
|
|
690
|
+
Parameters
|
|
691
|
+
----------
|
|
692
|
+
faces : [[int, ...], ...]
|
|
693
|
+
The nested list representation
|
|
694
|
+
|
|
695
|
+
Returns
|
|
696
|
+
-------
|
|
697
|
+
: np.array or list
|
|
698
|
+
The flat list of face connectivity
|
|
699
|
+
: np.array or list
|
|
700
|
+
The flat list of vertices per face
|
|
701
|
+
|
|
702
|
+
"""
|
|
703
|
+
faceCounts, faceIdxs = [], []
|
|
704
|
+
for f in faces:
|
|
705
|
+
faceCounts.append(len(f))
|
|
706
|
+
faceIdxs.extend(f)
|
|
707
|
+
if np is not None:
|
|
708
|
+
return np.array(faceCounts), np.array(faceIdxs)
|
|
709
|
+
return faceCounts, faceIdxs
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def unflattenFaces(faces, counts):
|
|
713
|
+
"""Take a flat face/count representation of faces
|
|
714
|
+
and turn it into a nested list representation
|
|
715
|
+
|
|
716
|
+
Parameters
|
|
717
|
+
----------
|
|
718
|
+
faces : np.array
|
|
719
|
+
The flat list of face connectivity
|
|
720
|
+
counts : np.array
|
|
721
|
+
The flat list of vertices per face
|
|
722
|
+
|
|
723
|
+
Returns
|
|
724
|
+
-------
|
|
725
|
+
: [[int, ...], ...]
|
|
726
|
+
The nested list representation
|
|
727
|
+
"""
|
|
728
|
+
out, ptr = [], 0
|
|
729
|
+
for c in counts:
|
|
730
|
+
out.append(faces[ptr : ptr + c].tolist())
|
|
731
|
+
ptr += c
|
|
732
|
+
return out
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
def buildAbc(
|
|
736
|
+
outPath,
|
|
737
|
+
points,
|
|
738
|
+
faces,
|
|
739
|
+
faceCounts=None,
|
|
740
|
+
uvs=None,
|
|
741
|
+
uvFaces=None,
|
|
742
|
+
normals=None,
|
|
743
|
+
normFaces=None,
|
|
744
|
+
name="polymsh",
|
|
745
|
+
shapeSuffix="Shape",
|
|
746
|
+
transformSuffix="",
|
|
747
|
+
propDict=None,
|
|
748
|
+
ogawa=True,
|
|
749
|
+
pBar=None,
|
|
750
|
+
):
|
|
751
|
+
"""
|
|
752
|
+
Build a single-mesh alembic file from all of the non-alembic raw data
|
|
753
|
+
|
|
754
|
+
Parameters
|
|
755
|
+
----------
|
|
756
|
+
outPath: str
|
|
757
|
+
The output path for the alembic file
|
|
758
|
+
points: list or ndarray
|
|
759
|
+
The list or array of points. Single multiple frames supported
|
|
760
|
+
faces: list
|
|
761
|
+
A list of lists of face indices, or a flattened list of indices.
|
|
762
|
+
If flat, then faceCounts must be provided
|
|
763
|
+
faceCounts: list
|
|
764
|
+
A list of the number of vertices per face. Defaults to None
|
|
765
|
+
uvs: list or ndarray
|
|
766
|
+
The Uvs for this mesh. Defaults to None
|
|
767
|
+
uvFaces: list
|
|
768
|
+
A list of lists of face indices, or a flattened list of indices.
|
|
769
|
+
If flat, then faceCounts must be provided. Defaults to None
|
|
770
|
+
normals: list or ndarray
|
|
771
|
+
The Normals for this mesh. Defaults to None
|
|
772
|
+
normFaces: list
|
|
773
|
+
A list of lists of face indices, or a flattened list of indices.
|
|
774
|
+
If flat, then faceCounts must be provided. Defaults to None
|
|
775
|
+
name: str
|
|
776
|
+
The name to give this mesh. Defaults to "polymsh"
|
|
777
|
+
shapeSuffix: str
|
|
778
|
+
The suffix to add to the shape of this mesh. Defaults to "Shape"
|
|
779
|
+
transformSuffix: str
|
|
780
|
+
The suffix to add to the transform of this mesh. Defaults to ""
|
|
781
|
+
propDict: dict
|
|
782
|
+
A dictionary of properties to add to the xform object
|
|
783
|
+
ogawa : bool
|
|
784
|
+
Whether to write to the Ogawa (True) or HDF5 (False) backend
|
|
785
|
+
pBar : QProgressDialog, optional
|
|
786
|
+
An optional progress dialog
|
|
787
|
+
"""
|
|
788
|
+
if faceCounts is None:
|
|
789
|
+
# All the faces are in list-of-list format
|
|
790
|
+
# put them in index-count format
|
|
791
|
+
faceCounts, faces = flattenFaces(faces)
|
|
792
|
+
if uvFaces is not None:
|
|
793
|
+
_, uvFaces = flattenFaces(uvFaces)
|
|
794
|
+
if normFaces is not None:
|
|
795
|
+
_, normFaces = flattenFaces(normFaces)
|
|
796
|
+
|
|
797
|
+
faceCounts = mkSampleIntArray(faceCounts)
|
|
798
|
+
faces = mkSampleIntArray(faces)
|
|
799
|
+
|
|
800
|
+
if not isinstance(uvs, OV2fGeomParamSample):
|
|
801
|
+
if uvFaces is not None and uvs is not None:
|
|
802
|
+
uvs = mkUvSample(uvs, indexes=uvFaces)
|
|
803
|
+
|
|
804
|
+
if not isinstance(normals, ON3fGeomParamSample):
|
|
805
|
+
if normFaces is not None and normals is not None:
|
|
806
|
+
normals = mkNormalSample(normals, indexes=normFaces)
|
|
807
|
+
|
|
808
|
+
oarch = OArchive(str(outPath), ogawa)
|
|
809
|
+
parent, opar, props, omesh, sch = None, None, None, None, None
|
|
810
|
+
try:
|
|
811
|
+
parent = oarch.getTop()
|
|
812
|
+
opar = OXform(parent, str(name + transformSuffix))
|
|
813
|
+
if propDict:
|
|
814
|
+
props = opar.getSchema().getUserProperties()
|
|
815
|
+
for k, v in six.iteritems(propDict):
|
|
816
|
+
writeStringProperty(props, str(k), str(v), ogawa=ogawa)
|
|
817
|
+
|
|
818
|
+
omesh = OPolyMesh(opar, str(name + shapeSuffix))
|
|
819
|
+
|
|
820
|
+
if np is not None:
|
|
821
|
+
points = np.array(points)
|
|
822
|
+
if len(points.shape) == 2:
|
|
823
|
+
points = points[None, ...]
|
|
824
|
+
else:
|
|
825
|
+
if not isinstance(points[0][0], (list, tuple)):
|
|
826
|
+
points = [points]
|
|
827
|
+
|
|
828
|
+
sch = omesh.getSchema()
|
|
829
|
+
for i, frame in enumerate(points):
|
|
830
|
+
pbPrint(pBar, message="Exporting Shape", val=i, maxVal=len(points))
|
|
831
|
+
abcFrame = mkSampleVertexPoints(frame)
|
|
832
|
+
setAlembicSample(sch, abcFrame, faceCounts, faces, uvs=uvs, normals=normals)
|
|
833
|
+
|
|
834
|
+
pbPrint(pBar, message="Done Exporting")
|
|
835
|
+
finally:
|
|
836
|
+
# Make sure all this gets deleted so the file is freed
|
|
837
|
+
del parent, opar, props, omesh, sch
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
# Simplex format specific stuff
|
|
841
|
+
def getSmpxArchiveData(abcPath):
|
|
842
|
+
"""Read and return the low level relevant data from a simplex alembic
|
|
843
|
+
|
|
844
|
+
Parameters
|
|
845
|
+
----------
|
|
846
|
+
abcPath : str
|
|
847
|
+
The path to the .smpx file
|
|
848
|
+
|
|
849
|
+
Returns
|
|
850
|
+
-------
|
|
851
|
+
: IArchive
|
|
852
|
+
An opened Alembic IArchive object handle
|
|
853
|
+
: IPolyMesh
|
|
854
|
+
An Alembic Mesh handle
|
|
855
|
+
: str
|
|
856
|
+
The json definition string
|
|
857
|
+
"""
|
|
858
|
+
if not os.path.isfile(str(abcPath)):
|
|
859
|
+
raise IOError("File does not exist: " + str(abcPath))
|
|
860
|
+
iarch = IArchive(str(abcPath)) # because alembic hates unicode
|
|
861
|
+
top, par, abcMesh = [None] * 3
|
|
862
|
+
try:
|
|
863
|
+
top = iarch.getTop()
|
|
864
|
+
par = top.children[0]
|
|
865
|
+
par = IXform(top, par.getName())
|
|
866
|
+
abcMesh = par.children[0]
|
|
867
|
+
abcMesh = IPolyMesh(par, abcMesh.getName())
|
|
868
|
+
# I *could* come up with a generic property reader
|
|
869
|
+
# but it's useless for me at this time
|
|
870
|
+
sch = par.getSchema()
|
|
871
|
+
props = sch.getUserProperties()
|
|
872
|
+
jsString = readStringProperty(props, "simplex")
|
|
873
|
+
|
|
874
|
+
except Exception: # pylint: disable=broad-except
|
|
875
|
+
# ensure that the .smpx file is released
|
|
876
|
+
iarch, top, par, abcMesh = [None] * 4
|
|
877
|
+
raise
|
|
878
|
+
|
|
879
|
+
# Must return the archive, otherwise it gets GC'd
|
|
880
|
+
return iarch, abcMesh, jsString
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
def readSmpx(path, pBar=None):
|
|
884
|
+
"""Read and return the raw alembic vertex/face data in the flat alembic style
|
|
885
|
+
|
|
886
|
+
Parameters
|
|
887
|
+
----------
|
|
888
|
+
abcPath : str
|
|
889
|
+
The path to the .smpx file
|
|
890
|
+
pBar : QProgressDialog, optional
|
|
891
|
+
An optional progress dialog
|
|
892
|
+
|
|
893
|
+
Returns
|
|
894
|
+
-------
|
|
895
|
+
: str
|
|
896
|
+
The simplex definition string
|
|
897
|
+
: [int, ...] or np.array
|
|
898
|
+
The number of vertices per face
|
|
899
|
+
: [[(float*3), ...], ...] or np.array
|
|
900
|
+
The vertex positions per shape
|
|
901
|
+
: [int, ...] or np.array
|
|
902
|
+
The flat indexes per face
|
|
903
|
+
: [(float*2), ...] or np.array or None
|
|
904
|
+
The UV's
|
|
905
|
+
: [int, ...] or np.array
|
|
906
|
+
The flat indexes per uv-face
|
|
907
|
+
"""
|
|
908
|
+
iarch, abcMesh, jsString = getSmpxArchiveData(path)
|
|
909
|
+
try:
|
|
910
|
+
faces, counts = getStaticMeshArrays(abcMesh)
|
|
911
|
+
verts = getSampleArray(abcMesh, pBar=pBar)
|
|
912
|
+
uvs = getUvArray(abcMesh)
|
|
913
|
+
uvFaces, _ = getFlatUvFaces(abcMesh)
|
|
914
|
+
finally:
|
|
915
|
+
del iarch, abcMesh
|
|
916
|
+
return jsString, counts, verts, faces, uvs, uvFaces
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
def buildSmpx(
|
|
920
|
+
outPath,
|
|
921
|
+
points,
|
|
922
|
+
faces,
|
|
923
|
+
jsString,
|
|
924
|
+
name,
|
|
925
|
+
faceCounts=None,
|
|
926
|
+
uvs=None,
|
|
927
|
+
uvFaces=None,
|
|
928
|
+
ogawa=True,
|
|
929
|
+
pBar=None,
|
|
930
|
+
):
|
|
931
|
+
"""
|
|
932
|
+
Build a simplex output from raw data
|
|
933
|
+
|
|
934
|
+
Parameters
|
|
935
|
+
----------
|
|
936
|
+
outPath: str
|
|
937
|
+
The output path for the alembic file
|
|
938
|
+
points: list or ndarray
|
|
939
|
+
The list or array of points. Single multiple frames supported
|
|
940
|
+
faces: list
|
|
941
|
+
A list of lists of face indices, or a flattened list of indices.
|
|
942
|
+
If flat, then faceCounts must be provided
|
|
943
|
+
jsString : str
|
|
944
|
+
The simplex definition string
|
|
945
|
+
name: str
|
|
946
|
+
The name to give this mesh
|
|
947
|
+
faceCounts: list
|
|
948
|
+
A list of the number of vertices per face. Defaults to None
|
|
949
|
+
uvs: list or ndarray
|
|
950
|
+
The Uvs for this mesh. Defaults to None
|
|
951
|
+
uvFaces: list
|
|
952
|
+
A list of lists of face indices, or a flattened list of indices.
|
|
953
|
+
If flat, then faceCounts must be provided. Defaults to None
|
|
954
|
+
ogawa : bool
|
|
955
|
+
Whether to write to the Ogawa (True) or HDF5 (False) backend
|
|
956
|
+
pBar : QProgressDialog, optional
|
|
957
|
+
An optional progress dialog
|
|
958
|
+
"""
|
|
959
|
+
buildAbc(
|
|
960
|
+
outPath,
|
|
961
|
+
points,
|
|
962
|
+
faces,
|
|
963
|
+
faceCounts=faceCounts,
|
|
964
|
+
uvs=uvs,
|
|
965
|
+
uvFaces=uvFaces,
|
|
966
|
+
name=name,
|
|
967
|
+
shapeSuffix="",
|
|
968
|
+
transformSuffix="",
|
|
969
|
+
propDict=dict(simplex=jsString),
|
|
970
|
+
ogawa=ogawa,
|
|
971
|
+
pBar=pBar,
|
|
972
|
+
)
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
def buildAlembicArchiveData(path, name, jsString, ogawa):
|
|
976
|
+
"""Set up an output alembic archive with a mesh ready for writing
|
|
977
|
+
|
|
978
|
+
Parameters
|
|
979
|
+
----------
|
|
980
|
+
path : str
|
|
981
|
+
The output file path
|
|
982
|
+
name : str
|
|
983
|
+
The name of the system
|
|
984
|
+
jsString : str
|
|
985
|
+
The simplex definition string
|
|
986
|
+
ogawa : bool
|
|
987
|
+
Whether to open in Ogawa (True) or HDF5 (False) mode
|
|
988
|
+
|
|
989
|
+
Returns
|
|
990
|
+
-------
|
|
991
|
+
: OArchive
|
|
992
|
+
The opened alembic output archive
|
|
993
|
+
: OPolyMesh
|
|
994
|
+
The mesh to write the shape data to
|
|
995
|
+
|
|
996
|
+
"""
|
|
997
|
+
arch = OArchive(str(path), ogawa)
|
|
998
|
+
par, props, abcMesh = [None] * 3
|
|
999
|
+
try:
|
|
1000
|
+
par = OXform(arch.getTop(), str(name))
|
|
1001
|
+
props = par.getSchema().getUserProperties()
|
|
1002
|
+
writeStringProperty(props, "simplex", jsString, ogawa=ogawa)
|
|
1003
|
+
abcMesh = OPolyMesh(par, str(name))
|
|
1004
|
+
except Exception:
|
|
1005
|
+
arch, par, props, abcMesh = [None] * 4
|
|
1006
|
+
raise
|
|
1007
|
+
return arch, abcMesh
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
def readFalloffData(abcPath):
|
|
1011
|
+
"""Load the relevant data from a simplex alembic
|
|
1012
|
+
|
|
1013
|
+
Parameters
|
|
1014
|
+
----------
|
|
1015
|
+
abcPath : str
|
|
1016
|
+
Path to the .smpx file
|
|
1017
|
+
|
|
1018
|
+
"""
|
|
1019
|
+
if not os.path.isfile(str(abcPath)):
|
|
1020
|
+
raise IOError("File does not exist: " + str(abcPath))
|
|
1021
|
+
iarch = IArchive(str(abcPath)) # because alembic hates unicode
|
|
1022
|
+
top, par, systemSchema, foPropPar, foProp = [None] * 5
|
|
1023
|
+
try:
|
|
1024
|
+
top = iarch.getTop()
|
|
1025
|
+
par = top.children[0]
|
|
1026
|
+
par = IXform(top, par.getName())
|
|
1027
|
+
systemSchema = par.getSchema()
|
|
1028
|
+
props = systemSchema.getUserProperties()
|
|
1029
|
+
foDict = {}
|
|
1030
|
+
try:
|
|
1031
|
+
foPropPar = props.getProperty("falloffs")
|
|
1032
|
+
except KeyError:
|
|
1033
|
+
pass
|
|
1034
|
+
else:
|
|
1035
|
+
nps = foPropPar.getNumProperties()
|
|
1036
|
+
for i in range(nps):
|
|
1037
|
+
foProp = foPropPar.getProperty(i)
|
|
1038
|
+
fon = foProp.getName()
|
|
1039
|
+
fov = foProp.getValue() # imath.FloatArray
|
|
1040
|
+
fov = list(fov) if np is None else np.array(fov)
|
|
1041
|
+
foDict[fon] = fov
|
|
1042
|
+
finally:
|
|
1043
|
+
iarch, top, par, systemSchema, foPropPar, foProp = [None] * 6
|
|
1044
|
+
|
|
1045
|
+
return foDict
|