11 from builtins
import object
12 from builtins
import next
13 from builtins
import range
14 import sys, math, ctypes, collections
15 import maya.api.OpenMaya
as om
16 import maya.api.OpenMayaUI
as omui
17 import maya.api.OpenMayaRender
as omr
21 The presence of this function tells Maya that the plugin produces, and
22 expects to be passed, objects created using the Maya Python API 2.0.
27 def useSelectHighlight(selectedList, path):
29 displayStatus = omr.MGeometryUtilities.displayStatus(path)
30 if displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
33 pathCopy = om.MDagPath(path)
35 while pathCopy.length() > 0:
36 if selectedList.hasItem(pathCopy):
42 def floatApproxEqual(left, right):
43 return abs(left - right) < 0.0001
51 class apiMeshGeomUV(object):
52 def __init__(self, other=None):
59 return self.faceVertexIndex[fvi]
61 def getUV(self, uvId):
62 return [ self.ucoord[uvId], self.vcoord[uvId] ]
65 return self.ucoord[uvId]
68 return self.vcoord[uvId]
71 return len(self.ucoord)
73 def append_uv(self, u, v):
74 self.ucoord.append( u )
75 self.vcoord.append( v )
78 self.ucoord = om.MFloatArray()
79 self.vcoord = om.MFloatArray()
80 self.faceVertexIndex = om.MIntArray()
82 def copy(self, other):
83 self.ucoord = om.MFloatArray(other.ucoord)
84 self.vcoord = om.MFloatArray(other.vcoord)
85 self.faceVertexIndex = om.MIntArray(other.faceVertexIndex)
87 class apiMeshGeom(object):
89 self.vertices = om.MPointArray()
90 self.face_counts = om.MIntArray()
91 self.face_connects = om.MIntArray()
92 self.normals = om.MVectorArray()
93 self.uvcoords = apiMeshGeomUV()
96 def copy(self, other):
97 self.vertices = om.MPointArray(other.vertices)
98 self.face_counts = om.MIntArray(other.face_counts)
99 self.face_connects = om.MIntArray(other.face_connects)
100 self.normals = om.MVectorArray(other.normals)
101 self.uvcoords = apiMeshGeomUV(other.uvcoords)
102 self.faceCount = other.faceCount
120 kWrapString =
"\n\t\t"
122 kNormalKeyword =
"vn"
123 kTextureKeyword =
"vt"
124 kFaceKeyword =
"face"
127 class apiMeshGeomIterator(om.MPxGeometryIterator):
128 def __init__(self, userGeometry, components):
129 om.MPxGeometryIterator.__init__(self, userGeometry, components)
130 self.geometry = userGeometry
137 om.MPxGeometryIterator.reset(self)
138 self.currentPoint = 0
140 maxVertex = len(self.geometry.vertices)
141 self.maxPoints = maxVertex
150 pnt = self.geometry.vertices[ self.index() ]
153 def setPoint(self, pnt):
158 self.geometry.vertices[ self.index() ] = pnt
160 def iteratorCount(self):
165 return len(self.geometry.vertices)
173 class apiMeshData(om.MPxGeometryData):
174 typeName =
"apiMeshData"
175 id = om.MTypeId(0x80778)
182 om.MPxGeometryData.__init__(self)
183 self.fGeometry = apiMeshGeom()
186 self.fGeometry =
None
188 def readASCII(self, argList, idx):
189 idx = self.readVerticesASCII(argList, idx)
190 idx = self.readNormalsASCII(argList, idx)
191 idx = self.readFacesASCII(argList, idx)
192 idx = self.readUVASCII(argList, idx)
195 def readBinary(self, inputData, length):
199 def writeASCII(self):
200 data = self.writeVerticesASCII()
201 data += self.writeNormalsASCII()
202 data += self.writeFacesASCII()
203 data += self.writeUVASCII()
206 def writeBinary(self):
211 self.fGeometry.copy(src.fGeometry)
214 return apiMeshData.id
217 return apiMeshData.typeName
225 def iterator(self, componentList, component, useComponents, world=None):
227 return apiMeshGeomIterator(self.fGeometry, componentList)
229 return apiMeshGeomIterator(self.fGeometry, component)
237 def readVerticesASCII(self, argList, idx):
240 geomStr = argList.asString(idx)
245 if geomStr == kVertexKeyword:
246 idx = argList.lastArgUsed()+1
247 vertexCount = argList.asInt(idx)
248 idx = argList.lastArgUsed()+1
249 for i
in range(vertexCount):
250 vertex = argList.asPoint(idx)
251 idx = argList.lastArgUsed()+1
252 self.fGeometry.vertices.append(vertex)
256 def readNormalsASCII(self, argList, idx):
259 geomStr = argList.asString(idx)
264 if geomStr == kNormalKeyword:
265 idx = argList.lastArgUsed()+1
266 normalCount = argList.asInt(idx)
267 idx = argList.lastArgUsed()+1
268 for i
in range(normalCount):
269 normal = argList.asVector(idx)
270 idx = argList.lastArgUsed()+1
271 self.fGeometry.normals.append(normal)
275 def readFacesASCII(self, argList, idx):
278 geomStr = argList.asString(idx)
283 while geomStr == kFaceKeyword:
284 idx = argList.lastArgUsed()+1
285 faceCount = argList.asInt(idx)
286 idx = argList.lastArgUsed()+1
287 self.fGeometry.face_counts.append(faceCount)
288 for i
in range(faceCount):
289 vid = argList.asInt(idx)
290 idx = argList.lastArgUsed()+1
291 self.fGeometry.face_connects.append(vid)
294 geomStr = argList.asString(idx)
299 self.fGeometry.faceCount = len(self.fGeometry.face_counts)
302 def readUVASCII(self, argList, idx):
303 self.fGeometry.uvcoords.reset()
307 geomStr = argList.asString(idx)
312 if geomStr == kUVKeyword:
313 idx = argList.lastArgUsed()+1
314 uvCount = argList.asInt(idx)
315 idx = argList.lastArgUsed()+1
316 faceVertexListCount = argList.asInt(idx)
317 idx = argList.lastArgUsed()+1
318 for i
in range(uvCount):
319 u = argList.asDouble(idx)
320 idx = argList.lastArgUsed()+1
321 v = argList.asDouble(idx)
322 idx = argList.lastArgUsed()+1
323 self.fGeometry.uvcoords.append_uv(u, v)
325 for i
in range(faceVertexListCount):
326 fvi = argList.asInt(idx)
327 idx = argList.lastArgUsed()+1
328 self.fGeometry.uvcoords.faceVertexIndex.append( fvi )
332 def writeVerticesASCII(self):
333 vertexCount = len(self.fGeometry.vertices)
337 data += kDblQteChar + kVertexKeyword + kDblQteChar + kSpaceChar + str(vertexCount)
339 for i
in range(vertexCount):
340 vertex = self.fGeometry.vertices[i]
343 data += str(vertex[0]) + kSpaceChar + str(vertex[1]) + kSpaceChar + str(vertex[2])
347 def writeNormalsASCII(self):
348 normalCount = len(self.fGeometry.normals)
352 data += kDblQteChar + kNormalKeyword + kDblQteChar + kSpaceChar + str(normalCount)
354 for i
in range(normalCount):
355 normal = self.fGeometry.normals[i]
358 data += str(normal[0]) + kSpaceChar + str(normal[1]) + kSpaceChar + str(normal[2])
362 def writeFacesASCII(self):
363 numFaces = len(self.fGeometry.face_counts)
368 for i
in range(numFaces):
369 faceVertexCount = self.fGeometry.face_counts[i]
373 data += kDblQteChar + kFaceKeyword + kDblQteChar + kSpaceChar + str(faceVertexCount)
377 for v
in range(faceVertexCount):
378 value = self.fGeometry.face_connects[vid]
380 data += str(value) + kSpaceChar
385 def writeUVASCII(self):
386 uvCount = self.fGeometry.uvcoords.uvcount()
387 faceVertexCount = len(self.fGeometry.uvcoords.faceVertexIndex)
394 data += kDblQteChar + kUVKeyword + kDblQteChar + kSpaceChar + str(uvCount) + kSpaceChar + str(faceVertexCount)
396 for i
in range(uvCount):
397 uv = self.fGeometry.uvcoords.getUV(i)
400 data += str(uv[0]) + kSpaceChar + str(uv[1]) + kSpaceChar
402 for i
in range(faceVertexCount):
403 value = self.fGeometry.uvcoords.faceVertexIndex[i]
406 data += str(value) + kSpaceChar
430 class apiMesh(om.MPxSurfaceShape):
431 sNodeName =
"apiMesh_py"
432 sDrawRegistrantId =
"apiMeshPlugin_py"
443 useWeightedTransformUsingFunction =
None
444 useWeightedTweakUsingFunction =
None
455 enableNumericDisplay =
None
463 typedAttr = om.MFnTypedAttribute()
464 numericAttr = om.MFnNumericAttribute()
467 apiMesh.inputSurface = typedAttr.create(
"inputSurface",
"is", apiMeshData.id, om.MObject.kNullObj )
468 typedAttr.storable =
False
469 om.MPxNode.addAttribute( apiMesh.inputSurface )
471 apiMesh.useWeightedTransformUsingFunction = numericAttr.create(
"useWeightedTransformUsingFunction",
"utru", om.MFnNumericData.kBoolean,
True )
472 numericAttr.keyable =
True
473 om.MPxNode.addAttribute( apiMesh.useWeightedTransformUsingFunction )
475 apiMesh.useWeightedTweakUsingFunction = numericAttr.create(
"useWeightedTweakUsingFunction",
"utwu", om.MFnNumericData.kBoolean,
True )
476 numericAttr.keyable =
True
477 om.MPxNode.addAttribute( apiMesh.useWeightedTweakUsingFunction )
479 enableNumericDisplay = numericAttr.create(
"enableNumericDisplay",
"end", om.MFnNumericData.kBoolean,
True )
480 numericAttr.keyable =
True
481 om.MPxNode.addAttribute( enableNumericDisplay )
487 apiMesh.bboxCorner1 = numericAttr.create(
"bboxCorner1",
"bb1", om.MFnNumericData.k3Double, 0 )
488 numericAttr.array =
False
489 numericAttr.usesArrayDataBuilder =
False
490 numericAttr.hidden =
False
491 numericAttr.keyable =
False
492 om.MPxNode.addAttribute( apiMesh.bboxCorner1 )
494 apiMesh.bboxCorner2 = numericAttr.create(
"bboxCorner2",
"bb2", om.MFnNumericData.k3Double, 0 )
495 numericAttr.array =
False
496 numericAttr.usesArrayDataBuilder =
False
497 numericAttr.hidden =
False
498 numericAttr.keyable =
False
499 om.MPxNode.addAttribute( apiMesh.bboxCorner2 )
503 apiMesh.outputSurface = typedAttr.create(
"outputSurface",
"os", apiMeshData.id, om.MObject.kNullObj )
504 typedAttr.writable =
False
505 om.MPxNode.addAttribute( apiMesh.outputSurface )
507 apiMesh.worldSurface = typedAttr.create(
"worldSurface",
"ws", apiMeshData.id, om.MObject.kNullObj )
508 typedAttr.cached =
False
509 typedAttr.writable =
False
510 typedAttr.array =
True
511 typedAttr.usesArrayDataBuilder =
True
512 typedAttr.disconnectBehavior = om.MFnAttribute.kDelete
513 typedAttr.worldSpace =
True
514 om.MPxNode.addAttribute( apiMesh.worldSurface )
518 apiMesh.cachedSurface = typedAttr.create(
"cachedSurface",
"cs", apiMeshData.id, om.MObject.kNullObj )
519 typedAttr.readable =
True
520 typedAttr.writable =
True
521 typedAttr.storable =
True
522 om.MPxNode.addAttribute( apiMesh.cachedSurface )
526 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.outputSurface )
527 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.worldSurface )
528 om.MPxNode.attributeAffects( apiMesh.outputSurface, apiMesh.worldSurface )
529 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.bboxCorner1 )
530 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.bboxCorner2 )
531 om.MPxNode.attributeAffects( apiMesh.cachedSurface, apiMesh.outputSurface )
532 om.MPxNode.attributeAffects( apiMesh.cachedSurface, apiMesh.worldSurface )
534 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlPoints, apiMesh.outputSurface )
535 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueX, apiMesh.outputSurface )
536 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueY, apiMesh.outputSurface )
537 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueZ, apiMesh.outputSurface )
538 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlPoints, apiMesh.cachedSurface )
539 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueX, apiMesh.cachedSurface )
540 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueY, apiMesh.cachedSurface )
541 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueZ, apiMesh.cachedSurface )
542 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlPoints, apiMesh.worldSurface )
543 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueX, apiMesh.worldSurface )
544 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueY, apiMesh.worldSurface )
545 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueZ, apiMesh.worldSurface )
548 om.MPxSurfaceShape.__init__(self)
558 def postConstructor(self):
573 self.isRenderable =
True
577 self.fHasHistoryOnCreate =
False
581 self.fShapeDirty =
True
582 self.fMaterialDirty =
True
584 def compute(self, plug, datablock):
597 if plug == apiMesh.outputSurface:
598 return self.computeOutputSurface( plug, datablock )
600 elif plug == apiMesh.cachedSurface:
601 return self.computeOutputSurface( plug, datablock )
603 elif plug == apiMesh.worldSurface:
604 return self.computeWorldSurface( plug, datablock )
610 def preEvaluation(self, context, evaluationNode):
622 if context.isNormal():
623 if evaluationNode.dirtyPlugExists(apiMesh.inputSurface)
or evaluationNode.dirtyPlugExists(apiMesh.mControlPoints):
626 def postEvaluation(self, context, evaluationNode, evalType):
639 if context.isNormal():
640 if evaluationNode.dirtyPlugExists(apiMesh.inputSurface)
or evaluationNode.dirtyPlugExists(apiMesh.mControlPoints):
641 self.notifyViewport()
643 def setDependentsDirty(self, plug, plugArray):
655 if plug == apiMesh.inputSurface
or plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
656 self.signalDirtyToViewport()
658 def getInternalValue(self, plug, handle):
684 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
692 if self.hasHistory():
693 return om.MPxNode.getInternalValue(self, plug, handle)
696 if plug == om.MPxSurfaceShape.mControlPoints
and not plug.isArray():
697 index = plug.logicalIndex()
698 pnt = self.getPointValue(index)
699 handle.set3Double( pnt[0], pnt[1], pnt[2] )
701 elif plug == om.MPxSurfaceShape.mControlValueX:
702 parentPlug = plug.parent()
703 index = parentPlug.logicalIndex()
704 val = self.getChannelValue( index, 0 )
705 handle.setDouble( val )
707 elif plug == om.MPxSurfaceShape.mControlValueY:
708 parentPlug = plug.parent()
709 index = parentPlug.logicalIndex()
710 val = self.getChannelValue( index, 1 )
711 handle.setDouble( val )
713 elif plug == om.MPxSurfaceShape.mControlValueZ:
714 parentPlug = plug.parent()
715 index = parentPlug.logicalIndex()
716 val = self.getChannelValue( index, 2 )
717 handle.setDouble( val )
726 elif plug == om.MPxSurfaceShape.mHasHistoryOnCreate:
727 handle.setBool( self.fHasHistoryOnCreate )
730 isOk = om.MPxSurfaceShape.getInternalValue(self, plug, handle)
734 def setInternalValue(self, plug, handle):
760 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
770 if self.hasHistory():
771 self.verticesUpdated()
772 return om.MPxNode.setInternalValue(self, plug, handle)
775 if plug == om.MPxSurfaceShape.mControlPoints
and not plug.isArray():
776 index = plug.logicalIndex()
777 self.setPointValue( index, handle.asDouble3() )
779 elif plug == om.MPxSurfaceShape.mControlValueX:
780 parentPlug = plug.parent()
781 index = parentPlug.logicalIndex()
782 self.setChannelValue( index, 0, handle.asDouble() )
784 elif plug == om.MPxSurfaceShape.mControlValueY:
785 parentPlug = plug.parent()
786 index = parentPlug.logicalIndex()
787 self.setChannelValue( index, 1, handle.asDouble() )
789 elif plug == om.MPxSurfaceShape.mControlValueZ:
790 parentPlug = plug.parent()
791 index = parentPlug.logicalIndex()
792 self.setChannelValue( index, 2, handle.asDouble() )
801 elif plug == om.MPxSurfaceShape.mHasHistoryOnCreate:
802 self.fHasHistoryOnCreate = handle.asBool()
805 isOk = om.MPxSurfaceShape.setInternalValue(self, plug, handle)
809 def connectionMade(self, plug, otherPlug, asSrc):
817 if plug == apiMesh.inputSurface:
818 thisObj = self.thisMObject()
819 historyPlug = om.MPlug( thisObj, om.MPxSurfaceShape.mHasHistoryOnCreate )
820 historyPlug.setBool(
True )
822 thisObj = self.thisMObject()
823 dgNode = om.MFnDependencyNode( thisObj )
824 instObjGroups = dgNode.findPlug(
"instObjGroups",
True)
825 if plug == instObjGroups:
826 self.setMaterialDirty(
True)
828 return om.MPxNode.connectionMade(self, plug, otherPlug, asSrc )
830 def connectionBroken(self, plug, otherPlug, asSrc):
838 if plug == apiMesh.inputSurface:
839 thisObj = self.thisMObject()
840 historyPlug = om.MPlug( thisObj, om.MPxSurfaceShape.mHasHistoryOnCreate )
841 historyPlug.setBool(
False )
843 thisObj = self.thisMObject()
844 dgNode = om.MFnDependencyNode( thisObj )
845 instObjGroups = dgNode.findPlug(
"instObjGroups",
True)
846 if plug == instObjGroups:
847 self.setMaterialDirty(
True)
849 return om.MPxNode.connectionBroken(self, plug, otherPlug, asSrc )
851 def shouldSave(self, plug):
862 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
863 if self.hasHistory():
867 result = om.MPxNode.shouldSave(self, plug)
872 elif plug == apiMesh.cachedSurface:
873 if self.hasHistory():
877 data = plug.asMObject()
878 result =
not data.isNull()
881 result = om.MPxNode.shouldSave(self, plug)
887 def componentToPlugs(self, component, list):
900 if component.hasFn(om.MFn.kSingleIndexedComponent):
901 fnVtxComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(component) )
902 thisNode = self.thisMObject()
903 plug = om.MPlug( thisNode, om.MPxSurfaceShape.mControlPoints )
907 self.convertToTweakNodePlug(plug)
909 for i
in range(fnVtxComp.elementCount):
910 plug.selectAncestorLogicalIndex(fnVtxComp.element(i), plug.attribute())
913 def matchComponent(self, item, spec, list):
937 result = om.MPxSurfaceShape.kMatchOk
939 dim = attrSpec.dimensions
948 if ( (1 == len(spec))
and (dim > 0)
and ((name ==
"vtx")
or (name ==
"f")) ):
950 attrIndex = attrSpec[0]
953 numComp = self.meshGeom().faceCount
954 typeComp = om.MFn.kMeshPolygonComponent
956 numComp = len(self.meshGeom().vertices)
957 typeComp = om.MFn.kMeshVertComponent
962 if attrIndex.hasLowerBound():
963 lower = attrIndex.getLower()
964 if attrIndex.hasUpperBound():
965 upper = attrIndex.getUpper()
969 if lower > upper
or upper >= numComp:
970 result = om.MPxSurfaceShape.kMatchInvalidAttributeRange
973 path = item.getDagPath(0)
974 fnComp = om.MFnSingleIndexedComponent()
975 objComp = fnComp.create( typeComp )
977 for i
in range(lower, upper+1):
978 fnComp.addElement( i )
980 list.add( (path, objComp),
False )
984 result = om.MPxSurfaceShape.matchComponent(self, item, spec, list )
988 def match(self, mask, componentList):
1009 if len(componentList) == 0:
1010 result = mask.intersects( om.MSelectionMask.kSelectMeshes )
1013 for comp
in componentList:
1014 if comp.apiType() == om.MFn.kMeshVertComponent
and mask.intersects(om.MSelectionMask.kSelectMeshVerts):
1022 def createFullVertexGroup(self):
1037 fnComponent = om.MFnSingleIndexedComponent()
1038 fullComponent = fnComponent.create( om.MFn.kMeshVertComponent )
1043 numVertices = len(self.meshGeom().vertices)
1044 fnComponent.setCompleteData( numVertices )
1046 return fullComponent
1048 def getShapeSelectionMask(self):
1058 selType = om.MSelectionMask.kSelectMeshes
1059 return om.MSelectionMask( selType )
1061 def getComponentSelectionMask(self):
1071 selMask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
1072 selMask.addMask(om.MSelectionMask.kSelectMeshEdges)
1073 selMask.addMask(om.MSelectionMask.kSelectMeshFaces)
1076 def localShapeInAttr(self):
1089 return apiMesh.inputSurface
1091 def localShapeOutAttr(self):
1105 return apiMesh.outputSurface
1107 def worldShapeOutAttr(self):
1121 return apiMesh.outputSurface
1123 def cachedShapeAttr(self):
1135 return apiMesh.cachedSurface
1138 def geometryData(self):
1146 datablock = self.forceCache()
1147 handle = datablock.inputValue( apiMesh.inputSurface )
1148 return handle.data()
1150 def closestPoint(self, toThisPoint, theClosestPoint, tolerance):
1161 geometry = self.meshGeom()
1162 numVertices = len(geometry.vertices)
1163 for i
in range(numVertices):
1164 tryThisOne = geometry.vertices[i]
1168 theClosestPoint = geometry.vertices[0]
1172 def transformUsing(self, mat, componentList, cachingMode=om.MPxSurfaceShape.kNoPointCaching, pointCache=None):
1190 geometry = self.meshGeom()
1194 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1195 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1200 cacheLen = len(pointCache)
1205 if len(componentList) > 0:
1208 for comp
in componentList:
1209 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1210 elemCount = fnComp.elementCount
1212 for idx
in range(elementCount):
1213 elemIndex = fnComp.element(idx)
1214 geometry.vertices[elemIndex] = pointCache[cacheIndex]
1216 if cacheIndex >= cacheLen:
1219 if cacheIndex >= cacheLen:
1226 vertLen = len(geometry.vertices)
1227 for idx
in range(vertLen):
1228 geometry.vertices[idx] = pointCache[cacheIndex]
1230 if cacheIndex >= cacheLen:
1237 if len(componentList) > 0:
1240 setSizeIncrement =
True
1241 for comp
in componentList:
1242 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1243 elemCount = fnComp.elementCount
1245 if savePoints
and setSizeIncrement:
1246 pointCache.sizeIncrement = elemCount
1247 setSizeIncrement =
False
1249 for idx
in range(elemCount):
1250 elemIndex = fnComp.element(idx)
1252 pointCache.append(geometry.vertices[elemIndex])
1254 geometry.vertices[elemIndex] *= mat
1255 geometry.normals[idx] = geometry.normals[idx].transformAsNormal( mat )
1261 vertLen = len(geometry.vertices)
1263 pointCache.sizeIncrement = vertLen
1265 for idx
in range(vertLen):
1267 pointCache.append(geometry.vertices[idx])
1269 geometry.vertices[idx] *= mat
1270 geometry.normals[idx] = geometry.normals[idx].transformAsNormal( mat )
1273 self.updateCachedSurface( geometry, componentList )
1275 def tweakUsing(self, mat, componentList, cachingMode, pointCache, handle):
1296 geometry = self.meshGeom()
1300 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1301 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1302 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1304 builder = handle.builder()
1309 cacheLen = len(pointCache)
1314 if len(componentList) > 0:
1317 for comp
in componentList:
1318 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1319 elemCount = fnComp.elementCount
1321 for idx
in range(elementCount):
1322 elemIndex = fnComp.element(idx)
1323 cachePt = pointCache[cacheIndex]
1324 elem = builder.addElement( elemIndex )
1325 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1327 if cacheIndex >= cacheLen:
1330 if cacheIndex >= cacheLen:
1337 vertLen = len(geometry.vertices)
1338 for idx
in range(vertLen):
1339 cachePt = pointCache[cacheIndex]
1340 elem = builder.addElement( idx )
1341 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1343 if cacheIndex >= cacheLen:
1351 if len(componentList) > 0:
1352 setSizeIncrement =
True
1353 for comp
in componentList:
1354 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1355 elemCount = fnComp.elementCount
1357 if savePoints
and setSizeIncrement:
1358 pointCache.sizeIncrement = elemCount
1359 setSizeIncrement =
False
1361 for idx
in range(elementCount):
1362 elemIndex = fnComp.element(idx)
1363 currPt = newPt = geometry.vertices[elemIndex]
1365 delta = newPt - currPt
1366 elem = builder.addElement( elemIndex )
1367 elem.set3Double(delta.x, delta.y, delta.z)
1372 pointCache.append(delta*(-1.0))
1374 elif updatePoints
and cacheIndex < cacheLen:
1375 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1382 vertLen = len(geometry.vertices)
1384 pointCache.sizeIncrement = vertLen
1386 for idx
in range(vertLen):
1387 currPt = newPt = geometry.vertices[idx]
1389 delta = newPt - currPt
1390 elem = builder.addElement( idx )
1391 elem.set3Double(delta.x, delta.y, delta.z)
1396 pointCache.append(delta*(-1.0))
1398 elif updatePoints
and idx < cacheLen:
1399 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1409 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
1412 self.signalDirtyToViewport()
1416 def weightedTransformUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane):
1442 plg_useWeightedTransformUsingFunction = om.MPlug( self.thisMObject(), apiMesh.useWeightedTransformUsingFunction )
1443 val_useWeightedTransformUsingFunction = plg_useWeightedTransformUsingFunction.asBool()
1444 if not val_useWeightedTransformUsingFunction:
1445 om.MPxSurfaceShape.weightedTransformUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane)
1446 self.signalDirtyToViewport()
1451 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1452 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1453 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1454 transformOrigPoints = (cachingMode == om.MPxSurfaceShape.kTransformOriginalPoints
and pointCache
is not None)
1457 spaceInv = om.MMatrix()
1459 spaceInv = space.inverse()
1463 geometry = self.meshGeom()
1466 setSizeIncrement =
True
1468 for comp
in componentList:
1469 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1470 elemCount = fnComp.elementCount
1471 hasWeights = fnComp.hasWeights
1472 hasSeam = (freezePlane
is not None)
1474 if savePoints
and setSizeIncrement:
1475 pointCache.sizeIncrement = elemCount
1476 setSizeIncrement =
False
1478 for idx
in range(elementCount):
1479 elemIndex = fnComp.element( idx )
1482 perc = fnComp.weight(idx).influence()
1485 if perc > almostZero:
1488 geometry.vertices[elemIndex] = om.MVector( pointCache[pointCacheIndex] )
1489 pointCacheIndex += 1
1494 pointCache.append( geometry.vertices[elemIndex] )
1496 elif transformOrigPoints:
1497 geometry.vertices[elemIndex] = om.MVector( pointCache[pointCacheIndex] )
1500 pointCache[pointCacheIndex] = geometry.vertices[elemIndex]
1505 mat = xform.asMatrix()
1507 mat = space * xform.asMatrix(perc) * spaceInv
1509 mat = xform.asMatrix(perc)
1512 currPt = newPt = geometry.vertices[elemIndex]
1516 if hasSeam
and fnComp.weight(idx).seam() > 0.0:
1517 newPt += freezePlane.normal() * (fnComp.weight(idx).seam() * (freezePlane.directedDistance(currPt) - freezePlane.directedDistance(newPt)))
1520 geometry.vertices[elemIndex] = newPt
1521 pointCacheIndex += 1
1524 self.updateCachedSurface( geometry, componentList )
1526 def weightedTweakUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane, handle):
1557 plg_useWeightedTweakUsingFunction = om.MPlug( self.thisMObject(), apiMesh.useWeightedTweakUsingFunction )
1558 val_useWeightedTweakUsingFunction = plg_useWeightedTweakUsingFunction.asBool()
1559 if not val_useWeightedTweakUsingFunction:
1560 om.MPxSurfaceShape.weightedTweakUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane, handle)
1563 geometry = self.meshGeom()
1567 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1568 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1569 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1570 transformOrigPoints = (cachingMode == om.MPxSurfaceShape.kTransformOriginalPoints
and pointCache
is not None)
1572 builder = handle.builder()
1577 cacheLen = len(pointCache)
1584 for comp
in componentList:
1585 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1586 elemCount = fnComp.elementCount
1588 for idx
in range(elementCount):
1589 elemIndex = fnComp.element( idx )
1590 cachePt = pointCache[cacheIndex]
1591 elem = builder.addElement( elemIndex )
1592 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1594 if cacheIndex >= cacheLen:
1605 setSizeIncrement =
True
1606 spaceInv = om.MMatrix()
1608 spaceInv = space.inverse()
1610 for comp
in componentList:
1611 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1612 elemCount = fnComp.elementCount
1613 hasWeights = fnComp.hasWeights
1614 hasSeam = (freezePlane
is not None)
1616 if savePoints
and setSizeIncrement:
1617 pointCache.sizeIncrement = elemCount
1618 setSizeIncrement =
False
1620 for idx
in range(elementCount):
1621 elemIndex = fnComp.element( idx )
1624 perc = fnComp.weight(idx).influence()
1627 if perc > almostZero:
1633 mat = xform.asMatrix()
1635 mat = space * xform.asMatrix(perc) * spaceInv
1637 mat = xform.asMatrix(perc)
1642 if transformOrigPoints:
1643 geometry.vertices[elemIndex] = om.MVector( pointCache[cacheIndex] )
1647 currPt = newPt = geometry.vertices[elemIndex]
1652 if hasSeam
and fnComp.weight(idx).seam() > 0.0:
1653 newPt += freezePlane.normal() * (fnComp.weight(idx).seam() * (freezePlane.directedDistance(currPt) - freezePlane.directedDistance(newPt)))
1656 delta = newPt - currPt
1658 elem = builder.addElement( elemIndex )
1659 elem.set3Double(delta.x, delta.y, delta.z)
1664 pointCache.append(delta*(-1.0))
1665 elif updatePoints
and cacheIndex < cacheLen:
1666 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1676 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
1680 def vertexOffsetDirection(self, component, direction, mode, normalize):
1699 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(component) )
1700 if component.apiType() != om.MFn.kMeshVertComponent:
1703 geometry = self.meshGeom()
1710 normal = geometry.normals[ idx ]
1712 if mode == om.MPxSurfaceShape.kNormal:
1715 direction.append( normal )
1724 a = math.abs(normal[0])
1726 if a < math.abs(normal[1]):
1730 if a < math.abs(normal[2]):
1736 a = math.sqrt(normal[i]*normal[i] + normal[j]*normal[j])
1737 uAxis[i] = -normal[j]/a
1738 uAxis[j] = normal[i]/a
1740 vAxis = normal^uAxis
1742 if mode == om.MPxSurfaceShape.kUTangent
or mode == om.MPxSurfaceShape.kUVNTriad:
1745 direction.append( uAxis )
1747 if mode == om.MPxSurfaceShape.kVTangent
or mode == om.MPxSurfaceShape.kUVNTriad:
1750 direction.append( vAxis )
1752 if mode == om.MPxSurfaceShape.kUVNTriad:
1755 direction.append( normal )
1761 def isBounded(self):
1770 def boundingBox(self):
1777 if self.fShapeDirty:
1781 thisNode = self.thisMObject()
1782 c1Plug = om.MPlug( thisNode, apiMesh.bboxCorner1 )
1783 c2Plug = om.MPlug( thisNode, apiMesh.bboxCorner2 )
1784 corner1Object = c1Plug.asMObject()
1785 corner2Object = c2Plug.asMObject()
1787 fnData = om.MFnNumericData()
1788 fnData.setObject( corner1Object )
1789 corner1 = fnData.getData()
1791 fnData.setObject( corner2Object )
1792 corner2 = fnData.getData()
1794 corner1Point = om.MPoint( corner1[0], corner1[1], corner1[2] )
1795 corner2Point = om.MPoint( corner2[0], corner2[1], corner2[2] )
1797 return om.MBoundingBox( corner1Point, corner2Point )
1801 def geometryIteratorSetup(self, componentList, components, forReadOnly=False):
1818 if components.isNull():
1819 vtxComponents = om.MObjectArray([self.convertToVertexComponent(c)
for c
in componentList])
1820 return apiMeshGeomIterator( self.meshGeom(), vtxComponents )
1822 return apiMeshGeomIterator( self.meshGeom(), self.convertToVertexComponent(components) )
1824 def acceptsGeometryIterator(self, arg0, arg1=None, arg2=None):
1850 def hasHistory(self):
1856 return self.fHasHistoryOnCreate
1858 def shapeDirty(self):
1865 return self.fShapeDirty
1867 def resetShapeDirty(self):
1873 self.fShapeDirty =
False
1875 def materialDirty(self):
1882 return self.fMaterialDirty
1884 def setMaterialDirty(self, dirty):
1890 self.fMaterialDirty = dirty
1892 def computeInputSurface(self, plug, datablock):
1901 if self.hasHistory():
1902 inputHandle = datablock.inputValue( apiMesh.inputSurface )
1904 surf = inputHandle.asPluginData()
1905 if not isinstance(surf, apiMeshData):
1906 raise RuntimeError(
"computeInputSurface : invalid inputSurface data found")
1910 fnDataCreator = om.MFnPluginData()
1911 fnDataCreator.create( apiMeshData.id )
1913 newCachedData = fnDataCreator.data()
1914 if not isinstance(newCachedData, apiMeshData):
1915 raise RuntimeError(
"computeInputSurface : invalid proxy cached apiMeshData object")
1917 newCachedData.fGeometry.copy(surf.fGeometry)
1919 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
1920 if not isinstance(cachedHandle, om.MDataHandle):
1921 raise RuntimeError(
"computeInputSurface : invalid cachedSurface")
1923 cachedHandle.setMPxData( newCachedData )
1925 def computeOutputSurface(self, plug, datablock):
1940 self.computeInputSurface( plug, datablock )
1944 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
1945 if not isinstance(cachedHandle, om.MDataHandle):
1946 raise RuntimeError(
"computeOutputSurface : invalid cachedSurface")
1948 cached = cachedHandle.asPluginData()
1949 if not isinstance(cached, apiMeshData):
1950 raise RuntimeError(
"computeOutputSurface : invalid cachedSurface data found")
1952 datablock.setClean( plug )
1956 if self.hasHistory():
1957 self.applyTweaks( datablock, cached.fGeometry )
1960 cpHandle = datablock.inputArrayValue( om.MPxSurfaceShape.mControlPoints )
1961 cpHandle.setAllClean()
1965 fnDataCreator = om.MFnPluginData()
1966 fnDataCreator.create( apiMeshData.id )
1968 newData = fnDataCreator.data()
1969 if not isinstance(newData, apiMeshData):
1970 raise RuntimeError(
"computeOutputSurface : invalid proxy cached apiMeshData object")
1974 newData.fGeometry.copy(cached.fGeometry)
1978 outHandle = datablock.outputValue( apiMesh.outputSurface )
1979 outHandle.setMPxData( newData )
1983 self.computeBoundingBox( datablock )
1988 def computeWorldSurface(self, plug, datablock):
1995 self.computeOutputSurface( plug, datablock )
1996 inHandle = datablock.outputValue( apiMesh.outputSurface )
1997 outSurf = inHandle.asPluginData()
1998 if not isinstance(outSurf, apiMeshData):
1999 raise RuntimeError(
"computeWorldSurface : invalid outSurf")
2003 fnDataCreator = om.MFnPluginData()
2004 fnDataCreator.create( apiMeshData.id )
2006 newData = fnDataCreator.data()
2007 if not isinstance(newData, apiMeshData):
2008 raise RuntimeError(
"computeWorldSurface : invalid proxy cached apiMeshData object")
2011 worldMat = self.getWorldMatrix(datablock, 0)
2012 newData.matrix = worldMat
2016 newData.fGeometry.copy( outSurf.fGeometry )
2020 arrayIndex = plug.logicalIndex()
2022 worldHandle = datablock.outputArrayValue( apiMesh.worldSurface )
2023 builder = worldHandle.builder()
2024 outHandle = builder.addElement( arrayIndex )
2026 outHandle.setMPxData( newData )
2031 def computeBoundingBox(self, datablock):
2041 lowerHandle = datablock.outputValue( apiMesh.bboxCorner1 )
2042 upperHandle = datablock.outputValue( apiMesh.bboxCorner2 )
2044 geometry = self.meshGeom()
2045 cnt = len(geometry.vertices)
2051 tmppnt = geometry.vertices[0]
2052 lower = [ tmppnt[0], tmppnt[1], tmppnt[2] ]
2053 upper = [ tmppnt[0], tmppnt[1], tmppnt[2] ]
2055 for i
in range(cnt):
2056 pnt = geometry.vertices[i]
2058 if pnt[0] < lower[0]: lower[0] = pnt[0]
2059 if pnt[1] < lower[1]: lower[1] = pnt[1]
2060 if pnt[2] < lower[2]: lower[2] = pnt[2]
2062 if pnt[0] > upper[0]: upper[0] = pnt[0]
2063 if pnt[1] > upper[1]: upper[1] = pnt[1]
2064 if pnt[2] > upper[2]: upper[2] = pnt[2]
2066 lowerHandle.set3Double(lower[0], lower[1], lower[2])
2067 upperHandle.set3Double(upper[0], upper[1], upper[2])
2069 lowerHandle.setClean()
2070 upperHandle.setClean()
2074 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2076 def convertToVertexComponent(self, components):
2078 Converts edge and face components into vertex components. This
2079 allows applying transform offsets to the vertex when edge or faces
2085 srcComponent = om.MFnSingleIndexedComponent(components)
2086 srcComponentType = srcComponent.componentType
2090 if srcComponentType != om.MFn.kMeshVertComponent:
2091 srcIndices = set(srcComponent.getElements())
2092 retVal = srcComponent.create(om.MFn.kMeshVertComponent)
2093 vtxComponent = om.MFnSingleIndexedComponent(retVal)
2095 geomPtr = self.meshGeom()
2099 for faceIdx
in range(0, geomPtr.faceCount):
2101 numVerts = geomPtr.face_counts[faceIdx]
2103 for v
in range(0, numVerts):
2104 if srcComponentType == om.MFn.kMeshEdgeComponent:
2105 if edgeId
in srcIndices:
2106 vindex1 = base + (v % numVerts)
2107 vindex2 = base + ((v+1) % numVerts)
2109 vertexId1 = geomPtr.face_connects[vindex1]
2110 vertexId2 = geomPtr.face_connects[vindex2]
2112 vtxComponent.addElement(vertexId1)
2113 vtxComponent.addElement(vertexId2)
2118 if faceIdx
in srcIndices:
2119 vindex = base + (v % numVerts)
2120 vertexId = geomPtr.face_connects[vindex]
2121 vtxComponent.addElement(vertexId)
2127 def applyTweaks(self, datablock, geometry):
2135 cpHandle = datablock.inputArrayValue( om.MPxSurfaceShape.mControlPoints )
2139 while not cpHandle.isDone():
2140 elemIndex = cpHandle.elementLogicalIndex()
2141 pntHandle = cpHandle.outputValue()
2143 offset = pntHandle.asDouble3()
2147 geometry.vertices[elemIndex] += om.MPoint(offset[0],offset[1],offset[2])
2152 def updateCachedSurface(self, geometry, componentList):
2171 datablock = self.forceCache()
2173 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
2174 cached = cachedHandle.asPluginData()
2176 dHandle = datablock.outputValue( om.MPxSurfaceShape.mControlPoints )
2181 if self.hasHistory()
and cached:
2186 self.buildControlPoints( datablock, len(geometry.vertices) )
2188 cpHandle = om.MArrayDataHandle( dHandle )
2192 for comp
in componentList:
2193 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
2194 for elemIndex
in fnComp.getElements():
2195 cpHandle.jumpToLogicalElement( elemIndex )
2196 pntHandle = cpHandle.outputValue()
2198 pnt = pntHandle.asDouble3()
2200 oldPnt = cached.fGeometry.vertices[elemIndex]
2201 newPnt = geometry.vertices[elemIndex]
2202 offset = newPnt - oldPnt
2208 pntHandle.set3Double(pnt[0], pnt[1], pnt[2])
2213 cached.fGeometry.copy(geometry)
2215 pCPs = om.MPlug( self.thisMObject(), om.MPxSurfaceShape.mControlPoints)
2216 pCPs.setMDataHandle(dHandle)
2220 self.computeBoundingBox( datablock )
2225 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2228 self.signalDirtyToViewport()
2230 def getPointValue(self, pntInd):
2237 geometry = self.cachedGeom()
2239 return geometry.vertices[ pntInd ]
2243 def getChannelValue(self, pntInd, vlInd):
2250 geometry = self.cachedGeom()
2252 return geometry.vertices[ pntInd ][ vlInd ]
2256 def setPointValue(self, pntInd, val):
2263 geometry = self.cachedGeom()
2265 geometry.vertices[ pntInd ] = om.MPoint(val)
2267 self.verticesUpdated()
2269 def setChannelValue(self, pntInd, vlInd, val):
2276 geometry = self.cachedGeom()
2278 geometry.vertices[ pntInd ][ vlInd ] = val
2280 self.verticesUpdated()
2282 def meshObject(self):
2293 datablock = self.forceCache()
2299 handle = datablock.inputValue( apiMesh.outputSurface )
2300 return handle.data()
2308 meshObj = self.meshObject()
2310 fnData = om.MFnPluginData( meshObj )
2311 data = fnData.data()
2312 if not isinstance(data, apiMeshData):
2313 raise RuntimeError(
"meshGeom : failed to get apiMeshData")
2314 return data.fGeometry
2316 def cachedObject(self):
2326 datablock = self.forceCache()
2327 handle = datablock.outputValue( apiMesh.cachedSurface )
2328 return handle.data()
2330 def cachedGeom(self):
2337 fnData = om.MFnPluginData( self.cachedObject() )
2338 data = fnData.data()
2339 if not isinstance(data, apiMeshData):
2340 raise RuntimeError(
"cachedGeom : failed to get apiMeshData")
2342 return data.fGeometry
2344 def buildControlPoints(self, datablock, count):
2352 cpH = datablock.outputArrayValue( om.MPxSurfaceShape.mControlPoints )
2354 oldBuilder = cpH.builder()
2355 if count != len(oldBuilder):
2358 builder = om.MArrayDataBuilder( oldBuilder )
2360 for vtx
in range(count):
2361 builder.addElement( vtx )
2367 def verticesUpdated(self):
2375 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2376 self.childChanged( om.MPxSurfaceShape.kObjectChanged )
2378 def setShapeDirty(self):
2379 self.fShapeDirty =
True
2381 def notifyViewport(self):
2382 omr.MRenderer.setGeometryDrawDirty(self.thisMObject())
2384 def signalDirtyToViewport(self):
2385 self.setShapeDirty()
2386 self.notifyViewport()
2388 class apiMeshGeometryShape(apiMesh):
2389 sDrawDbClassification =
"drawdb/geometry/apiMesh_py"
2391 id = om.MTypeId(0x8009B)
2394 super(apiMeshGeometryShape, self).__init__()
2398 return apiMeshGeometryShape()
2402 return apiMesh.initialize()
2404 class apiMeshSubsceneShape(apiMesh):
2405 sDrawDbClassification =
"drawdb/subscene/apiMesh_py"
2407 id = om.MTypeId(0x8009C)
2410 super(apiMeshSubsceneShape, self).__init__()
2414 return apiMeshSubsceneShape()
2418 om.MPxNode.inheritAttributesFrom(apiMesh.sNodeName)
2430 class apiMeshUI(omui.MPxSurfaceShapeUI):
2437 omui.MPxSurfaceShapeUI.__init__(self)
2448 def drawUV(self, view, info):
2458 meshNode = self.surfaceShape()
2459 geom = meshNode.meshGeom()
2461 if geom.uvcoords.uvcount() > 0:
2462 view.setDrawColor( om.MColor( (1.0, 0.0, 0.0) ) )
2464 if info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawWireframe:
2465 self.drawUVWireframe( geom, view, info )
2467 elif info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawEverything
or info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawUVForSelect:
2468 self.drawUVWireframe( geom, view, info )
2469 self.drawUVMapCoordNum( geom, view, info,
True )
2472 self.drawUVWireframe( geom, view, info )
2474 def canDrawUV(self):
2480 meshNode = self.surfaceShape()
2481 geom = meshNode.meshGeom()
2482 return (geom.uvcoords.uvcount() > 0)
2486 def select(self, selectInfo, selectionList, worldSpaceSelectPts):
2500 componentSelected =
False
2503 hilited = (selectInfo.displayStatus() == omui.M3dView.kHilite)
2505 componentSelected = self.selectVertices( selectInfo, selectionList, worldSpaceSelectPts )
2506 selected = selected
or componentSelected
2509 meshNode = self.surfaceShape()
2516 priorityMask = om.MSelectionMask( om.MSelectionMask.kSelectNurbsSurfaces )
2518 item = om.MSelectionList()
2519 item.add( selectInfo.selectPath() )
2521 xformedPt = om.MPoint()
2522 if selectInfo.singleSelection():
2523 center = meshNode.boundingBox().center
2525 xformedPt *= selectInfo.selectPath().inclusiveMatrix()
2527 selectInfo.addSelection( item, xformedPt, selectionList, worldSpaceSelectPts, priorityMask,
False )
2537 def selectVertices(self, selectInfo, selectionList, worldSpaceSelectPts):
2551 view = selectInfo.view()
2552 path = selectInfo.multiPath()
2553 singleSelection = selectInfo.singleSelection()
2557 fnComponent = om.MFnSingleIndexedComponent()
2558 surfaceComponent = fnComponent.create( om.MFn.kMeshVertComponent )
2563 alignmentMatrix = om.MMatrix()
2565 alignmentMatrix = selectInfo.getAlignmentMatrix()
2567 singlePoint = om.MPoint()
2568 selectionPoint = om.MPoint()
2569 closestPointVertexIndex = -1
2574 meshNode = self.surfaceShape()
2575 geom = meshNode.meshGeom()
2580 for currentPoint
in geom.vertices:
2586 glBegin( GL_POINTS )
2587 glVertex3f( currentPoint[0], currentPoint[1], currentPoint[2] )
2590 if view.endSelect() > 0:
2594 xformedPoint = currentPoint
2595 xformedPoint.homogenize()
2596 xformedPoint *= alignmentMatrix
2598 if closestPointVertexIndex < 0
or z > previousZ:
2599 closestPointVertexIndex = vertexIndex
2600 singlePoint = currentPoint
2606 fnComponent.addElement( vertexIndex )
2610 if selected
and singleSelection:
2611 fnComponent.addElement(closestPointVertexIndex)
2615 selectionPoint = singlePoint
2616 selectionPoint *= path.inclusiveMatrix()
2621 selectionItem = om.MSelectionList()
2622 selectionItem.add( path, surfaceComponent )
2624 mask = om.MSelectionMask( om.MSelectionMask.kSelectComponentsMask )
2625 selectInfo.addSelection( selectionItem, selectionPoint, selectionList, worldSpaceSelectPts, mask,
True )
2629 def drawUVWireframe(self, geom, view, info):
2641 for i
in range(geom.faceCount):
2645 for v
in range(geom.face_counts[i]-1):
2646 uvId1 = geom.uvcoords.uvId(vid)
2647 uvId2 = geom.uvcoords.uvId(vid+1)
2649 uv1 = geom.uvcoords.getUV(uvId1)
2650 uv2 = geom.uvcoords.getUV(uvId2)
2652 glVertex3f( uv1[0], uv1[1], 0.0 )
2653 glVertex3f( uv2[0], uv2[1], 0.0 )
2656 uvId1 = geom.uvcoords.uvId(vid)
2657 uvId2 = geom.uvcoords.uvId(vid_start)
2659 uv1 = geom.uvcoords.getUV(uvId1)
2660 uv2 = geom.uvcoords.getUV(uvId2)
2662 glVertex3f( uv1[0], uv1[1], 0.0 )
2663 glVertex3f( uv2[0], uv2[1], 0.0 )
2670 def drawUVMapCoord(self, view, uvId, uv, drawNumbers):
2678 view.drawText( str(uvId), om.MPoint( uv[0], uv[1], 0 ), omui.M3dView.kCenter )
2680 glVertex3f( uv[0], uv[1], 0.0 )
2682 def drawUVMapCoordNum(self, geom, view, info, drawNumbers):
2690 ptSize = glGetFloatv( GL_POINT_SIZE )
2693 for uvId
in range(geom.uvcoords.uvcount()):
2694 uv = geom.uvcoords.getUV( uvId )
2695 self.drawUVMapCoord( view, uvId, uv, drawNumbers )
2697 glPointSize( ptSize )
2710 class apiMeshCreator(om.MPxNode):
2711 id = om.MTypeId(0x8008A)
2721 outputSurface =
None
2725 return apiMeshCreator()
2729 typedAttr = om.MFnTypedAttribute()
2730 numericAttr = om.MFnNumericAttribute()
2731 enumAttr = om.MFnEnumAttribute()
2734 apiMeshCreator.size = numericAttr.create(
"size",
"sz", om.MFnNumericData.kDouble, 1 )
2735 numericAttr.array =
False
2736 numericAttr.usesArrayDataBuilder =
False
2737 numericAttr.hidden =
False
2738 numericAttr.keyable =
True
2739 om.MPxNode.addAttribute( apiMeshCreator.size )
2741 apiMeshCreator.shapeType = enumAttr.create(
"shapeType",
"st", 0 )
2742 enumAttr.addField(
"cube", 0 )
2743 enumAttr.addField(
"sphere", 1 )
2744 enumAttr.hidden =
False
2745 enumAttr.keyable =
True
2746 om.MPxNode.addAttribute( apiMeshCreator.shapeType )
2748 apiMeshCreator.inputMesh = typedAttr.create(
"inputMesh",
"im", om.MFnData.kMesh, om.MObject.kNullObj )
2749 typedAttr.hidden =
True
2750 om.MPxNode.addAttribute( apiMeshCreator.inputMesh )
2753 apiMeshCreator.outputSurface = typedAttr.create(
"outputSurface",
"os", apiMeshData.id, om.MObject.kNullObj )
2754 typedAttr.writable =
False
2755 om.MPxNode.addAttribute( apiMeshCreator.outputSurface )
2759 om.MPxNode.attributeAffects( apiMeshCreator.inputMesh, apiMeshCreator.outputSurface )
2760 om.MPxNode.attributeAffects( apiMeshCreator.size, apiMeshCreator.outputSurface )
2761 om.MPxNode.attributeAffects( apiMeshCreator.shapeType, apiMeshCreator.outputSurface )
2764 om.MPxNode.__init__(self)
2772 def compute(self, plug, datablock):
2780 if plug == apiMeshCreator.outputSurface:
2784 fnDataCreator = om.MFnPluginData()
2785 fnDataCreator.create( apiMeshData.id )
2787 newData = fnDataCreator.data()
2788 if not isinstance(newData, apiMeshData):
2789 raise RuntimeError(
"compute : invalid proxy cached apiMeshData object")
2791 geometry = newData.fGeometry
2796 hasHistory = self.computeInputMesh( plug, datablock, geometry )
2802 sizeHandle = datablock.inputValue( apiMeshCreator.size )
2803 shape_size = sizeHandle.asDouble()
2804 typeHandle = datablock.inputValue( apiMeshCreator.shapeType )
2805 shape_type = typeHandle.asShort()
2808 self.buildCube( shape_size, geometry )
2809 elif shape_type == 1:
2810 self.buildSphere( shape_size, 32, geometry )
2812 geometry.faceCount = len(geometry.face_counts)
2816 outHandle = datablock.outputValue( apiMeshCreator.outputSurface )
2817 outHandle.setMPxData( newData )
2818 datablock.setClean( plug )
2832 def computeInputMesh(self, plug, datablock, geometry):
2843 inputData = datablock.inputValue( apiMeshCreator.inputMesh )
2844 surf = inputData.asMesh()
2848 thisObj = self.thisMObject()
2849 surfPlug = om.MPlug( thisObj, apiMeshCreator.inputMesh )
2850 if not surfPlug.isConnected:
2851 datablock.setClean( plug )
2856 surfFn = om.MFnMesh(surf)
2857 geometry.vertices = surfFn.getPoints(om.MSpace.kObject)
2861 hasUVs = surfFn.numUVs() > 0
2862 uvs = surfFn.getUVs()
2863 geometry.uvcoords.ucoord = uvs[0]
2864 geometry.uvcoords.vcoord = uvs[1]
2866 for i
in range(surfFn.numPolygons()):
2867 polyVerts = surfFn.getPolygonVertices(i)
2869 pvc = len(polyVerts)
2870 geometry.face_counts.append( pvc )
2872 for v
in range(pvc):
2874 uvId = surfFn.getPolygonUVid(i, v)
2875 geometry.uvcoords.faceVertexIndex.append( uvId )
2876 geometry.face_connects.append( polyVerts[v] )
2878 for n
in range(len(geometry.vertices)):
2879 normal = surfFn.getVertexNormal(n)
2880 geometry.normals.append( normal )
2884 def buildCube(self, cube_size, geometry):
2891 geometry.vertices.clear()
2892 geometry.normals.clear()
2893 geometry.face_counts.clear()
2894 geometry.face_connects.clear()
2895 geometry.uvcoords.reset()
2897 geometry.vertices.append( om.MPoint( -cube_size, -cube_size, -cube_size ) )
2898 geometry.vertices.append( om.MPoint( cube_size, -cube_size, -cube_size ) )
2899 geometry.vertices.append( om.MPoint( cube_size, -cube_size, cube_size ) )
2900 geometry.vertices.append( om.MPoint( -cube_size, -cube_size, cube_size ) )
2901 geometry.vertices.append( om.MPoint( -cube_size, cube_size, -cube_size ) )
2902 geometry.vertices.append( om.MPoint( -cube_size, cube_size, cube_size ) )
2903 geometry.vertices.append( om.MPoint( cube_size, cube_size, cube_size ) )
2904 geometry.vertices.append( om.MPoint( cube_size, cube_size, -cube_size ) )
2906 normal_value = 0.5775
2907 geometry.normals.append( om.MVector( -normal_value, -normal_value, -normal_value ) )
2908 geometry.normals.append( om.MVector( normal_value, -normal_value, -normal_value ) )
2909 geometry.normals.append( om.MVector( normal_value, -normal_value, normal_value ) )
2910 geometry.normals.append( om.MVector( -normal_value, -normal_value, normal_value ) )
2911 geometry.normals.append( om.MVector( -normal_value, normal_value, -normal_value ) )
2912 geometry.normals.append( om.MVector( -normal_value, normal_value, normal_value ) )
2913 geometry.normals.append( om.MVector( normal_value, normal_value, normal_value ) )
2914 geometry.normals.append( om.MVector( normal_value, normal_value, -normal_value ) )
2919 uv_pts = [ [ 0.375, 0.0 ],
2936 num_face_connects = 24
2937 uv_fvid = [ 0, 1, 2, 3,
2944 for i
in range(uv_count):
2945 geometry.uvcoords.append_uv( uv_pts[i][0], uv_pts[i][1] )
2947 for i
in range(num_face_connects):
2948 geometry.uvcoords.faceVertexIndex.append( uv_fvid[i] )
2954 face_counts = [ 4, 4, 4, 4, 4, 4 ]
2956 for i
in range(num_faces):
2957 geometry.face_counts.append( face_counts[i] )
2961 face_connects = [ 0, 1, 2, 3,
2968 for i
in range(num_face_connects):
2969 geometry.face_connects.append( face_connects[i] )
2971 def buildSphere(self, radius, divisions, geometry):
2979 geometry.vertices.clear()
2980 geometry.normals.clear()
2981 geometry.face_counts.clear()
2982 geometry.face_connects.clear()
2983 geometry.uvcoords.reset()
2987 u_delta = math.pi / divisions
2988 v_delta = 2 * math.pi / divisions
2990 topPole = om.MPoint( 0.0, radius, 0.0 )
2991 botPole = om.MPoint( 0.0, -radius, 0.0 )
2995 geometry.vertices.append( botPole )
2996 geometry.normals.append( botPole - om.MPoint.kOrigin )
2998 for i
in range(divisions-1):
3002 for j
in range(divisions):
3003 x = radius * math.cos(u) * math.cos(v)
3004 y = radius * math.sin(u)
3005 z = radius * math.cos(u) * math.sin(v)
3007 pnt = om.MPoint( x, y, z )
3008 geometry.vertices.append( pnt )
3009 geometry.normals.append( pnt - om.MPoint.kOrigin )
3012 geometry.vertices.append( topPole )
3013 geometry.normals.append( topPole - om.MPoint.kOrigin )
3019 for i
in range(divisions):
3020 for j
in range(divisions):
3022 geometry.face_counts.append( 3 )
3024 geometry.face_connects.append( 0 )
3025 geometry.face_connects.append( j + vid )
3026 if j == divisions-1:
3027 geometry.face_connects.append( vid )
3029 geometry.face_connects.append( j + vid + 1 )
3031 elif i == divisions-1:
3032 geometry.face_counts.append( 3 )
3034 geometry.face_connects.append( j + vid + 1 - divisions )
3035 geometry.face_connects.append( vid + 1 )
3036 if j == divisions-1:
3037 geometry.face_connects.append( vid + 1 - divisions )
3039 geometry.face_connects.append( j + vid + 2 - divisions )
3042 geometry.face_counts.append( 4 )
3044 geometry.face_connects.append( j + vid + 1 - divisions )
3045 geometry.face_connects.append( j + vid + 1 )
3046 if j == divisions-1:
3047 geometry.face_connects.append( vid + 1 )
3048 geometry.face_connects.append( vid + 1 - divisions )
3050 geometry.face_connects.append( j + vid + 2 )
3051 geometry.face_connects.append( j + vid + 2 - divisions )
3058 class ShadedItemUserData(om.MUserData):
3059 def __init__(self, override):
3060 om.MUserData.__init__(self, legacy=
False)
3061 self.fOverride = override
3065 class apiMeshHWSelectionUserData(om.MUserData):
3067 om.MUserData.__init__(self, legacy=
False)
3068 self.fMeshGeom =
None
3069 self.fInstanceIndex = 0
3070 self.fFaceViewSelectedStates =
None
3073 sViewSelectedInstanceMark = -1
3074 sViewSelectedFaceSelectionNames = set()
3079 def gatherViewSelectedFaceInfo(frameContext, instances, meshGeom):
3080 viewSelectedFaceInfo = collections.defaultdict(list)
3082 if (
not meshGeom
or meshGeom.faceCount <= 0):
3083 return False, viewSelectedFaceInfo
3085 renderingDestinationResult = frameContext.renderingDestination()
3087 if (renderingDestinationResult[0] != omr.MFrameContext.k3dViewport):
3088 return False, viewSelectedFaceInfo
3090 view = omui.M3dView.getM3dViewFromModelPanel(renderingDestinationResult[1])
3092 if(
not view
or not view.viewIsFiltered()):
3093 return False, viewSelectedFaceInfo
3096 viewSelectedList = view.filteredObjectList()
3097 if(viewSelectedList):
3099 for instIdx
in range(len(instances)):
3100 intersectionList = om.MSelectionList()
3102 intersectionList.add(instances[instIdx])
3103 intersectionList.intersect(viewSelectedList,
True)
3105 selectionIt = om.MItSelectionList(intersectionList)
3106 while not selectionIt.isDone():
3107 comp = selectionIt.getComponent()[1]
3110 viewSelectedFaceInfo[instIdx].append(sViewSelectedInstanceMark)
3113 fnComp = om.MFnSingleIndexedComponent(comp)
3115 if (fnComp.componentType == om.MFn.kMeshPolygonComponent):
3116 faceIds = fnComp.getElements()
3118 for i
in range(len(faceIds)):
3120 if (faceId >= 0
and faceId < meshGeom.faceCount):
3121 viewSelectedFaceInfo[instIdx].append(faceId)
3125 return True, viewSelectedFaceInfo
3129 def shouldDrawInstance(viewSelectedFaceInfo, instIdx):
3132 if instIdx
in viewSelectedFaceInfo:
3133 faceIds = viewSelectedFaceInfo[instIdx]
3136 if id != sViewSelectedInstanceMark:
3154 class simpleComponentConverterSubsceneOverride(omr.MPxComponentConverter):
3155 def __init__(self, componentType, selectionType):
3156 omr.MPxComponentConverter.__init__(self)
3158 self.fComponentType = componentType
3159 self.fSelectionType = selectionType
3161 self.fComponent = om.MFnSingleIndexedComponent()
3162 self.fComponentObject = om.MObject.kNullObj
3163 self.fLookupTable = []
3165 def initialize(self, renderItem):
3167 self.fComponentObject = self.fComponent.create( self.fComponentType )
3172 if self.fComponentType == om.MFn.kMeshPolygonComponent:
3173 selectionData = renderItem.getCustomData()
3174 if isinstance(selectionData, apiMeshHWSelectionUserData):
3175 meshGeom = selectionData.fMeshGeom
3176 faceStates = selectionData.fFaceViewSelectedStates
3180 for i
in range(meshGeom.faceCount):
3181 numVerts = meshGeom.face_counts[i]
3183 if(
not faceStates
or faceStates[i]):
3184 numTriangles += numVerts - 2
3186 self.fLookupTable = [0]*numTriangles
3190 for faceId
in range(meshGeom.faceCount):
3192 numVerts = meshGeom.face_counts[faceId]
3194 if(
not faceStates
or faceStates[faceId]):
3195 for v
in range(1, numVerts-1):
3196 self.fLookupTable[triId] = faceId
3199 def addIntersection(self, intersection):
3206 if self.fComponentType == om.MFn.kMeshEdgeComponent:
3209 if intersection.instanceID == 1
or intersection.instanceID == 3:
3212 idx = intersection.index
3214 if self.fComponentType == om.MFn.kMeshPolygonComponent:
3215 if idx >= 0
and idx < len(self.fLookupTable):
3216 idx = self.fLookupTable[idx]
3218 self.fComponent.addElement(idx)
3220 def component(self):
3222 return self.fComponentObject
3224 def selectionMask(self):
3226 return self.fSelectionType
3230 def creatorVertexSelection():
3231 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
3232 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
3233 return simpleComponentConverterSubsceneOverride(om.MFn.kMeshVertComponent, mask)
3237 def creatorEdgeSelection():
3238 return simpleComponentConverterSubsceneOverride(om.MFn.kMeshEdgeComponent, om.MSelectionMask.kSelectMeshEdges)
3242 def creatorFaceSelection():
3243 return simpleComponentConverterSubsceneOverride(om.MFn.kMeshPolygonComponent, om.MSelectionMask.kSelectMeshFaces)
3245 class apiMeshSubSceneOverride(omr.MPxSubSceneOverride):
3246 sWireName =
"apiMeshWire_subscene_py"
3247 sSelectName =
"apiMeshSelection_subscene_py"
3248 sBoxName =
"apiMeshBox_subscene_py"
3249 sSelectedBoxName =
"apiMeshBoxSelection_subscene_py"
3250 sShadedName =
"apiMeshShaded_subscene_py"
3251 sTexturedName =
"apiMeshTextured_subscene_py"
3253 sVertexSelectionName =
"apiMeshVertexSelection_subscene_py"
3254 sEdgeSelectionName =
"apiMeshEdgeSelection_subscene_py"
3255 sFaceSelectionName =
"apiMeshFaceSelection_subscene_py"
3257 sActiveVertexName =
"apiMeshActiveVertex_subscene_py"
3258 sActiveEdgeName =
"apiMeshActiveEdge_subscene_py"
3259 sActiveFaceName =
"apiMeshActiveFace_subscene_py"
3261 sNameSeparator =
"_"
3263 class InstanceInfo(object):
3264 def __init__(self, transform, isSelected):
3265 self.fTransform = transform
3266 self.fIsSelected = isSelected
3270 return apiMeshSubSceneOverride(obj)
3273 def shadedItemLinkLost(userData):
3274 if not userData
is None and not userData.fOverride
is None:
3275 if not userData.fOverride.fMesh
is None:
3276 userData.fOverride.fMesh.setMaterialDirty(
True)
3277 userData.fOverride =
None
3280 def __init__(self, obj):
3281 omr.MPxSubSceneOverride.__init__(self, obj)
3283 node = om.MFnDependencyNode(obj)
3284 self.fMesh = node.userNode()
3285 self.fObject = om.MObject(obj)
3286 self.fWireShader =
None
3287 self.fThickWireShader =
None
3288 self.fSelectShader =
None
3289 self.fThickSelectShader =
None
3290 self.fShadedShader =
None
3291 self.fVertexComponentShader =
None
3292 self.fEdgeComponentShader =
None
3293 self.fFaceComponentShader =
None
3294 self.fPositionBuffer =
None
3295 self.fNormalBuffer =
None
3296 self.fBoxPositionBuffer =
None
3297 self.fWireIndexBuffer =
None
3298 self.fBoxIndexBuffer =
None
3299 self.fShadedIndexBuffer =
None
3300 self.fActiveVerticesIndexBuffer =
None
3301 self.fActiveEdgesIndexBuffer =
None
3302 self.fActiveFacesIndexBuffer =
None
3303 self.fThickLineWidth = -1.0
3304 self.fQueuedLineWidth = -1.0
3305 self.fNumInstances = 0
3306 self.fIsInstanceMode =
False
3307 self.fQueueUpdate =
False
3308 self.fUseQueuedLineUpdate =
False
3310 self.fInstanceInfoCache = collections.defaultdict(set)
3312 self.fActiveVerticesSet = set()
3313 self.fActiveEdgesSet = set()
3314 self.fActiveFacesSet = set()
3316 self.fViewSelectedFaceInfoCache = collections.defaultdict(list)
3317 self.fLinkLostCallbackData = []
3322 shaderMgr = omr.MRenderer.getShaderManager()
3324 if self.fWireShader:
3325 shaderMgr.releaseShader(self.fWireShader)
3326 self.fWireShader =
None
3328 if self.fThickWireShader:
3329 shaderMgr.releaseShader(self.fThickWireShader)
3330 self.fThickWireShader =
None
3332 if self.fSelectShader:
3333 shaderMgr.releaseShader(self.fSelectShader)
3334 self.fSelectShader =
None
3336 if self.fThickSelectShader:
3337 shaderMgr.releaseShader(self.fThickSelectShader)
3338 self.fThickSelectShader =
None
3340 if self.fShadedShader:
3341 shaderMgr.releaseShader(self.fShadedShader)
3342 self.fShadedShader =
None
3344 if self.fVertexComponentShader:
3345 shaderMgr.releaseShader(self.fVertexComponentShader)
3346 self.fVertexComponentShader =
None
3348 if self.fEdgeComponentShader:
3349 shaderMgr.releaseShader(self.fEdgeComponentShader)
3350 self.fEdgeComponentShader =
None
3352 if self.fFaceComponentShader:
3353 shaderMgr.releaseShader(self.fFaceComponentShader)
3354 self.fFaceComponentShader =
None
3358 def supportedDrawAPIs(self):
3360 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
3362 def requiresUpdate(self, container, frameContext):
3364 if len(container) == 0:
3371 def update(self, container, frameContext):
3373 self.manageRenderItems(container, frameContext, self.fMesh.shapeDirty()
or len(container) == 0)
3376 self.fMesh.resetShapeDirty()
3378 def furtherUpdateRequired(self, frameContext):
3379 if self.fUseQueuedLineUpdate:
3380 if not frameContext.inUserInteraction()
and not frameContext.userChangingViewContext():
3381 return self.fQueueUpdate
3385 def manageRenderItems(self, container, frameContext, updateGeometry):
3387 if not self.fMesh
or self.fObject.isNull():
3390 shaderMgr = omr.MRenderer.getShaderManager()
3394 node = om.MFnDagNode(self.fObject)
3395 instances = node.getAllPaths()
3396 if len(instances) == 0:
3400 sRed = [1.0, 0.0, 0.0, 1.0]
3401 sGreen = [0.0, 1.0, 0.0, 1.0]
3402 sWhite = [1.0, 1.0, 1.0, 1.0]
3405 if not self.fWireShader:
3406 self.fWireShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3407 self.fWireShader.setParameter(
"solidColor", sRed)
3409 if not self.fThickWireShader:
3410 self.fThickWireShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3411 self.fThickWireShader.setParameter(
"solidColor", sRed)
3413 if not self.fSelectShader:
3414 self.fSelectShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3415 self.fSelectShader.setParameter(
"solidColor", sGreen)
3417 if not self.fThickSelectShader:
3418 self.fThickSelectShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3419 self.fThickSelectShader.setParameter(
"solidColor", sGreen)
3421 if not self.fVertexComponentShader:
3422 self.fVertexComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dFatPointShader)
3423 self.fVertexComponentShader.setParameter(
"solidColor", sWhite)
3424 self.fVertexComponentShader.setParameter(
"pointSize", [5.0, 5.0])
3426 if not self.fEdgeComponentShader:
3427 self.fEdgeComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3428 self.fEdgeComponentShader.setParameter(
"solidColor", sWhite)
3429 self.fEdgeComponentShader.setParameter(
"lineWidth", [2.0, 2.0])
3431 if not self.fFaceComponentShader:
3432 self.fFaceComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3433 self.fFaceComponentShader.setParameter(
"solidColor", sWhite)
3435 if not self.fShadedShader:
3436 self.fShadedShader = shaderMgr.getStockShader(omr.MShaderManager.k3dBlinnShader)
3440 self.rebuildGeometryBuffers()
3442 if not all((self.fPositionBuffer, self.fNormalBuffer, self.fBoxPositionBuffer, self.fWireIndexBuffer, self.fBoxIndexBuffer, self.fShadedIndexBuffer)):
3445 isActiveViewFiltered, viewSelectedFaceInfo = gatherViewSelectedFaceInfo(frameContext, instances, self.fMesh.meshGeom())
3447 selectedList = om.MGlobal.getActiveSelectionList()
3449 anyMatrixChanged =
False
3450 itemsChanged =
False
3451 instanceArrayLength = len(instances)
3452 numInstanceSelected = 0
3453 numInstanceUnselected = 0
3456 instanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3457 selectedInstanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3458 unselectedInstanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3460 for instIdx
in range(instanceArrayLength):
3466 instance = instances[instIdx]
3467 instanceNum = instance.instanceNumber()
3469 if (instance.isValid
and instance.isVisible
and (
not isActiveViewFiltered
or shouldDrawInstance(viewSelectedFaceInfo, instIdx))):
3470 instanceInfo = apiMeshSubSceneOverride.InstanceInfo(instance.inclusiveMatrix(), useSelectHighlight(selectedList, instance))
3472 if( instanceNum
not in self.fInstanceInfoCache
or
3473 self.fInstanceInfoCache[instanceNum].fIsSelected != instanceInfo.fIsSelected
or
3474 not self.fInstanceInfoCache[instanceNum].fTransform.isEquivalent(instanceInfo.fTransform)):
3476 self.fInstanceInfoCache[instanceNum] = instanceInfo
3477 anyMatrixChanged =
True
3479 instanceMatrixArray[numInstances] = instanceInfo.fTransform
3482 if instanceInfo.fIsSelected:
3483 selectedInstanceMatrixArray[numInstanceSelected] = instanceInfo.fTransform
3484 numInstanceSelected += 1
3486 unselectedInstanceMatrixArray[numInstanceUnselected] = instanceInfo.fTransform
3487 numInstanceUnselected += 1
3489 if (instanceNum
in self.fInstanceInfoCache):
3491 del self.fInstanceInfoCache[instanceNum]
3493 anyMatrixChanged =
True
3495 instanceMatrixArray.setLength(numInstances)
3496 selectedInstanceMatrixArray.setLength(numInstanceSelected)
3497 unselectedInstanceMatrixArray.setLength(numInstanceUnselected)
3498 if self.fNumInstances != numInstances:
3499 anyMatrixChanged =
True
3500 self.fNumInstances = numInstances
3502 anyInstanceSelected = numInstanceSelected > 0
3503 anyInstanceUnselected = numInstanceUnselected > 0
3505 activeVerticesSet = set()
3506 activeEdgesSet = set()
3507 activeFacesSet = set()
3509 meshGeom = self.fMesh.meshGeom()
3510 if meshGeom
and self.fMesh.hasActiveComponents():
3511 activeComponents = self.fMesh.activeComponents()
3512 if len(activeComponents) > 0:
3513 fnComponent = om.MFnSingleIndexedComponent( activeComponents[0] )
3514 if fnComponent.elementCount > 0:
3515 activeIds = fnComponent.getElements()
3517 if fnComponent.componentType == om.MFn.kMeshVertComponent:
3518 activeVerticesSet = set(activeIds)
3520 elif fnComponent.componentType == om.MFn.kMeshEdgeComponent:
3521 activeEdgesSet = set(activeIds)
3523 elif fnComponent.componentType == om.MFn.kMeshPolygonComponent:
3524 activeFacesSet = set(activeIds)
3527 updateActiveItems = updateGeometry
or self.fActiveVerticesSet != activeVerticesSet
or self.fActiveEdgesSet != activeEdgesSet
or self.fActiveFacesSet != activeFacesSet
3528 self.fActiveVerticesSet = activeVerticesSet
3529 self.fActiveEdgesSet = activeEdgesSet
3530 self.fActiveFacesSet = activeFacesSet
3532 if updateActiveItems:
3533 self.rebuildActiveComponentIndexBuffers()
3535 anyVertexSelected = bool(self.fActiveVerticesSet)
3536 anyEdgeSelected = bool(self.fActiveEdgesSet)
3537 anyFaceSelected = bool(self.fActiveFacesSet)
3539 if (anyVertexSelected
and not self.fActiveVerticesIndexBuffer)
or (anyEdgeSelected
and not self.fActiveEdgesIndexBuffer)
or (anyFaceSelected
and not self.fActiveFacesIndexBuffer):
3544 wireItem = container.find(self.sWireName)
3545 if not wireItem
and anyInstanceUnselected:
3546 wireItem = omr.MRenderItem.create( self.sWireName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3547 wireItem.setDrawMode(omr.MGeometry.kWireframe)
3548 wireItem.setDepthPriority(omr.MRenderItem.sActiveWireDepthPriority)
3549 wireItem.setShader(self.fWireShader)
3550 container.add(wireItem)
3553 elif wireItem
and not anyInstanceUnselected:
3554 container.remove(self.sWireName)
3558 selectItem = container.find(self.sSelectName)
3559 if not selectItem
and anyInstanceSelected:
3560 selectItem = omr.MRenderItem.create( self.sSelectName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3561 selectItem.setDrawMode(omr.MGeometry.kWireframe | omr.MGeometry.kShaded | omr.MGeometry.kTextured)
3562 selectItem.setDepthPriority(omr.MRenderItem.sActiveWireDepthPriority)
3563 selectItem.setShader(self.fSelectShader)
3564 container.add(selectItem)
3567 elif selectItem
and not anyInstanceSelected:
3568 container.remove(self.sSelectName)
3572 boxItem = container.find(self.sBoxName)
3573 if not boxItem
and anyInstanceUnselected:
3574 boxItem = omr.MRenderItem.create( self.sBoxName, omr.MRenderItem.NonMaterialSceneItem, omr.MGeometry.kLines)
3575 boxItem.setDrawMode(omr.MGeometry.kBoundingBox)
3576 boxItem.setShader(self.fWireShader)
3577 container.add(boxItem)
3580 elif boxItem
and not anyInstanceUnselected:
3581 container.remove(self.sBoxName)
3585 selectedBoxItem = container.find(self.sSelectedBoxName)
3586 if not selectedBoxItem
and anyInstanceSelected:
3587 selectedBoxItem = omr.MRenderItem.create( self.sSelectedBoxName, omr.MRenderItem.NonMaterialSceneItem, omr.MGeometry.kLines)
3588 selectedBoxItem.setDrawMode(omr.MGeometry.kBoundingBox)
3589 selectedBoxItem.setShader(self.fSelectShader)
3590 container.add(selectedBoxItem)
3593 elif selectedBoxItem
and not anyInstanceSelected:
3594 container.remove(self.sSelectedBoxName)
3595 selectedBoxItem =
None
3598 shadedItem = container.find(self.sShadedName)
3601 shadedItem = omr.MRenderItem.create( self.sShadedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
3602 shadedItem.setDrawMode(omr.MGeometry.kShaded)
3603 shadedItem.setExcludedFromPostEffects(
False)
3604 shadedItem.setCastsShadows(
True)
3605 shadedItem.setReceivesShadows(
True)
3606 container.add(shadedItem)
3609 texturedItem = container.find(self.sTexturedName)
3610 if not texturedItem:
3612 texturedItem = omr.MRenderItem.create( self.sTexturedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
3613 texturedItem.setDrawMode(omr.MGeometry.kTextured)
3614 texturedItem.setExcludedFromPostEffects(
False)
3615 texturedItem.setCastsShadows(
True)
3616 texturedItem.setReceivesShadows(
True)
3617 container.add(texturedItem)
3626 connectedPlugs = om.MPlugArray()
3627 (sets, comps) = node.getConnectedSetsAndMembers(0,
True)
3629 dn = om.MFnDependencyNode(obj)
3630 shaderPlug = dn.findPlug(
"surfaceShader",
True)
3631 connectedPlugs = shaderPlug.connectedTo(
True,
False)
3632 if len(connectedPlugs) > 0:
3633 shader = connectedPlugs[0].node()
3638 updateMaterial = self.fMesh.materialDirty()
3639 self.fMesh.setMaterialDirty(
False)
3642 if updateMaterial
or not shadedItem.isShaderFromNode():
3644 not shadedItem.setShaderFromNode(shader,
3646 apiMeshSubSceneOverride.shadedItemLinkLost,
3647 ShadedItemUserData(self),
3649 shadedItem.setShader(self.fShadedShader)
3652 if updateMaterial
or not texturedItem.isShaderFromNode():
3654 not texturedItem.setShaderFromNode(shader,
3656 apiMeshSubSceneOverride.shadedItemLinkLost,
3657 ShadedItemUserData(self),
3659 texturedItem.setShader(self.fShadedShader)
3661 print(
"Unexpected error:", sys.exc_info()[0])
3665 vertexSelectionItem = container.find(self.sVertexSelectionName)
3666 if not vertexSelectionItem:
3667 vertexSelectionItem = omr.MRenderItem.create( self.sVertexSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
3669 vertexSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
3671 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
3672 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
3673 vertexSelectionItem.setSelectionMask( mask )
3675 vertexSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
3676 vertexSelectionItem.setShader(self.fVertexComponentShader)
3677 container.add(vertexSelectionItem)
3683 useDrawInstancingOnEdgeSelectionItem =
False
3686 edgeSelectionItem = container.find(self.sEdgeSelectionName)
3687 if not edgeSelectionItem:
3689 drawMode = omr.MGeometry.kSelectionOnly
3690 depthPriority = omr.MRenderItem.sSelectionDepthPriority
3691 if useDrawInstancingOnEdgeSelectionItem:
3693 drawMode = omr.MGeometry.kAll
3695 depthPriority = omr.MRenderItem.sActiveWireDepthPriority-1
3697 edgeSelectionItem = omr.MRenderItem.create( self.sEdgeSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3698 edgeSelectionItem.setDrawMode(drawMode)
3700 edgeSelectionItem.setDepthPriority(depthPriority)
3702 edgeSelectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshEdges )
3703 edgeSelectionItem.setShader(self.fWireShader)
3704 container.add(edgeSelectionItem)
3708 faceSelectionItem = container.find(self.sFaceSelectionName)
3709 if not faceSelectionItem:
3710 faceSelectionItem = omr.MRenderItem.create( self.sFaceSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
3712 faceSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
3714 faceSelectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshFaces )
3716 faceSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
3717 faceSelectionItem.setShader(self.fFaceComponentShader)
3718 container.add(faceSelectionItem)
3723 mySelectionData = apiMeshHWSelectionUserData()
3724 mySelectionData.fMeshGeom = self.fMesh.meshGeom()
3725 faceSelectionItem.setCustomData(mySelectionData)
3728 activeVertexItem = container.find(self.sActiveVertexName)
3729 if not activeVertexItem
and anyVertexSelected:
3730 activeVertexItem = omr.MRenderItem.create( self.sActiveVertexName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
3731 activeVertexItem.setDrawMode(omr.MGeometry.kAll)
3732 activeVertexItem.setDepthPriority(omr.MRenderItem.sActivePointDepthPriority)
3733 activeVertexItem.setShader(self.fVertexComponentShader)
3734 container.add(activeVertexItem)
3737 elif activeVertexItem
and not anyVertexSelected:
3738 container.remove(self.sActiveVertexName)
3739 activeVertexItem =
None
3743 activeEdgeItem = container.find(self.sActiveEdgeName)
3744 if not activeEdgeItem
and anyEdgeSelected:
3745 activeEdgeItem = omr.MRenderItem.create( self.sActiveEdgeName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3746 activeEdgeItem.setDrawMode(omr.MGeometry.kAll)
3747 activeEdgeItem.setDepthPriority(omr.MRenderItem.sActiveLineDepthPriority)
3748 activeEdgeItem.setShader(self.fEdgeComponentShader)
3749 container.add(activeEdgeItem)
3752 elif activeEdgeItem
and not anyEdgeSelected:
3753 container.remove(self.sActiveEdgeName)
3754 activeEdgeItem =
None
3758 activeFaceItem = container.find(self.sActiveFaceName)
3759 if not activeFaceItem
and anyFaceSelected:
3760 activeFaceItem = omr.MRenderItem.create( self.sActiveFaceName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
3761 activeFaceItem.setDrawMode(omr.MGeometry.kAll)
3762 activeFaceItem.setDepthPriority(omr.MRenderItem.sActiveLineDepthPriority)
3763 activeFaceItem.setShader(self.fFaceComponentShader)
3764 container.add(activeFaceItem)
3767 elif activeFaceItem
and not anyFaceSelected:
3768 container.remove(self.sActiveFaceName)
3769 activeFaceItem =
None
3773 lineWidth = frameContext.getGlobalLineWidth()
3774 userWidthChange =
not floatApproxEqual(lineWidth, self.fThickLineWidth)
3777 targetRefinedLineWidth = 50.0
3779 self.fThickLineWidth = lineWidth
3783 if self.fUseQueuedLineUpdate:
3784 self.fQueuedLineWidth = lineWidth
3785 if self.fQueuedLineWidth < targetRefinedLineWidth:
3786 self.fQueueUpdate =
True
3792 if self.fUseQueuedLineUpdate
and self.fQueueUpdate:
3793 if self.fQueuedLineWidth < targetRefinedLineWidth:
3794 lineWidth = self.fQueuedLineWidth
3795 self.fQueuedLineWidth += 1
3796 self.fQueueUpdate =
True
3801 self.fQueueUpdate =
False
3804 if not floatApproxEqual(lineWidth, 1.0):
3806 lineWidthArray = [ lineWidth, lineWidth ]
3807 self.fThickWireShader.setParameter(
"lineWidth", lineWidthArray)
3808 self.fThickSelectShader.setParameter(
"lineWidth", lineWidthArray)
3810 wireItem.setShader(self.fThickWireShader)
3812 selectItem.setShader(self.fThickSelectShader)
3816 wireItem.setShader(self.fWireShader)
3818 selectItem.setShader(self.fSelectShader)
3821 if itemsChanged
or updateGeometry:
3822 bounds = self.fMesh.boundingBox()
3824 wireBuffers = omr.MVertexBufferArray()
3825 wireBuffers.append(self.fPositionBuffer,
"positions")
3827 self.setGeometryForRenderItem(wireItem, wireBuffers, self.fWireIndexBuffer, bounds)
3829 self.setGeometryForRenderItem(selectItem, wireBuffers, self.fWireIndexBuffer, bounds)
3831 boxBuffers = omr.MVertexBufferArray()
3832 boxBuffers.append(self.fBoxPositionBuffer,
"positions")
3834 self.setGeometryForRenderItem(boxItem, boxBuffers, self.fBoxIndexBuffer, bounds)
3836 self.setGeometryForRenderItem(selectedBoxItem, boxBuffers, self.fBoxIndexBuffer, bounds)
3838 shadedBuffers = omr.MVertexBufferArray()
3839 shadedBuffers.append(self.fPositionBuffer,
"positions")
3840 shadedBuffers.append(self.fNormalBuffer,
"normals")
3841 self.setGeometryForRenderItem(shadedItem, shadedBuffers, self.fShadedIndexBuffer, bounds)
3842 self.setGeometryForRenderItem(texturedItem, shadedBuffers, self.fShadedIndexBuffer, bounds)
3845 self.setGeometryForRenderItem(vertexSelectionItem, wireBuffers, objectBox = bounds)
3846 self.setGeometryForRenderItem(edgeSelectionItem, wireBuffers, self.fWireIndexBuffer, bounds)
3847 self.setGeometryForRenderItem(faceSelectionItem, wireBuffers, self.fShadedIndexBuffer, bounds)
3850 if itemsChanged
or updateActiveItems:
3851 bounds = self.fMesh.boundingBox()
3853 vertexBuffer = omr.MVertexBufferArray()
3854 vertexBuffer.append(self.fPositionBuffer,
"positions")
3856 if activeVertexItem:
3857 self.setGeometryForRenderItem(activeVertexItem, vertexBuffer, self.fActiveVerticesIndexBuffer, bounds)
3859 self.setGeometryForRenderItem(activeEdgeItem, vertexBuffer, self.fActiveEdgesIndexBuffer, bounds)
3861 self.setGeometryForRenderItem(activeFaceItem, vertexBuffer, self.fActiveFacesIndexBuffer, bounds)
3864 if itemsChanged
or anyMatrixChanged:
3865 if not self.fIsInstanceMode
and numInstances == 1:
3868 objToWorld = instanceMatrixArray[0]
3871 wireItem.setMatrix(objToWorld)
3873 selectItem.setMatrix(objToWorld)
3875 boxItem.setMatrix(objToWorld)
3877 selectedBoxItem.setMatrix(objToWorld)
3878 shadedItem.setMatrix(objToWorld)
3879 texturedItem.setMatrix(objToWorld)
3881 vertexSelectionItem.setMatrix(objToWorld)
3882 edgeSelectionItem.setMatrix(objToWorld)
3883 faceSelectionItem.setMatrix(objToWorld)
3885 if useDrawInstancingOnEdgeSelectionItem:
3888 transform1 = objToWorld
3891 transform2 = objToWorld * 2
3894 transform3 = objToWorld * 3
3898 transforms = om.MMatrixArray((transform1, transform2, transform3))
3899 self.setInstanceTransformArray(edgeSelectionItem, transforms)
3904 self.removeAllInstances(edgeSelectionItem)
3908 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform1)
3909 print(
"newInstanceId " + str(newInstanceId))
3910 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform2)
3911 print(
"newInstanceId " + str(newInstanceId))
3912 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform3)
3913 print(
"newInstanceId " + str(newInstanceId))
3915 if activeVertexItem:
3916 activeVertexItem.setMatrix(objToWorld)
3918 activeEdgeItem.setMatrix(objToWorld)
3920 activeFaceItem.setMatrix(objToWorld)
3935 self.setInstanceTransformArray(wireItem, unselectedInstanceMatrixArray)
3937 self.setInstanceTransformArray(selectItem, selectedInstanceMatrixArray)
3939 self.setInstanceTransformArray(boxItem, unselectedInstanceMatrixArray)
3941 self.setInstanceTransformArray(selectedBoxItem, selectedInstanceMatrixArray)
3942 self.setInstanceTransformArray(shadedItem, instanceMatrixArray)
3943 self.setInstanceTransformArray(texturedItem, instanceMatrixArray)
3945 self.setInstanceTransformArray(vertexSelectionItem, instanceMatrixArray)
3946 self.setInstanceTransformArray(edgeSelectionItem, instanceMatrixArray)
3947 self.setInstanceTransformArray(faceSelectionItem, instanceMatrixArray)
3949 if activeVertexItem:
3950 self.setInstanceTransformArray(activeVertexItem, instanceMatrixArray)
3952 self.setInstanceTransformArray(activeEdgeItem, instanceMatrixArray)
3954 self.setInstanceTransformArray(activeFaceItem, instanceMatrixArray)
3959 self.fIsInstanceMode =
True
3961 self.manageIsolateSelectRenderItems(container, frameContext, instances, viewSelectedFaceInfo, shader, updateMaterial, updateGeometry)
3963 if itemsChanged
or anyMatrixChanged
or updateGeometry:
3965 omr.MRenderer.setLightsAndShadowsDirty()
3967 def manageIsolateSelectRenderItems(self, container, frameContext, instances, viewSelectedFaceInfo, shader, updateMaterial, updateGeometry):
3968 if (
not self.fMesh):
3971 meshGeom = self.fMesh.meshGeom()
3976 destination = frameContext.renderingDestination()
3977 if (destination[0] != omr.MFrameContext.k3dViewport):
3981 activeViewName = destination[1]
3983 updateViewSelectedFaces =
False
3985 if(activeViewName
not in self.fViewSelectedFaceInfoCache):
3987 if(len(viewSelectedFaceInfo) != 0):
3988 updateViewSelectedFaces =
True
3990 elif(self.fViewSelectedFaceInfoCache[activeViewName] != viewSelectedFaceInfo):
3991 updateViewSelectedFaces =
True
3996 if updateViewSelectedFaces:
3999 prevInstIdxArray = set()
4000 if (activeViewName
in self.fViewSelectedFaceInfoCache):
4001 prevInfo = self.fViewSelectedFaceInfoCache[activeViewName]
4002 for instIdx, faceIdxList
in list(prevInfo.items()):
4003 for faceIdx
in faceIdxList:
4004 if faceIdx != sViewSelectedInstanceMark:
4005 prevInstIdxArray.add(instIdx)
4008 currInstIdxArray = set()
4009 for instIdx, faceIdxList
in list(viewSelectedFaceInfo.items()):
4010 for faceIdx
in faceIdxList:
4011 if (faceIdx != sViewSelectedInstanceMark):
4012 currInstIdxArray.add(instIdx)
4015 self.fViewSelectedFaceInfoCache[activeViewName] = viewSelectedFaceInfo
4021 diffInstIdxArray = prevInstIdxArray - currInstIdxArray
4023 for instIdx
in diffInstIdxArray:
4024 namePostfix = self.sNameSeparator + str(instIdx) + self.sNameSeparator + activeViewName
4026 shadedName = self.sShadedName + namePostfix
4027 container.remove(shadedName)
4029 texturedName = self.sTexturedName + namePostfix
4030 container.remove(texturedName)
4032 faceSelectionName = self.sFaceSelectionName + namePostfix
4033 container.remove(faceSelectionName)
4037 for instIdx
in currInstIdxArray:
4038 namePostfix = self.sNameSeparator + str(instIdx) + self.sNameSeparator + activeViewName
4040 shadedName = self.sShadedName + namePostfix
4041 viewSelectedShadedItem = container.find(shadedName)
4042 if not viewSelectedShadedItem:
4044 viewSelectedShadedItem = omr.MRenderItem.create(shadedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
4045 viewSelectedShadedItem.setDrawMode(omr.MGeometry.kShaded)
4046 viewSelectedShadedItem.setExcludedFromPostEffects(
False)
4047 viewSelectedShadedItem.setCastsShadows(
True)
4048 viewSelectedShadedItem.setReceivesShadows(
True)
4050 container.add(viewSelectedShadedItem)
4052 userData = apiMeshHWSelectionUserData()
4053 userData.fMeshGeom = meshGeom
4054 userData.fInstanceIndex = instIdx
4055 viewSelectedShadedItem.setCustomData(userData)
4057 texturedName = self.sTexturedName + namePostfix
4058 viewSelectedTexturedItem = container.find(texturedName)
4059 if not viewSelectedTexturedItem:
4061 viewSelectedTexturedItem = omr.MRenderItem.create(texturedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
4063 viewSelectedTexturedItem.setDrawMode(omr.MGeometry.kTextured)
4064 viewSelectedTexturedItem.setExcludedFromPostEffects(
False)
4065 viewSelectedTexturedItem.setCastsShadows(
True)
4066 viewSelectedTexturedItem.setReceivesShadows(
True)
4067 container.add(viewSelectedTexturedItem)
4069 userData = apiMeshHWSelectionUserData()
4070 userData.fMeshGeom = meshGeom
4071 userData.fInstanceIndex = instIdx
4072 viewSelectedTexturedItem.setCustomData(userData)
4074 faceSelectionName = self.sFaceSelectionName + namePostfix
4075 viewSelectedFaceSelectionItem = container.find(faceSelectionName)
4076 if not viewSelectedFaceSelectionItem:
4078 viewSelectedFaceSelectionItem = omr.MRenderItem.create(faceSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
4081 viewSelectedFaceSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
4083 viewSelectedFaceSelectionItem.setSelectionMask(om.MSelectionMask.kSelectMeshFaces)
4085 viewSelectedFaceSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
4086 viewSelectedFaceSelectionItem.setShader(self.fFaceComponentShader)
4087 container.add(viewSelectedFaceSelectionItem)
4089 userData = apiMeshHWSelectionUserData()
4090 userData.fMeshGeom = meshGeom
4091 userData.fInstanceIndex = instIdx
4092 viewSelectedFaceSelectionItem.setCustomData(userData)
4095 if (faceSelectionName
not in sViewSelectedFaceSelectionNames):
4096 omr.MDrawRegistry.registerComponentConverter(faceSelectionName, simpleComponentConverterSubsceneOverride.creatorFaceSelection)
4097 sViewSelectedFaceSelectionNames.add(faceSelectionName)
4102 for key
in self.fViewSelectedFaceInfoCache:
4104 faceInfo = self.fViewSelectedFaceInfoCache[key]
4105 isActiveView = viewName == activeViewName
4107 instIdxArray = set()
4108 for instIdx
in faceInfo:
4109 faceIdx = faceInfo[instIdx]
4110 if (faceIdx != sViewSelectedInstanceMark):
4111 instIdxArray.add(instIdx)
4113 for instIdx
in instIdxArray:
4114 namePostfix = self.sNameSeparator + str(instIdx) + self.sNameSeparator + viewName
4116 viewSelectedShadedItem = container.find(self.sShadedName + namePostfix)
4117 viewSelectedTexturedItem = container.find(self.sTexturedName + namePostfix)
4118 viewSelectedFaceSelectionItem = container.find(self.sFaceSelectionName + namePostfix)
4119 if (
not viewSelectedShadedItem
or not viewSelectedTexturedItem
or not viewSelectedFaceSelectionItem):
4123 viewSelectedShadedItem.enable(isActiveView)
4124 viewSelectedTexturedItem.enable(isActiveView)
4125 viewSelectedFaceSelectionItem.enable(isActiveView)
4128 instance = instances[instIdx]
4129 objToWorld = instance.inclusiveMatrix()
4130 viewSelectedShadedItem.setMatrix(objToWorld)
4131 viewSelectedTexturedItem.setMatrix(objToWorld)
4132 viewSelectedFaceSelectionItem.setMatrix(objToWorld)
4135 if (updateViewSelectedFaces
or updateMaterial
or updateGeometry):
4137 if (updateMaterial
or not viewSelectedShadedItem.isShaderFromNode()):
4139 userData = ShadedItemUserData(self)
4141 if shader
and viewSelectedShadedItem.setShaderFromNode(shader, instance, apiMeshSubSceneOverride.shadedItemLinkLost, userData,
True):
4142 self.fLinkLostCallbackData.append(userData)
4144 viewSelectedShadedItem.setShader(self.fShadedShader)
4146 if (updateMaterial
or not viewSelectedTexturedItem.isShaderFromNode()):
4147 userData = ShadedItemUserData(self)
4149 if shader
and viewSelectedTexturedItem.setShaderFromNode(shader, instance, apiMeshSubSceneOverride.shadedItemLinkLost, userData,
True):
4150 self.fLinkLostCallbackData.append(userData)
4152 viewSelectedTexturedItem.setShader(self.fShadedShader)
4154 shadedBuffers = omr.MVertexBufferArray()
4155 shadedBuffers.append(self.fPositionBuffer,
"positions")
4156 shadedBuffers.append(self.fNormalBuffer,
"normals")
4158 selectionBuffers = omr.MVertexBufferArray()
4159 selectionBuffers.append(self.fPositionBuffer,
"positions")
4162 for faceIdx
in range(meshGeom.faceCount):
4163 faceStates.append(
False)
4165 faceIds = faceInfo[instIdx]
4166 for faceIdx
in faceIds:
4167 if (faceIdx != sViewSelectedInstanceMark):
4168 faceStates[faceIdx] =
True
4171 for faceIdx
in range(meshGeom.faceCount):
4172 numVerts = meshGeom.face_counts[faceIdx]
4174 if faceStates[faceIdx]:
4175 numTriangles += numVerts - 2
4177 indexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4178 bufferSize = numTriangles * 3
4180 dataAddress = indexBuffer.acquire(bufferSize,
True)
4182 data = (ctypes.c_uint * bufferSize).from_address(dataAddress)
4186 for faceIdx
in range(meshGeom.faceCount):
4188 numVerts = meshGeom.face_counts[faceIdx]
4190 if (faceStates[faceIdx]):
4191 for v
in range(1, numVerts - 1):
4192 data[idx] = meshGeom.face_connects[base]
4194 data[idx] = meshGeom.face_connects[base + v]
4196 data[idx] = meshGeom.face_connects[base + v + 1]
4199 indexBuffer.commit(dataAddress)
4202 bounds = self.fMesh.boundingBox()
4203 self.setGeometryForRenderItem(viewSelectedShadedItem, shadedBuffers, indexBuffer, bounds)
4204 self.setGeometryForRenderItem(viewSelectedTexturedItem, shadedBuffers, indexBuffer, bounds)
4205 self.setGeometryForRenderItem(viewSelectedFaceSelectionItem, selectionBuffers, indexBuffer, bounds)
4208 userData = viewSelectedShadedItem.getCustomData()
4209 if userData
and isinstance(userData, apiMeshHWSelectionUserData):
4210 userData.fMeshGeom = meshGeom
4212 userData = viewSelectedTexturedItem.getCustomData()
4213 if userData
and isinstance(userData, apiMeshHWSelectionUserData):
4214 userData.fMeshGeom = meshGeom
4216 userData = viewSelectedFaceSelectionItem.getCustomData()
4217 if userData
and isinstance(userData, apiMeshHWSelectionUserData):
4218 userData.fMeshGeom = meshGeom
4219 userData.fFaceViewSelectedStates = faceStates
4221 def rebuildGeometryBuffers(self):
4223 meshGeom = self.fMesh.meshGeom()
4226 bounds = self.fMesh.boundingBox()
4229 self.clearGeometryBuffers()
4234 totalPoints = len(meshGeom.vertices)
4235 for i
in range(meshGeom.faceCount):
4236 numVerts = meshGeom.face_counts[i]
4238 numTriangles += numVerts - 2
4239 totalVerts += numVerts
4242 posDesc = omr.MVertexBufferDescriptor(
"", omr.MGeometry.kPosition, omr.MGeometry.kFloat, 3)
4243 normalDesc = omr.MVertexBufferDescriptor(
"", omr.MGeometry.kNormal, omr.MGeometry.kFloat, 3)
4245 self.fPositionBuffer = omr.MVertexBuffer(posDesc)
4246 self.fNormalBuffer = omr.MVertexBuffer(normalDesc)
4247 self.fBoxPositionBuffer = omr.MVertexBuffer(posDesc)
4249 positionDataAddress = self.fPositionBuffer.acquire(totalPoints,
True)
4250 normalDataAddress = self.fNormalBuffer.acquire(totalPoints,
True)
4251 boxPositionDataAddress = self.fBoxPositionBuffer.acquire(8,
True)
4254 self.fWireIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4255 self.fBoxIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4256 self.fShadedIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4258 wireBufferDataAddress = self.fWireIndexBuffer.acquire(2*totalVerts,
True)
4259 boxBufferDataAddress = self.fBoxIndexBuffer.acquire(24,
True)
4260 shadedBufferDataAddress = self.fShadedIndexBuffer.acquire(3*numTriangles,
True)
4263 if not all((positionDataAddress, normalDataAddress, boxPositionDataAddress, wireBufferDataAddress, boxBufferDataAddress, shadedBufferDataAddress)):
4264 self.clearGeometryBuffers()
4267 positionData = ((ctypes.c_float * 3)*totalPoints).from_address(positionDataAddress)
4268 normalData = ((ctypes.c_float * 3)*totalPoints).from_address(normalDataAddress)
4269 boxPositionData = ((ctypes.c_float * 3)*8).from_address(boxPositionDataAddress)
4271 wireBufferData = (ctypes.c_uint * (2*totalVerts)).from_address(wireBufferDataAddress)
4272 boxBufferData = (ctypes.c_uint * 24).from_address(boxBufferDataAddress)
4273 shadedBufferData = ((ctypes.c_uint * 3)*numTriangles).from_address(shadedBufferDataAddress)
4276 for vid,position
in enumerate(meshGeom.vertices):
4277 positionData[vid][0] = position[0]
4278 positionData[vid][1] = position[1]
4279 positionData[vid][2] = position[2]
4281 for vid,normal
in enumerate(meshGeom.normals):
4282 normalData[vid][0] = normal[0]
4283 normalData[vid][1] = normal[1]
4284 normalData[vid][2] = normal[2]
4286 self.fPositionBuffer.commit(positionDataAddress)
4287 positionDataAddress =
None
4288 self.fNormalBuffer.commit(normalDataAddress)
4289 normalDataAddress =
None
4294 boxPositionData[0][0] = bbmin.x
4295 boxPositionData[0][1] = bbmin.y
4296 boxPositionData[0][2] = bbmin.z
4298 boxPositionData[1][0] = bbmin.x
4299 boxPositionData[1][1] = bbmin.y
4300 boxPositionData[1][2] = bbmax.z
4302 boxPositionData[2][0] = bbmax.x
4303 boxPositionData[2][1] = bbmin.y
4304 boxPositionData[2][2] = bbmax.z
4306 boxPositionData[3][0] = bbmax.x
4307 boxPositionData[3][1] = bbmin.y
4308 boxPositionData[3][2] = bbmin.z
4310 boxPositionData[4][0] = bbmin.x
4311 boxPositionData[4][1] = bbmax.y
4312 boxPositionData[4][2] = bbmin.z
4314 boxPositionData[5][0] = bbmin.x
4315 boxPositionData[5][1] = bbmax.y
4316 boxPositionData[5][2] = bbmax.z
4318 boxPositionData[6][0] = bbmax.x
4319 boxPositionData[6][1] = bbmax.y
4320 boxPositionData[6][2] = bbmax.z
4322 boxPositionData[7][0] = bbmax.x
4323 boxPositionData[7][1] = bbmax.y
4324 boxPositionData[7][2] = bbmin.z
4326 self.fBoxPositionBuffer.commit(boxPositionDataAddress)
4327 boxPositionDataAddress =
None
4333 for i
in range(meshGeom.faceCount):
4335 numVerts = meshGeom.face_counts[i]
4338 for v
in range(numVerts-1):
4339 wireBufferData[idx] = meshGeom.face_connects[vid]
4342 wireBufferData[idx] = meshGeom.face_connects[vid]
4345 wireBufferData[idx] = meshGeom.face_connects[vid]
4348 wireBufferData[idx] = meshGeom.face_connects[first]
4354 self.fWireIndexBuffer.commit(wireBufferDataAddress)
4355 wireBufferDataAddress =
None
4358 indexData = [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ]
4360 boxBufferData[i] = indexData[i]
4362 self.fBoxIndexBuffer.commit(boxBufferDataAddress)
4363 boxBufferDataAddress =
None
4368 for i
in range(meshGeom.faceCount):
4370 numVerts = meshGeom.face_counts[i]
4372 for v
in range(1, numVerts-1):
4373 shadedBufferData[idx][0] = meshGeom.face_connects[base]
4374 shadedBufferData[idx][1] = meshGeom.face_connects[base+v]
4375 shadedBufferData[idx][2] = meshGeom.face_connects[base+v+1]
4380 self.fShadedIndexBuffer.commit(shadedBufferDataAddress)
4381 shadedBufferDataAddress =
None
4383 def rebuildActiveComponentIndexBuffers(self):
4385 meshGeom = self.fMesh.meshGeom()
4390 self.clearActiveComponentIndexBuffers()
4393 numActiveVertices = len(self.fActiveVerticesSet)
4394 if numActiveVertices > 0:
4395 self.fActiveVerticesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4396 activeVerticesDataAddress = self.fActiveVerticesIndexBuffer.acquire(numActiveVertices,
True)
4397 if activeVerticesDataAddress:
4398 activeVerticesData = (ctypes.c_uint*numActiveVertices).from_address(activeVerticesDataAddress)
4401 for vid
in self.fActiveVerticesSet:
4402 activeVerticesData[idx] = vid
4405 self.fActiveVerticesIndexBuffer.commit(activeVerticesDataAddress)
4406 activeVerticesDataAddress =
None
4409 numActiveEdges = len(self.fActiveEdgesSet)
4410 if numActiveEdges > 0:
4411 self.fActiveEdgesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4412 activeEdgesDataAddress = self.fActiveEdgesIndexBuffer.acquire(2*numActiveEdges,
True)
4413 if activeEdgesDataAddress:
4414 activeEdgesData = ((ctypes.c_uint * 2)*numActiveEdges).from_address(activeEdgesDataAddress)
4420 for i
in range(meshGeom.faceCount):
4422 numVerts = meshGeom.face_counts[i]
4425 for v
in range(numVerts-1):
4426 if eid
in self.fActiveEdgesSet:
4427 activeEdgesData[idx][0] = meshGeom.face_connects[vid]
4428 activeEdgesData[idx][1] = meshGeom.face_connects[vid + 1]
4433 if eid
in self.fActiveEdgesSet:
4434 activeEdgesData[idx][0] = meshGeom.face_connects[vid]
4435 activeEdgesData[idx][1] = meshGeom.face_connects[first]
4442 self.fActiveEdgesIndexBuffer.commit(activeEdgesDataAddress)
4443 activeEdgesDataAddress =
None
4446 numActiveFaces = len(self.fActiveFacesSet)
4447 if numActiveFaces > 0:
4448 numActiveFacesTriangles = 0
4449 for i
in range(meshGeom.faceCount):
4450 if i
in self.fActiveFacesSet:
4451 numVerts = meshGeom.face_counts[i]
4453 numActiveFacesTriangles += numVerts - 2
4455 self.fActiveFacesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4456 activeFacesDataAddress = self.fActiveFacesIndexBuffer.acquire(3*numActiveFacesTriangles,
True)
4457 if activeFacesDataAddress:
4458 activeFacesData = ((ctypes.c_uint * 3)*numActiveFacesTriangles).from_address(activeFacesDataAddress)
4462 for i
in range(meshGeom.faceCount):
4463 numVerts = meshGeom.face_counts[i]
4465 if i
in self.fActiveFacesSet:
4466 for v
in range(1, numVerts-1):
4467 activeFacesData[idx][0] = meshGeom.face_connects[vid]
4468 activeFacesData[idx][1] = meshGeom.face_connects[vid+v]
4469 activeFacesData[idx][2] = meshGeom.face_connects[vid+v+1]
4474 self.fActiveFacesIndexBuffer.commit(activeFacesDataAddress)
4475 activeFacesDataAddress =
None
4477 def clearBuffers(self):
4478 self.clearGeometryBuffers()
4479 self.clearActiveComponentIndexBuffers()
4481 def clearGeometryBuffers(self):
4482 self.fPositionBuffer =
None
4483 self.fNormalBuffer =
None
4484 self.fBoxPositionBuffer =
None
4485 self.fWireIndexBuffer =
None
4486 self.fBoxIndexBuffer =
None
4487 self.fShadedIndexBuffer =
None
4489 def clearActiveComponentIndexBuffers(self):
4490 self.fActiveVerticesIndexBuffer =
None
4491 self.fActiveEdgesIndexBuffer =
None
4492 self.fActiveFacesIndexBuffer =
None
4494 def updateSelectionGranularity(self, path, selectionContext):
4505 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4506 if displayStatus == omr.MGeometryUtilities.kHilite:
4508 globalComponentMask = om.MGlobal.objectSelectionMask()
4509 if om.MGlobal.selectionMode() == om.MGlobal.kSelectComponentMode:
4510 globalComponentMask = om.MGlobal.componentSelectionMask()
4512 supportedComponentMask = om.MSelectionMask( om.MSelectionMask.kSelectMeshVerts )
4513 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshEdges )
4514 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshFaces )
4515 supportedComponentMask.addMask( om.MSelectionMask.kSelectPointsForGravity )
4517 if globalComponentMask.intersects(supportedComponentMask):
4518 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4519 elif omr.MPxSubSceneOverride.pointSnappingActive():
4520 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4522 def getSelectionPath(self, renderItem, dagPath):
4523 node = om.MFnDagNode(self.fObject)
4527 instances = node.getAllPaths()
4528 if not instances
or len(instances) == 0:
4531 dagPath.set(instances[0])
4534 def getInstancedSelectionPath(self, renderItem, intersection, dagPath):
4535 node = om.MFnDagNode(self.fObject)
4539 instances = node.getAllPaths()
4540 instanceCount = len(instances)
4541 if not instances
or instanceCount == 0:
4544 instanceId = intersection.instanceID
4547 if(instanceCount == 1
or instanceId == -1):
4549 userData = renderItem.getCustomData()
4551 isinstance(userData, apiMeshHWSelectionUserData)
and
4552 userData.fInstanceIndex >= 0
and
4553 userData.fInstanceIndex < instanceCount):
4554 instanceId = userData.fInstanceIndex
4556 dagPath.set(instances[instanceId])
4563 elif(instanceId >=1
and instanceId <= instanceCount):
4564 view = omui.M3dView.active3dView()
4565 if view.viewIsFiltered():
4567 viewSelectedList = view.filteredObjectList()
4568 if viewSelectedList:
4569 for instIdx
in range(instanceCount):
4570 instance = instances[instIdx]
4571 if instance.isValid()
and instance.isVisible():
4572 intersectionList = om.MSelectionList()
4574 intersectionList.add(instance)
4575 intersectionList.intersect(viewSelectedList,
True)
4577 selectionIt = om.MItSelectionList(intersectionList)
4578 while not selectionIt.isDone():
4579 comp = selectionIt.getComponent()[1]
4582 instanceId = instanceId - 1
4584 dagPath.set(instance)
4588 for instIdx
in range(instanceCount):
4589 instance = instances[instIdx]
4590 if (instance.isValid()
and instance.isVisible()):
4591 instanceId = instanceId - 1
4592 if (instanceId == 0):
4593 dagPath.set(instance)
4607 class apiMeshUserData(om.MUserData):
4609 om.MUserData.__init__(self,
True)
4611 self.fNumModifications = 0
4614 def callbackDataPrint(context, renderItemList):
4615 for item
in renderItemList:
4617 path = item.sourceDagPath()
4618 print(
"\tITEM: '" + item.name() +
"' -- SOURCE: '" + path.fullPathName() +
"'")
4620 passCtx = context.getPassContext()
4621 passId = passCtx.passIdentifier()
4622 passSem = passCtx.passSemantics()
4623 print(
"\tAPI mesh drawing in pass[" + passId +
"], semantic[" + passSem +
"]")
4626 def apiMeshPreDrawCallback(context, renderItemList, shaderInstance):
4627 print(
"PRE-draw callback triggered for render item list with data:")
4628 callbackDataPrint(context, renderItemList)
4631 def apiMeshPostDrawCallback(context, renderItemList, shaderInstance):
4632 print(
"POST-draw callback triggered for render item list with data:")
4633 callbackDataPrint(context, renderItemList)
4637 class meshVertComponentConverterGeometryOverride(omr.MPxComponentConverter):
4639 omr.MPxComponentConverter.__init__(self)
4641 self.fComponent = om.MFnSingleIndexedComponent()
4642 self.fComponentObject = om.MObject.kNullObj
4645 def initialize(self, renderItem):
4647 self.fComponentObject = self.fComponent.create( om.MFn.kMeshVertComponent )
4653 selectionData = renderItem.getCustomData()
4654 if isinstance(selectionData, apiMeshHWSelectionUserData):
4655 meshGeom = selectionData.fMeshGeom
4659 for i
in range(meshGeom.faceCount):
4660 numVerts = meshGeom.face_counts[i]
4662 numTriangles += numVerts - 2
4663 self.fVertices = [0]*(3*numTriangles)
4668 for faceIdx
in range(meshGeom.faceCount):
4670 numVerts = meshGeom.face_counts[faceIdx]
4672 for v
in range(1, numVerts-1):
4673 self.fVertices[idx] = meshGeom.face_connects[base]
4674 self.fVertices[idx+1] = meshGeom.face_connects[base+v]
4675 self.fVertices[idx+2] = meshGeom.face_connects[base+v+1]
4679 def addIntersection(self, intersection):
4682 rawIdx = intersection.index
4684 if rawIdx >= 0
and rawIdx < len(self.fVertices):
4685 idx = self.fVertices[rawIdx]
4686 self.fComponent.addElement(idx)
4688 def component(self):
4690 return self.fComponentObject
4692 def selectionMask(self):
4694 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
4695 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
4700 return meshVertComponentConverterGeometryOverride()
4704 class meshEdgeComponentConverterGeometryOverride(omr.MPxComponentConverter):
4706 omr.MPxComponentConverter.__init__(self)
4708 self.fComponent = om.MFnSingleIndexedComponent()
4709 self.fComponentObject = om.MObject.kNullObj
4712 def initialize(self, renderItem):
4714 self.fComponentObject = self.fComponent.create( om.MFn.kMeshEdgeComponent )
4726 selectionData = renderItem.getCustomData()
4727 if isinstance(selectionData, apiMeshHWSelectionUserData):
4728 meshGeom = selectionData.fMeshGeom
4732 for i
in range(meshGeom.faceCount):
4733 numVerts = meshGeom.face_counts[i]
4735 totalVerts += numVerts
4736 self.fEdges = [0]*(totalVerts)
4741 for faceIdx
in range(meshGeom.faceCount):
4743 numVerts = meshGeom.face_counts[faceIdx]
4745 for v
in range(numVerts):
4746 self.fEdges[idx] = edgeId
4750 def addIntersection(self, intersection):
4753 rawIdx = intersection.index
4755 if rawIdx >= 0
and rawIdx < len(self.fEdges):
4756 idx = self.fEdges[rawIdx]
4757 self.fComponent.addElement(idx)
4759 def component(self):
4761 return self.fComponentObject
4763 def selectionMask(self):
4765 return om.MSelectionMask(om.MSelectionMask.kSelectMeshEdges)
4769 return meshEdgeComponentConverterGeometryOverride()
4773 class meshFaceComponentConverterGeometryOverride(omr.MPxComponentConverter):
4775 omr.MPxComponentConverter.__init__(self)
4777 self.fComponent = om.MFnSingleIndexedComponent()
4778 self.fComponentObject = om.MObject.kNullObj
4781 def initialize(self, renderItem):
4783 self.fComponentObject = self.fComponent.create( om.MFn.kMeshPolygonComponent )
4795 selectionData = renderItem.getCustomData()
4796 if isinstance(selectionData, apiMeshHWSelectionUserData):
4797 meshGeom = selectionData.fMeshGeom
4800 isolateSelect = renderItem.isIsolateSelectCopy()
4803 enableFaces = [0] * meshGeom.faceCount
4804 for i
in range(meshGeom.faceCount):
4805 enableFaces[i] =
False
4807 fnComponent = om.MFnSingleIndexedComponent( renderItem.shadingComponent() )
4808 if(fnComponent.componentType == om.MFn.kMeshPolygonComponent):
4809 faceIds = fnComponent.getElements()
4811 for i
in range(len(faceIds)):
4812 enableFaces[faceIds[i]] =
True
4816 for i
in range(meshGeom.faceCount):
4817 numVerts = meshGeom.face_counts[i]
4819 if(
not isolateSelect
or enableFaces[i]):
4820 numTriangles += numVerts - 2
4822 self.fFaces = [0]*numTriangles
4826 for faceIdx
in range(meshGeom.faceCount):
4828 numVerts = meshGeom.face_counts[faceIdx]
4830 if(
not isolateSelect
or enableFaces[faceIdx]):
4831 for v
in range(1, numVerts-1):
4832 self.fFaces[idx] = faceIdx
4837 def addIntersection(self, intersection):
4840 rawIdx = intersection.index
4842 if rawIdx >= 0
and rawIdx < len(self.fFaces):
4843 idx = self.fFaces[rawIdx]
4844 self.fComponent.addElement(idx)
4846 def component(self):
4848 return self.fComponentObject
4850 def selectionMask(self):
4852 return om.MSelectionMask(om.MSelectionMask.kSelectMeshFaces)
4856 return meshFaceComponentConverterGeometryOverride()
4858 class apiMeshGeometryOverride(omr.MPxGeometryOverride):
4860 sWireframeItemName =
"apiMeshWire_py"
4861 sShadedTemplateItemName =
"apiMeshShadedTemplateWire_py"
4862 sSelectedWireframeItemName =
"apiMeshSelectedWireFrame_py"
4863 sVertexItemName =
"apiMeshVertices_py"
4864 sEdgeSelectionItemName =
"apiMeshEdgeSelection_py"
4865 sFaceSelectionItemName =
"apiMeshFaceSelection_py"
4866 sActiveVertexItemName =
"apiMeshActiveVertices_py"
4867 sVertexIdItemName =
"apiMeshVertexIds_py"
4868 sVertexPositionItemName =
"apiMeshVertexPositions_py"
4869 sShadedModeFaceCenterItemName =
"apiMeshFaceCenterInShadedMode_py"
4870 sWireframeModeFaceCenterItemName =
"apiMeshFaceCenterInWireframeMode_py"
4871 sShadedProxyItemName =
"apiShadedProxy_py"
4872 sAffectedEdgeItemName =
"apiMeshAffectedEdges_py"
4873 sAffectedFaceItemName =
"apiMeshAffectedFaces_py"
4874 sActiveVertexStreamName =
"apiMeshSharedVertexStream_py"
4875 sFaceCenterStreamName =
"apiMeshFaceCenterStream_py"
4879 return apiMeshGeometryOverride(obj)
4881 def __init__(self, obj):
4882 omr.MPxGeometryOverride.__init__(self, obj)
4884 node = om.MFnDependencyNode(obj)
4885 self.fMesh = node.userNode()
4886 self.fMeshGeom =
None
4887 self.fColorRemapTexture =
None
4889 self.fActiveVertices = om.MIntArray()
4890 self.fActiveVerticesSet = set()
4891 self.fActiveEdgesSet = set()
4892 self.fActiveFacesSet = set()
4893 self.fCastsShadows =
False
4894 self.fReceivesShadows =
False
4896 self.fEnableNumericDisplay =
False
4902 self.fDrawSharedActiveVertices =
True
4904 self.fDrawActiveVerticesWithRamp =
False
4905 self.fLinearSampler =
None
4908 self.fDrawFaceCenters =
True
4910 if self.fDrawActiveVerticesWithRamp:
4911 self.fDrawFaceCenters =
False
4916 self.fUseCustomColors =
False
4927 self.fProxyShader = omr.MShaderManager.k3dCPVThickDashLineShader
4931 self.fInternalItems_NoShadowCast =
False
4932 self.fInternalItems_NoShadowReceive =
False
4933 self.fInternalItems_NoPostEffects =
False
4937 self.fExternalItems_NoShadowCast =
False
4938 self.fExternalItems_NoShadowReceive =
False
4939 self.fExternalItemsNonTri_NoShadowCast =
False
4940 self.fExternalItemsNonTri_NoShadowReceive =
False
4944 self.fExternalItems_NoPostEffects =
True
4945 self.fExternalItemsNonTri_NoPostEffects =
True
4949 self.fMeshGeom =
None
4951 if self.fColorRemapTexture:
4952 textureMgr = omr.MRenderer.getTextureManager()
4954 textureMgr.releaseTexture(self.fColorRemapTexture)
4955 self.fColorRemapTexture =
None
4957 if self.fLinearSampler:
4958 omr.MStateManager.releaseSamplerState(self.fLinearSampler)
4959 self.fLinearSampler =
None
4961 def supportedDrawAPIs(self):
4963 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
4968 self.fActiveVertices.clear()
4969 self.fActiveVerticesSet = set()
4970 self.fActiveEdgesSet = set()
4971 self.fActiveFacesSet = set()
4973 self.fMeshGeom = self.fMesh.meshGeom()
4975 if self.fMeshGeom
and self.fMesh.hasActiveComponents():
4976 activeComponents = self.fMesh.activeComponents()
4977 if len(activeComponents) > 0:
4978 fnComponent = om.MFnSingleIndexedComponent( activeComponents[0] )
4979 if fnComponent.elementCount > 0:
4980 activeIds = fnComponent.getElements()
4982 if fnComponent.componentType == om.MFn.kMeshVertComponent:
4983 self.fActiveVertices = activeIds
4984 self.fActiveVerticesSet = set(activeIds)
4986 elif fnComponent.componentType == om.MFn.kMeshEdgeComponent:
4987 self.fActiveEdgesSet = set(activeIds)
4989 elif fnComponent.componentType == om.MFn.kMeshPolygonComponent:
4990 self.fActiveFacesSet = set(activeIds)
4992 def updateRenderItems(self, path, list):
4996 shaderMgr = omr.MRenderer.getShaderManager()
5000 dagNode = om.MFnDagNode(path)
5001 castsShadowsPlug = dagNode.findPlug(
"castsShadows",
False)
5002 self.fCastsShadows = castsShadowsPlug.asBool()
5003 receiveShadowsPlug = dagNode.findPlug(
"receiveShadows",
False)
5004 self.fReceivesShadows = receiveShadowsPlug.asBool()
5005 enableNumericDisplayPlug = dagNode.findPlug(
"enableNumericDisplay",
False)
5006 self.fEnableNumericDisplay = enableNumericDisplayPlug.asBool()
5009 self.updateDormantAndTemplateWireframeItems(path, list, shaderMgr)
5010 self.updateActiveWireframeItem(path, list, shaderMgr)
5013 self.updateDormantVerticesItem(path, list, shaderMgr)
5014 self.updateActiveVerticesItem(path, list, shaderMgr)
5017 self.updateVertexNumericItems(path, list, shaderMgr)
5020 if self.fDrawFaceCenters:
5021 self.updateWireframeModeFaceCenterItem(path, list, shaderMgr)
5022 self.updateShadedModeFaceCenterItem(path, list, shaderMgr)
5025 self.updateAffectedComponentItems(path, list, shaderMgr)
5028 self.updateSelectionComponentItems(path, list, shaderMgr)
5031 self.updateProxyShadedItem(path, list, shaderMgr)
5037 testShadedOverrides = self.fInternalItems_NoShadowCast
or self.fInternalItems_NoShadowReceive
or self.fInternalItems_NoPostEffects
5038 if testShadedOverrides:
5043 drawMode = item.drawMode()
5044 if drawMode == omr.MGeometry.kShaded
or drawMode == omr.MGeometry.kTextured:
5045 if item.name() != self.sShadedTemplateItemName:
5046 item.setCastsShadows(
not self.fInternalItems_NoShadowCast
and self.fCastsShadows )
5047 item.setReceivesShadows(
not self.fInternalItems_NoShadowReceive
and self.fReceivesShadows )
5048 item.setExcludedFromPostEffects( self.fInternalItems_NoPostEffects )
5050 def populateGeometry(self, requirements, renderItems, data):
5061 debugPopulateGeometry =
False
5062 if debugPopulateGeometry:
5063 print(
"> Begin populate geometry")
5066 activeVertexCount = len(self.fActiveVertices)
5071 for i
in range(self.fMeshGeom.faceCount):
5072 numVerts = self.fMeshGeom.face_counts[i]
5074 numTriangles += numVerts - 2
5075 totalVerts += numVerts
5078 self.updateGeometryRequirements(requirements, data, activeVertexCount, totalVerts, debugPopulateGeometry)
5081 wireIndexBuffer =
None
5083 for item
in renderItems:
5092 itemBuffers = item.requiredVertexBuffers()
5093 for desc
in itemBuffers:
5094 print(
"Buffer Required for Item '" + item.name() +
"':")
5095 print(
"\tBufferName: " + desc.name)
5096 print(
"\tDataType: " + omr.MGeometry.dataTypeString(desc.dataType) +
" (dimension " + str(desc.dimension) +
")")
5097 print(
"\tSemantic: " + omr.MGeometry.semanticString(desc.semantic))
5102 myCustomData = item.getCustomData()
5103 if isinstance(myCustomData, apiMeshUserData):
5104 print(
"Custom data '" + myCustomData.fMessage +
"', modified count='" + str(myCustomData.fNumModifications) +
"'")
5106 print(
"No custom data")
5110 if item.name() == self.sActiveVertexItemName:
5111 self.updateIndexingForVertices( item, data, numTriangles, activeVertexCount, debugPopulateGeometry)
5115 if self.fDrawFaceCenters
and (item.name() == self.sShadedModeFaceCenterItemName
or item.name() == self.sWireframeModeFaceCenterItemName):
5116 self.updateIndexingForFaceCenters( item, data, debugPopulateGeometry)
5120 elif item.name() == self.sVertexItemName
or item.name() == self.sVertexIdItemName
or item.name() == self.sVertexPositionItemName:
5121 self.updateIndexingForDormantVertices( item, data, numTriangles )
5125 elif item.name() == self.sWireframeItemName
or item.name() == self.sShadedTemplateItemName
or item.name() == self.sSelectedWireframeItemName
or (item.primitive() != omr.MGeometry.kTriangles
and item.name() == self.sShadedProxyItemName):
5126 self.updateIndexingForWireframeItems(wireIndexBuffer, item, data, totalVerts)
5132 elif item.name() == self.sAffectedEdgeItemName:
5133 self.updateIndexingForEdges(item, data, totalVerts,
True)
5134 elif item.name() == self.sEdgeSelectionItemName:
5135 self.updateIndexingForEdges(item, data, totalVerts,
False)
5141 elif item.name() == self.sAffectedFaceItemName:
5142 self.updateIndexingForFaces(item, data, numTriangles,
True)
5143 elif item.name() == self.sFaceSelectionItemName:
5144 self.updateIndexingForFaces(item, data, numTriangles,
False)
5148 elif item.primitive() == omr.MGeometry.kTriangles:
5149 self.updateIndexingForShadedTriangles(item, data, numTriangles)
5151 if debugPopulateGeometry:
5152 print(
"> End populate geometry")
5155 self.fMeshGeom =
None
5156 self.fActiveVertices.clear()
5157 self.fActiveVerticesSet = set()
5158 self.fActiveEdgesSet = set()
5159 self.fActiveFacesSet = set()
5161 def updateSelectionGranularity(self, path, selectionContext):
5173 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5174 if displayStatus == omr.MGeometryUtilities.kHilite:
5176 globalComponentMask = om.MGlobal.objectSelectionMask()
5177 if om.MGlobal.selectionMode() == om.MGlobal.kSelectComponentMode:
5178 globalComponentMask = om.MGlobal.componentSelectionMask()
5180 supportedComponentMask = om.MSelectionMask( om.MSelectionMask.kSelectMeshVerts )
5181 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshEdges )
5182 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshFaces )
5183 supportedComponentMask.addMask( om.MSelectionMask.kSelectPointsForGravity )
5185 if globalComponentMask.intersects(supportedComponentMask):
5186 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
5187 elif omr.MPxGeometryOverride.pointSnappingActive():
5188 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
5190 def printShader(self, shader):
5195 params = shader.parameterList()
5196 print(
"DEBUGGING SHADER, BEGIN PARAM LIST OF LENGTH " + str(len(params)))
5198 for param
in params:
5199 paramType = shader.parameterType(param)
5200 isArray = shader.isArrayParameter(param)
5202 typeAsStr =
"Unknown"
5203 if paramType == omr.MShaderInstance.kInvalid:
5204 typeAsStr =
"Invalid"
5205 elif paramType == omr.MShaderInstance.kBoolean:
5206 typeAsStr =
"Boolean"
5207 elif paramType == omr.MShaderInstance.kInteger:
5208 typeAsStr =
"Integer"
5209 elif paramType == omr.MShaderInstance.kFloat:
5211 elif paramType == omr.MShaderInstance.kFloat2:
5212 typeAsStr =
"Float2"
5213 elif paramType == omr.MShaderInstance.kFloat3:
5214 typeAsStr =
"Float3"
5215 elif paramType == omr.MShaderInstance.kFloat4:
5216 typeAsStr =
"Float4"
5217 elif paramType == omr.MShaderInstance.kFloat4x4Row:
5218 typeAsStr =
"Float4x4Row"
5219 elif paramType == omr.MShaderInstance.kFloat4x4Col:
5220 typeAsStr =
"Float4x4Col"
5221 elif paramType == omr.MShaderInstance.kTexture1:
5222 typeAsStr =
"1D Texture"
5223 elif paramType == omr.MShaderInstance.kTexture2:
5224 typeAsStr =
"2D Texture"
5225 elif paramType == omr.MShaderInstance.kTexture3:
5226 typeAsStr =
"3D Texture"
5227 elif paramType == omr.MShaderInstance.kTextureCube:
5228 typeAsStr =
"Cube Texture"
5229 elif paramType == omr.MShaderInstance.kSampler:
5230 typeAsStr =
"Sampler"
5232 print(
"ParamName='" + param +
"', ParamType='" + typeAsStr +
"', IsArrayParameter:'" + str(isArray) +
"'")
5234 print(
"END PARAM LIST")
5236 def setSolidColor(self, shaderInstance, defaultColor, customColor=None):
5239 color = defaultColor
5240 if self.fUseCustomColors
and customColor:
5243 shaderInstance.setParameter(
"solidColor", color)
5247 def setSolidPointSize(self, shaderInstance, size):
5251 shaderInstance.setParameter(
"pointSize", [size, size])
5255 def setLineWidth(self, shaderInstance, width):
5259 shaderInstance.setParameter(
"lineWidth", [width, width])
5263 def enableActiveComponentDisplay(self, path):
5275 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5276 if displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
5282 if path.isTemplated():
5288 def updateDormantAndTemplateWireframeItems(self, path, list, shaderMgr):
5300 dormantColor = [ 0.0, 0.0, 1.0, 1.0 ]
5301 templateColor = [ 0.45, 0.45, 0.45, 1.0 ]
5302 activeTemplateColor = [ 1.0, 0.5, 0.5, 1.0 ]
5311 wireframeItem =
None
5312 index = list.indexOf(self.sWireframeItemName)
5314 wireframeItem = omr.MRenderItem.create( self.sWireframeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5315 wireframeItem.setDrawMode(omr.MGeometry.kWireframe)
5319 wireframeItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
5321 list.append(wireframeItem)
5326 preCb = apiMeshPreDrawCallback
5327 postCb = apiMeshPostDrawCallback
5329 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader, preCb, postCb)
5332 wireframeItem.setShader(shader)
5336 self.printShader( shader )
5339 shaderMgr.releaseShader(shader)
5341 wireframeItem = list[index]
5345 shadedTemplateItem =
None
5346 index = list.indexOf(self.sShadedTemplateItemName)
5348 shadedTemplateItem = omr.MRenderItem.create( self.sShadedTemplateItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5349 shadedTemplateItem.setDrawMode(omr.MGeometry.kAll)
5353 shadedTemplateItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
5355 list.append(shadedTemplateItem)
5357 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
5360 shadedTemplateItem.setShader(shader)
5364 self.printShader( shader )
5367 shaderMgr.releaseShader(shader)
5369 shadedTemplateItem = list[index]
5372 shadedTemplateItem.setCastsShadows(
not self.fExternalItemsNonTri_NoShadowCast )
5373 shadedTemplateItem.setReceivesShadows(
not self.fExternalItemsNonTri_NoShadowReceive )
5374 shadedTemplateItem.setExcludedFromPostEffects( self.fExternalItemsNonTri_NoPostEffects )
5376 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5377 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5382 shader = wireframeItem.getShader()
5384 if displayStatus == omr.MGeometryUtilities.kTemplate:
5385 self.setSolidColor( shader, wireColor, templateColor)
5386 wireframeItem.enable(
True)
5388 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
5389 self.setSolidColor( shader, wireColor, activeTemplateColor)
5390 wireframeItem.enable(
True)
5392 elif displayStatus == omr.MGeometryUtilities.kDormant:
5393 self.setSolidColor( shader, wireColor, dormantColor)
5394 wireframeItem.enable(
True)
5396 elif displayStatus == omr.MGeometryUtilities.kActiveAffected:
5397 theColor = [ 0.5, 0.0, 1.0, 1.0 ]
5398 self.setSolidColor( shader, wireColor, theColor)
5399 wireframeItem.enable(
True)
5402 wireframeItem.enable(
False)
5406 if shadedTemplateItem:
5407 isTemplate = path.isTemplated()
5408 shader = shadedTemplateItem.getShader()
5410 if displayStatus == omr.MGeometryUtilities.kTemplate:
5411 self.setSolidColor( shader, wireColor, templateColor)
5412 shadedTemplateItem.enable(isTemplate)
5414 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
5415 self.setSolidColor( shader, wireColor, activeTemplateColor)
5416 shadedTemplateItem.enable(isTemplate)
5418 elif displayStatus == omr.MGeometryUtilities.kDormant:
5419 self.setSolidColor( shader, wireColor, dormantColor)
5420 shadedTemplateItem.enable(isTemplate)
5423 shadedTemplateItem.enable(
False)
5425 def updateActiveWireframeItem(self, path, list, shaderMgr):
5430 index = list.indexOf(self.sSelectedWireframeItemName)
5432 selectItem = omr.MRenderItem.create(self.sSelectedWireframeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5433 selectItem.setDrawMode(omr.MGeometry.kAll)
5438 selectItem.setDepthPriority( omr.MRenderItem.sActiveWireDepthPriority )
5439 list.append(selectItem)
5444 shaderId = omr.MShaderManager.k3dSolidShader
5446 shaderId = omr.MShaderManager.k3dThickLineShader
5448 shader = shaderMgr.getStockShader(shaderId)
5451 selectItem.setShader(shader)
5453 shaderMgr.releaseShader(shader)
5455 selectItem = list[index]
5459 shader = selectItem.getShader()
5461 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5462 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5464 if displayStatus == omr.MGeometryUtilities.kLead:
5465 theColor = [ 0.0, 0.8, 0.0, 1.0 ]
5466 self.setSolidColor( shader, wireColor, theColor)
5467 selectItem.enable(
True)
5469 elif displayStatus == omr.MGeometryUtilities.kActive:
5470 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5471 self.setSolidColor( shader, wireColor, theColor)
5472 selectItem.enable(
True)
5474 elif displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
5475 theColor = [ 0.0, 0.5, 0.7, 1.0 ]
5476 self.setSolidColor( shader, wireColor, theColor)
5477 selectItem.enable(
True)
5480 selectItem.enable(
False)
5483 myCustomData = selectItem.getCustomData()
5484 if not myCustomData:
5486 myCustomData = apiMeshUserData()
5487 myCustomData.fMessage =
"I'm custom data!"
5488 selectItem.setCustomData(myCustomData)
5491 myCustomData.fNumModifications += 1
5493 def updateWireframeModeFaceCenterItem(self, path, list, shaderMgr):
5497 wireframeModeFaceCenterItem =
None
5498 index = list.indexOf(self.sWireframeModeFaceCenterItemName)
5500 wireframeModeFaceCenterItem = omr.MRenderItem.create(self.sWireframeModeFaceCenterItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5501 wireframeModeFaceCenterItem.setDrawMode(omr.MGeometry.kWireframe)
5502 wireframeModeFaceCenterItem.setDepthPriority( omr.MRenderItem.sActiveWireDepthPriority )
5504 list.append(wireframeModeFaceCenterItem)
5506 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
5510 self.setSolidPointSize( shader, pointSize )
5512 wireframeModeFaceCenterItem.setShader(shader, self.sFaceCenterStreamName )
5515 shaderMgr.releaseShader(shader)
5517 wireframeModeFaceCenterItem = list[index]
5519 if wireframeModeFaceCenterItem:
5520 shader = wireframeModeFaceCenterItem.getShader()
5523 theColor = [ 0.0, 0.0, 1.0, 1.0 ]
5524 self.setSolidColor( shader, theColor )
5527 isTemplate = path.isTemplated()
5528 wireframeModeFaceCenterItem.enable(
not isTemplate )
5530 def updateShadedModeFaceCenterItem(self, path, list, shaderMgr):
5534 shadedModeFaceCenterItem =
None
5535 index = list.indexOf(self.sShadedModeFaceCenterItemName)
5537 shadedModeFaceCenterItem = omr.MRenderItem.create( self.sShadedModeFaceCenterItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5538 shadedModeFaceCenterItem.setDrawMode(omr.MGeometry.kShaded | omr.MGeometry.kTextured)
5540 shadedModeFaceCenterItem.setDepthPriority(omr.MRenderItem.sActivePointDepthPriority)
5542 list.append(shadedModeFaceCenterItem)
5544 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
5548 self.setSolidPointSize( shader, pointSize )
5550 shadedModeFaceCenterItem.setShader(shader, self.sFaceCenterStreamName )
5553 shaderMgr.releaseShader(shader)
5555 shadedModeFaceCenterItem = list[index]
5557 if shadedModeFaceCenterItem:
5558 shadedModeFaceCenterItem.setExcludedFromPostEffects(
True)
5560 shader = shadedModeFaceCenterItem.getShader()
5561 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5565 self.setSolidColor( shader, wireColor )
5567 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5568 if displayStatus == omr.MGeometryUtilities.kActive
or displayStatus == omr.MGeometryUtilities.kLead
or displayStatus == omr.MGeometryUtilities.kActiveComponent
or displayStatus == omr.MGeometryUtilities.kLive
or displayStatus == omr.MGeometryUtilities.kHilite:
5569 shadedModeFaceCenterItem.enable(
True)
5572 shadedModeFaceCenterItem.enable(
False)
5574 def updateDormantVerticesItem(self, path, list, shaderMgr):
5579 index = list.indexOf(self.sVertexItemName)
5581 vertexItem = omr.MRenderItem.create(self.sVertexItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5584 vertexItem.setDrawMode(omr.MGeometry.kAll)
5587 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
5588 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
5589 vertexItem.setSelectionMask( mask )
5594 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5595 list.append(vertexItem)
5597 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
5601 self.setSolidPointSize( shader, pointSize )
5604 vertexItem.setShader(shader)
5607 shaderMgr.releaseShader(shader)
5609 vertexItem = list[index]
5612 shader = vertexItem.getShader()
5614 theColor = [ 0.0, 0.0, 1.0, 1.0 ]
5615 self.setSolidColor( shader, theColor )
5617 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5621 if displayStatus == omr.MGeometryUtilities.kHilite
or omr.MPxGeometryOverride.pointSnappingActive():
5625 if path.isTemplated():
5626 vertexItem.enable(
False)
5628 vertexItem.enable(
True)
5630 vertexItem.enable(
False)
5632 mySelectionData = vertexItem.getCustomData()
5633 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5635 mySelectionData = apiMeshHWSelectionUserData()
5636 vertexItem.setCustomData(mySelectionData)
5638 mySelectionData.fMeshGeom = self.fMeshGeom
5640 def updateActiveVerticesItem(self, path, list, shaderMgr):
5645 index = list.indexOf(self.sActiveVertexItemName)
5647 activeItem = omr.MRenderItem.create(self.sActiveVertexItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5648 activeItem.setDrawMode(omr.MGeometry.kAll)
5651 activeItem.setDepthPriority( omr.MRenderItem.sActivePointDepthPriority )
5652 list.append(activeItem)
5654 shaderId = omr.MShaderManager.k3dFatPointShader
5655 if self.fDrawActiveVerticesWithRamp:
5656 shaderId = omr.MShaderManager.k3dColorLookupFatPointShader
5658 shader = shaderMgr.getStockShader( shaderId )
5662 self.setSolidPointSize( shader, pointSize )
5666 if self.fDrawActiveVerticesWithRamp:
5667 textureMgr = omr.MRenderer.getTextureManager()
5670 if not self.fColorRemapTexture:
5672 colorArray = [ 1.0, 0.0, 0.0, 1.0,
5674 0.0, 0.0, 1.0, 1.0 ]
5677 textureDesc = omr.MTextureDescription()
5678 textureDesc.setToDefault2DTexture()
5679 textureDesc.fWidth = arrayLen
5680 textureDesc.fHeight = 1
5681 textureDesc.fDepth = 1
5682 textureDesc.fBytesPerSlice = textureDesc.fBytesPerRow = 24*arrayLen
5683 textureDesc.fMipmaps = 1
5684 textureDesc.fArraySlices = 1
5685 textureDesc.fTextureType = omr.MRenderer.kImage1D
5686 textureDesc.fFormat = omr.MRenderer.kR32G32B32A32_FLOAT
5687 self.fColorRemapTexture = textureMgr.acquireTexture(
"", textureDesc, colorArray,
False)
5689 if not self.fLinearSampler:
5690 samplerDesc = omr.MSamplerStateDesc()
5691 samplerDesc.addressU = omr.MSamplerState.kTexClamp
5692 samplerDesc.addressV = omr.MSamplerState.kTexClamp
5693 samplerDesc.addressW = omr.MSamplerState.kTexClamp
5694 samplerDesc.filter = omr.MSamplerState.kMinMagMipLinear
5695 fLinearSampler = omr.MStateManager.acquireSamplerState(samplerDesc)
5697 if self.fColorRemapTexture
and self.fLinearSampler:
5699 shader.setParameter(
"map", self.fColorRemapTexture)
5700 shader.setParameter(
"samp", self.fLinearSampler)
5704 rampValueRange = om.MFloatVector(0.0, 1.0)
5705 shader.setParameter(
"UVRange", rampValueRange)
5709 if self.fDrawSharedActiveVertices:
5710 activeItem.setShader(shader, self.sActiveVertexStreamName)
5712 activeItem.setShader(shader,
None)
5715 shaderMgr.releaseShader(shader)
5718 activeItem = list[index]
5721 shader = activeItem.getShader()
5724 theColor = [ 1.0, 1.0, 0.0, 1.0 ]
5725 self.setSolidColor( shader, theColor )
5727 enable = (bool(self.fActiveVerticesSet)
and self.enableActiveComponentDisplay(path))
5728 activeItem.enable( enable )
5730 def updateVertexNumericItems(self, path, list, shaderMgr):
5738 index = list.indexOf(self.sVertexIdItemName)
5740 vertexItem = omr.MRenderItem.create( self.sVertexIdItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5741 vertexItem.setDrawMode(omr.MGeometry.kAll)
5742 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5743 list.append(vertexItem)
5746 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dIntegerNumericShader )
5749 vertexItem.setShader(shader, self.sVertexIdItemName)
5750 shaderMgr.releaseShader(shader)
5752 vertexItem = list[index]
5755 shader = vertexItem.getShader()
5758 theColor = [ 1.0, 1.0, 0.0, 1.0 ]
5759 self.setSolidColor( shader, theColor )
5761 vertexItem.enable(self.fEnableNumericDisplay)
5766 index = list.indexOf(self.sVertexPositionItemName)
5768 vertexItem = omr.MRenderItem.create( self.sVertexPositionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5769 vertexItem.setDrawMode(omr.MGeometry.kAll)
5770 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5771 list.append(vertexItem)
5774 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFloat3NumericShader )
5777 vertexItem.setShader(shader, self.sVertexPositionItemName)
5778 shaderMgr.releaseShader(shader)
5780 vertexItem = list[index]
5783 shader = vertexItem.getShader()
5786 theColor = [ 0.0, 1.0, 1.0, 1.0 ]
5787 self.setSolidColor( shader, theColor)
5789 vertexItem.enable(self.fEnableNumericDisplay)
5791 def updateAffectedComponentItems(self, path, list, shaderMgr):
5798 componentItem =
None
5799 index = list.indexOf(self.sAffectedEdgeItemName)
5801 componentItem = omr.MRenderItem.create( self.sAffectedEdgeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5802 componentItem.setDrawMode(omr.MGeometry.kAll)
5806 componentItem.setDepthPriority( omr.MRenderItem.sActiveLineDepthPriority )
5807 list.append(componentItem)
5809 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dThickLineShader )
5813 self.setLineWidth( shader, lineSize )
5816 componentItem.setShader(shader,
None)
5819 shaderMgr.releaseShader(shader)
5821 componentItem = list[index]
5824 shader = componentItem.getShader()
5827 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5828 self.setSolidColor( shader, theColor )
5830 enable = ((bool(self.fActiveVerticesSet)
or bool(self.fActiveEdgesSet))
and self.enableActiveComponentDisplay(path))
5831 componentItem.enable( enable )
5837 componentItem =
None
5838 index = list.indexOf(self.sAffectedFaceItemName)
5840 componentItem = omr.MRenderItem.create( self.sAffectedFaceItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
5841 componentItem.setDrawMode(omr.MGeometry.kAll)
5844 componentItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
5847 componentItem.setAllowIsolateSelectCopy(
True)
5849 list.append(componentItem)
5851 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dStippleShader )
5854 componentItem.setShader(shader,
None)
5857 shaderMgr.releaseShader(shader)
5859 componentItem = list[index]
5862 shader = componentItem.getShader()
5865 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5866 self.setSolidColor( shader, theColor )
5868 enable = ((bool(self.fActiveVerticesSet)
or bool(self.fActiveFacesSet))
and self.enableActiveComponentDisplay(path))
5869 componentItem.enable( enable )
5871 def updateSelectionComponentItems(self, path, list, shaderMgr):
5886 selectionItem =
None
5887 index = list.indexOf(self.sEdgeSelectionItemName)
5889 selectionItem = omr.MRenderItem.create( self.sEdgeSelectionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5892 selectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
5895 selectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshEdges )
5898 selectionItem.setDepthPriority( omr.MRenderItem.sSelectionDepthPriority )
5899 list.append(selectionItem)
5901 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
5904 selectionItem.setShader(shader,
None)
5907 shaderMgr.releaseShader(shader)
5909 selectionItem = list[index]
5912 selectionItem.enable(
True)
5914 mySelectionData = selectionItem.getCustomData()
5915 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5917 mySelectionData = apiMeshHWSelectionUserData()
5918 selectionItem.setCustomData(mySelectionData)
5920 mySelectionData.fMeshGeom = self.fMeshGeom
5924 index = list.indexOf(self.sFaceSelectionItemName)
5926 selectionItem = omr.MRenderItem.create( self.sFaceSelectionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
5929 selectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
5932 selectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshFaces )
5935 selectionItem.setDepthPriority( omr.MRenderItem.sSelectionDepthPriority )
5938 selectionItem.setAllowIsolateSelectCopy(
True)
5940 list.append(selectionItem)
5942 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
5945 selectionItem.setShader(shader,
None)
5948 shaderMgr.releaseShader(shader)
5950 selectionItem = list[index]
5953 selectionItem.enable(
True)
5955 mySelectionData = selectionItem.getCustomData()
5956 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5958 mySelectionData = apiMeshHWSelectionUserData()
5959 selectionItem.setCustomData(mySelectionData)
5961 mySelectionData.fMeshGeom = self.fMeshGeom
5963 def updateProxyShadedItem(self, path, list, shaderMgr):
5968 dormantColor = [ 0.0, 0.0, 1.0, 1.0 ]
5969 templateColor = [ 0.45, 0.45, 0.45, 1.0 ]
5970 activeTemplateColor = [ 1.0, 0.5, 0.5, 1.0 ]
5977 raiseAboveShaded =
True
5978 shadedDrawMode = omr.MGeometry.kShaded | omr.MGeometry.kTextured
5981 useFragmentShader = self.fProxyShader < 0
5982 if not useFragmentShader:
5983 shadedDrawMode |= omr.MGeometry.kWireframe
5988 itemType = omr.MRenderItem.NonMaterialSceneItem
5989 primitive = omr.MGeometry.kLines
5990 filledProxy = useFragmentShader
or self.fProxyShader == omr.MShaderManager.k3dStippleShader
5992 itemType = omr.MRenderItem.MaterialSceneItem
5993 primitive = omr.MGeometry.kTriangles
5995 depthPriority = omr.MRenderItem.sDormantWireDepthPriority
5996 if raiseAboveShaded:
5997 depthPriority = omr.MRenderItem.sActiveWireDepthPriority
6000 index = list.indexOf(self.sShadedProxyItemName)
6002 proxyItem = omr.MRenderItem.create( self.sShadedProxyItemName, itemType, primitive)
6003 proxyItem.setDrawMode(shadedDrawMode)
6004 proxyItem.setDepthPriority( depthPriority )
6006 proxyItem.setCastsShadows(
not self.fExternalItems_NoShadowCast
and self.fCastsShadows )
6007 proxyItem.setReceivesShadows(
not self.fExternalItems_NoShadowReceive
and self.fReceivesShadows )
6008 proxyItem.setExcludedFromPostEffects( self.fExternalItems_NoPostEffects )
6010 list.append(proxyItem)
6015 if useFragmentShader:
6016 shader = shaderMgr.getFragmentShader(
"mayaLambertSurface",
"outSurfaceFinal",
True)
6017 sBlue = [ 0.4, 0.4, 1.0 ]
6018 shader.setParameter(
"color", sBlue)
6019 shader.setIsTransparent(
False)
6021 shader = shaderMgr.getStockShader( self.fProxyShader )
6025 self.setLineWidth(shader, 10.0)
6028 proxyItem.setShader(shader)
6030 shaderMgr.releaseShader(shader)
6032 proxyItem = list[index]
6039 proxyItem.setCastsShadows(
not self.fExternalItems_NoShadowCast
and self.fCastsShadows )
6040 proxyItem.setReceivesShadows(
not self.fExternalItems_NoShadowReceive
and self.fReceivesShadows )
6041 proxyItem.setExcludedFromPostEffects( self.fExternalItems_NoPostEffects )
6046 haveShadedItems =
False
6050 drawMode = item.drawMode()
6051 if drawMode == omr.MGeometry.kShaded
or drawMode == omr.MGeometry.kTextured:
6052 if item.name() != self.sShadedTemplateItemName:
6053 haveShadedItems =
True
6056 displayStatus = omr.MGeometryUtilities.displayStatus(path)
6057 wireColor = omr.MGeometryUtilities.wireframeColor(path)
6064 shader = proxyItem.getShader()
6066 if displayStatus == omr.MGeometryUtilities.kTemplate:
6067 self.setSolidColor( shader, wireColor, templateColor )
6069 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
6070 self.setSolidColor( shader, wireColor, activeTemplateColor )
6072 elif displayStatus == omr.MGeometryUtilities.kDormant:
6073 self.setSolidColor( shader, wireColor, dormantColor )
6080 if path.isTemplated():
6081 proxyItem.enable(
False)
6083 proxyItem.enable(
not haveShadedItems)
6085 proxyItem.enable(
not haveShadedItems)
6088 def updateGeometryRequirements(self, requirements, data, activeVertexCount, totalVerts, debugPopulateGeometry):
6094 positionBuffer =
None
6095 positionDataAddress =
None
6098 vertexNumericIdBuffer =
None
6099 vertexNumericIdDataAddress =
None
6100 vertexNumericIdData =
None
6102 vertexNumericIdPositionBuffer =
None
6103 vertexNumericIdPositionDataAddress =
None
6104 vertexNumericIdPositionData =
None
6106 vertexNumericLocationBuffer =
None
6107 vertexNumericLocationDataAddress =
None
6108 vertexNumericLocationData =
None
6110 vertexNumericLocationPositionBuffer =
None
6111 vertexNumericLocationPositionDataAddress =
None
6112 vertexNumericLocationPositionData =
None
6114 activeVertexPositionBuffer =
None
6115 activeVertexPositionDataAddress =
None
6116 activeVertexPositionData =
None
6118 activeVertexUVBuffer =
None
6119 activeVertexUVDataAddress =
None
6120 activeVertexUVData =
None
6122 faceCenterPositionBuffer =
None
6123 faceCenterPositionDataAddress =
None
6124 faceCenterPositionData =
None
6127 normalDataAddress =
None
6131 cpvDataAddress =
None
6135 uvDataAddress =
None
6138 numUVs = self.fMeshGeom.uvcoords.uvcount()
6140 descList = requirements.vertexRequirements()
6141 satisfiedRequirements = [
False,] * len(descList)
6142 for i
in range(len(descList)):
6146 if self.fDrawSharedActiveVertices
and (desc.name == self.sActiveVertexStreamName):
6147 if desc.semantic == omr.MGeometry.kPosition:
6148 if not activeVertexPositionBuffer:
6149 activeVertexPositionBuffer = data.createVertexBuffer(desc)
6150 if activeVertexPositionBuffer:
6151 satisfiedRequirements[i] =
True
6152 if debugPopulateGeometry:
6153 print(
">>> Fill in data for active vertex requirement '" + desc.name +
"'. Semantic = kPosition")
6154 activeVertexPositionDataAddress = activeVertexPositionBuffer.acquire(activeVertexCount,
True)
6155 if activeVertexPositionDataAddress:
6156 activeVertexPositionData = ((ctypes.c_float * 3)*activeVertexCount).from_address(activeVertexPositionDataAddress)
6158 elif desc.semantic == omr.MGeometry.kTexture:
6159 if not activeVertexUVBuffer:
6160 activeVertexUVBuffer = data.createVertexBuffer(desc)
6161 if activeVertexUVBuffer:
6162 satisfiedRequirements[i] =
True
6163 if debugPopulateGeometry:
6164 print(
">>> Fill in data for active vertex requirement '" + desc.name +
"'. Semantic = kTexture")
6165 activeVertexUVDataAddress = activeVertexUVBuffer.acquire(activeVertexCount,
True)
6166 if activeVertexUVDataAddress:
6167 activeVertexUVData = ((ctypes.c_float * 3)*activeVertexCount).from_address(activeVertexUVDataAddress)
6174 elif self.fDrawFaceCenters
and desc.name == self.sFaceCenterStreamName:
6175 if desc.semantic == omr.MGeometry.kPosition:
6176 if not faceCenterPositionBuffer:
6177 faceCenterPositionBuffer = data.createVertexBuffer(desc)
6178 if faceCenterPositionBuffer:
6179 satisfiedRequirements[i] =
True
6180 if debugPopulateGeometry:
6181 print(
">>> Fill in data for face center vertex requirement '" + desc.name +
"'. Semantic = kPosition")
6182 faceCenterPositionDataAddress = faceCenterPositionBuffer.acquire(self.fMeshGeom.faceCount,
True)
6183 if faceCenterPositionDataAddress:
6184 faceCenterPositionData = ((ctypes.c_float * 3)*self.fMeshGeom.faceCount).from_address(faceCenterPositionDataAddress)
6193 if desc.semantic == omr.MGeometry.kPosition:
6194 if desc.name == self.sVertexIdItemName:
6195 if not vertexNumericIdPositionBuffer:
6196 vertexNumericIdPositionBuffer = data.createVertexBuffer(desc)
6197 if vertexNumericIdPositionBuffer:
6198 satisfiedRequirements[i] =
True
6199 if debugPopulateGeometry:
6200 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition")
6201 print(
"Acquire 3loat-numeric position buffer")
6202 vertexNumericIdPositionDataAddress = vertexNumericIdPositionBuffer.acquire(totalVerts,
True)
6203 if vertexNumericIdPositionDataAddress:
6204 vertexNumericIdPositionData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericIdPositionDataAddress)
6206 elif desc.name == self.sVertexPositionItemName:
6207 if not vertexNumericLocationPositionBuffer:
6208 vertexNumericLocationPositionBuffer = data.createVertexBuffer(desc)
6209 if vertexNumericLocationPositionBuffer:
6210 satisfiedRequirements[i] =
True
6211 if debugPopulateGeometry:
6212 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition")
6213 print(
"Acquire 3loat-numeric position buffer")
6214 vertexNumericLocationPositionDataAddress = vertexNumericLocationPositionBuffer.acquire(totalVerts,
True)
6215 if vertexNumericLocationPositionDataAddress:
6216 vertexNumericLocationPositionData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericLocationPositionDataAddress)
6219 if not positionBuffer:
6220 positionBuffer = data.createVertexBuffer(desc)
6222 satisfiedRequirements[i] =
True
6223 if debugPopulateGeometry:
6224 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition")
6225 print(
"Acquire unnamed position buffer")
6226 positionDataAddress = positionBuffer.acquire(totalVerts,
True)
6227 if positionDataAddress:
6228 positionData = ((ctypes.c_float * 3)*totalVerts).from_address(positionDataAddress)
6230 elif desc.semantic == omr.MGeometry.kNormal:
6231 if not normalBuffer:
6232 normalBuffer = data.createVertexBuffer(desc)
6234 satisfiedRequirements[i] =
True
6235 if debugPopulateGeometry:
6236 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kNormal")
6237 normalDataAddress = normalBuffer.acquire(totalVerts,
True)
6238 if normalDataAddress:
6239 normalData = ((ctypes.c_float * 3)*totalVerts).from_address(normalDataAddress)
6241 elif desc.semantic == omr.MGeometry.kTexture:
6242 numericValue =
"numericvalue"
6243 numeric3Value =
"numeric3value"
6246 if desc.semanticName.lower() == numericValue
and desc.name == self.sVertexIdItemName:
6247 if not vertexNumericIdBuffer:
6248 vertexNumericIdBuffer = data.createVertexBuffer(desc)
6249 if vertexNumericIdBuffer:
6250 satisfiedRequirements[i] =
True
6251 if debugPopulateGeometry:
6252 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture")
6253 print(
"Acquire 1loat numeric buffer")
6254 vertexNumericIdDataAddress = vertexNumericIdBuffer.acquire(totalVerts,
True)
6255 if vertexNumericIdDataAddress:
6256 vertexNumericIdData = ((ctypes.c_float * 1)*totalVerts).from_address(vertexNumericIdDataAddress)
6259 elif desc.semanticName.lower() == numeric3Value
and desc.name == self.sVertexPositionItemName:
6260 if not vertexNumericLocationBuffer:
6261 vertexNumericLocationBuffer = data.createVertexBuffer(desc)
6262 if vertexNumericLocationBuffer:
6263 satisfiedRequirements[i] =
True
6264 if debugPopulateGeometry:
6265 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture")
6266 print(
"Acquire 3loat numeric location buffer")
6267 vertexNumericLocationDataAddress = vertexNumericLocationBuffer.acquire(totalVerts,
True)
6268 if vertexNumericLocationDataAddress:
6269 vertexNumericLocationData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericLocationDataAddress)
6272 elif desc.name != self.sVertexIdItemName
and desc.name != self.sVertexPositionItemName:
6274 uvBuffer = data.createVertexBuffer(desc)
6276 satisfiedRequirements[i] =
True
6277 if debugPopulateGeometry:
6278 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture")
6279 print(
"Acquire a uv buffer")
6280 uvDataAddress = uvBuffer.acquire(totalVerts,
True)
6282 uvData = ((ctypes.c_float * 2)*totalVerts).from_address(uvDataAddress)
6284 elif desc.semantic == omr.MGeometry.kColor:
6286 cpvBuffer = data.createVertexBuffer(desc)
6288 satisfiedRequirements[i] =
True
6289 if debugPopulateGeometry:
6290 print(
">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kColor")
6291 cpvDataAddress = cpvBuffer.acquire(totalVerts,
True)
6293 cpvData = ((ctypes.c_float * 4)*totalVerts).from_address(cpvDataAddress)
6304 for i
in range(self.fMeshGeom.faceCount):
6306 numVerts = self.fMeshGeom.face_counts[i]
6308 for v
in range(numVerts):
6309 if any((positionData, vertexNumericIdPositionData, vertexNumericLocationPositionData, vertexNumericLocationData)):
6310 position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
6313 positionData[pid][0] = position[0]
6314 positionData[pid][1] = position[1]
6315 positionData[pid][2] = position[2]
6317 if vertexNumericIdPositionData:
6318 vertexNumericIdPositionData[pid][0] = position[0]
6319 vertexNumericIdPositionData[pid][1] = position[1]
6320 vertexNumericIdPositionData[pid][2] = position[2]
6322 if vertexNumericLocationPositionData:
6323 vertexNumericLocationPositionData[pid][0] = position[0]
6324 vertexNumericLocationPositionData[pid][1] = position[1]
6325 vertexNumericLocationPositionData[pid][2] = position[2]
6327 if vertexNumericLocationData:
6328 vertexNumericLocationData[pid][0] = position[0]
6329 vertexNumericLocationData[pid][1] = position[1]
6330 vertexNumericLocationData[pid][2] = position[2]
6335 normal = self.fMeshGeom.normals[self.fMeshGeom.face_connects[vid]]
6336 normalData[nid][0] = normal[0]
6337 normalData[nid][1] = normal[1]
6338 normalData[nid][2] = normal[2]
6345 uvNum = self.fMeshGeom.uvcoords.uvId(vid)
6346 uv = self.fMeshGeom.uvcoords.getUV(uvNum)
6347 uvData[uvid][0] = uv[0]
6348 uvData[uvid][1] = uv[0]
6355 position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
6356 cpvData[cid][0] = position[0]
6357 cpvData[cid][1] = position[1]
6358 cpvData[cid][2] = position[2]
6359 cpvData[cid][3] = 1.0
6364 if vertexNumericIdData:
6365 vertexNumericIdData[vid] = (ctypes.c_float * 1)(self.fMeshGeom.face_connects[vid])
6373 if positionDataAddress:
6374 positionBuffer.commit(positionDataAddress)
6376 if normalDataAddress:
6377 normalBuffer.commit(normalDataAddress)
6380 uvBuffer.commit(uvDataAddress)
6383 cpvBuffer.commit(cpvDataAddress)
6385 if vertexNumericIdDataAddress:
6386 vertexNumericIdBuffer.commit(vertexNumericIdDataAddress)
6388 if vertexNumericIdPositionDataAddress:
6389 vertexNumericIdPositionBuffer.commit(vertexNumericIdPositionDataAddress)
6391 if vertexNumericLocationDataAddress:
6392 vertexNumericLocationBuffer.commit(vertexNumericLocationDataAddress)
6394 if vertexNumericLocationPositionDataAddress:
6395 vertexNumericLocationPositionBuffer.commit(vertexNumericLocationPositionDataAddress)
6400 if activeVertexPositionData:
6401 if debugPopulateGeometry:
6402 print(
">>> Fill in the data for active vertex position buffer base on component list")
6406 if activeVertexCount > len(self.fMeshGeom.vertices):
6407 activeVertexCount = len(self.fMeshGeom.vertices)
6409 for i
in range(activeVertexCount):
6410 position = self.fMeshGeom.vertices[ self.fActiveVertices[i] ]
6411 activeVertexPositionData[i][0] = position[0]
6412 activeVertexPositionData[i][1] = position[1]
6413 activeVertexPositionData[i][2] = position[2]
6415 activeVertexPositionBuffer.commit(activeVertexPositionDataAddress)
6417 if activeVertexUVData:
6418 if debugPopulateGeometry:
6419 print(
">>> Fill in the data for active vertex uv buffer base on component list")
6423 if activeVertexCount > len(self.fMeshGeom.vertices):
6424 activeVertexCount = len(self.fMeshGeom.vertices)
6426 for i
in range(activeVertexCount):
6427 activeVertexUVData[i] = i // activeVertexCount
6429 activeVertexUVBuffer.commit(activeVertexUVDataAddress)
6434 if faceCenterPositionData:
6435 if debugPopulateGeometry:
6436 print(
">>> Fill in the data for face center position buffer")
6442 for faceId
in range(self.fMeshGeom.faceCount):
6448 faceCenterPosition = om.MPoint()
6451 numVerts = self.fMeshGeom.face_counts[faceId]
6453 for v
in range(numVerts):
6454 face_vertex_position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
6455 x += face_vertex_position[0]
6456 y += face_vertex_position[1]
6457 z += face_vertex_position[2]
6461 faceCenterPosition = om.MPoint(x, y, z) / numVerts
6466 faceCenterPositionData[faceId][0] = faceCenterPosition[0]
6467 faceCenterPositionData[faceId][1] = faceCenterPosition[1]
6468 faceCenterPositionData[faceId][2] = faceCenterPosition[2]
6470 faceCenterPositionBuffer.commit(faceCenterPositionDataAddress)
6474 for i
in range(len(descList)):
6475 if satisfiedRequirements[i]:
6478 if self.fDrawSharedActiveVertices
and (desc.name == self.sActiveVertexStreamName):
6479 if desc.semantic == omr.MGeometry.kPosition:
6480 satisfiedRequirements[i] =
True
6481 self.cloneVertexBuffer(activeVertexPositionBuffer, data, desc, activeVertexCount, debugPopulateGeometry)
6482 elif desc.semantic == omr.MGeometry.kTexture:
6483 satisfiedRequirements[i] =
True
6484 self.cloneVertexBuffer(activeVertexUVBuffer, data, desc, activeVertexCount, debugPopulateGeometry)
6485 elif self.fDrawFaceCenters
and desc.name == self.sFaceCenterStreamName:
6486 if desc.semantic == omr.MGeometry.kPosition:
6487 satisfiedRequirements[i] =
True
6488 self.cloneVertexBuffer(faceCenterPositionBuffer, data, desc, self.fMeshGeom.faceCount, debugPopulateGeometry)
6490 if desc.semantic == omr.MGeometry.kPosition:
6491 if desc.name == self.sVertexIdItemName:
6492 satisfiedRequirements[i] =
True
6493 self.cloneVertexBuffer(vertexNumericIdPositionBuffer, data, desc, totalVerts, debugPopulateGeometry)
6494 elif desc.name == self.sVertexPositionItemName:
6495 satisfiedRequirements[i] =
True
6496 self.cloneVertexBuffer(vertexNumericLocationPositionBuffer, data, desc, totalVerts, debugPopulateGeometry)
6498 satisfiedRequirements[i] =
True
6499 self.cloneVertexBuffer(positionBuffer, data, desc, totalVerts, debugPopulateGeometry)
6500 elif desc.semantic == omr.MGeometry.kNormal:
6501 satisfiedRequirements[i] =
True
6502 self.cloneVertexBuffer(normalBuffer, data, desc, totalVerts, debugPopulateGeometry)
6503 elif desc.semantic == omr.MGeometry.kTexture:
6504 numericValue =
"numericvalue"
6505 numeric3Value =
"numeric3value"
6506 if desc.semanticName.lower() == numericValue
and desc.name == self.sVertexIdItemName:
6507 satisfiedRequirements[i] =
True
6508 self.cloneVertexBuffer(vertexNumericIdBuffer, data, desc, totalVerts, debugPopulateGeometry)
6509 elif desc.semanticName.lower() == numeric3Value
and desc.name == self.sVertexPositionItemName:
6510 satisfiedRequirements[i] =
True
6511 self.cloneVertexBuffer(vertexNumericLocationBuffer, data, desc, totalVerts, debugPopulateGeometry)
6512 elif desc.name != self.sVertexIdItemName
and desc.name != self.sVertexPositionItemName:
6513 satisfiedRequirements[i] =
True
6514 self.cloneVertexBuffer(uvBuffer, data, desc, totalVerts, debugPopulateGeometry)
6515 elif desc.semantic == omr.MGeometry.kColor:
6516 satisfiedRequirements[i] =
True
6517 self.cloneVertexBuffer(cpvBuffer, data, desc, totalVerts, debugPopulateGeometry)
6519 if not satisfiedRequirements[i]:
6522 destBuffer = data.createVertexBuffer(desc)
6524 satisfiedRequirements[i] =
True
6525 if debugPopulateGeometry:
6526 print(
">>> Fill in dummy requirement '%s'" % (desc.name, ))
6527 destBufferDataAddress = destBuffer.acquire(totalVerts,
True)
6528 if destBufferDataAddress:
6529 destBufferData = ((ctypes.c_float * desc.dimension)*totalVerts).from_address(destBufferDataAddress)
6531 for j
in range(totalVerts):
6532 if desc.dimension == 4:
6533 destBufferData[j] = (1.0, 0.0, 0.0, 1.0)
6534 elif desc.dimension == 3:
6535 destBufferData[j] = (1.0, 0.0, 0.0)
6537 for k
in range(desc.dimension):
6538 destBufferData[j][k] = 0.0
6539 destBuffer.commit(destBufferDataAddress)
6544 def cloneVertexBuffer(self, srcBuffer, data, desc, dataSize, debugPopulateGeometry):
6546 destBuffer = data.createVertexBuffer(desc)
6548 if debugPopulateGeometry:
6549 print(
">>> Cloning requirement '%s'" % (desc.name, ))
6550 destBufferDataAddress = destBuffer.acquire(dataSize,
True)
6551 srcBufferDataAddress = srcBuffer.map()
6552 if destBufferDataAddress
and srcBufferDataAddress:
6553 destBufferData = ((ctypes.c_float * desc.dimension)*dataSize).from_address(destBufferDataAddress)
6554 srcBufferData = ((ctypes.c_float * desc.dimension)*dataSize).from_address(srcBufferDataAddress)
6555 if destBufferData
and srcBufferData:
6556 for j
in range(dataSize):
6557 for k
in range(desc.dimension):
6558 destBufferData[j][k] = srcBufferData[j][k]
6559 destBuffer.commit(destBufferDataAddress)
6563 def updateIndexingForWireframeItems(self, wireIndexBuffer, item, data, totalVerts):
6571 if not wireIndexBuffer:
6572 wireIndexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6574 dataAddress = wireIndexBuffer.acquire(2*totalVerts,
True)
6576 data = (ctypes.c_uint * (2*totalVerts)).from_address(dataAddress)
6580 for faceIdx
in range(self.fMeshGeom.faceCount):
6582 numVerts = self.fMeshGeom.face_counts[faceIdx]
6585 for v
in range(numVerts-1):
6601 wireIndexBuffer.commit(dataAddress)
6605 item.associateWithIndexBuffer(wireIndexBuffer)
6607 def updateIndexingForDormantVertices(self, item, data, numTriangles):
6610 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6612 dataAddress = indexBuffer.acquire(3*numTriangles,
True)
6614 data = (ctypes.c_uint*(3*numTriangles)).from_address(dataAddress)
6619 for faceIdx
in range(self.fMeshGeom.faceCount):
6621 numVerts = self.fMeshGeom.face_counts[faceIdx]
6623 for v
in range(1, numVerts-1):
6625 data[idx+1] = base+v
6626 data[idx+2] = base+v+1
6631 indexBuffer.commit(dataAddress)
6633 item.associateWithIndexBuffer(indexBuffer)
6635 def updateIndexingForFaceCenters(self, item, data, debugPopulateGeometry):
6638 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6640 dataAddress = indexBuffer.acquire(self.fMeshGeom.faceCount,
True)
6642 data = (ctypes.c_uint * self.fMeshGeom.faceCount).from_address(dataAddress)
6643 if debugPopulateGeometry:
6644 print(
">>> Set up indexing for face centers")
6646 for i
in range(self.fMeshGeom.faceCount):
6651 for i
in range(self.fMeshGeom.faceCount):
6653 numVerts = self.fMeshGeom.face_counts[i]
6658 indexBuffer.commit(dataAddress)
6660 item.associateWithIndexBuffer(indexBuffer)
6662 def updateIndexingForVertices(self, item, data, numTriangles, activeVertexCount, debugPopulateGeometry):
6665 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6677 if self.fDrawSharedActiveVertices:
6678 dataAddress = indexBuffer.acquire(activeVertexCount,
True)
6680 data = (ctypes.c_uint*activeVertexCount).from_address(dataAddress)
6681 if debugPopulateGeometry:
6682 print(
">>> Set up indexing for shared vertices")
6684 for i
in range(activeVertexCount):
6690 if debugPopulateGeometry:
6691 print(
">>> Set up indexing for unshared vertices")
6693 vertexCount = 3*numTriangles
6694 dataAddress = indexBuffer.acquire(vertexCount,
True)
6696 data = (ctypes.c_uint*vertexCount).from_address(dataAddress)
6697 for i
in range(vertexCount):
6698 data[i] = vertexCount+1
6700 selectionIdSet = self.fActiveVerticesSet
6707 for faceIdx
in range(self.fMeshGeom.faceCount):
6709 numVerts = self.fMeshGeom.face_counts[faceIdx]
6711 for v
in range(1, numVerts-1):
6712 vertexId = self.fMeshGeom.face_connects[base]
6713 if vertexId
in selectionIdSet:
6715 data[idx] = lastFound
6718 vertexId = self.fMeshGeom.face_connects[base+v]
6719 if vertexId
in selectionIdSet:
6721 data[idx] = lastFound
6724 vertexId = self.fMeshGeom.face_connects[base+v+1]
6725 if vertexId
in selectionIdSet:
6726 lastFound = base+v+1
6727 data[idx] = lastFound
6732 for i
in range(vertexCount):
6733 if data[i] == vertexCount+1:
6737 indexBuffer.commit(dataAddress)
6739 item.associateWithIndexBuffer(indexBuffer)
6741 def updateIndexingForEdges(self, item, data, totalVerts, fromSelection):
6744 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6746 totalEdges = 2*totalVerts
6747 totalEdgesP1 = 2*totalVerts+1
6748 dataAddress = indexBuffer.acquire(totalEdges,
True)
6750 data = (ctypes.c_uint*totalEdges).from_address(dataAddress)
6751 for i
in range(totalEdges):
6752 data[i] = totalEdgesP1
6755 displayAll =
not fromSelection
6756 displayActives = (
not displayAll
and bool(self.fActiveEdgesSet))
6757 displayAffected = (
not displayAll
and not displayActives)
6759 selectionIdSet =
None
6761 selectionIdSet = self.fActiveEdgesSet
6762 elif displayAffected:
6763 selectionIdSet = self.fActiveVerticesSet
6769 for faceIdx
in range(self.fMeshGeom.faceCount):
6771 numVerts = self.fMeshGeom.face_counts[faceIdx]
6773 for v
in range(numVerts):
6774 enableEdge = displayAll
6775 vindex1 = base + (v % numVerts)
6776 vindex2 = base + ((v+1) % numVerts)
6782 vertexId = self.fMeshGeom.face_connects[vindex1]
6783 if vertexId
in selectionIdSet:
6788 vertexId2 = self.fMeshGeom.face_connects[vindex2]
6789 if vertexId2
in selectionIdSet:
6793 elif displayActives:
6796 if edgeId
in selectionIdSet:
6811 for i
in range(totalEdges):
6812 if data[i] == totalEdgesP1:
6815 indexBuffer.commit(dataAddress)
6817 item.associateWithIndexBuffer(indexBuffer)
6819 def updateIndexingForFaces(self, item, data, numTriangles, fromSelection):
6822 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6824 numTriangleVertices = 3*numTriangles
6825 dataAddress = indexBuffer.acquire(numTriangleVertices,
True)
6827 data = (ctypes.c_uint*numTriangleVertices).from_address(dataAddress)
6828 for i
in range(numTriangleVertices):
6829 data[i] = numTriangleVertices+1
6832 displayAll =
not fromSelection
6833 displayActives = (
not displayAll
and bool(self.fActiveFacesSet))
6834 displayAffected = (
not displayAll
and not displayActives)
6835 isolateSelect = item.isIsolateSelectCopy()
6839 enableFaces = [0] * self.fMeshGeom.faceCount
6841 for i
in range(self.fMeshGeom.faceCount):
6842 enableFaces[i] =
False
6845 fnComponent = om.MFnSingleIndexedComponent( item.shadingComponent() )
6846 if(fnComponent.componentType == om.MFn.kMeshPolygonComponent):
6847 faceIds = fnComponent.getElements()
6849 for i
in range(len(faceIds)):
6850 enableFaces[faceIds[i]] =
True
6853 selectionIdSet =
None
6855 selectionIdSet = self.fActiveFacesSet
6856 elif displayAffected:
6857 selectionIdSet = self.fActiveVerticesSet
6862 for faceIdx
in range(self.fMeshGeom.faceCount):
6864 numVerts = self.fMeshGeom.face_counts[faceIdx]
6871 for v
in range(1, numVerts-1):
6872 vertexId = self.fMeshGeom.face_connects[base]
6873 if vertexId
in selectionIdSet:
6878 vertexId2 = self.fMeshGeom.face_connects[base+v]
6879 if vertexId2
in selectionIdSet:
6884 vertexId3 = self.fMeshGeom.face_connects[base+v+1]
6885 if vertexId3
in selectionIdSet:
6887 lastFound = base+v+1
6889 elif displayActives:
6890 if (
not isolateSelect
or enableFaces[faceIdx]):
6893 if faceIdx
in selectionIdSet:
6896 elif (
not isolateSelect
or enableFaces[faceIdx]):
6905 for v
in range(1, numVerts-1):
6907 data[idx+1] = base+v
6908 data[idx+2] = base+v+1
6914 for i
in range(numTriangleVertices):
6915 if data[i] == numTriangleVertices+1:
6918 indexBuffer.commit(dataAddress)
6920 item.associateWithIndexBuffer(indexBuffer)
6922 def updateIndexingForShadedTriangles(self, item, data, numTriangles):
6926 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6928 isolateSelect = item.isIsolateSelectCopy()
6932 enableFaces = [0] * self.fMeshGeom.faceCount
6934 for i
in range(self.fMeshGeom.faceCount):
6935 enableFaces[i] =
False
6937 fnComponent = om.MFnSingleIndexedComponent( item.shadingComponent() )
6938 if(fnComponent.componentType == om.MFn.kMeshPolygonComponent):
6939 faceIds = fnComponent.getElements()
6941 for i
in range(len(faceIds)):
6942 enableFaces[faceIds[i]] =
True
6944 indices = [0] * numTriangles * 3
6948 for faceIdx
in range(self.fMeshGeom.faceCount):
6950 numVerts = self.fMeshGeom.face_counts[faceIdx]
6952 if (
not isolateSelect
or enableFaces[faceIdx]):
6953 for v
in range(1, numVerts-1):
6955 indices[idx+1] = base+v
6956 indices[idx+2] = base+v+1
6960 dataAddress = indexBuffer.acquire(len(indices),
True)
6962 data = (ctypes.c_uint * len(indices)).from_address(dataAddress)
6964 for i
in range(len(indices)):
6965 data[i] = indices[i]
6967 indexBuffer.commit(dataAddress)
6969 item.associateWithIndexBuffer(indexBuffer)
6982 def initializePlugin(obj):
6983 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
6986 plugin.registerData(
"apiMeshData_py", apiMeshData.id, apiMeshData.creator, om.MPxData.kGeometryData)
6988 sys.stderr.write(
"Failed to register data\n")
6992 plugin.registerShape(
"apiMesh_py", apiMeshGeometryShape.id, apiMeshGeometryShape.creator, apiMeshGeometryShape.initialize, apiMeshUI.creator, apiMeshGeometryShape.sDrawDbClassification)
6994 sys.stderr.write(
"Failed to register node\n")
6998 plugin.registerShape(
"apiMeshSubscene_py", apiMeshSubsceneShape.id, apiMeshSubsceneShape.creator, apiMeshSubsceneShape.initialize, apiMeshUI.creator, apiMeshSubsceneShape.sDrawDbClassification)
7000 sys.stderr.write(
"Failed to register node\n")
7004 plugin.registerNode(
"apiMeshCreator_py", apiMeshCreator.id, apiMeshCreator.creator, apiMeshCreator.initialize)
7006 sys.stderr.write(
"Failed to register node\n")
7010 omr.MDrawRegistry.registerGeometryOverrideCreator(apiMeshGeometryShape.sDrawDbClassification, apiMesh.sDrawRegistrantId, apiMeshGeometryOverride.creator)
7012 sys.stderr.write(
"Failed to register override\n")
7016 omr.MDrawRegistry.registerSubSceneOverrideCreator(apiMeshSubsceneShape.sDrawDbClassification, apiMesh.sDrawRegistrantId, apiMeshSubSceneOverride.creator)
7018 sys.stderr.write(
"Failed to register override\n")
7022 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sVertexItemName, meshVertComponentConverterGeometryOverride.creator)
7023 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sEdgeSelectionItemName, meshEdgeComponentConverterGeometryOverride.creator)
7024 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sFaceSelectionItemName, meshFaceComponentConverterGeometryOverride.creator)
7026 sys.stderr.write(
"Failed to register component converters\n")
7030 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sVertexSelectionName, simpleComponentConverterSubsceneOverride.creatorVertexSelection)
7031 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sEdgeSelectionName, simpleComponentConverterSubsceneOverride.creatorEdgeSelection)
7032 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sFaceSelectionName, simpleComponentConverterSubsceneOverride.creatorFaceSelection)
7034 sys.stderr.write(
"Failed to register component converters\n")
7037 def uninitializePlugin(obj):
7038 plugin = om.MFnPlugin(obj)
7040 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sVertexSelectionName)
7041 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sEdgeSelectionName)
7042 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sFaceSelectionName)
7045 for faceSelectionName
in sViewSelectedFaceSelectionNames:
7046 omr.MDrawRegistry.deregisterComponentConverter(faceSelectionName)
7049 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sVertexItemName)
7050 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sEdgeSelectionItemName)
7051 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sFaceSelectionItemName)
7054 omr.MDrawRegistry.deregisterGeometryOverrideCreator(apiMeshGeometryShape.sDrawDbClassification, apiMesh.sDrawRegistrantId)
7056 sys.stderr.write(
"Failed to deregister override\n")
7060 omr.MDrawRegistry.deregisterSubSceneOverrideCreator(apiMeshSubsceneShape.sDrawDbClassification, apiMesh.sDrawRegistrantId)
7062 sys.stderr.write(
"Failed to deregister override\n")
7066 plugin.deregisterNode(apiMeshCreator.id)
7068 sys.stderr.write(
"Failed to deregister node\n")
7072 plugin.deregisterNode(apiMeshSubsceneShape.id)
7074 sys.stderr.write(
"Failed to deregister node\n")
7078 plugin.deregisterNode(apiMeshGeometryShape.id)
7080 sys.stderr.write(
"Failed to deregister node\n")
7084 plugin.deregisterData(apiMeshData.id)
7086 sys.stderr.write(
"Failed to deregister data\n")