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,2944 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# pylint: disable=invalid-name
|
|
20
|
+
from __future__ import absolute_import, print_function
|
|
21
|
+
|
|
22
|
+
import json
|
|
23
|
+
import os
|
|
24
|
+
import tempfile
|
|
25
|
+
from contextlib import contextmanager
|
|
26
|
+
from functools import wraps
|
|
27
|
+
from itertools import repeat
|
|
28
|
+
|
|
29
|
+
import dcc.xsi as dcc
|
|
30
|
+
import numpy as np
|
|
31
|
+
import six
|
|
32
|
+
from alembic.AbcGeom import OPolyMeshSchemaSample
|
|
33
|
+
from imath import IntArray, V3f, V3fArray
|
|
34
|
+
from six.moves import range, zip
|
|
35
|
+
|
|
36
|
+
from ..commands.alembicCommon import mkUvSample
|
|
37
|
+
from ..commands.buildIceXML import buildIceXML, buildLoaderXML, buildSliderIceXML
|
|
38
|
+
from Qt import QtCore
|
|
39
|
+
from Qt.QtCore import Signal
|
|
40
|
+
from Qt.QtWidgets import QApplication, QDialog, QMainWindow, QSplashScreen
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# UNDO STACK INTEGRATION
|
|
44
|
+
@contextmanager
|
|
45
|
+
def undoContext(inst=None):
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
Parameters
|
|
49
|
+
----------
|
|
50
|
+
inst :
|
|
51
|
+
(Default value = None)
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
if inst is None:
|
|
58
|
+
DCC.staticUndoOpen()
|
|
59
|
+
else:
|
|
60
|
+
inst.undoOpen()
|
|
61
|
+
try:
|
|
62
|
+
yield
|
|
63
|
+
finally:
|
|
64
|
+
if inst is None:
|
|
65
|
+
DCC.staticUndoClose()
|
|
66
|
+
else:
|
|
67
|
+
inst.undoClose()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def undoable(f):
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
75
|
+
f :
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
@wraps(f)
|
|
84
|
+
def stacker(*args, **kwargs):
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
*args :
|
|
90
|
+
|
|
91
|
+
**kwargs :
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
|
|
97
|
+
"""
|
|
98
|
+
with undoContext():
|
|
99
|
+
return f(*args, **kwargs)
|
|
100
|
+
|
|
101
|
+
return stacker
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# temporarily disconnect inputs from the slider list
|
|
105
|
+
@contextmanager
|
|
106
|
+
def disconnected(sliders, prop):
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
Parameters
|
|
110
|
+
----------
|
|
111
|
+
sliders :
|
|
112
|
+
|
|
113
|
+
prop :
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
params = [slider.thing for slider in sliders]
|
|
121
|
+
pairs = []
|
|
122
|
+
toRemove = []
|
|
123
|
+
for param in params:
|
|
124
|
+
if param.IsAnimated(dcc.constants.siExpressionSource):
|
|
125
|
+
pairs.append((param.Name, param.Source.Definition.Value))
|
|
126
|
+
|
|
127
|
+
toRemove.append(param)
|
|
128
|
+
dcc.xsi.RemoveAnimation(toRemove)
|
|
129
|
+
dcc.xsi.SetValue(params, 0.0)
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
yield pairs
|
|
133
|
+
finally:
|
|
134
|
+
for paramName, exp in pairs:
|
|
135
|
+
param = prop.Parameters(paramName)
|
|
136
|
+
if param is not None:
|
|
137
|
+
param.AddExpression(exp)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class DCC(object):
|
|
141
|
+
""" """
|
|
142
|
+
|
|
143
|
+
program = "xsi"
|
|
144
|
+
shapeNamePrefix = ""
|
|
145
|
+
texName = "Texture_Projection"
|
|
146
|
+
|
|
147
|
+
def __init__(self, simplex, stack=None):
|
|
148
|
+
self.name = None # the name of the system
|
|
149
|
+
self.mesh = None # the mesh object with the system
|
|
150
|
+
self.inProp = None # the control property on the object
|
|
151
|
+
self.shapeCluster = None # the cluster containing the shapes
|
|
152
|
+
self.shapeTree = None # the ICETree driving the shapes
|
|
153
|
+
self.shapeNode = None # the shape compound node in the IceTree
|
|
154
|
+
self.sliderNode = None # the slider compound node in the IceTree
|
|
155
|
+
self.op = None # the simplex node in the IceTree
|
|
156
|
+
self.simplex = simplex # the abstract representation of the setup
|
|
157
|
+
self.undoDepth = 0
|
|
158
|
+
self._live = True
|
|
159
|
+
self.sliderMul = self.simplex.sliderMul
|
|
160
|
+
|
|
161
|
+
cls = type(self)
|
|
162
|
+
self.shapeNamePrefix = cls.shapeNamePrefix
|
|
163
|
+
# Reset the prefix because othewise, someone will forget
|
|
164
|
+
cls.shapeNamePrefix = ""
|
|
165
|
+
|
|
166
|
+
def getShapeThing(self, shapeName):
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
Parameters
|
|
170
|
+
----------
|
|
171
|
+
shapeName :
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
|
|
177
|
+
"""
|
|
178
|
+
for prop in self.shapeCluster.Properties:
|
|
179
|
+
if prop.Name == self.shapeNamePrefix + shapeName:
|
|
180
|
+
return [prop, None, None, None]
|
|
181
|
+
return None
|
|
182
|
+
|
|
183
|
+
def getSliderThing(self, sliderName):
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
Parameters
|
|
187
|
+
----------
|
|
188
|
+
sliderName :
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
Returns
|
|
192
|
+
-------
|
|
193
|
+
|
|
194
|
+
"""
|
|
195
|
+
return self.inProp.Parameters(sliderName)
|
|
196
|
+
|
|
197
|
+
def preLoad(self, simp, simpDict, create=True, pBar=None):
|
|
198
|
+
"""
|
|
199
|
+
|
|
200
|
+
Parameters
|
|
201
|
+
----------
|
|
202
|
+
simp :
|
|
203
|
+
|
|
204
|
+
simpDict :
|
|
205
|
+
|
|
206
|
+
create :
|
|
207
|
+
(Default value = True)
|
|
208
|
+
pBar :
|
|
209
|
+
(Default value = None)
|
|
210
|
+
|
|
211
|
+
Returns
|
|
212
|
+
-------
|
|
213
|
+
|
|
214
|
+
"""
|
|
215
|
+
# Pre-build all the nodes and parameters quickly
|
|
216
|
+
if pBar is not None:
|
|
217
|
+
pBar.setLabelText("Loading Connections")
|
|
218
|
+
QApplication.processEvents()
|
|
219
|
+
ev = simpDict["encodingVersion"]
|
|
220
|
+
|
|
221
|
+
shapeNames = simpDict.get("shapes")
|
|
222
|
+
if not shapeNames:
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
if ev > 1:
|
|
226
|
+
shapeNames = [i["name"] for i in shapeNames]
|
|
227
|
+
|
|
228
|
+
# Gather all the missing shapes to create in one go
|
|
229
|
+
if pBar is not None:
|
|
230
|
+
pBar.setMaximum(len(shapeNames))
|
|
231
|
+
pBar.setLabelText("Checking for missing shapes")
|
|
232
|
+
pBar.setValue(0)
|
|
233
|
+
QApplication.processEvents()
|
|
234
|
+
|
|
235
|
+
toMake = self._checkAllShapeValidity(shapeNames, pBar=pBar)
|
|
236
|
+
|
|
237
|
+
if toMake:
|
|
238
|
+
# Make 1 master duplicate and store it as a shapekey
|
|
239
|
+
# This ensures that all the shapes are created on the correct cluster
|
|
240
|
+
dupName = "__Simplex_Master_Dup"
|
|
241
|
+
tempVertArray, tempFaceArray = self.mesh.ActivePrimitive.Geometry.Get2()
|
|
242
|
+
dup = self.mesh.parent.AddPolygonMesh(tempVertArray, tempFaceArray, dupName)
|
|
243
|
+
dup.Properties("Visibility").viewvis = False
|
|
244
|
+
|
|
245
|
+
newShape = dcc.xsi.StoreShapeKey(
|
|
246
|
+
self.shapeCluster,
|
|
247
|
+
dup.Name,
|
|
248
|
+
dcc.constants.siShapeObjectReferenceMode,
|
|
249
|
+
1,
|
|
250
|
+
0,
|
|
251
|
+
0,
|
|
252
|
+
dcc.constants.siShapeContentPrimaryShape,
|
|
253
|
+
False,
|
|
254
|
+
)
|
|
255
|
+
dcc.xsi.FreezeObj(newShape)
|
|
256
|
+
dcc.xsi.DeleteObj(dup)
|
|
257
|
+
sks = [newShape]
|
|
258
|
+
|
|
259
|
+
if len(toMake) > 1:
|
|
260
|
+
# If there are more shapes to make, then we make them by
|
|
261
|
+
# duplicating the shapes from the mixer. This is easily
|
|
262
|
+
# 50x faster than creating shapes via any other method
|
|
263
|
+
if pBar is not None:
|
|
264
|
+
pBar.setMaximum(len(toMake))
|
|
265
|
+
pBar.setValue(0)
|
|
266
|
+
pBar.setLabelText("Creating Empty Shapes")
|
|
267
|
+
QApplication.processEvents()
|
|
268
|
+
|
|
269
|
+
mixShape = "{0}.{1}".format(
|
|
270
|
+
newShape.model.mixer.FullName, newShape.Name
|
|
271
|
+
)
|
|
272
|
+
# This may fail on stupid-dense meshes.
|
|
273
|
+
# Maybe add a pointCount vs. chunk size heuristic?
|
|
274
|
+
chunk = 20
|
|
275
|
+
for i in range(0, len(toMake[1:]), chunk):
|
|
276
|
+
if pBar is not None:
|
|
277
|
+
pBar.setValue(i)
|
|
278
|
+
QApplication.processEvents()
|
|
279
|
+
|
|
280
|
+
curSize = min(len(toMake) - 1, i + chunk) - i
|
|
281
|
+
# Can't duplicate more than 1 at a time, otherwise we get memory issues
|
|
282
|
+
dupShapes = dcc.xsi.Duplicate(
|
|
283
|
+
mixShape,
|
|
284
|
+
curSize,
|
|
285
|
+
dcc.constants.siCurrentHistory,
|
|
286
|
+
dcc.constants.siSharedParent,
|
|
287
|
+
dcc.constants.siShareGrouping,
|
|
288
|
+
dcc.constants.siNoProperties,
|
|
289
|
+
dcc.constants.siDuplicateAnimation,
|
|
290
|
+
dcc.constants.siShareConstraints,
|
|
291
|
+
dcc.constants.siNoSelection,
|
|
292
|
+
)
|
|
293
|
+
for dd in dupShapes:
|
|
294
|
+
cs = dcc.xsi.GetValue(
|
|
295
|
+
"{0}.{1}".format(self.shapeCluster.FullName, dd.Name)
|
|
296
|
+
)
|
|
297
|
+
sks.append(cs)
|
|
298
|
+
|
|
299
|
+
if pBar is not None:
|
|
300
|
+
pBar.setLabelText("Naming Shapes")
|
|
301
|
+
pBar.setValue(0)
|
|
302
|
+
pBar.setMaximum(len(sks))
|
|
303
|
+
QApplication.processEvents()
|
|
304
|
+
|
|
305
|
+
with self.noShapeNode():
|
|
306
|
+
chunk = 20
|
|
307
|
+
pfxToMake = [self.shapeNamePrefix + i for i in toMake]
|
|
308
|
+
for idx in range(0, len(sks), chunk):
|
|
309
|
+
if pBar is not None:
|
|
310
|
+
pBar.setValue(idx)
|
|
311
|
+
pns = ",".join(
|
|
312
|
+
[p.fullname + ".Name" for p in sks[idx : idx + chunk]]
|
|
313
|
+
)
|
|
314
|
+
dcc.xsi.SetValue(pns, pfxToMake[idx : idx + chunk])
|
|
315
|
+
|
|
316
|
+
dcc.xsi.FreezeObj(
|
|
317
|
+
[i for i in self.shapeCluster.Properties if len(i.NestedObjects) > 2]
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
clsCombiner = dcc.operator.getOperatorFromStack(
|
|
321
|
+
self.mesh, "clustershapecombiner"
|
|
322
|
+
)
|
|
323
|
+
if clsCombiner:
|
|
324
|
+
dcc.xsi.DeleteObj(clsCombiner)
|
|
325
|
+
|
|
326
|
+
sliderNames = simpDict.get("sliders")
|
|
327
|
+
if not sliderNames:
|
|
328
|
+
return
|
|
329
|
+
if ev > 1:
|
|
330
|
+
sliderNames = [i["name"] for i in sliderNames]
|
|
331
|
+
else:
|
|
332
|
+
sliderNames = [i[0] for i in sliderNames]
|
|
333
|
+
|
|
334
|
+
for sliderName in sliderNames:
|
|
335
|
+
sliderParam = self.inProp.Parameters(sliderName)
|
|
336
|
+
if not sliderParam:
|
|
337
|
+
if not create:
|
|
338
|
+
raise RuntimeError(
|
|
339
|
+
"Slider {0} not found with creation turned off".format(
|
|
340
|
+
sliderName
|
|
341
|
+
)
|
|
342
|
+
)
|
|
343
|
+
self.inProp.AddParameter3(
|
|
344
|
+
sliderName, dcc.constants.siFloat, 0, -2.0, 2.0
|
|
345
|
+
)
|
|
346
|
+
return None
|
|
347
|
+
|
|
348
|
+
def postLoad(self, simp, preRet):
|
|
349
|
+
"""
|
|
350
|
+
|
|
351
|
+
Parameters
|
|
352
|
+
----------
|
|
353
|
+
simp :
|
|
354
|
+
|
|
355
|
+
preRet :
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
Returns
|
|
359
|
+
-------
|
|
360
|
+
|
|
361
|
+
"""
|
|
362
|
+
self.rebuildSliderNode()
|
|
363
|
+
self.resetShapeIndexes()
|
|
364
|
+
self.recreateShapeNode()
|
|
365
|
+
self.updateSlidersRange(simp.sliders)
|
|
366
|
+
|
|
367
|
+
def checkForErrors(self, window):
|
|
368
|
+
""" Check for any DCC specific errors
|
|
369
|
+
|
|
370
|
+
Parameters
|
|
371
|
+
----------
|
|
372
|
+
window : QMainWindow
|
|
373
|
+
The simplex window
|
|
374
|
+
"""
|
|
375
|
+
pass
|
|
376
|
+
|
|
377
|
+
# System IO
|
|
378
|
+
@undoable
|
|
379
|
+
def loadNodes(self, simp, thing, create=True, pBar=None):
|
|
380
|
+
"""Create a new system based on the simplex tree
|
|
381
|
+
Build any DCC objects that are missing if create=True
|
|
382
|
+
Raises a runtime error if missing objects are found and
|
|
383
|
+
create=False
|
|
384
|
+
|
|
385
|
+
Parameters
|
|
386
|
+
----------
|
|
387
|
+
simp :
|
|
388
|
+
|
|
389
|
+
thing :
|
|
390
|
+
|
|
391
|
+
create :
|
|
392
|
+
(Default value = True)
|
|
393
|
+
pBar :
|
|
394
|
+
(Default value = None)
|
|
395
|
+
|
|
396
|
+
Returns
|
|
397
|
+
-------
|
|
398
|
+
|
|
399
|
+
"""
|
|
400
|
+
self.name = simp.name
|
|
401
|
+
self.mesh = thing
|
|
402
|
+
|
|
403
|
+
# find/build the shapeCluster
|
|
404
|
+
if pBar is not None:
|
|
405
|
+
pBar.setLabelText("Loading Nodes")
|
|
406
|
+
QApplication.processEvents()
|
|
407
|
+
|
|
408
|
+
shapeCluster = thing.ActivePrimitive.Geometry.Clusters("Shape")
|
|
409
|
+
if not shapeCluster:
|
|
410
|
+
shapeCluster = thing.ActivePrimitive.Geometry.Clusters(
|
|
411
|
+
"%s_Shapes" % self.name
|
|
412
|
+
)
|
|
413
|
+
if not shapeCluster:
|
|
414
|
+
if not create:
|
|
415
|
+
raise RuntimeError("Shape cluster not found with creation turned off")
|
|
416
|
+
self.shapeCluster = dcc.xsi.CreateCluster("%s.pnt[*]" % thing.FullName)[0]
|
|
417
|
+
self.shapeCluster.Name = "%s_Shapes" % self.name
|
|
418
|
+
dcc.xsi.SelectObj(thing)
|
|
419
|
+
else:
|
|
420
|
+
self.shapeCluster = shapeCluster
|
|
421
|
+
|
|
422
|
+
# find/build the Icetree
|
|
423
|
+
shapeTree = thing.ActivePrimitive.ICETrees("%s_IceTree" % self.name)
|
|
424
|
+
if not shapeTree:
|
|
425
|
+
if not create:
|
|
426
|
+
raise RuntimeError(
|
|
427
|
+
"Simplex shape ICETree not found with creation turned off"
|
|
428
|
+
)
|
|
429
|
+
self.shapeTree = dcc.ice.ICETree(
|
|
430
|
+
None,
|
|
431
|
+
self.mesh,
|
|
432
|
+
"%s_IceTree" % self.name,
|
|
433
|
+
dcc.constants.siConstructionModePrimaryShape,
|
|
434
|
+
)
|
|
435
|
+
else:
|
|
436
|
+
self.shapeTree = dcc.ice.ICETree(shapeTree)
|
|
437
|
+
|
|
438
|
+
# find/build the Slider compound in the Icetree
|
|
439
|
+
sliderComp = None
|
|
440
|
+
for node in self.shapeTree.compoundNodes:
|
|
441
|
+
if node.name == "SliderArray":
|
|
442
|
+
sliderComp = node
|
|
443
|
+
break
|
|
444
|
+
if not sliderComp:
|
|
445
|
+
if not create:
|
|
446
|
+
raise RuntimeError(
|
|
447
|
+
"Slider array compound not found in ICETree with creation turned off"
|
|
448
|
+
)
|
|
449
|
+
sliderArray = self.shapeTree.addNode("BuildArray")
|
|
450
|
+
sliderComp = self.shapeTree.createCompound([sliderArray])
|
|
451
|
+
sliderComp.rename("SliderArray")
|
|
452
|
+
sliderComp.exposePort(sliderArray.outputPorts["array"])
|
|
453
|
+
self.sliderNode = sliderComp
|
|
454
|
+
|
|
455
|
+
# find/build the simplex node in the Icetree
|
|
456
|
+
ops = DCC.getSimplexOperatorsOnObjectByName(thing, self.name)
|
|
457
|
+
if not ops:
|
|
458
|
+
if not create:
|
|
459
|
+
raise RuntimeError("Simplex Operator not found with create turned off")
|
|
460
|
+
op = dcc.ice.ICENode(
|
|
461
|
+
dcc.xsi.AddICENode("SimplexNode", self.shapeTree.fullName)
|
|
462
|
+
)
|
|
463
|
+
op.inputPorts["Sliders"].connect(self.sliderNode.outputPorts["Array"])
|
|
464
|
+
setter = self.shapeTree.addSetDataNode("Self._%s_SimplexVector" % self.name)
|
|
465
|
+
setter.Value.connect(op.outputPorts["Weights"])
|
|
466
|
+
self.shapeTree.connect(setter.Execute, 1)
|
|
467
|
+
self.op = op
|
|
468
|
+
else:
|
|
469
|
+
self.op = ops
|
|
470
|
+
|
|
471
|
+
# find/build the shape compound in the Icetree
|
|
472
|
+
shapeNode = None
|
|
473
|
+
for node in self.shapeTree.compoundNodes:
|
|
474
|
+
if node.name == "ShapeCompound":
|
|
475
|
+
shapeNode = node
|
|
476
|
+
break
|
|
477
|
+
if not shapeNode:
|
|
478
|
+
if not create:
|
|
479
|
+
raise RuntimeError(
|
|
480
|
+
"Shape compound not found in ICETree with creation turned off"
|
|
481
|
+
)
|
|
482
|
+
setter = self.shapeTree.addSetDataNode("Self.PointPosition")
|
|
483
|
+
self.shapeTree.connect(setter.Execute)
|
|
484
|
+
shapeCompound = self.rebuildShapeNode(simp)
|
|
485
|
+
getter = self.shapeTree.addGetDataNode("Self._%s_SimplexVector" % self.name)
|
|
486
|
+
getter.value.connect(shapeCompound.inputPorts["In"])
|
|
487
|
+
setter.Value.connect(shapeCompound.Result)
|
|
488
|
+
self.shapeNode = shapeCompound
|
|
489
|
+
else:
|
|
490
|
+
self.shapeNode = shapeNode
|
|
491
|
+
|
|
492
|
+
# find/build the input and output properties
|
|
493
|
+
inProp = thing.Properties("%s_inProperty" % self.name)
|
|
494
|
+
if not inProp:
|
|
495
|
+
if not create:
|
|
496
|
+
raise RuntimeError(
|
|
497
|
+
"Control parameters not found with creation turned off"
|
|
498
|
+
)
|
|
499
|
+
self.inProp = self.mesh.AddProperty(
|
|
500
|
+
"CustomProperty", False, "%s_inProperty" % self.name
|
|
501
|
+
)
|
|
502
|
+
else:
|
|
503
|
+
self.inProp = inProp
|
|
504
|
+
|
|
505
|
+
def _checkAllShapeValidity(self, shapeNames, errorOnMissing=False, pBar=None):
|
|
506
|
+
"""Check shapes to see if they exist, and either gather the missing files, or
|
|
507
|
+
Load the proper data onto the shapes
|
|
508
|
+
|
|
509
|
+
Parameters
|
|
510
|
+
----------
|
|
511
|
+
shapeNames :
|
|
512
|
+
|
|
513
|
+
errorOnMissing :
|
|
514
|
+
(Default value = False)
|
|
515
|
+
pBar :
|
|
516
|
+
(Default value = None)
|
|
517
|
+
|
|
518
|
+
Returns
|
|
519
|
+
-------
|
|
520
|
+
|
|
521
|
+
"""
|
|
522
|
+
propByName = {i.Name: i for i in list(self.shapeCluster.Properties)}
|
|
523
|
+
|
|
524
|
+
if pBar is not None:
|
|
525
|
+
pBar.setMaximum(len(shapeNames))
|
|
526
|
+
if errorOnMissing:
|
|
527
|
+
pBar.setLabelText("Checking Validity")
|
|
528
|
+
else:
|
|
529
|
+
pBar.setLabelText("Checking For Missing Shapes")
|
|
530
|
+
pBar.setValue(0)
|
|
531
|
+
QApplication.processEvents()
|
|
532
|
+
|
|
533
|
+
# Keep the set ordered, but make a set for quick checking
|
|
534
|
+
missingNameSet = set()
|
|
535
|
+
missingNames = []
|
|
536
|
+
seen = set()
|
|
537
|
+
|
|
538
|
+
for i, shapeName in enumerate(shapeNames):
|
|
539
|
+
if shapeName in seen:
|
|
540
|
+
continue
|
|
541
|
+
seen.add(shapeName)
|
|
542
|
+
|
|
543
|
+
if pBar is not None:
|
|
544
|
+
pBar.setValue(i)
|
|
545
|
+
QApplication.processEvents()
|
|
546
|
+
|
|
547
|
+
if self.shapeNamePrefix + shapeName not in propByName:
|
|
548
|
+
if errorOnMissing:
|
|
549
|
+
raise RuntimeError("Missing shape: {}".format(shapeName))
|
|
550
|
+
else:
|
|
551
|
+
if shapeName not in missingNameSet:
|
|
552
|
+
missingNameSet.add(shapeName)
|
|
553
|
+
missingNames.append(shapeName)
|
|
554
|
+
return missingNames
|
|
555
|
+
|
|
556
|
+
def _loadShapeIceNodes(self, simp):
|
|
557
|
+
"""load the ICE nodes related to the given shapeKey
|
|
558
|
+
|
|
559
|
+
Parameters
|
|
560
|
+
----------
|
|
561
|
+
simp :
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
Returns
|
|
565
|
+
-------
|
|
566
|
+
|
|
567
|
+
"""
|
|
568
|
+
# Ice nodes are created in-order by the buildIceXML function
|
|
569
|
+
# so we can take advantage of that to properly connect the shapes
|
|
570
|
+
simpNode = self.shapeNode
|
|
571
|
+
children = simpNode.nodes
|
|
572
|
+
# addNode, passNode, getSelfPos = children[:3]
|
|
573
|
+
shapeNodes = children[3:]
|
|
574
|
+
propByName = {i.Name: i for i in list(self.shapeCluster.Properties)}
|
|
575
|
+
|
|
576
|
+
for i, shape in enumerate(simp.shapes):
|
|
577
|
+
selector = shapeNodes[(3 * i) + 0]._nativePointer
|
|
578
|
+
getData = shapeNodes[(3 * i) + 1]._nativePointer
|
|
579
|
+
multiplier = shapeNodes[(3 * i) + 2]._nativePointer
|
|
580
|
+
shape.thing = [
|
|
581
|
+
propByName[self.shapeNamePrefix + shape.name],
|
|
582
|
+
getData,
|
|
583
|
+
selector,
|
|
584
|
+
multiplier,
|
|
585
|
+
]
|
|
586
|
+
|
|
587
|
+
@contextmanager
|
|
588
|
+
def noShapeNode(self):
|
|
589
|
+
""" """
|
|
590
|
+
# Clear the shape node so we don't take the renaming speed hit
|
|
591
|
+
if self.shapeNode:
|
|
592
|
+
vectorGetter = list(
|
|
593
|
+
self.shapeNode.inputPortList[0].connectedNodes.values()
|
|
594
|
+
)[0]
|
|
595
|
+
pointSetter = list(
|
|
596
|
+
self.shapeNode.outputPortList[0].connectedNodes.values()
|
|
597
|
+
)[0]
|
|
598
|
+
# Also disconnect the pointSetter so we don't get the null deformation
|
|
599
|
+
self.shapeTree.disconnect(2)
|
|
600
|
+
self.shapeNode.delete()
|
|
601
|
+
else:
|
|
602
|
+
vectorGetter, pointSetter = None, None
|
|
603
|
+
yield
|
|
604
|
+
|
|
605
|
+
if vectorGetter is None and pointSetter is None:
|
|
606
|
+
self.shapeNode = self.rebuildShapeNode(self.simplex)
|
|
607
|
+
else:
|
|
608
|
+
# Rebuild the shape and slider nodes
|
|
609
|
+
self.shapeTree.connect(pointSetter.Execute, 2)
|
|
610
|
+
shapeCompound = self.rebuildShapeNode(self.simplex)
|
|
611
|
+
pointSetter.Value.connect(shapeCompound.Result)
|
|
612
|
+
vectorGetter.value.connect(shapeCompound.inputPorts["In"])
|
|
613
|
+
self.shapeNode = shapeCompound
|
|
614
|
+
self._loadShapeIceNodes(self.simplex)
|
|
615
|
+
self.rebuildSliderNode()
|
|
616
|
+
|
|
617
|
+
@staticmethod
|
|
618
|
+
def _getTextureProp(mesh, texName):
|
|
619
|
+
"""
|
|
620
|
+
|
|
621
|
+
Parameters
|
|
622
|
+
----------
|
|
623
|
+
mesh :
|
|
624
|
+
|
|
625
|
+
texName :
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
Returns
|
|
629
|
+
-------
|
|
630
|
+
|
|
631
|
+
"""
|
|
632
|
+
import pywintypes
|
|
633
|
+
|
|
634
|
+
textureCls = [
|
|
635
|
+
cluster
|
|
636
|
+
for cluster in mesh.ActivePrimitive.Geometry.Clusters
|
|
637
|
+
if cluster.Type == "sample"
|
|
638
|
+
]
|
|
639
|
+
try:
|
|
640
|
+
for cluster in textureCls:
|
|
641
|
+
prop = cluster.Properties(texName)
|
|
642
|
+
if prop:
|
|
643
|
+
return prop
|
|
644
|
+
except pywintypes.com_error:
|
|
645
|
+
pass
|
|
646
|
+
return None
|
|
647
|
+
|
|
648
|
+
@classmethod
|
|
649
|
+
def buildRestAbc(cls, abcMesh, name):
|
|
650
|
+
"""
|
|
651
|
+
|
|
652
|
+
Parameters
|
|
653
|
+
----------
|
|
654
|
+
abcMesh :
|
|
655
|
+
|
|
656
|
+
name :
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
Returns
|
|
660
|
+
-------
|
|
661
|
+
|
|
662
|
+
"""
|
|
663
|
+
with undoContext():
|
|
664
|
+
meshSchema = abcMesh.getSchema()
|
|
665
|
+
rawFaces = meshSchema.getFaceIndicesProperty().samples[0]
|
|
666
|
+
rawCounts = meshSchema.getFaceCountsProperty().samples[0]
|
|
667
|
+
rawPos = meshSchema.getPositionsProperty().samples[0]
|
|
668
|
+
iuvs = meshSchema.getUVsParam()
|
|
669
|
+
|
|
670
|
+
uvws = None
|
|
671
|
+
if iuvs.valid():
|
|
672
|
+
uvValue = iuvs.getValueProperty().getValue()
|
|
673
|
+
uvs = list(zip(uvValue.x, uvValue.y, repeat(0.0)))
|
|
674
|
+
if iuvs.isIndexed():
|
|
675
|
+
idxs = list(iuvs.getIndexProperty().getValue())
|
|
676
|
+
uvs = [uvs[i] for i in idxs]
|
|
677
|
+
uvws = []
|
|
678
|
+
ptr = 0
|
|
679
|
+
for i in rawCounts:
|
|
680
|
+
uvws.extend(reversed(uvs[ptr : ptr + i]))
|
|
681
|
+
ptr += i
|
|
682
|
+
|
|
683
|
+
faces = []
|
|
684
|
+
ptr = 0
|
|
685
|
+
for i in rawCounts:
|
|
686
|
+
faces.append(i)
|
|
687
|
+
faces.extend(reversed(rawFaces[ptr : ptr + i]))
|
|
688
|
+
ptr += i
|
|
689
|
+
|
|
690
|
+
vertexArray = [list(rawPos.x), list(rawPos.y), list(rawPos.z)]
|
|
691
|
+
|
|
692
|
+
cName = "{0}_SIMPLEX".format(name)
|
|
693
|
+
model = dcc.xsi.ActiveSceneRoot.AddModel(
|
|
694
|
+
None, "{0}_SIMPLEXModel".format(name)
|
|
695
|
+
)
|
|
696
|
+
mesh = model.AddPolygonMesh(vertexArray, faces, cName)
|
|
697
|
+
|
|
698
|
+
if uvws is not None:
|
|
699
|
+
dcc.xsi.CreateProjection(mesh, "", "", "", cls.texName, True, "", "")
|
|
700
|
+
texProp = cls._getTextureProp(mesh, cls.texName)
|
|
701
|
+
|
|
702
|
+
if texProp is not None:
|
|
703
|
+
dcc.xsi.FreezeObj(texProp)
|
|
704
|
+
if len(uvws) == texProp.Elements.Count:
|
|
705
|
+
texProp.Elements.Array = list(zip(*uvws))
|
|
706
|
+
dcc.xsi.FreezeObj(texProp)
|
|
707
|
+
|
|
708
|
+
return mesh
|
|
709
|
+
|
|
710
|
+
@staticmethod
|
|
711
|
+
def vertCount(mesh):
|
|
712
|
+
geo = mesh.ActivePrimitive.Geometry
|
|
713
|
+
vertArray, faceArray = geo.Get2()
|
|
714
|
+
return len(vertArray[0])
|
|
715
|
+
|
|
716
|
+
@undoable
|
|
717
|
+
def loadAbc(self, abcMesh, js, pBar=False):
|
|
718
|
+
"""
|
|
719
|
+
|
|
720
|
+
Parameters
|
|
721
|
+
----------
|
|
722
|
+
abcMesh :
|
|
723
|
+
|
|
724
|
+
js :
|
|
725
|
+
|
|
726
|
+
pBar :
|
|
727
|
+
(Default value = False)
|
|
728
|
+
|
|
729
|
+
Returns
|
|
730
|
+
-------
|
|
731
|
+
|
|
732
|
+
"""
|
|
733
|
+
shapes = js["shapes"]
|
|
734
|
+
if js["encodingVersion"] > 1:
|
|
735
|
+
shapes = [i["name"] for i in shapes]
|
|
736
|
+
|
|
737
|
+
if pBar is not None:
|
|
738
|
+
pBar.show()
|
|
739
|
+
pBar.setMaximum(len(shapes))
|
|
740
|
+
longName = max(shapes, key=len)
|
|
741
|
+
pBar.setValue(1)
|
|
742
|
+
pBar.setLabelText("Loading:\n{0}".format("_" * len(longName)))
|
|
743
|
+
QApplication.processEvents()
|
|
744
|
+
|
|
745
|
+
# Load the alembic via geometry
|
|
746
|
+
preAtc = self.mesh.model.Properties("alembic_timecontrol")
|
|
747
|
+
loader = dcc.io.abcImport(
|
|
748
|
+
abcMesh.getArchive().getName(), parentNode=self.mesh.parent()
|
|
749
|
+
)
|
|
750
|
+
postAtc = self.mesh.model.Properties("alembic_timecontrol")
|
|
751
|
+
loader = loader[0]
|
|
752
|
+
loader.name = "Loader"
|
|
753
|
+
loader.Properties("Visibility").viewvis = False
|
|
754
|
+
dcc.xsi.FreezeModeling(loader)
|
|
755
|
+
dcc.xsi.DeleteObj(
|
|
756
|
+
"{0}.polymsh.alembic_polymesh.Expression".format(loader.FullName)
|
|
757
|
+
)
|
|
758
|
+
|
|
759
|
+
tVal = "{0}.polymsh.alembic_polymesh.time".format(loader.FullName)
|
|
760
|
+
dcc.xsi.SetValue(tVal, 0)
|
|
761
|
+
|
|
762
|
+
# rester = dcc.xsi.Duplicate(loader, 1,
|
|
763
|
+
# dcc.constants.siCurrentHistory, dcc.constants.siSharedParent,
|
|
764
|
+
# dcc.constants.siNoGrouping, dcc.constants.siNoProperties,
|
|
765
|
+
# dcc.constants.siNoAnimation, dcc.constants.siNoConstraints,
|
|
766
|
+
# dcc.constants.siNoSelection)
|
|
767
|
+
|
|
768
|
+
tempVertArray, tempFaceArray = loader.ActivePrimitive.Geometry.Get2()
|
|
769
|
+
rester = loader.parent.AddPolygonMesh(tempVertArray, tempFaceArray, "Rester")
|
|
770
|
+
rester.Properties("Visibility").viewvis = False
|
|
771
|
+
|
|
772
|
+
matcher = self._matchDelta(loader, rester)
|
|
773
|
+
|
|
774
|
+
cluster = self.shapeCluster.FullName
|
|
775
|
+
# "{0}.polymsh.cls.Face_Shapes".format(self.mesh.FullName)
|
|
776
|
+
|
|
777
|
+
with self.noShapeNode():
|
|
778
|
+
|
|
779
|
+
for i, shapeName in enumerate(shapes):
|
|
780
|
+
if pBar is not None:
|
|
781
|
+
pBar.setValue(i)
|
|
782
|
+
pBar.setLabelText("Loading:\n{0}".format(shapeName))
|
|
783
|
+
QApplication.processEvents()
|
|
784
|
+
if pBar.wasCanceled():
|
|
785
|
+
return
|
|
786
|
+
dcc.xsi.SetValue(tVal, i)
|
|
787
|
+
dcc.xsi.ReplaceShapeKey(
|
|
788
|
+
"{0}.{1}".format(cluster, self.shapeNamePrefix + shapeName)
|
|
789
|
+
)
|
|
790
|
+
|
|
791
|
+
matcher.delete()
|
|
792
|
+
dcc.xsi.DeleteObj(loader)
|
|
793
|
+
dcc.xsi.DeleteObj(rester)
|
|
794
|
+
self.deleteShapeCombiner()
|
|
795
|
+
if preAtc is None:
|
|
796
|
+
if postAtc is not None:
|
|
797
|
+
# Clear the alembic time control
|
|
798
|
+
dcc.xsi.DeleteObj(postAtc)
|
|
799
|
+
|
|
800
|
+
# Force a rebuild of the Icetree
|
|
801
|
+
self.recreateShapeNode()
|
|
802
|
+
|
|
803
|
+
if pBar is not None:
|
|
804
|
+
pBar.setValue(len(shapes))
|
|
805
|
+
|
|
806
|
+
def _matchDelta(self, loader, rester):
|
|
807
|
+
"""
|
|
808
|
+
|
|
809
|
+
Parameters
|
|
810
|
+
----------
|
|
811
|
+
loader :
|
|
812
|
+
|
|
813
|
+
rester :
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
Returns
|
|
817
|
+
-------
|
|
818
|
+
|
|
819
|
+
"""
|
|
820
|
+
xmlString = buildLoaderXML(loader, rester)
|
|
821
|
+
fHandle, compoundPath = tempfile.mkstemp(".xsicompound", text=True)
|
|
822
|
+
f = os.fdopen(fHandle, "w")
|
|
823
|
+
f.write(xmlString)
|
|
824
|
+
f.close()
|
|
825
|
+
tree = dcc.ice.ICETree(
|
|
826
|
+
None,
|
|
827
|
+
self.mesh,
|
|
828
|
+
"SimplexDeltaMatch",
|
|
829
|
+
dcc.constants.siConstructionModePrimaryShape,
|
|
830
|
+
)
|
|
831
|
+
compound = dcc.ice.ICECompoundNode(
|
|
832
|
+
dcc.xsi.AddICECompoundNode(compoundPath, tree._nativePointer)
|
|
833
|
+
)
|
|
834
|
+
tree.connect(compound.Value)
|
|
835
|
+
os.remove(compoundPath)
|
|
836
|
+
return tree
|
|
837
|
+
|
|
838
|
+
def getShapeVertices(self, shape):
|
|
839
|
+
"""
|
|
840
|
+
|
|
841
|
+
Parameters
|
|
842
|
+
----------
|
|
843
|
+
shape :
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
Returns
|
|
847
|
+
-------
|
|
848
|
+
|
|
849
|
+
"""
|
|
850
|
+
dcc.xsi.DeactivateAbove("%s.modelingmarker" % self.mesh.ActivePrimitive, True)
|
|
851
|
+
restVerts = self.mesh.ActivePrimitive.Geometry.Points.PositionArray
|
|
852
|
+
restVerts = np.array(list(zip(*restVerts)))
|
|
853
|
+
shapeDeltas = np.array(shape.thing[0].Elements.Array).T
|
|
854
|
+
dcc.xsi.DeactivateAbove("%s.modelingmarker" % self.mesh.ActivePrimitive, "")
|
|
855
|
+
return restVerts + shapeDeltas
|
|
856
|
+
|
|
857
|
+
def getAllShapeVertices(self, shapes, pBar=None):
|
|
858
|
+
"""
|
|
859
|
+
|
|
860
|
+
Parameters
|
|
861
|
+
----------
|
|
862
|
+
shapes :
|
|
863
|
+
|
|
864
|
+
pBar :
|
|
865
|
+
(Default value = None)
|
|
866
|
+
|
|
867
|
+
Returns
|
|
868
|
+
-------
|
|
869
|
+
|
|
870
|
+
"""
|
|
871
|
+
for shape in shapes:
|
|
872
|
+
shape.verts = self.getShapeVertices(shape)
|
|
873
|
+
|
|
874
|
+
def pushAllShapeVertices(self, shapes, pBar=None):
|
|
875
|
+
"""
|
|
876
|
+
|
|
877
|
+
Parameters
|
|
878
|
+
----------
|
|
879
|
+
shapes :
|
|
880
|
+
|
|
881
|
+
pBar :
|
|
882
|
+
(Default value = None)
|
|
883
|
+
|
|
884
|
+
Returns
|
|
885
|
+
-------
|
|
886
|
+
|
|
887
|
+
"""
|
|
888
|
+
# take all the verts stored on the shapes
|
|
889
|
+
# and push them back to the DCC
|
|
890
|
+
for shape in shapes:
|
|
891
|
+
self.pushShapeVertices(shape)
|
|
892
|
+
|
|
893
|
+
def pushShapeVertices(self, shape):
|
|
894
|
+
"""
|
|
895
|
+
|
|
896
|
+
Parameters
|
|
897
|
+
----------
|
|
898
|
+
shape :
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
Returns
|
|
902
|
+
-------
|
|
903
|
+
|
|
904
|
+
"""
|
|
905
|
+
# Push the vertices for a specific shape back to the DCC
|
|
906
|
+
pass
|
|
907
|
+
|
|
908
|
+
def _getMeshVertices(self, mesh, world=False):
|
|
909
|
+
"""
|
|
910
|
+
|
|
911
|
+
Parameters
|
|
912
|
+
----------
|
|
913
|
+
mesh :
|
|
914
|
+
|
|
915
|
+
world :
|
|
916
|
+
(Default value = False)
|
|
917
|
+
|
|
918
|
+
Returns
|
|
919
|
+
-------
|
|
920
|
+
|
|
921
|
+
"""
|
|
922
|
+
# We're ignoring world in XSI because we don't use it for that
|
|
923
|
+
vts = mesh.ActivePrimitive.Geometry.Points.PositionArray
|
|
924
|
+
vts = list(zip(*vts))
|
|
925
|
+
return vts
|
|
926
|
+
|
|
927
|
+
def _exportAbcVertices(self, mesh, shape, world=False):
|
|
928
|
+
"""
|
|
929
|
+
|
|
930
|
+
Parameters
|
|
931
|
+
----------
|
|
932
|
+
mesh :
|
|
933
|
+
|
|
934
|
+
shape :
|
|
935
|
+
|
|
936
|
+
world :
|
|
937
|
+
(Default value = False)
|
|
938
|
+
|
|
939
|
+
Returns
|
|
940
|
+
-------
|
|
941
|
+
|
|
942
|
+
"""
|
|
943
|
+
vts = np.array(self._getMeshVertices(mesh, world=world))
|
|
944
|
+
shapeVts = np.array(shape.thing[0].Elements.Array)
|
|
945
|
+
outVerts = vts + shapeVts.T
|
|
946
|
+
|
|
947
|
+
vertices = V3fArray(len(vts))
|
|
948
|
+
setter = V3f(0, 0, 0)
|
|
949
|
+
for i in range(len(outVerts)):
|
|
950
|
+
setter.setValue(outVerts[i, 0], outVerts[i, 1], outVerts[i, 2])
|
|
951
|
+
vertices[i] = setter
|
|
952
|
+
return vertices
|
|
953
|
+
|
|
954
|
+
def _exportAbcFaces(self, mesh):
|
|
955
|
+
"""
|
|
956
|
+
|
|
957
|
+
Parameters
|
|
958
|
+
----------
|
|
959
|
+
mesh :
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
Returns
|
|
963
|
+
-------
|
|
964
|
+
|
|
965
|
+
"""
|
|
966
|
+
geo = mesh.ActivePrimitive.Geometry
|
|
967
|
+
vertArray, faceArray = geo.Get2()
|
|
968
|
+
|
|
969
|
+
texProp = self._getTextureProp(mesh, self.texName)
|
|
970
|
+
uvSample = None
|
|
971
|
+
if texProp is not None:
|
|
972
|
+
uvs = texProp.Elements.Array
|
|
973
|
+
uvs = list(zip(*uvs))
|
|
974
|
+
uvD = {uv: i for i, uv in enumerate(set(uvs))}
|
|
975
|
+
uvIdxs = [uvD[uv] for uv in uvs]
|
|
976
|
+
uvs = [None] * len(uvD)
|
|
977
|
+
for uv, idx in six.iteritems(uvD):
|
|
978
|
+
uvs[idx] = uv
|
|
979
|
+
uvSample = mkUvSample(uvs, uvIdxs)
|
|
980
|
+
|
|
981
|
+
ptr = 0
|
|
982
|
+
faces = []
|
|
983
|
+
faceCounts = []
|
|
984
|
+
while ptr < len(faceArray):
|
|
985
|
+
count = faceArray[ptr]
|
|
986
|
+
faceCounts.append(count)
|
|
987
|
+
ptr += 1
|
|
988
|
+
indices = reversed(faceArray[ptr : ptr + count])
|
|
989
|
+
ptr += count
|
|
990
|
+
faces.extend(indices)
|
|
991
|
+
|
|
992
|
+
abcFaceIndices = IntArray(len(faces))
|
|
993
|
+
for i in range(len(faces)):
|
|
994
|
+
abcFaceIndices[i] = faces[i]
|
|
995
|
+
|
|
996
|
+
abcFaceCounts = IntArray(len(faceCounts))
|
|
997
|
+
for i in range(len(faceCounts)):
|
|
998
|
+
abcFaceCounts[i] = faceCounts[i]
|
|
999
|
+
|
|
1000
|
+
return abcFaceIndices, abcFaceCounts, uvSample
|
|
1001
|
+
|
|
1002
|
+
@classmethod
|
|
1003
|
+
def getMeshTopology(cls, mesh, uvName=None):
|
|
1004
|
+
"""Get the topology of a mesh
|
|
1005
|
+
|
|
1006
|
+
Parameters
|
|
1007
|
+
----------
|
|
1008
|
+
mesh : object
|
|
1009
|
+
The DCC Mesh to read
|
|
1010
|
+
uvName : str, optional
|
|
1011
|
+
The name of the uv set to read
|
|
1012
|
+
|
|
1013
|
+
Returns
|
|
1014
|
+
-------
|
|
1015
|
+
np.array :
|
|
1016
|
+
The vertex array
|
|
1017
|
+
np.array :
|
|
1018
|
+
The "faces" array
|
|
1019
|
+
np.array :
|
|
1020
|
+
The "counts" array
|
|
1021
|
+
np.array :
|
|
1022
|
+
The uv positions
|
|
1023
|
+
np.array :
|
|
1024
|
+
The "uvFaces" array
|
|
1025
|
+
"""
|
|
1026
|
+
geo = mesh.ActivePrimitive.Geometry
|
|
1027
|
+
vertArray, faceArray = geo.Get2()
|
|
1028
|
+
|
|
1029
|
+
verts = list(zip(*vertArray))
|
|
1030
|
+
texProp = cls._getTextureProp(mesh, uvName)
|
|
1031
|
+
uvs, uvIdxs = None, None
|
|
1032
|
+
if texProp is not None:
|
|
1033
|
+
uvs = texProp.Elements.Array
|
|
1034
|
+
uvs = list(zip(*uvs))
|
|
1035
|
+
uvD = {uv: i for i, uv in enumerate(set(uvs))}
|
|
1036
|
+
uvIdxs = [uvD[uv] for uv in uvs]
|
|
1037
|
+
uvs = [None] * len(uvD)
|
|
1038
|
+
for uv, idx in six.iteritems(uvD):
|
|
1039
|
+
uvs[idx] = uv
|
|
1040
|
+
|
|
1041
|
+
ptr = 0
|
|
1042
|
+
faces = []
|
|
1043
|
+
faceCounts = []
|
|
1044
|
+
while ptr < len(faceArray):
|
|
1045
|
+
count = faceArray[ptr]
|
|
1046
|
+
faceCounts.append(count)
|
|
1047
|
+
ptr += 1
|
|
1048
|
+
indices = reversed(faceArray[ptr : ptr + count])
|
|
1049
|
+
ptr += count
|
|
1050
|
+
faces.extend(indices)
|
|
1051
|
+
|
|
1052
|
+
return verts, faces, faceCounts, uvs, uvIdxs
|
|
1053
|
+
|
|
1054
|
+
def loadMeshTopology(self):
|
|
1055
|
+
""" """
|
|
1056
|
+
self._faces, self._counts, self._uvs = self._exportAbcFaces(self.mesh)
|
|
1057
|
+
|
|
1058
|
+
def exportAbc(
|
|
1059
|
+
self, dccMesh, abcMesh, js, world=False, ensureCorrect=False, pBar=None
|
|
1060
|
+
):
|
|
1061
|
+
""" """
|
|
1062
|
+
# dccMesh doesn't work in XSI, so just ignore it
|
|
1063
|
+
# export the data to alembic
|
|
1064
|
+
shapeDict = {i.name: i for i in self.simplex.shapes}
|
|
1065
|
+
if js["encodingVersion"] > 1:
|
|
1066
|
+
shapeNames = [i["name"] for i in js["shapes"]]
|
|
1067
|
+
else:
|
|
1068
|
+
shapeNames = js["shapes"]
|
|
1069
|
+
shapes = [shapeDict[i] for i in shapeNames]
|
|
1070
|
+
|
|
1071
|
+
faces, counts, uvSample = self._exportAbcFaces(dccMesh)
|
|
1072
|
+
schema = abcMesh.getSchema()
|
|
1073
|
+
|
|
1074
|
+
if pBar is not None:
|
|
1075
|
+
pBar.show()
|
|
1076
|
+
pBar.setMaximum(len(shapes))
|
|
1077
|
+
|
|
1078
|
+
# deactivate evaluation above modeling to insure no deformations are present
|
|
1079
|
+
dcc.xsi.DeactivateAbove("%s.modelingmarker" % dccMesh.ActivePrimitive, True)
|
|
1080
|
+
|
|
1081
|
+
for i, shape in enumerate(shapes):
|
|
1082
|
+
if pBar is not None:
|
|
1083
|
+
pBar.setLabelText("Exporting:\n{0}".format(shape.name))
|
|
1084
|
+
pBar.setValue(i)
|
|
1085
|
+
QApplication.processEvents()
|
|
1086
|
+
if pBar.wasCanceled():
|
|
1087
|
+
return
|
|
1088
|
+
verts = self._exportAbcVertices(dccMesh, shape, world)
|
|
1089
|
+
if uvSample is None:
|
|
1090
|
+
abcSample = OPolyMeshSchemaSample(verts, faces, counts)
|
|
1091
|
+
else:
|
|
1092
|
+
# I Can't just do iUVs=None. Alembic uses something different for its defaults
|
|
1093
|
+
abcSample = OPolyMeshSchemaSample(verts, faces, counts, iUVs=uvSample)
|
|
1094
|
+
schema.set(abcSample)
|
|
1095
|
+
|
|
1096
|
+
dcc.xsi.DeactivateAbove("%s.modelingmarker" % dccMesh.ActivePrimitive, "")
|
|
1097
|
+
|
|
1098
|
+
# Revision tracking
|
|
1099
|
+
def getRevision(self):
|
|
1100
|
+
""" """
|
|
1101
|
+
try:
|
|
1102
|
+
return self.op.inputPorts["Revision"].parameters["Revision"].value
|
|
1103
|
+
except AttributeError:
|
|
1104
|
+
return None # object does not exist
|
|
1105
|
+
|
|
1106
|
+
def incrementRevision(self):
|
|
1107
|
+
""" """
|
|
1108
|
+
value = self.getRevision()
|
|
1109
|
+
if value is None:
|
|
1110
|
+
return
|
|
1111
|
+
|
|
1112
|
+
dcc.xsi.SetValue("%s.Revision" % self.op.fullName, value + 1)
|
|
1113
|
+
d = self.simplex.buildDefinition()
|
|
1114
|
+
jsString = json.dumps(d)
|
|
1115
|
+
self.setSimplexString(self.op, jsString)
|
|
1116
|
+
return value + 1
|
|
1117
|
+
|
|
1118
|
+
def setRevision(self, val):
|
|
1119
|
+
"""
|
|
1120
|
+
|
|
1121
|
+
Parameters
|
|
1122
|
+
----------
|
|
1123
|
+
val :
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
Returns
|
|
1127
|
+
-------
|
|
1128
|
+
|
|
1129
|
+
"""
|
|
1130
|
+
dcc.xsi.SetValue("%s.Revision" % self.op.fullName, val)
|
|
1131
|
+
|
|
1132
|
+
# System level
|
|
1133
|
+
@undoable
|
|
1134
|
+
def renameSystem(self, name):
|
|
1135
|
+
"""
|
|
1136
|
+
|
|
1137
|
+
Parameters
|
|
1138
|
+
----------
|
|
1139
|
+
name :
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
Returns
|
|
1143
|
+
-------
|
|
1144
|
+
|
|
1145
|
+
"""
|
|
1146
|
+
self.name = name
|
|
1147
|
+
self.inProp.Name = "%s_inProperty" % name
|
|
1148
|
+
self.shapeTree._nativePointer.Name = "%s_IceTree" % name
|
|
1149
|
+
self.shapeCluster.Name = "%s_Shapes" % name
|
|
1150
|
+
|
|
1151
|
+
# rename data in the simplex vector setter and getter
|
|
1152
|
+
vectorSetter = list(self.op.outputPortList[0].connectedNodes.values())[0]
|
|
1153
|
+
vectorGetter = list(self.shapeNode.inputPortList[0].connectedNodes.values())[0]
|
|
1154
|
+
# pointSetter = self.shapeNode.outputPortList[0].connectedNodes.values()[0]
|
|
1155
|
+
for node in [vectorSetter, vectorGetter]:
|
|
1156
|
+
dcc.xsi.SetValue(
|
|
1157
|
+
"%s.Reference" % node.fullName, "self._%s_SimplexVector" % name
|
|
1158
|
+
)
|
|
1159
|
+
|
|
1160
|
+
# rename the shape nodes in the IceTree by recreating the shape node
|
|
1161
|
+
self.recreateShapeNode()
|
|
1162
|
+
|
|
1163
|
+
def recreateShapeNode(self):
|
|
1164
|
+
""" """
|
|
1165
|
+
# vectorSetter = self.op.outputPortList[0].connectedNodes.values()[0]
|
|
1166
|
+
vectorGetter = list(self.shapeNode.inputPortList[0].connectedNodes.values())[0]
|
|
1167
|
+
pointSetter = list(self.shapeNode.outputPortList[0].connectedNodes.values())[0]
|
|
1168
|
+
|
|
1169
|
+
self.shapeNode.delete()
|
|
1170
|
+
shapeCompound = self.rebuildShapeNode(self.simplex)
|
|
1171
|
+
pointSetter.Value.connect(shapeCompound.Result)
|
|
1172
|
+
vectorGetter.value.connect(shapeCompound.inputPorts["In"])
|
|
1173
|
+
|
|
1174
|
+
self.shapeNode = shapeCompound
|
|
1175
|
+
self._loadShapeIceNodes(self.simplex)
|
|
1176
|
+
|
|
1177
|
+
self.rebuildSliderNode()
|
|
1178
|
+
|
|
1179
|
+
def rebuildSliderNode(self):
|
|
1180
|
+
""" """
|
|
1181
|
+
if len(self.inProp.Parameters) == 0:
|
|
1182
|
+
print("No input sliders")
|
|
1183
|
+
return
|
|
1184
|
+
|
|
1185
|
+
if self.sliderNode:
|
|
1186
|
+
self.sliderNode.delete()
|
|
1187
|
+
|
|
1188
|
+
sliderNames = [slider.name for slider in self.simplex.sliders]
|
|
1189
|
+
# Possibly None
|
|
1190
|
+
xmlString = buildSliderIceXML(sliderNames, self.name)
|
|
1191
|
+
|
|
1192
|
+
fHandle, compoundPath = tempfile.mkstemp(".xsicompound", text=True)
|
|
1193
|
+
f = os.fdopen(fHandle, "w")
|
|
1194
|
+
f.write(xmlString)
|
|
1195
|
+
f.close()
|
|
1196
|
+
compound = dcc.ice.ICECompoundNode(
|
|
1197
|
+
dcc.xsi.AddICECompoundNode(compoundPath, self.shapeTree._nativePointer)
|
|
1198
|
+
)
|
|
1199
|
+
self.sliderNode = compound
|
|
1200
|
+
os.remove(compoundPath)
|
|
1201
|
+
|
|
1202
|
+
self.op.inputPorts["Sliders"].connect(compound.outputPorts["Array"])
|
|
1203
|
+
|
|
1204
|
+
# set the simplex string on simplex node
|
|
1205
|
+
self.setSimplexString(self.op, self.simplex.dump())
|
|
1206
|
+
|
|
1207
|
+
def resetShapeIndexes(self):
|
|
1208
|
+
""" """
|
|
1209
|
+
# set the simplex string on simplex node
|
|
1210
|
+
self.setSimplexString(self.op, self.simplex.dump())
|
|
1211
|
+
|
|
1212
|
+
# check the shape node for proper indexes
|
|
1213
|
+
for i, shape in enumerate(self.simplex.shapes):
|
|
1214
|
+
if shape.thing[2] is None:
|
|
1215
|
+
continue
|
|
1216
|
+
port = shape.thing[2].InputPorts("index")
|
|
1217
|
+
if port:
|
|
1218
|
+
if port.Value != i:
|
|
1219
|
+
dcc.xsi.SetValue("%s.index" % shape.thing[2], i)
|
|
1220
|
+
else:
|
|
1221
|
+
print("SHAPE HAS STRANGENESS", shape.name)
|
|
1222
|
+
raise RuntimeError("BAD")
|
|
1223
|
+
|
|
1224
|
+
# Shapes
|
|
1225
|
+
@undoable
|
|
1226
|
+
def createShape(
|
|
1227
|
+
self,
|
|
1228
|
+
shape,
|
|
1229
|
+
live=False,
|
|
1230
|
+
dataReferences=None,
|
|
1231
|
+
deleteCombiner=True,
|
|
1232
|
+
rebuild=False,
|
|
1233
|
+
freeze=True,
|
|
1234
|
+
):
|
|
1235
|
+
"""
|
|
1236
|
+
|
|
1237
|
+
Parameters
|
|
1238
|
+
----------
|
|
1239
|
+
shape :
|
|
1240
|
+
|
|
1241
|
+
live :
|
|
1242
|
+
(Default value = False)
|
|
1243
|
+
dataReferences :
|
|
1244
|
+
(Default value = None)
|
|
1245
|
+
deleteCombiner :
|
|
1246
|
+
(Default value = True)
|
|
1247
|
+
rebuild :
|
|
1248
|
+
(Default value = False)
|
|
1249
|
+
freeze :
|
|
1250
|
+
(Default value = True)
|
|
1251
|
+
|
|
1252
|
+
Returns
|
|
1253
|
+
-------
|
|
1254
|
+
|
|
1255
|
+
"""
|
|
1256
|
+
|
|
1257
|
+
ret, nn = self.createRawShape(
|
|
1258
|
+
shape.name,
|
|
1259
|
+
dataReferences=dataReferences,
|
|
1260
|
+
deleteCombiner=False,
|
|
1261
|
+
rebuild=rebuild,
|
|
1262
|
+
freeze=freeze,
|
|
1263
|
+
)
|
|
1264
|
+
|
|
1265
|
+
if deleteCombiner:
|
|
1266
|
+
self.deleteShapeCombiner()
|
|
1267
|
+
|
|
1268
|
+
if live:
|
|
1269
|
+
self.extractShape(shape, live=True, offset=10.0)
|
|
1270
|
+
|
|
1271
|
+
shape.name = nn
|
|
1272
|
+
return ret
|
|
1273
|
+
|
|
1274
|
+
def createRawShape(
|
|
1275
|
+
self,
|
|
1276
|
+
shapeName,
|
|
1277
|
+
dataReferences=None,
|
|
1278
|
+
elementArray=None,
|
|
1279
|
+
deleteCombiner=True,
|
|
1280
|
+
rebuild=True,
|
|
1281
|
+
freeze=True,
|
|
1282
|
+
):
|
|
1283
|
+
"""
|
|
1284
|
+
|
|
1285
|
+
Parameters
|
|
1286
|
+
----------
|
|
1287
|
+
shapeName :
|
|
1288
|
+
|
|
1289
|
+
dataReferences :
|
|
1290
|
+
(Default value = None)
|
|
1291
|
+
elementArray :
|
|
1292
|
+
(Default value = None)
|
|
1293
|
+
deleteCombiner :
|
|
1294
|
+
(Default value = True)
|
|
1295
|
+
rebuild :
|
|
1296
|
+
(Default value = True)
|
|
1297
|
+
freeze :
|
|
1298
|
+
(Default value = True)
|
|
1299
|
+
|
|
1300
|
+
Returns
|
|
1301
|
+
-------
|
|
1302
|
+
|
|
1303
|
+
"""
|
|
1304
|
+
|
|
1305
|
+
newShape = self.shapeCluster.Properties(shapeName)
|
|
1306
|
+
if newShape is None:
|
|
1307
|
+
newShape = dcc.xsi.StoreShapeKey(
|
|
1308
|
+
self.shapeCluster,
|
|
1309
|
+
shapeName,
|
|
1310
|
+
dcc.constants.siShapeObjectReferenceMode,
|
|
1311
|
+
1,
|
|
1312
|
+
0,
|
|
1313
|
+
0,
|
|
1314
|
+
dcc.constants.siShapeContentPrimaryShape,
|
|
1315
|
+
False,
|
|
1316
|
+
)
|
|
1317
|
+
# determine whether to do a inbetween shape or not based on the progression
|
|
1318
|
+
if elementArray:
|
|
1319
|
+
newShape.Elements.Array = elementArray
|
|
1320
|
+
else:
|
|
1321
|
+
dcc.shape.resetShapeKey(newShape)
|
|
1322
|
+
if freeze:
|
|
1323
|
+
dcc.xsi.FreezeObj(newShape)
|
|
1324
|
+
|
|
1325
|
+
# create the node structure in the ICETree if not there already
|
|
1326
|
+
shapeNodes = self.getShapeIceNodes(newShape, dataReferences)
|
|
1327
|
+
|
|
1328
|
+
if rebuild:
|
|
1329
|
+
self.resetShapeIndexes()
|
|
1330
|
+
|
|
1331
|
+
if deleteCombiner:
|
|
1332
|
+
self.deleteShapeCombiner()
|
|
1333
|
+
|
|
1334
|
+
return [newShape] + shapeNodes, newShape.Name
|
|
1335
|
+
|
|
1336
|
+
def getInbetweenArray(self, shapes):
|
|
1337
|
+
"""
|
|
1338
|
+
|
|
1339
|
+
Parameters
|
|
1340
|
+
----------
|
|
1341
|
+
shapes :
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
Returns
|
|
1345
|
+
-------
|
|
1346
|
+
|
|
1347
|
+
"""
|
|
1348
|
+
blendArray = [0] * 3 * self.mesh.ActivePrimitive.Geometry.Points.Count
|
|
1349
|
+
shapeArray = self.getSimplexEvaluation()
|
|
1350
|
+
if not shapeArray:
|
|
1351
|
+
return None
|
|
1352
|
+
shapeList = [shape.name for shape in self.simplex.shapes]
|
|
1353
|
+
|
|
1354
|
+
for shape in shapes:
|
|
1355
|
+
if not shape.thing:
|
|
1356
|
+
continue
|
|
1357
|
+
|
|
1358
|
+
if len(shapeArray[0]) == 1:
|
|
1359
|
+
continue
|
|
1360
|
+
idx = shapeList.index(shape.name)
|
|
1361
|
+
shapeBlend = shapeArray[0][idx]
|
|
1362
|
+
shapeTuple = shape.thing[0].Elements.Array
|
|
1363
|
+
|
|
1364
|
+
for i in range(len(shapeTuple[0])):
|
|
1365
|
+
blendArray[i * 3 + 0] += shapeTuple[0][i] * shapeBlend
|
|
1366
|
+
blendArray[i * 3 + 1] += shapeTuple[1][i] * shapeBlend
|
|
1367
|
+
blendArray[i * 3 + 2] += shapeTuple[2][i] * shapeBlend
|
|
1368
|
+
|
|
1369
|
+
return blendArray
|
|
1370
|
+
|
|
1371
|
+
@undoable
|
|
1372
|
+
def getShapeIceNodes(self, shapeKey, dataReferences):
|
|
1373
|
+
"""build/return the ICE nodes related to the given shapeKey
|
|
1374
|
+
|
|
1375
|
+
Parameters
|
|
1376
|
+
----------
|
|
1377
|
+
shapeKey :
|
|
1378
|
+
|
|
1379
|
+
dataReferences :
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
Returns
|
|
1383
|
+
-------
|
|
1384
|
+
|
|
1385
|
+
"""
|
|
1386
|
+
simpNode = self.shapeNode
|
|
1387
|
+
if not dataReferences:
|
|
1388
|
+
dataReferences = DCC.getDataReferences(simpNode)
|
|
1389
|
+
ports = simpNode.exposedPorts
|
|
1390
|
+
if ports[0][0].isOutput():
|
|
1391
|
+
addNode = ports[0][0].parent
|
|
1392
|
+
passNode = ports[1][0].parent
|
|
1393
|
+
else:
|
|
1394
|
+
addNode = ports[1][0].parent
|
|
1395
|
+
passNode = ports[0][0].parent
|
|
1396
|
+
|
|
1397
|
+
shapeRef = "%s.positions" % shapeKey.FullName.replace(
|
|
1398
|
+
"%s.polymsh" % self.mesh.FullName, "self"
|
|
1399
|
+
)
|
|
1400
|
+
if shapeRef in list(dataReferences.keys()):
|
|
1401
|
+
shapeNode = dataReferences[shapeRef]
|
|
1402
|
+
else:
|
|
1403
|
+
shapeNode = simpNode.addGetDataNode(shapeRef)
|
|
1404
|
+
|
|
1405
|
+
multNode = shapeNode.outputPorts["value"].connectedNodes
|
|
1406
|
+
if "Multiply by Scalar" in list(multNode.keys()):
|
|
1407
|
+
multNode = multNode["Multiply by Scalar"]
|
|
1408
|
+
else:
|
|
1409
|
+
multNode = simpNode.addNode("MultiplyByScalar")
|
|
1410
|
+
|
|
1411
|
+
if multNode.name not in list(
|
|
1412
|
+
shapeNode.outputPorts["value"].connectedNodes.keys()
|
|
1413
|
+
):
|
|
1414
|
+
shapeNode.outputPorts["value"].connect(multNode.inputPorts["value"])
|
|
1415
|
+
|
|
1416
|
+
if addNode not in list(multNode.outputPorts["result"].connectedNodes.values()):
|
|
1417
|
+
addPort = DCC.firstAvailablePort(addNode)
|
|
1418
|
+
multNode.outputPorts["result"].connect(addPort)
|
|
1419
|
+
|
|
1420
|
+
indexNode = multNode.inputPorts["factor"].connectedNodes
|
|
1421
|
+
if "Select in Array" in list(indexNode.keys()):
|
|
1422
|
+
indexNode = indexNode["Select in Array"]
|
|
1423
|
+
else:
|
|
1424
|
+
indexNode = simpNode.addNode("SelectInArray")
|
|
1425
|
+
indexNode.value.connect(multNode.inputPorts["factor"])
|
|
1426
|
+
indexNode.inputPorts["array"].connect(passNode.outputPorts["out"])
|
|
1427
|
+
|
|
1428
|
+
return [
|
|
1429
|
+
shapeNode._nativePointer,
|
|
1430
|
+
indexNode._nativePointer,
|
|
1431
|
+
multNode._nativePointer,
|
|
1432
|
+
]
|
|
1433
|
+
|
|
1434
|
+
def checkShapeValidity(self, shape, dataReferences=None):
|
|
1435
|
+
"""
|
|
1436
|
+
|
|
1437
|
+
Parameters
|
|
1438
|
+
----------
|
|
1439
|
+
shape :
|
|
1440
|
+
|
|
1441
|
+
dataReferences :
|
|
1442
|
+
(Default value = None)
|
|
1443
|
+
|
|
1444
|
+
Returns
|
|
1445
|
+
-------
|
|
1446
|
+
|
|
1447
|
+
"""
|
|
1448
|
+
s = self.shapeCluster.Properties(shape.name)
|
|
1449
|
+
if not s:
|
|
1450
|
+
return False
|
|
1451
|
+
|
|
1452
|
+
simpNode = self.shapeNode
|
|
1453
|
+
if not dataReferences:
|
|
1454
|
+
dataReferences = DCC.getDataReferences(simpNode)
|
|
1455
|
+
shapeRef = "%s.positions" % s.FullName.replace(
|
|
1456
|
+
"%s.polymsh" % self.mesh.FullName, "self"
|
|
1457
|
+
)
|
|
1458
|
+
if shapeRef not in list(dataReferences.keys()):
|
|
1459
|
+
return False
|
|
1460
|
+
return True
|
|
1461
|
+
|
|
1462
|
+
def rebuildShapeNode(self, simp, shapeNames=None):
|
|
1463
|
+
"""
|
|
1464
|
+
|
|
1465
|
+
Parameters
|
|
1466
|
+
----------
|
|
1467
|
+
simp :
|
|
1468
|
+
|
|
1469
|
+
shapeNames :
|
|
1470
|
+
(Default value = None)
|
|
1471
|
+
|
|
1472
|
+
Returns
|
|
1473
|
+
-------
|
|
1474
|
+
|
|
1475
|
+
"""
|
|
1476
|
+
if shapeNames is None:
|
|
1477
|
+
shapeNames = [shape.name for shape in simp.shapes]
|
|
1478
|
+
xmlString = buildIceXML(
|
|
1479
|
+
shapeNames, self.name, self.shapeCluster.Name, self.shapeNamePrefix
|
|
1480
|
+
)
|
|
1481
|
+
|
|
1482
|
+
fHandle, compoundPath = tempfile.mkstemp(".xsicompound", text=True)
|
|
1483
|
+
f = os.fdopen(fHandle, "w")
|
|
1484
|
+
f.write(xmlString)
|
|
1485
|
+
f.close()
|
|
1486
|
+
|
|
1487
|
+
node = dcc.xsi.AddICECompoundNode(compoundPath, self.shapeTree._nativePointer)
|
|
1488
|
+
shapeCompound = dcc.ice.ICECompoundNode(node)
|
|
1489
|
+
os.remove(compoundPath)
|
|
1490
|
+
|
|
1491
|
+
return shapeCompound
|
|
1492
|
+
|
|
1493
|
+
@staticmethod
|
|
1494
|
+
def firstAvailablePort(node):
|
|
1495
|
+
"""
|
|
1496
|
+
|
|
1497
|
+
Parameters
|
|
1498
|
+
----------
|
|
1499
|
+
node :
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
Returns
|
|
1503
|
+
-------
|
|
1504
|
+
|
|
1505
|
+
"""
|
|
1506
|
+
openPorts = [port for port in node.inputPortList if not port.isConnected()]
|
|
1507
|
+
if not openPorts:
|
|
1508
|
+
return node.addPortAtEnd(node.portAtEnd().name)
|
|
1509
|
+
else:
|
|
1510
|
+
return openPorts[0]
|
|
1511
|
+
|
|
1512
|
+
@undoable
|
|
1513
|
+
def extractShape(self, shape, live=True, offset=10.0):
|
|
1514
|
+
"""make a mesh representing a shape. Can be live or not
|
|
1515
|
+
|
|
1516
|
+
Parameters
|
|
1517
|
+
----------
|
|
1518
|
+
shape :
|
|
1519
|
+
|
|
1520
|
+
live :
|
|
1521
|
+
(Default value = True)
|
|
1522
|
+
offset :
|
|
1523
|
+
(Default value = 10.0)
|
|
1524
|
+
|
|
1525
|
+
Returns
|
|
1526
|
+
-------
|
|
1527
|
+
|
|
1528
|
+
"""
|
|
1529
|
+
shapeKey = shape.thing[0]
|
|
1530
|
+
print("Extracting %s" % shapeKey.Name)
|
|
1531
|
+
shapeGeo = self.extractShapeAsGeo(shapeKey)
|
|
1532
|
+
shapeGeo.posx.Value = offset
|
|
1533
|
+
if live:
|
|
1534
|
+
self.connectShape(shape, shapeGeo, live, delete=False)
|
|
1535
|
+
return shapeGeo
|
|
1536
|
+
|
|
1537
|
+
@undoable
|
|
1538
|
+
def connectShape(
|
|
1539
|
+
self, shape, mesh=None, live=False, delete=False, deleteCombiner=True
|
|
1540
|
+
):
|
|
1541
|
+
"""Force a shape to match a mesh
|
|
1542
|
+
The "connect shape" button is:
|
|
1543
|
+
mesh=None, delete=True
|
|
1544
|
+
The "match shape" button is:
|
|
1545
|
+
mesh=someMesh, delete=False
|
|
1546
|
+
There is a possibility of a "make live" button:
|
|
1547
|
+
live=True, delete=False
|
|
1548
|
+
|
|
1549
|
+
Parameters
|
|
1550
|
+
----------
|
|
1551
|
+
shape :
|
|
1552
|
+
|
|
1553
|
+
mesh :
|
|
1554
|
+
(Default value = None)
|
|
1555
|
+
live :
|
|
1556
|
+
(Default value = False)
|
|
1557
|
+
delete :
|
|
1558
|
+
(Default value = False)
|
|
1559
|
+
deleteCombiner :
|
|
1560
|
+
(Default value = True)
|
|
1561
|
+
|
|
1562
|
+
Returns
|
|
1563
|
+
-------
|
|
1564
|
+
|
|
1565
|
+
"""
|
|
1566
|
+
# print("Connected {0}".format(shape.name))
|
|
1567
|
+
|
|
1568
|
+
if not mesh:
|
|
1569
|
+
mesh = DCC.findExtractedShape(shape.name)
|
|
1570
|
+
if not mesh:
|
|
1571
|
+
print("No extracted shape found to connect for %s" % shape.name)
|
|
1572
|
+
return
|
|
1573
|
+
|
|
1574
|
+
# print("Connected {0}".format(shape.name))
|
|
1575
|
+
|
|
1576
|
+
tempShape = dcc.xsi.SelectShapeKey(
|
|
1577
|
+
self.shapeCluster,
|
|
1578
|
+
mesh,
|
|
1579
|
+
dcc.constants.siShapeObjectReferenceMode,
|
|
1580
|
+
live,
|
|
1581
|
+
False,
|
|
1582
|
+
)[0]
|
|
1583
|
+
dcc.xsi.DeleteObj(shape.thing[0])
|
|
1584
|
+
tempShape.Name = shape.name
|
|
1585
|
+
shape.thing[0] = tempShape
|
|
1586
|
+
|
|
1587
|
+
# print("Connected {0}".format(tempShape.Name))
|
|
1588
|
+
|
|
1589
|
+
if not live:
|
|
1590
|
+
dcc.xsi.FreezeObj(tempShape)
|
|
1591
|
+
if delete:
|
|
1592
|
+
dcc.xsi.DeleteObj(mesh)
|
|
1593
|
+
if deleteCombiner:
|
|
1594
|
+
self.deleteShapeCombiner()
|
|
1595
|
+
|
|
1596
|
+
# print("Connected {0}".format(tempShape.Name))
|
|
1597
|
+
|
|
1598
|
+
@staticmethod
|
|
1599
|
+
def findExtractedShape(shape):
|
|
1600
|
+
"""
|
|
1601
|
+
|
|
1602
|
+
Parameters
|
|
1603
|
+
----------
|
|
1604
|
+
shape :
|
|
1605
|
+
|
|
1606
|
+
|
|
1607
|
+
Returns
|
|
1608
|
+
-------
|
|
1609
|
+
|
|
1610
|
+
"""
|
|
1611
|
+
testName = "%s_Extract" % shape
|
|
1612
|
+
testObj = dcc.xsi.ActiveSceneRoot.FindChild(testName)
|
|
1613
|
+
|
|
1614
|
+
return testObj
|
|
1615
|
+
|
|
1616
|
+
@undoable
|
|
1617
|
+
def extractPosedShape(self, shape):
|
|
1618
|
+
"""
|
|
1619
|
+
|
|
1620
|
+
Parameters
|
|
1621
|
+
----------
|
|
1622
|
+
shape :
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
Returns
|
|
1626
|
+
-------
|
|
1627
|
+
|
|
1628
|
+
"""
|
|
1629
|
+
pass
|
|
1630
|
+
|
|
1631
|
+
@undoable
|
|
1632
|
+
def zeroShape(self, shape):
|
|
1633
|
+
"""Set the shape to be completely zeroed
|
|
1634
|
+
|
|
1635
|
+
Parameters
|
|
1636
|
+
----------
|
|
1637
|
+
shape :
|
|
1638
|
+
|
|
1639
|
+
|
|
1640
|
+
Returns
|
|
1641
|
+
-------
|
|
1642
|
+
|
|
1643
|
+
"""
|
|
1644
|
+
shapeKey = shape.thing[0]
|
|
1645
|
+
dcc.shape.resetShapeKey(shapeKey)
|
|
1646
|
+
dcc.xsi.FreezeObj(shapeKey)
|
|
1647
|
+
|
|
1648
|
+
print("Shape %s has been reset" % shape.name)
|
|
1649
|
+
|
|
1650
|
+
@undoable
|
|
1651
|
+
def deleteShape(self, toDelShape):
|
|
1652
|
+
"""Remove a shape from the system
|
|
1653
|
+
|
|
1654
|
+
Parameters
|
|
1655
|
+
----------
|
|
1656
|
+
toDelShape :
|
|
1657
|
+
|
|
1658
|
+
|
|
1659
|
+
Returns
|
|
1660
|
+
-------
|
|
1661
|
+
|
|
1662
|
+
"""
|
|
1663
|
+
dcc.xsi.DeleteObj(toDelShape.thing)
|
|
1664
|
+
|
|
1665
|
+
# rebuild the operator
|
|
1666
|
+
self.resetShapeIndexes()
|
|
1667
|
+
|
|
1668
|
+
@undoable
|
|
1669
|
+
def renameShape(self, shape, name):
|
|
1670
|
+
"""Change the name of the shape
|
|
1671
|
+
|
|
1672
|
+
Parameters
|
|
1673
|
+
----------
|
|
1674
|
+
shape :
|
|
1675
|
+
|
|
1676
|
+
name :
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
Returns
|
|
1680
|
+
-------
|
|
1681
|
+
|
|
1682
|
+
"""
|
|
1683
|
+
shape.thing[0].Name = name
|
|
1684
|
+
name = shape.thing[0].Name
|
|
1685
|
+
|
|
1686
|
+
shapeNodeList = shape.thing[1].Reference.Value.split(".")
|
|
1687
|
+
shapeNodeList[-2] = name
|
|
1688
|
+
shape.thing[1].Reference.Value = ".".join(shapeNodeList)
|
|
1689
|
+
|
|
1690
|
+
self.resetShapeIndexes()
|
|
1691
|
+
|
|
1692
|
+
@undoable
|
|
1693
|
+
def convertShapeToCorrective(self, shape):
|
|
1694
|
+
"""
|
|
1695
|
+
|
|
1696
|
+
Parameters
|
|
1697
|
+
----------
|
|
1698
|
+
shape :
|
|
1699
|
+
|
|
1700
|
+
|
|
1701
|
+
Returns
|
|
1702
|
+
-------
|
|
1703
|
+
|
|
1704
|
+
"""
|
|
1705
|
+
pass
|
|
1706
|
+
|
|
1707
|
+
def deleteShapeCombiner(self):
|
|
1708
|
+
""" """
|
|
1709
|
+
clsCombiner = dcc.operator.getOperatorFromStack(
|
|
1710
|
+
self.mesh, "clustershapecombiner"
|
|
1711
|
+
)
|
|
1712
|
+
if clsCombiner:
|
|
1713
|
+
dcc.xsi.DeleteObj(clsCombiner)
|
|
1714
|
+
|
|
1715
|
+
def freezeAllShapes(self):
|
|
1716
|
+
""" """
|
|
1717
|
+
toFreeze = [
|
|
1718
|
+
shape.thing[0]
|
|
1719
|
+
for shape in self.simplex.shapes
|
|
1720
|
+
if len(shape.thing[0].NestedObjects) > 2
|
|
1721
|
+
]
|
|
1722
|
+
dcc.xsi.FreezeObj(toFreeze)
|
|
1723
|
+
|
|
1724
|
+
# Falloffs
|
|
1725
|
+
def createFalloff(self, falloff):
|
|
1726
|
+
"""
|
|
1727
|
+
|
|
1728
|
+
Parameters
|
|
1729
|
+
----------
|
|
1730
|
+
falloff :
|
|
1731
|
+
|
|
1732
|
+
|
|
1733
|
+
Returns
|
|
1734
|
+
-------
|
|
1735
|
+
|
|
1736
|
+
"""
|
|
1737
|
+
pass # for eventual live splits
|
|
1738
|
+
|
|
1739
|
+
def duplicateFalloff(self, falloff, newFalloff, newName):
|
|
1740
|
+
"""
|
|
1741
|
+
|
|
1742
|
+
Parameters
|
|
1743
|
+
----------
|
|
1744
|
+
falloff :
|
|
1745
|
+
|
|
1746
|
+
newFalloff :
|
|
1747
|
+
|
|
1748
|
+
newName :
|
|
1749
|
+
|
|
1750
|
+
|
|
1751
|
+
Returns
|
|
1752
|
+
-------
|
|
1753
|
+
|
|
1754
|
+
"""
|
|
1755
|
+
pass # for eventual live splits
|
|
1756
|
+
|
|
1757
|
+
def deleteFalloff(self, falloff):
|
|
1758
|
+
"""
|
|
1759
|
+
|
|
1760
|
+
Parameters
|
|
1761
|
+
----------
|
|
1762
|
+
falloff :
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
Returns
|
|
1766
|
+
-------
|
|
1767
|
+
|
|
1768
|
+
"""
|
|
1769
|
+
pass # for eventual live splits
|
|
1770
|
+
|
|
1771
|
+
def setFalloffData(
|
|
1772
|
+
self, falloff, splitType, axis, minVal, minHandle, maxHandle, maxVal, mapName
|
|
1773
|
+
):
|
|
1774
|
+
"""
|
|
1775
|
+
|
|
1776
|
+
Parameters
|
|
1777
|
+
----------
|
|
1778
|
+
falloff :
|
|
1779
|
+
|
|
1780
|
+
splitType :
|
|
1781
|
+
|
|
1782
|
+
axis :
|
|
1783
|
+
|
|
1784
|
+
minVal :
|
|
1785
|
+
|
|
1786
|
+
minHandle :
|
|
1787
|
+
|
|
1788
|
+
maxHandle :
|
|
1789
|
+
|
|
1790
|
+
maxVal :
|
|
1791
|
+
|
|
1792
|
+
mapName :
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
Returns
|
|
1796
|
+
-------
|
|
1797
|
+
|
|
1798
|
+
"""
|
|
1799
|
+
pass # for eventual live splits
|
|
1800
|
+
|
|
1801
|
+
def getFalloffThing(self, falloff):
|
|
1802
|
+
"""
|
|
1803
|
+
|
|
1804
|
+
Parameters
|
|
1805
|
+
----------
|
|
1806
|
+
falloff :
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
Returns
|
|
1810
|
+
-------
|
|
1811
|
+
|
|
1812
|
+
"""
|
|
1813
|
+
return falloff.name
|
|
1814
|
+
|
|
1815
|
+
# Sliders
|
|
1816
|
+
@undoable
|
|
1817
|
+
def createSlider(self, slider, rebuildOp=True):
|
|
1818
|
+
"""Create a new slider with a name
|
|
1819
|
+
|
|
1820
|
+
Parameters
|
|
1821
|
+
----------
|
|
1822
|
+
slider :
|
|
1823
|
+
|
|
1824
|
+
rebuildOp :
|
|
1825
|
+
(Default value = True)
|
|
1826
|
+
|
|
1827
|
+
Returns
|
|
1828
|
+
-------
|
|
1829
|
+
|
|
1830
|
+
"""
|
|
1831
|
+
name = slider.name
|
|
1832
|
+
param = self.createSliderParam(slider, name)
|
|
1833
|
+
|
|
1834
|
+
# connect solver
|
|
1835
|
+
if rebuildOp:
|
|
1836
|
+
self.rebuildSliderNode()
|
|
1837
|
+
self.resetShapeIndexes()
|
|
1838
|
+
self.deleteShapeCombiner()
|
|
1839
|
+
return param
|
|
1840
|
+
|
|
1841
|
+
@undoable
|
|
1842
|
+
def renameSlider(self, slider, name):
|
|
1843
|
+
"""Set the name of a slider
|
|
1844
|
+
|
|
1845
|
+
Parameters
|
|
1846
|
+
----------
|
|
1847
|
+
slider :
|
|
1848
|
+
|
|
1849
|
+
name :
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
Returns
|
|
1853
|
+
-------
|
|
1854
|
+
|
|
1855
|
+
"""
|
|
1856
|
+
param = self.createSliderParam(slider, name)
|
|
1857
|
+
if slider.thing.IsAnimated(dcc.constants.siAnySource):
|
|
1858
|
+
dcc.xsi.CopyAnimation(slider.thing, True, True, False, True, True)
|
|
1859
|
+
dcc.xsi.PasteAnimation(param, 1)
|
|
1860
|
+
|
|
1861
|
+
dcc.xsi.RemoveCustomParam(slider.thing)
|
|
1862
|
+
slider.thing = param
|
|
1863
|
+
|
|
1864
|
+
self.rebuildSliderNode()
|
|
1865
|
+
self.resetShapeIndexes()
|
|
1866
|
+
|
|
1867
|
+
@undoable
|
|
1868
|
+
def setSliderRange(self, slider):
|
|
1869
|
+
"""
|
|
1870
|
+
|
|
1871
|
+
Parameters
|
|
1872
|
+
----------
|
|
1873
|
+
slider :
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
Returns
|
|
1877
|
+
-------
|
|
1878
|
+
|
|
1879
|
+
"""
|
|
1880
|
+
vals = [v.value for v in slider.prog.pairs]
|
|
1881
|
+
dcc.xsi.EditParameterDefinition(
|
|
1882
|
+
slider.thing,
|
|
1883
|
+
"",
|
|
1884
|
+
"",
|
|
1885
|
+
-2.0,
|
|
1886
|
+
2.0,
|
|
1887
|
+
min(vals) * self.sliderMul,
|
|
1888
|
+
max(vals) * self.sliderMul,
|
|
1889
|
+
)
|
|
1890
|
+
|
|
1891
|
+
@undoable
|
|
1892
|
+
def renameCombo(self, combo, name):
|
|
1893
|
+
"""
|
|
1894
|
+
|
|
1895
|
+
Parameters
|
|
1896
|
+
----------
|
|
1897
|
+
combo :
|
|
1898
|
+
|
|
1899
|
+
name :
|
|
1900
|
+
|
|
1901
|
+
|
|
1902
|
+
Returns
|
|
1903
|
+
-------
|
|
1904
|
+
|
|
1905
|
+
"""
|
|
1906
|
+
pass
|
|
1907
|
+
|
|
1908
|
+
@undoable
|
|
1909
|
+
def deleteSlider(self, toDelSlider):
|
|
1910
|
+
"""Remove a slider
|
|
1911
|
+
|
|
1912
|
+
Parameters
|
|
1913
|
+
----------
|
|
1914
|
+
toDelSlider :
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
Returns
|
|
1918
|
+
-------
|
|
1919
|
+
|
|
1920
|
+
"""
|
|
1921
|
+
dcc.xsi.RemoveCustomParam(toDelSlider.thing)
|
|
1922
|
+
self.rebuildSliderNode()
|
|
1923
|
+
self.resetShapeIndexes()
|
|
1924
|
+
|
|
1925
|
+
def createSliderParam(self, slider, name):
|
|
1926
|
+
"""
|
|
1927
|
+
|
|
1928
|
+
Parameters
|
|
1929
|
+
----------
|
|
1930
|
+
slider :
|
|
1931
|
+
|
|
1932
|
+
name :
|
|
1933
|
+
|
|
1934
|
+
|
|
1935
|
+
Returns
|
|
1936
|
+
-------
|
|
1937
|
+
|
|
1938
|
+
"""
|
|
1939
|
+
vals = [v.value for v in slider.prog.pairs]
|
|
1940
|
+
param = self.inProp.AddParameter3(name, dcc.constants.siFloat, 0, -2.0, 2.0)
|
|
1941
|
+
dcc.xsi.EditParameterDefinition(
|
|
1942
|
+
param,
|
|
1943
|
+
"",
|
|
1944
|
+
"",
|
|
1945
|
+
-2.0,
|
|
1946
|
+
2.0,
|
|
1947
|
+
min(vals) * self.sliderMul,
|
|
1948
|
+
max(vals) * self.sliderMul,
|
|
1949
|
+
)
|
|
1950
|
+
return param
|
|
1951
|
+
|
|
1952
|
+
@undoable
|
|
1953
|
+
def addProgFalloff(self, prog, falloff):
|
|
1954
|
+
"""
|
|
1955
|
+
|
|
1956
|
+
Parameters
|
|
1957
|
+
----------
|
|
1958
|
+
prog :
|
|
1959
|
+
|
|
1960
|
+
falloff :
|
|
1961
|
+
|
|
1962
|
+
|
|
1963
|
+
Returns
|
|
1964
|
+
-------
|
|
1965
|
+
|
|
1966
|
+
"""
|
|
1967
|
+
pass # for eventual live splits
|
|
1968
|
+
|
|
1969
|
+
@undoable
|
|
1970
|
+
def removeProgFalloff(self, prog, falloff):
|
|
1971
|
+
"""
|
|
1972
|
+
|
|
1973
|
+
Parameters
|
|
1974
|
+
----------
|
|
1975
|
+
prog :
|
|
1976
|
+
|
|
1977
|
+
falloff :
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
Returns
|
|
1981
|
+
-------
|
|
1982
|
+
|
|
1983
|
+
"""
|
|
1984
|
+
pass # for eventual live splits
|
|
1985
|
+
|
|
1986
|
+
@undoable
|
|
1987
|
+
def setSlidersWeights(self, sliders, weights):
|
|
1988
|
+
"""Set the weight of a slider. This does not change the definition
|
|
1989
|
+
|
|
1990
|
+
Parameters
|
|
1991
|
+
----------
|
|
1992
|
+
sliders :
|
|
1993
|
+
|
|
1994
|
+
weights :
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
Returns
|
|
1998
|
+
-------
|
|
1999
|
+
|
|
2000
|
+
"""
|
|
2001
|
+
for slider, weight in zip(sliders, weights):
|
|
2002
|
+
slider.thing.Value = weight
|
|
2003
|
+
|
|
2004
|
+
@undoable
|
|
2005
|
+
def setSliderWeight(self, slider, weight):
|
|
2006
|
+
"""
|
|
2007
|
+
|
|
2008
|
+
Parameters
|
|
2009
|
+
----------
|
|
2010
|
+
slider :
|
|
2011
|
+
|
|
2012
|
+
weight :
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
Returns
|
|
2016
|
+
-------
|
|
2017
|
+
|
|
2018
|
+
"""
|
|
2019
|
+
slider.thing.Value = weight
|
|
2020
|
+
|
|
2021
|
+
@undoable
|
|
2022
|
+
def updateSlidersRange(self, sliders):
|
|
2023
|
+
"""
|
|
2024
|
+
|
|
2025
|
+
Parameters
|
|
2026
|
+
----------
|
|
2027
|
+
sliders :
|
|
2028
|
+
|
|
2029
|
+
|
|
2030
|
+
Returns
|
|
2031
|
+
-------
|
|
2032
|
+
|
|
2033
|
+
"""
|
|
2034
|
+
for slider in sliders:
|
|
2035
|
+
vals = [v.value for v in slider.prog.pairs]
|
|
2036
|
+
dcc.xsi.EditParameterDefinition(
|
|
2037
|
+
slider.thing,
|
|
2038
|
+
"",
|
|
2039
|
+
"",
|
|
2040
|
+
-2.0,
|
|
2041
|
+
2.0,
|
|
2042
|
+
min(vals) * self.sliderMul,
|
|
2043
|
+
max(vals) * self.sliderMul,
|
|
2044
|
+
)
|
|
2045
|
+
|
|
2046
|
+
# Combos
|
|
2047
|
+
def _createDelta(self, combo, target, tVal):
|
|
2048
|
+
"""Part of the combo extraction process.
|
|
2049
|
+
Combo shapes are fixit shapes added on top of any sliders.
|
|
2050
|
+
This means that the actual combo-shape by itself will not look good by itself,
|
|
2051
|
+
and that's bad for artist interaction.
|
|
2052
|
+
So we must create a setup to take the final sculpted shape, and subtract
|
|
2053
|
+
the any direct slider deformations to get the actual "combo shape" as a delta
|
|
2054
|
+
It is this delta shape that is then plugged into the system
|
|
2055
|
+
|
|
2056
|
+
Parameters
|
|
2057
|
+
----------
|
|
2058
|
+
combo :
|
|
2059
|
+
|
|
2060
|
+
target :
|
|
2061
|
+
|
|
2062
|
+
tVal :
|
|
2063
|
+
|
|
2064
|
+
|
|
2065
|
+
Returns
|
|
2066
|
+
-------
|
|
2067
|
+
|
|
2068
|
+
"""
|
|
2069
|
+
|
|
2070
|
+
# check if delta object already exists
|
|
2071
|
+
deltaName = "%s_Delta" % combo.name
|
|
2072
|
+
deltaObj = dcc.xsi.ActiveSceneRoot.FindChild(deltaName)
|
|
2073
|
+
if deltaObj:
|
|
2074
|
+
return deltaObj
|
|
2075
|
+
|
|
2076
|
+
# create and extract a temporary shape to use as a reference
|
|
2077
|
+
# of everything but the actual combo shape
|
|
2078
|
+
tempShape = dcc.xsi.StoreShapeKey(
|
|
2079
|
+
self.shapeCluster,
|
|
2080
|
+
"temp",
|
|
2081
|
+
dcc.constants.siShapeObjectReferenceMode,
|
|
2082
|
+
1,
|
|
2083
|
+
0,
|
|
2084
|
+
0,
|
|
2085
|
+
dcc.constants.siShapeContentPrimaryShape,
|
|
2086
|
+
False,
|
|
2087
|
+
)
|
|
2088
|
+
affected = self.getComboAffected(combo)
|
|
2089
|
+
|
|
2090
|
+
with disconnected(affected[0], self.inProp):
|
|
2091
|
+
# set sliders for the combo
|
|
2092
|
+
for pair in combo.pairs:
|
|
2093
|
+
pair.slider.thing.Value = pair.value * tVal
|
|
2094
|
+
|
|
2095
|
+
tempShape.Elements.Array = self.getInbetweenArray(affected[1])
|
|
2096
|
+
|
|
2097
|
+
# build delta object
|
|
2098
|
+
deltaObj = self.extractShapeAsGeo(tempShape)
|
|
2099
|
+
deltaObj.Name = deltaName
|
|
2100
|
+
deltaObj.Properties("visibility").Parameters("viewvis").Value = False
|
|
2101
|
+
deltaObj.posx.Value = 10.0
|
|
2102
|
+
deltaObj.posz.Value = -10.0
|
|
2103
|
+
|
|
2104
|
+
# apply shape of target to delta object
|
|
2105
|
+
dcc.xsi.SelectShapeKey(
|
|
2106
|
+
deltaObj, target, dcc.constants.siShapeObjectReferenceMode, True, True
|
|
2107
|
+
)[0]
|
|
2108
|
+
|
|
2109
|
+
# get undeformed shape to apply to get delta, and apply as a shape to delta
|
|
2110
|
+
tempBase = self.extractShapeAsGeo(self.simplex.restShape.thing[0])
|
|
2111
|
+
|
|
2112
|
+
dcc.xsi.SelectShapeKey(
|
|
2113
|
+
deltaObj, tempBase, dcc.constants.siShapeObjectReferenceMode, False, True
|
|
2114
|
+
)[0]
|
|
2115
|
+
|
|
2116
|
+
for param in deltaObj.Properties("ShapeWeights").Parameters:
|
|
2117
|
+
dcc.xsi.RemoveAnimation(param)
|
|
2118
|
+
param.Value = 1
|
|
2119
|
+
|
|
2120
|
+
dcc.xsi.DeleteObj(tempBase)
|
|
2121
|
+
dcc.xsi.DeleteObj(tempShape)
|
|
2122
|
+
|
|
2123
|
+
return deltaObj
|
|
2124
|
+
|
|
2125
|
+
def getComboAffected(self, combo):
|
|
2126
|
+
"""
|
|
2127
|
+
|
|
2128
|
+
Parameters
|
|
2129
|
+
----------
|
|
2130
|
+
combo :
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
Returns
|
|
2134
|
+
-------
|
|
2135
|
+
type
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
"""
|
|
2139
|
+
# Get all related sliders to the combo
|
|
2140
|
+
comboSliders = [i.slider for i in combo.pairs]
|
|
2141
|
+
comboSlidersSet = set(comboSliders)
|
|
2142
|
+
|
|
2143
|
+
# get list of combo shapes that have an impact on the current combo
|
|
2144
|
+
affected = []
|
|
2145
|
+
for slider in comboSliders:
|
|
2146
|
+
for pair in slider.prog.pairs:
|
|
2147
|
+
if pair.shape not in affected:
|
|
2148
|
+
affected.append(pair.shape)
|
|
2149
|
+
for c in self.simplex.combos:
|
|
2150
|
+
if c == combo:
|
|
2151
|
+
continue
|
|
2152
|
+
cSliders = set(i.slider for i in c.pairs)
|
|
2153
|
+
if cSliders <= comboSlidersSet:
|
|
2154
|
+
for pair in c.prog.pairs:
|
|
2155
|
+
affected.append(pair.shape)
|
|
2156
|
+
|
|
2157
|
+
return [comboSliders, affected]
|
|
2158
|
+
|
|
2159
|
+
@undoable
|
|
2160
|
+
def extractTraversalShape(self, trav, shape, live=True, offset=10.0):
|
|
2161
|
+
"""
|
|
2162
|
+
|
|
2163
|
+
Parameters
|
|
2164
|
+
----------
|
|
2165
|
+
trav :
|
|
2166
|
+
|
|
2167
|
+
shape :
|
|
2168
|
+
|
|
2169
|
+
live :
|
|
2170
|
+
(Default value = True)
|
|
2171
|
+
offset :
|
|
2172
|
+
(Default value = 10.0)
|
|
2173
|
+
|
|
2174
|
+
Returns
|
|
2175
|
+
-------
|
|
2176
|
+
|
|
2177
|
+
"""
|
|
2178
|
+
pass
|
|
2179
|
+
|
|
2180
|
+
@undoable
|
|
2181
|
+
def connectTraversalShape(self, trav, shape, mesh=None, live=True, delete=False):
|
|
2182
|
+
"""
|
|
2183
|
+
|
|
2184
|
+
Parameters
|
|
2185
|
+
----------
|
|
2186
|
+
trav :
|
|
2187
|
+
|
|
2188
|
+
shape :
|
|
2189
|
+
|
|
2190
|
+
mesh :
|
|
2191
|
+
(Default value = None)
|
|
2192
|
+
live :
|
|
2193
|
+
(Default value = True)
|
|
2194
|
+
delete :
|
|
2195
|
+
(Default value = False)
|
|
2196
|
+
|
|
2197
|
+
Returns
|
|
2198
|
+
-------
|
|
2199
|
+
|
|
2200
|
+
"""
|
|
2201
|
+
pass
|
|
2202
|
+
|
|
2203
|
+
@undoable
|
|
2204
|
+
def extractComboShape(self, combo, shape, live=True, offset=10.0):
|
|
2205
|
+
"""Extract a shape from a combo progression
|
|
2206
|
+
|
|
2207
|
+
Parameters
|
|
2208
|
+
----------
|
|
2209
|
+
combo :
|
|
2210
|
+
|
|
2211
|
+
shape :
|
|
2212
|
+
|
|
2213
|
+
live :
|
|
2214
|
+
(Default value = True)
|
|
2215
|
+
offset :
|
|
2216
|
+
(Default value = 10.0)
|
|
2217
|
+
|
|
2218
|
+
Returns
|
|
2219
|
+
-------
|
|
2220
|
+
|
|
2221
|
+
"""
|
|
2222
|
+
|
|
2223
|
+
# extract the rest shape to use as a base
|
|
2224
|
+
tempShape = dcc.xsi.StoreShapeKey(
|
|
2225
|
+
self.shapeCluster,
|
|
2226
|
+
"temp",
|
|
2227
|
+
dcc.constants.siShapeObjectReferenceMode,
|
|
2228
|
+
1,
|
|
2229
|
+
0,
|
|
2230
|
+
0,
|
|
2231
|
+
dcc.constants.siShapeContentPrimaryShape,
|
|
2232
|
+
False,
|
|
2233
|
+
)
|
|
2234
|
+
|
|
2235
|
+
affected = self.getComboAffected(combo)
|
|
2236
|
+
|
|
2237
|
+
with disconnected(affected[0], self.inProp):
|
|
2238
|
+
# set the relevant sliders for the combo
|
|
2239
|
+
for pair in combo.pairs:
|
|
2240
|
+
pair.slider.thing.Value = pair.value
|
|
2241
|
+
|
|
2242
|
+
# also grab the shape that we are affecting
|
|
2243
|
+
affected[1].append(shape)
|
|
2244
|
+
|
|
2245
|
+
# get the blendarray
|
|
2246
|
+
tempShape.Elements.Array = self.getInbetweenArray(affected[1])
|
|
2247
|
+
|
|
2248
|
+
# extracted = dcc.shape.extractShapeKeyAsGeo(tempShape)
|
|
2249
|
+
extracted = self.extractShapeAsGeo(tempShape)
|
|
2250
|
+
extracted.Name = "%s_Extract" % shape.name
|
|
2251
|
+
extracted.posx.Value = offset
|
|
2252
|
+
|
|
2253
|
+
dcc.xsi.DeleteObj(tempShape)
|
|
2254
|
+
|
|
2255
|
+
if live:
|
|
2256
|
+
self.connectComboShape(combo, shape, extracted, live=live, delete=False)
|
|
2257
|
+
|
|
2258
|
+
return extracted
|
|
2259
|
+
|
|
2260
|
+
@undoable
|
|
2261
|
+
def connectComboShape(self, combo, shape, mesh=None, live=False, delete=False):
|
|
2262
|
+
"""Connect a shape into a combo progression
|
|
2263
|
+
|
|
2264
|
+
Parameters
|
|
2265
|
+
----------
|
|
2266
|
+
combo :
|
|
2267
|
+
|
|
2268
|
+
shape :
|
|
2269
|
+
|
|
2270
|
+
mesh :
|
|
2271
|
+
(Default value = None)
|
|
2272
|
+
live :
|
|
2273
|
+
(Default value = False)
|
|
2274
|
+
delete :
|
|
2275
|
+
(Default value = False)
|
|
2276
|
+
|
|
2277
|
+
Returns
|
|
2278
|
+
-------
|
|
2279
|
+
|
|
2280
|
+
"""
|
|
2281
|
+
if not mesh:
|
|
2282
|
+
mesh = DCC.findExtractedShape(shape.name)
|
|
2283
|
+
if not mesh:
|
|
2284
|
+
print("No extracted shape found to connect for %s" % shape.name)
|
|
2285
|
+
return
|
|
2286
|
+
shapeIdx = combo.prog.getShapeIndex(shape)
|
|
2287
|
+
tVal = combo.prog.pairs[shapeIdx].value
|
|
2288
|
+
delta = self._createDelta(combo, mesh, tVal)
|
|
2289
|
+
self.connectShape(shape, delta, live, delete)
|
|
2290
|
+
if delete:
|
|
2291
|
+
dcc.xsi.DeleteObj(mesh)
|
|
2292
|
+
|
|
2293
|
+
@undoable
|
|
2294
|
+
def extractShapeAsGeo(self, shapeKey):
|
|
2295
|
+
"""
|
|
2296
|
+
|
|
2297
|
+
Parameters
|
|
2298
|
+
----------
|
|
2299
|
+
shapeKey :
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
Returns
|
|
2303
|
+
-------
|
|
2304
|
+
|
|
2305
|
+
"""
|
|
2306
|
+
# create new object with same shape as mesh using dirty tricks to set geometry directly
|
|
2307
|
+
temp = dcc.xsi.ActiveSceneRoot.AddGeometry(
|
|
2308
|
+
"Cube", "MeshSurface", "%s_Extract" % shapeKey.Name
|
|
2309
|
+
)
|
|
2310
|
+
dcc.xsi.FreezeObj(temp)
|
|
2311
|
+
dcc.xsi.DeactivateAbove("%s.modelingmarker" % self.mesh.ActivePrimitive, True)
|
|
2312
|
+
vertArray, faceArray = self.mesh.ActivePrimitive.Geometry.Get2()
|
|
2313
|
+
temp.ActivePrimitive.Geometry.set(vertArray, faceArray)
|
|
2314
|
+
dcc.xsi.DeactivateAbove("%s.modelingmarker" % self.mesh.ActivePrimitive, "")
|
|
2315
|
+
|
|
2316
|
+
# copy over the shape
|
|
2317
|
+
tempShape = dcc.xsi.StoreShapeKey(
|
|
2318
|
+
temp, "Shape", dcc.constants.siShapeObjectReferenceMode
|
|
2319
|
+
)
|
|
2320
|
+
tempShape.Elements.Array = shapeKey.Elements.Array
|
|
2321
|
+
dcc.xsi.ApplyShapeKey(tempShape, None, None, 100, None, None, None, 2)
|
|
2322
|
+
dcc.xsi.FreezeObj(temp)
|
|
2323
|
+
|
|
2324
|
+
return temp
|
|
2325
|
+
|
|
2326
|
+
@staticmethod
|
|
2327
|
+
def setDisabled(op):
|
|
2328
|
+
"""
|
|
2329
|
+
|
|
2330
|
+
Parameters
|
|
2331
|
+
----------
|
|
2332
|
+
op :
|
|
2333
|
+
|
|
2334
|
+
|
|
2335
|
+
Returns
|
|
2336
|
+
-------
|
|
2337
|
+
|
|
2338
|
+
"""
|
|
2339
|
+
nc = op.rootNodeContainer
|
|
2340
|
+
pairs = []
|
|
2341
|
+
for pName, port in six.iteritems(nc.inputPorts):
|
|
2342
|
+
outs = list(port.connectedPorts.values())
|
|
2343
|
+
if outs:
|
|
2344
|
+
pairs.append((port, outs[0]))
|
|
2345
|
+
port.disconnect()
|
|
2346
|
+
return pairs
|
|
2347
|
+
|
|
2348
|
+
@staticmethod
|
|
2349
|
+
def reEnable(helpers):
|
|
2350
|
+
"""
|
|
2351
|
+
|
|
2352
|
+
Parameters
|
|
2353
|
+
----------
|
|
2354
|
+
helpers :
|
|
2355
|
+
|
|
2356
|
+
|
|
2357
|
+
Returns
|
|
2358
|
+
-------
|
|
2359
|
+
|
|
2360
|
+
"""
|
|
2361
|
+
for inPort, outPort in helpers:
|
|
2362
|
+
inPort.connect(outPort)
|
|
2363
|
+
|
|
2364
|
+
# Data Access
|
|
2365
|
+
@staticmethod
|
|
2366
|
+
def getSimplexOperatorsOnObject(thing):
|
|
2367
|
+
"""
|
|
2368
|
+
|
|
2369
|
+
Parameters
|
|
2370
|
+
----------
|
|
2371
|
+
thing :
|
|
2372
|
+
|
|
2373
|
+
|
|
2374
|
+
Returns
|
|
2375
|
+
-------
|
|
2376
|
+
type
|
|
2377
|
+
|
|
2378
|
+
|
|
2379
|
+
"""
|
|
2380
|
+
out = []
|
|
2381
|
+
for tree in thing.ActivePrimitive.ICETrees:
|
|
2382
|
+
simplexNodes = [
|
|
2383
|
+
dcc.ice.ICENode(node)
|
|
2384
|
+
for node in tree.Nodes
|
|
2385
|
+
if node.Type == "SimplexNode"
|
|
2386
|
+
]
|
|
2387
|
+
out.extend(simplexNodes)
|
|
2388
|
+
return out
|
|
2389
|
+
|
|
2390
|
+
@staticmethod
|
|
2391
|
+
def getSimplexOperatorsOnObjectByName(thing, name):
|
|
2392
|
+
"""
|
|
2393
|
+
|
|
2394
|
+
Parameters
|
|
2395
|
+
----------
|
|
2396
|
+
thing :
|
|
2397
|
+
|
|
2398
|
+
name :
|
|
2399
|
+
|
|
2400
|
+
|
|
2401
|
+
Returns
|
|
2402
|
+
-------
|
|
2403
|
+
type
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
"""
|
|
2407
|
+
ops = DCC.getSimplexOperatorsOnObject(thing)
|
|
2408
|
+
ops = DCC.filterSimplexByName(ops, name)
|
|
2409
|
+
|
|
2410
|
+
if not ops:
|
|
2411
|
+
return None
|
|
2412
|
+
else:
|
|
2413
|
+
return ops[0]
|
|
2414
|
+
|
|
2415
|
+
@staticmethod
|
|
2416
|
+
def getSimplexString(op):
|
|
2417
|
+
"""
|
|
2418
|
+
|
|
2419
|
+
Parameters
|
|
2420
|
+
----------
|
|
2421
|
+
op :
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
Returns
|
|
2425
|
+
-------
|
|
2426
|
+
type
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
"""
|
|
2430
|
+
return op.inputPorts["Definition"].parameters["Definition_string"].value
|
|
2431
|
+
|
|
2432
|
+
@staticmethod
|
|
2433
|
+
def getSimplexStringOnThing(thing, systemName):
|
|
2434
|
+
"""
|
|
2435
|
+
|
|
2436
|
+
Parameters
|
|
2437
|
+
----------
|
|
2438
|
+
thing :
|
|
2439
|
+
|
|
2440
|
+
systemName :
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
Returns
|
|
2444
|
+
-------
|
|
2445
|
+
type
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
"""
|
|
2449
|
+
op = DCC.getSimplexOperatorsOnObjectByName(thing, systemName)
|
|
2450
|
+
return DCC.getSimplexString(op)
|
|
2451
|
+
|
|
2452
|
+
@staticmethod
|
|
2453
|
+
def filterSimplexByObject(ops, thing):
|
|
2454
|
+
"""
|
|
2455
|
+
|
|
2456
|
+
Parameters
|
|
2457
|
+
----------
|
|
2458
|
+
ops :
|
|
2459
|
+
|
|
2460
|
+
thing :
|
|
2461
|
+
|
|
2462
|
+
|
|
2463
|
+
Returns
|
|
2464
|
+
-------
|
|
2465
|
+
|
|
2466
|
+
"""
|
|
2467
|
+
filtered = []
|
|
2468
|
+
if not ops:
|
|
2469
|
+
return filtered
|
|
2470
|
+
for i in ops:
|
|
2471
|
+
if not i.Parent3DObject:
|
|
2472
|
+
# dcc.xsi.DeleteObj(i)
|
|
2473
|
+
continue
|
|
2474
|
+
if i.Parent3DObject.IsEqualTo(thing):
|
|
2475
|
+
filtered.append(i)
|
|
2476
|
+
return filtered
|
|
2477
|
+
|
|
2478
|
+
@staticmethod
|
|
2479
|
+
def filterSimplexByName(ops, name):
|
|
2480
|
+
"""
|
|
2481
|
+
|
|
2482
|
+
Parameters
|
|
2483
|
+
----------
|
|
2484
|
+
ops :
|
|
2485
|
+
|
|
2486
|
+
name :
|
|
2487
|
+
|
|
2488
|
+
|
|
2489
|
+
Returns
|
|
2490
|
+
-------
|
|
2491
|
+
|
|
2492
|
+
"""
|
|
2493
|
+
filtered = []
|
|
2494
|
+
if not ops:
|
|
2495
|
+
return filtered
|
|
2496
|
+
for i in ops:
|
|
2497
|
+
js = json.loads(DCC.getSimplexString(i))
|
|
2498
|
+
if js["systemName"] == name:
|
|
2499
|
+
filtered.append(i)
|
|
2500
|
+
return filtered
|
|
2501
|
+
|
|
2502
|
+
@staticmethod
|
|
2503
|
+
def setSimplexString(op, val):
|
|
2504
|
+
"""set the definition string from a simplex operator
|
|
2505
|
+
|
|
2506
|
+
Parameters
|
|
2507
|
+
----------
|
|
2508
|
+
op :
|
|
2509
|
+
|
|
2510
|
+
val :
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
Returns
|
|
2514
|
+
-------
|
|
2515
|
+
|
|
2516
|
+
"""
|
|
2517
|
+
if op:
|
|
2518
|
+
dcc.xsi.SetValue("%s.Definition_string" % op.fullName, val)
|
|
2519
|
+
return val
|
|
2520
|
+
else:
|
|
2521
|
+
return val
|
|
2522
|
+
|
|
2523
|
+
@staticmethod
|
|
2524
|
+
def selectObject(thing):
|
|
2525
|
+
"""Select an object in the DCC
|
|
2526
|
+
|
|
2527
|
+
Parameters
|
|
2528
|
+
----------
|
|
2529
|
+
thing :
|
|
2530
|
+
|
|
2531
|
+
|
|
2532
|
+
Returns
|
|
2533
|
+
-------
|
|
2534
|
+
|
|
2535
|
+
"""
|
|
2536
|
+
dcc.xsi.SelectObj(thing)
|
|
2537
|
+
|
|
2538
|
+
def selectCtrl(self):
|
|
2539
|
+
"""Select the system's control object"""
|
|
2540
|
+
self.selectObject(self.inProp)
|
|
2541
|
+
|
|
2542
|
+
@staticmethod
|
|
2543
|
+
def getObjectByName(name):
|
|
2544
|
+
"""
|
|
2545
|
+
|
|
2546
|
+
Parameters
|
|
2547
|
+
----------
|
|
2548
|
+
name :
|
|
2549
|
+
|
|
2550
|
+
|
|
2551
|
+
Returns
|
|
2552
|
+
-------
|
|
2553
|
+
type
|
|
2554
|
+
|
|
2555
|
+
|
|
2556
|
+
"""
|
|
2557
|
+
return dcc.xsi.Dictionary.GetObject(name, False)
|
|
2558
|
+
|
|
2559
|
+
@staticmethod
|
|
2560
|
+
def getObjectName(thing):
|
|
2561
|
+
"""
|
|
2562
|
+
|
|
2563
|
+
Parameters
|
|
2564
|
+
----------
|
|
2565
|
+
thing :
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
Returns
|
|
2569
|
+
-------
|
|
2570
|
+
type
|
|
2571
|
+
|
|
2572
|
+
|
|
2573
|
+
"""
|
|
2574
|
+
return thing.Name
|
|
2575
|
+
|
|
2576
|
+
@staticmethod
|
|
2577
|
+
def getSelectedObjects():
|
|
2578
|
+
""" """
|
|
2579
|
+
# For maya, only return transform nodes
|
|
2580
|
+
return list(dcc.xsi.Selection)
|
|
2581
|
+
|
|
2582
|
+
@staticmethod
|
|
2583
|
+
def getDataReferences(node):
|
|
2584
|
+
"""
|
|
2585
|
+
|
|
2586
|
+
Parameters
|
|
2587
|
+
----------
|
|
2588
|
+
node :
|
|
2589
|
+
|
|
2590
|
+
|
|
2591
|
+
Returns
|
|
2592
|
+
-------
|
|
2593
|
+
|
|
2594
|
+
"""
|
|
2595
|
+
dataDict = {}
|
|
2596
|
+
for n in node.nodes:
|
|
2597
|
+
if n.type != "SceneReferenceNode":
|
|
2598
|
+
continue
|
|
2599
|
+
dataDict[n.Reference.Value] = n
|
|
2600
|
+
return dataDict
|
|
2601
|
+
|
|
2602
|
+
@staticmethod
|
|
2603
|
+
def staticUndoOpen():
|
|
2604
|
+
""" """
|
|
2605
|
+
dcc.xsi.OpenUndo("SimplexUndo")
|
|
2606
|
+
|
|
2607
|
+
@staticmethod
|
|
2608
|
+
def staticUndoClose():
|
|
2609
|
+
""" """
|
|
2610
|
+
dcc.xsi.CloseUndo()
|
|
2611
|
+
|
|
2612
|
+
def undoOpen(self):
|
|
2613
|
+
""" """
|
|
2614
|
+
if self.undoDepth == 0:
|
|
2615
|
+
self.staticUndoOpen()
|
|
2616
|
+
self.undoDepth += 1
|
|
2617
|
+
|
|
2618
|
+
def undoClose(self):
|
|
2619
|
+
""" """
|
|
2620
|
+
self.undoDepth -= 1
|
|
2621
|
+
if self.undoDepth == 0:
|
|
2622
|
+
self.staticUndoClose()
|
|
2623
|
+
|
|
2624
|
+
def getSimplexEvaluation(self):
|
|
2625
|
+
""" """
|
|
2626
|
+
geo = self.mesh.ActivePrimitive.Geometry
|
|
2627
|
+
evalArray = geo.GetICEAttributeFromName(
|
|
2628
|
+
"_%s_SimplexVector" % self.name
|
|
2629
|
+
).DataArray2D
|
|
2630
|
+
return evalArray
|
|
2631
|
+
|
|
2632
|
+
@classmethod
|
|
2633
|
+
def getPersistentFalloff(cls, thing):
|
|
2634
|
+
"""
|
|
2635
|
+
|
|
2636
|
+
Parameters
|
|
2637
|
+
----------
|
|
2638
|
+
thing :
|
|
2639
|
+
|
|
2640
|
+
|
|
2641
|
+
Returns
|
|
2642
|
+
-------
|
|
2643
|
+
|
|
2644
|
+
"""
|
|
2645
|
+
return thing.FullName
|
|
2646
|
+
|
|
2647
|
+
@classmethod
|
|
2648
|
+
def loadPersistentFalloff(cls, thing):
|
|
2649
|
+
"""
|
|
2650
|
+
|
|
2651
|
+
Parameters
|
|
2652
|
+
----------
|
|
2653
|
+
thing :
|
|
2654
|
+
|
|
2655
|
+
|
|
2656
|
+
Returns
|
|
2657
|
+
-------
|
|
2658
|
+
|
|
2659
|
+
"""
|
|
2660
|
+
return cls.getObjectByName(thing)
|
|
2661
|
+
|
|
2662
|
+
@classmethod
|
|
2663
|
+
def getPersistentShape(cls, thing):
|
|
2664
|
+
"""
|
|
2665
|
+
|
|
2666
|
+
Parameters
|
|
2667
|
+
----------
|
|
2668
|
+
thing :
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
Returns
|
|
2672
|
+
-------
|
|
2673
|
+
|
|
2674
|
+
"""
|
|
2675
|
+
# return cls.getObjectName(thing)
|
|
2676
|
+
if thing is None:
|
|
2677
|
+
return None
|
|
2678
|
+
names = []
|
|
2679
|
+
for item in thing:
|
|
2680
|
+
app = None if item is None else item.FullName
|
|
2681
|
+
names.append(app)
|
|
2682
|
+
return names
|
|
2683
|
+
|
|
2684
|
+
@classmethod
|
|
2685
|
+
def loadPersistentShape(cls, thing):
|
|
2686
|
+
"""
|
|
2687
|
+
|
|
2688
|
+
Parameters
|
|
2689
|
+
----------
|
|
2690
|
+
thing :
|
|
2691
|
+
|
|
2692
|
+
|
|
2693
|
+
Returns
|
|
2694
|
+
-------
|
|
2695
|
+
|
|
2696
|
+
"""
|
|
2697
|
+
if thing is None:
|
|
2698
|
+
return None
|
|
2699
|
+
items = []
|
|
2700
|
+
for name in thing:
|
|
2701
|
+
items.append(cls.getObjectByName(name))
|
|
2702
|
+
return items
|
|
2703
|
+
|
|
2704
|
+
@classmethod
|
|
2705
|
+
def getPersistentSlider(cls, thing):
|
|
2706
|
+
"""
|
|
2707
|
+
|
|
2708
|
+
Parameters
|
|
2709
|
+
----------
|
|
2710
|
+
thing :
|
|
2711
|
+
|
|
2712
|
+
|
|
2713
|
+
Returns
|
|
2714
|
+
-------
|
|
2715
|
+
|
|
2716
|
+
"""
|
|
2717
|
+
return thing.FullName
|
|
2718
|
+
|
|
2719
|
+
@classmethod
|
|
2720
|
+
def loadPersistentSlider(cls, thing):
|
|
2721
|
+
"""
|
|
2722
|
+
|
|
2723
|
+
Parameters
|
|
2724
|
+
----------
|
|
2725
|
+
thing :
|
|
2726
|
+
|
|
2727
|
+
|
|
2728
|
+
Returns
|
|
2729
|
+
-------
|
|
2730
|
+
|
|
2731
|
+
"""
|
|
2732
|
+
return cls.getObjectByName(thing)
|
|
2733
|
+
|
|
2734
|
+
def getFreezeThing(self, combo):
|
|
2735
|
+
return []
|
|
2736
|
+
|
|
2737
|
+
|
|
2738
|
+
class SliderDispatch(QtCore.QObject):
|
|
2739
|
+
""" """
|
|
2740
|
+
|
|
2741
|
+
valueChanged = Signal()
|
|
2742
|
+
|
|
2743
|
+
def __init__(self, node, parent=None):
|
|
2744
|
+
super(SliderDispatch, self).__init__(parent)
|
|
2745
|
+
|
|
2746
|
+
def emitValueChanged(self, *args, **kwargs):
|
|
2747
|
+
"""
|
|
2748
|
+
|
|
2749
|
+
Parameters
|
|
2750
|
+
----------
|
|
2751
|
+
*args :
|
|
2752
|
+
|
|
2753
|
+
**kwargs :
|
|
2754
|
+
|
|
2755
|
+
|
|
2756
|
+
Returns
|
|
2757
|
+
-------
|
|
2758
|
+
|
|
2759
|
+
"""
|
|
2760
|
+
self.valueChanged.emit()
|
|
2761
|
+
|
|
2762
|
+
|
|
2763
|
+
class Dispatch(QtCore.QObject):
|
|
2764
|
+
""" """
|
|
2765
|
+
|
|
2766
|
+
beforeNew = Signal()
|
|
2767
|
+
afterNew = Signal()
|
|
2768
|
+
beforeOpen = Signal()
|
|
2769
|
+
afterOpen = Signal()
|
|
2770
|
+
undo = Signal()
|
|
2771
|
+
redo = Signal()
|
|
2772
|
+
|
|
2773
|
+
def __init__(self, parent=None):
|
|
2774
|
+
super(Dispatch, self).__init__(parent)
|
|
2775
|
+
self.callbackIDs = []
|
|
2776
|
+
self.connectCallbacks()
|
|
2777
|
+
|
|
2778
|
+
def connectCallbacks(self):
|
|
2779
|
+
""" """
|
|
2780
|
+
if self.callbackIDs:
|
|
2781
|
+
self.disconnectCallbacks()
|
|
2782
|
+
|
|
2783
|
+
# self.callbackIDs.append(om.MSceneMessage.addCallback(om.MSceneMessage.kBeforeNew, self.emitBeforeNew))
|
|
2784
|
+
# self.callbackIDs.append(om.MSceneMessage.addCallback(om.MSceneMessage.kAfterNew, self.emitAfterNew))
|
|
2785
|
+
# self.callbackIDs.append(om.MSceneMessage.addCallback(om.MSceneMessage.kBeforeOpen, self.emitBeforeOpen))
|
|
2786
|
+
# self.callbackIDs.append(om.MSceneMessage.addCallback(om.MSceneMessage.kAfterOpen, self.emitAfterOpen))
|
|
2787
|
+
# self.callbackIDs.append(om.MEventMessage.addEventCallback("Undo", self.emitUndo))
|
|
2788
|
+
# self.callbackIDs.append(om.MEventMessage.addEventCallback("Redo", self.emitRedo))
|
|
2789
|
+
|
|
2790
|
+
def disconnectCallbacks(self):
|
|
2791
|
+
""" """
|
|
2792
|
+
for i in self.callbackIDs:
|
|
2793
|
+
# om.MMessage.removeCallback(i)
|
|
2794
|
+
pass
|
|
2795
|
+
|
|
2796
|
+
def emitBeforeNew(self, *args, **kwargs):
|
|
2797
|
+
"""
|
|
2798
|
+
|
|
2799
|
+
Parameters
|
|
2800
|
+
----------
|
|
2801
|
+
*args :
|
|
2802
|
+
|
|
2803
|
+
**kwargs :
|
|
2804
|
+
|
|
2805
|
+
|
|
2806
|
+
Returns
|
|
2807
|
+
-------
|
|
2808
|
+
|
|
2809
|
+
"""
|
|
2810
|
+
self.beforeNew.emit()
|
|
2811
|
+
|
|
2812
|
+
def emitAfterNew(self, *args, **kwargs):
|
|
2813
|
+
"""
|
|
2814
|
+
|
|
2815
|
+
Parameters
|
|
2816
|
+
----------
|
|
2817
|
+
*args :
|
|
2818
|
+
|
|
2819
|
+
**kwargs :
|
|
2820
|
+
|
|
2821
|
+
|
|
2822
|
+
Returns
|
|
2823
|
+
-------
|
|
2824
|
+
|
|
2825
|
+
"""
|
|
2826
|
+
self.afterNew.emit()
|
|
2827
|
+
|
|
2828
|
+
def emitBeforeOpen(self, *args, **kwargs):
|
|
2829
|
+
"""
|
|
2830
|
+
|
|
2831
|
+
Parameters
|
|
2832
|
+
----------
|
|
2833
|
+
*args :
|
|
2834
|
+
|
|
2835
|
+
**kwargs :
|
|
2836
|
+
|
|
2837
|
+
|
|
2838
|
+
Returns
|
|
2839
|
+
-------
|
|
2840
|
+
|
|
2841
|
+
"""
|
|
2842
|
+
self.beforeOpen.emit()
|
|
2843
|
+
|
|
2844
|
+
def emitAfterOpen(self, *args, **kwargs):
|
|
2845
|
+
"""
|
|
2846
|
+
|
|
2847
|
+
Parameters
|
|
2848
|
+
----------
|
|
2849
|
+
*args :
|
|
2850
|
+
|
|
2851
|
+
**kwargs :
|
|
2852
|
+
|
|
2853
|
+
|
|
2854
|
+
Returns
|
|
2855
|
+
-------
|
|
2856
|
+
|
|
2857
|
+
"""
|
|
2858
|
+
self.afterOpen.emit()
|
|
2859
|
+
|
|
2860
|
+
def emitUndo(self, *args, **kwargs):
|
|
2861
|
+
"""
|
|
2862
|
+
|
|
2863
|
+
Parameters
|
|
2864
|
+
----------
|
|
2865
|
+
*args :
|
|
2866
|
+
|
|
2867
|
+
**kwargs :
|
|
2868
|
+
|
|
2869
|
+
|
|
2870
|
+
Returns
|
|
2871
|
+
-------
|
|
2872
|
+
|
|
2873
|
+
"""
|
|
2874
|
+
self.undo.emit()
|
|
2875
|
+
|
|
2876
|
+
def emitRedo(self, *args, **kwargs):
|
|
2877
|
+
"""
|
|
2878
|
+
|
|
2879
|
+
Parameters
|
|
2880
|
+
----------
|
|
2881
|
+
*args :
|
|
2882
|
+
|
|
2883
|
+
**kwargs :
|
|
2884
|
+
|
|
2885
|
+
|
|
2886
|
+
Returns
|
|
2887
|
+
-------
|
|
2888
|
+
|
|
2889
|
+
"""
|
|
2890
|
+
self.redo.emit()
|
|
2891
|
+
|
|
2892
|
+
def __del__(self):
|
|
2893
|
+
self.disconnectCallbacks()
|
|
2894
|
+
|
|
2895
|
+
|
|
2896
|
+
DISPATCH = Dispatch()
|
|
2897
|
+
|
|
2898
|
+
|
|
2899
|
+
def rootWindow():
|
|
2900
|
+
"""Returns the currently active QT main window
|
|
2901
|
+
Only works for QT UI's like Maya
|
|
2902
|
+
|
|
2903
|
+
Parameters
|
|
2904
|
+
----------
|
|
2905
|
+
|
|
2906
|
+
Returns
|
|
2907
|
+
-------
|
|
2908
|
+
|
|
2909
|
+
"""
|
|
2910
|
+
# for MFC apps there should be no root window
|
|
2911
|
+
window = None
|
|
2912
|
+
if QApplication.instance():
|
|
2913
|
+
inst = QApplication.instance()
|
|
2914
|
+
window = inst.activeWindow()
|
|
2915
|
+
# Ignore QSplashScreen's, they should never be considered the root window.
|
|
2916
|
+
if isinstance(window, QSplashScreen):
|
|
2917
|
+
return None
|
|
2918
|
+
# If the application does not have focus try to find A top level widget
|
|
2919
|
+
# that doesn't have a parent and is a QMainWindow or QDialog
|
|
2920
|
+
if window is None:
|
|
2921
|
+
windows = []
|
|
2922
|
+
dialogs = []
|
|
2923
|
+
for w in QApplication.instance().topLevelWidgets():
|
|
2924
|
+
if w.parent() is None:
|
|
2925
|
+
if isinstance(w, QMainWindow):
|
|
2926
|
+
windows.append(w)
|
|
2927
|
+
elif isinstance(w, QDialog):
|
|
2928
|
+
dialogs.append(w)
|
|
2929
|
+
if windows:
|
|
2930
|
+
window = windows[0]
|
|
2931
|
+
elif dialogs:
|
|
2932
|
+
window = dialogs[0]
|
|
2933
|
+
|
|
2934
|
+
# grab the root window
|
|
2935
|
+
if window:
|
|
2936
|
+
while True:
|
|
2937
|
+
parent = window.parent()
|
|
2938
|
+
if not parent:
|
|
2939
|
+
break
|
|
2940
|
+
if isinstance(parent, QSplashScreen):
|
|
2941
|
+
break
|
|
2942
|
+
window = parent
|
|
2943
|
+
|
|
2944
|
+
return window
|