simplex-solver 3.1.0__39-abi3-win_amd64.whl

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