11 import sys, math, ctypes, collections
12 import maya.api.OpenMaya
as om
13 import maya.api.OpenMayaUI
as omui
14 import maya.api.OpenMayaRender
as omr
18 The presence of this function tells Maya that the plugin produces, and
19 expects to be passed, objects created using the Maya Python API 2.0.
24 def useSelectHighlight(selectedList, path):
26 displayStatus = omr.MGeometryUtilities.displayStatus(path)
27 if displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
30 pathCopy = om.MDagPath(path)
32 while pathCopy.length() > 0:
33 if selectedList.hasItem(pathCopy):
39 def floatApproxEqual(left, right):
40 return abs(left - right) < 0.0001
49 def __init__(self, other=None):
56 return self.faceVertexIndex[fvi]
58 def getUV(self, uvId):
59 return [ self.ucoord[uvId], self.vcoord[uvId] ]
62 return self.ucoord[uvId]
65 return self.vcoord[uvId]
68 return len(self.ucoord)
70 def append_uv(self, u, v):
71 self.ucoord.append( u )
72 self.vcoord.append( v )
75 self.ucoord = om.MFloatArray()
76 self.vcoord = om.MFloatArray()
77 self.faceVertexIndex = om.MIntArray()
79 def copy(self, other):
80 self.ucoord = om.MFloatArray(other.ucoord)
81 self.vcoord = om.MFloatArray(other.vcoord)
82 self.faceVertexIndex = om.MIntArray(other.faceVertexIndex)
86 self.vertices = om.MPointArray()
87 self.face_counts = om.MIntArray()
88 self.face_connects = om.MIntArray()
89 self.normals = om.MVectorArray()
90 self.uvcoords = apiMeshGeomUV()
93 def copy(self, other):
94 self.vertices = om.MPointArray(other.vertices)
95 self.face_counts = om.MIntArray(other.face_counts)
96 self.face_connects = om.MIntArray(other.face_connects)
97 self.normals = om.MVectorArray(other.normals)
98 self.uvcoords = apiMeshGeomUV(other.uvcoords)
99 self.faceCount = other.faceCount
117 kWrapString =
"\n\t\t"
119 kNormalKeyword =
"vn"
120 kTextureKeyword =
"vt"
121 kFaceKeyword =
"face"
124 class apiMeshGeomIterator(om.MPxGeometryIterator):
125 def __init__(self, userGeometry, components):
126 om.MPxGeometryIterator.__init__(self, userGeometry, components)
127 self.geometry = userGeometry
134 om.MPxGeometryIterator.reset(self)
135 self.currentPoint = 0
137 maxVertex = len(self.geometry.vertices)
138 self.maxPoints = maxVertex
147 pnt = self.geometry.vertices[ self.index() ]
150 def setPoint(self, pnt):
155 self.geometry.vertices[ self.index() ] = pnt
157 def iteratorCount(self):
162 return len(self.geometry.vertices)
170 class apiMeshData(om.MPxGeometryData):
171 typeName =
"apiMeshData"
172 id = om.MTypeId(0x80777)
179 om.MPxGeometryData.__init__(self)
180 self.fGeometry = apiMeshGeom()
183 self.fGeometry =
None
185 def readASCII(self, argList, idx):
186 idx = self.readVerticesASCII(argList, idx)
187 idx = self.readNormalsASCII(argList, idx)
188 idx = self.readFacesASCII(argList, idx)
189 idx = self.readUVASCII(argList, idx)
192 def readBinary(self, inputData, length):
196 def writeASCII(self):
197 data = self.writeVerticesASCII()
198 data += self.writeNormalsASCII()
199 data += self.writeFacesASCII()
200 data += writeUVASCII()
203 def writeBinary(self):
208 self.fGeometry.copy(src.fGeometry)
211 return apiMeshData.id
214 return apiMeshData.typeName
222 def iterator(self, componentList, component, useComponents, world=None):
224 return apiMeshGeomIterator(self.fGeometry, componentList)
226 return apiMeshGeomIterator(self.fGeometry, component)
234 def readVerticesASCII(self, argList, idx):
237 geomStr = argList.asString(idx)
242 if geomStr == kVertexKeyword:
243 idx = argList.lastArgUsed()+1
244 vertexCount = argList.asInt(idx)
245 idx = argList.lastArgUsed()+1
246 for i
in xrange(vertexCount):
247 vertex = argList.asPoint(idx)
248 idx = argList.lastArgUsed()+1
249 self.fGeometry.vertices.append(vertex)
253 def readNormalsASCII(self, argList, idx):
256 geomStr = argList.asString(idx)
261 if geomStr == kNormalKeyword:
262 idx = argList.lastArgUsed()+1
263 normalCount = argList.asInt(idx)
264 idx = argList.lastArgUsed()+1
265 for i
in xrange(normalCount):
266 normal = argList.asVector(idx)
267 idx = argList.lastArgUsed()+1
268 self.fGeometry.normals.append(normal)
272 def readFacesASCII(self, argList, idx):
275 geomStr = argList.asString(idx)
280 while geomStr == kFaceKeyword:
281 idx = argList.lastArgUsed()+1
282 faceCount = argList.asInt(idx)
283 idx = argList.lastArgUsed()+1
284 self.fGeometry.face_counts.append(faceCount)
285 for i
in xrange(faceCount):
286 vid = argList.asInt(idx)
287 idx = argList.lastArgUsed()+1
288 self.fGeometry.face_connects.append(vid)
291 geomStr = argList.asString(idx)
296 self.fGeometry.faceCount = len(self.fGeometry.face_counts)
299 def readUVASCII(self, argList, idx):
300 self.fGeometry.uvcoords.reset()
304 geomStr = argList.asString(idx)
309 if geomStr == kUVKeyword:
310 idx = argList.lastArgUsed()+1
311 uvCount = argList.asInt(idx)
312 idx = argList.lastArgUsed()+1
313 faceVertexListCount = argList.asInt(idx)
314 idx = argList.lastArgUsed()+1
315 for i
in xrange(uvCount):
316 u = argList.asDouble(idx)
317 idx = argList.lastArgUsed()+1
318 v = argList.asDouble(idx)
319 idx = argList.lastArgUsed()+1
320 self.fGeometry.uvcoords.append_uv(u, v)
322 for i
in xrange(faceVertexListCount):
323 fvi = argList.asInt(idx)
324 idx = argList.lastArgUsed()+1
325 self.fGeometry.uvcoords.faceVertexIndex.append( fvi )
329 def writeVerticesASCII(self):
330 vertexCount = len(self.fGeometry.vertices)
334 data += kDblQteChar + kVertexKeyword + kDblQteChar + kSpaceChar + str(vertexCount)
336 for i
in xrange(vertexCount):
337 vertex = self.fGeometry.vertices[i]
340 data += str(vertex[0]) + kSpaceChar + str(vertex[1]) + kSpaceChar + str(vertex[2])
344 def writeNormalsASCII(self):
345 normalCount = len(self.fGeometry.normals)
349 data += kDblQteChar + kNormalKeyword + kDblQteChar + kSpaceChar + str(normalCount)
351 for i
in xrange(normalCount):
352 normal = self.fGeometry.normals[i]
355 data += str(normal[0]) + kSpaceChar + str(normal[1]) + kSpaceChar + str(normal[2])
359 def writeFacesASCII(self):
360 numFaces = len(self.fGeometry.face_counts)
365 for i
in xrange(numFaces):
366 faceVertexCount = self.fGeometry.face_counts[i]
370 data += kDblQteChar + kFaceKeyword + kDblQteChar + kSpaceChar + str(faceVertexCount)
374 for v
in xrange(faceVertexCount):
375 value = self.fGeometry.face_connects[vid]
377 data += str(value) + kSpaceChar
382 def writeUVASCII(self):
383 uvCount = self.fGeometry.uvcoords.uvcount()
384 faceVertexCount = len(self.fGeometry.uvcoords.faceVertexIndex)
391 data += kDblQteChar + kUVKeyword + kDblQteChar + kSpaceChar + str(uvCount) + kSpaceChar + str(faceVertexCount)
393 for i
in xrange(uvCount):
394 uv = self.fGeometry.uvcoords.getUV(i)
397 data += uv[0] + kSpaceChar + uv[1] + kSpaceChar
399 for i
in xrange(faceVertexCount):
400 value = self.fGeometry.uvcoords.faceVertexIndex[i]
403 data += value + kSpaceChar
427 class apiMesh(om.MPxSurfaceShape):
428 id = om.MTypeId(0x80099)
439 useWeightedTransformUsingFunction =
None
440 useWeightedTweakUsingFunction =
None
457 typedAttr = om.MFnTypedAttribute()
458 numericAttr = om.MFnNumericAttribute()
461 apiMesh.inputSurface = typedAttr.create(
"inputSurface",
"is", apiMeshData.id, om.MObject.kNullObj )
462 typedAttr.storable =
False
463 om.MPxNode.addAttribute( apiMesh.inputSurface )
465 apiMesh.useWeightedTransformUsingFunction = numericAttr.create(
"useWeightedTransformUsingFunction",
"utru", om.MFnNumericData.kBoolean,
True )
466 numericAttr.keyable =
True
467 om.MPxNode.addAttribute( apiMesh.useWeightedTransformUsingFunction )
469 apiMesh.useWeightedTweakUsingFunction = numericAttr.create(
"useWeightedTweakUsingFunction",
"utwu", om.MFnNumericData.kBoolean,
True )
470 numericAttr.keyable =
True
471 om.MPxNode.addAttribute( apiMesh.useWeightedTweakUsingFunction )
477 apiMesh.bboxCorner1 = numericAttr.create(
"bboxCorner1",
"bb1", om.MFnNumericData.k3Double, 0 )
478 numericAttr.array =
False
479 numericAttr.usesArrayDataBuilder =
False
480 numericAttr.hidden =
False
481 numericAttr.keyable =
False
482 om.MPxNode.addAttribute( apiMesh.bboxCorner1 )
484 apiMesh.bboxCorner2 = numericAttr.create(
"bboxCorner2",
"bb2", om.MFnNumericData.k3Double, 0 )
485 numericAttr.array =
False
486 numericAttr.usesArrayDataBuilder =
False
487 numericAttr.hidden =
False
488 numericAttr.keyable =
False
489 om.MPxNode.addAttribute( apiMesh.bboxCorner2 )
493 apiMesh.outputSurface = typedAttr.create(
"outputSurface",
"os", apiMeshData.id, om.MObject.kNullObj )
494 typedAttr.writable =
False
495 om.MPxNode.addAttribute( apiMesh.outputSurface )
497 apiMesh.worldSurface = typedAttr.create(
"worldSurface",
"ws", apiMeshData.id, om.MObject.kNullObj )
498 typedAttr.cached =
False
499 typedAttr.writable =
False
500 typedAttr.array =
True
501 typedAttr.usesArrayDataBuilder =
True
502 typedAttr.disconnectBehavior = om.MFnAttribute.kDelete
503 typedAttr.worldSpace =
True
504 om.MPxNode.addAttribute( apiMesh.worldSurface )
508 apiMesh.cachedSurface = typedAttr.create(
"cachedSurface",
"cs", apiMeshData.id, om.MObject.kNullObj )
509 typedAttr.readable =
True
510 typedAttr.writable =
True
511 typedAttr.storable =
True
512 om.MPxNode.addAttribute( apiMesh.cachedSurface )
516 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.outputSurface )
517 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.worldSurface )
518 om.MPxNode.attributeAffects( apiMesh.outputSurface, apiMesh.worldSurface )
519 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.bboxCorner1 )
520 om.MPxNode.attributeAffects( apiMesh.inputSurface, apiMesh.bboxCorner2 )
521 om.MPxNode.attributeAffects( apiMesh.cachedSurface, apiMesh.outputSurface )
522 om.MPxNode.attributeAffects( apiMesh.cachedSurface, apiMesh.worldSurface )
524 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlPoints, apiMesh.outputSurface )
525 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueX, apiMesh.outputSurface )
526 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueY, apiMesh.outputSurface )
527 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueZ, apiMesh.outputSurface )
528 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlPoints, apiMesh.cachedSurface )
529 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueX, apiMesh.cachedSurface )
530 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueY, apiMesh.cachedSurface )
531 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueZ, apiMesh.cachedSurface )
532 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlPoints, apiMesh.worldSurface )
533 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueX, apiMesh.worldSurface )
534 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueY, apiMesh.worldSurface )
535 om.MPxNode.attributeAffects( om.MPxSurfaceShape.mControlValueZ, apiMesh.worldSurface )
538 om.MPxSurfaceShape.__init__(self)
548 def postConstructor(self):
563 self.isRenderable =
True
567 self.fHasHistoryOnCreate =
False
571 self.fShapeDirty =
True
572 self.fMaterialDirty =
True
574 def compute(self, plug, datablock):
587 if plug == apiMesh.outputSurface:
588 return self.computeOutputSurface( plug, datablock )
590 elif plug == apiMesh.cachedSurface:
591 return self.computeOutputSurface( plug, datablock )
593 elif plug == apiMesh.worldSurface:
594 return self.computeWorldSurface( plug, datablock )
599 def preEvaluation(self, context, evaluationNode):
611 if context.isNormal():
612 if evaluationNode.dirtyPlugExists(apiMesh.inputSurface)
or evaluationNode.dirtyPlugExists(apiMesh.mControlPoints):
615 def postEvaluation(self, context, evaluationNode, evalType):
628 if context.isNormal():
629 if evaluationNode.dirtyPlugExists(apiMesh.inputSurface)
or evaluationNode.dirtyPlugExists(apiMesh.mControlPoints):
630 self.notifyViewport()
632 def setDependentsDirty(self, plug, plugArray):
644 if plug == apiMesh.inputSurface
or plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
645 self.signalDirtyToViewport()
647 def getInternalValue(self, plug, handle):
673 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
681 if self.hasHistory():
682 return om.MPxNode.getInternalValue(self, plug, handle)
685 if plug == om.MPxSurfaceShape.mControlPoints
and not plug.isArray():
686 index = plug.logicalIndex()
687 pnt = self.getPointValue(index)
688 handle.set3Double( pnt[0], pnt[1], pnt[2] )
690 elif plug == om.MPxSurfaceShape.mControlValueX:
691 parentPlug = plug.parent()
692 index = parentPlug.logicalIndex()
693 val = self.getChannelValue( index, 0 )
694 handle.setDouble( val )
696 elif plug == om.MPxSurfaceShape.mControlValueY:
697 parentPlug = plug.parent()
698 index = parentPlug.logicalIndex()
699 val = self.getChannelValue( index, 1 )
700 handle.setDouble( val )
702 elif plug == om.MPxSurfaceShape.mControlValueZ:
703 parentPlug = plug.parent()
704 index = parentPlug.logicalIndex()
705 val = self.getChannelValue( index, 2 )
706 handle.setDouble( val )
715 elif plug == om.MPxSurfaceShape.mHasHistoryOnCreate:
716 handle.setBool( self.fHasHistoryOnCreate )
719 isOk = om.MPxSurfaceShape.getInternalValue(self, plug, handle)
723 def setInternalValue(self, plug, handle):
749 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
759 if self.hasHistory():
760 self.verticesUpdated()
761 return om.MPxNode.setInternalValue(self, plug, handle)
764 if plug == om.MPxSurfaceShape.mControlPoints
and not plug.isArray():
765 index = plug.logicalIndex()
766 self.setPointValue( index, handle.asDouble3() )
768 elif plug == om.MPxSurfaceShape.mControlValueX:
769 parentPlug = plug.parent()
770 index = parentPlug.logicalIndex()
771 self.setChannelValue( index, 0, handle.asDouble() )
773 elif plug == om.MPxSurfaceShape.mControlValueY:
774 parentPlug = plug.parent()
775 index = parentPlug.logicalIndex()
776 self.setChannelValue( index, 1, handle.asDouble() )
778 elif plug == om.MPxSurfaceShape.mControlValueZ:
779 parentPlug = plug.parent()
780 index = parentPlug.logicalIndex()
781 self.setChannelValue( index, 2, handle.asDouble() )
790 elif plug == om.MPxSurfaceShape.mHasHistoryOnCreate:
791 self.fHasHistoryOnCreate = handle.asBool()
794 isOk = om.MPxSurfaceShape.setInternalValue(self, plug, handle)
798 def connectionMade(self, plug, otherPlug, asSrc):
806 if plug == apiMesh.inputSurface:
807 thisObj = self.thisMObject()
808 historyPlug = om.MPlug( thisObj, om.MPxSurfaceShape.mHasHistoryOnCreate )
809 historyPlug.setBool(
True )
811 thisObj = self.thisMObject()
812 dgNode = om.MFnDependencyNode( thisObj )
813 instObjGroups = dgNode.findPlug(
"instObjGroups",
True)
814 if plug == instObjGroups:
815 self.setMaterialDirty(
True)
817 return om.MPxNode.connectionMade(self, plug, otherPlug, asSrc )
819 def connectionBroken(self, plug, otherPlug, asSrc):
827 if plug == apiMesh.inputSurface:
828 thisObj = self.thisMObject()
829 historyPlug = om.MPlug( thisObj, om.MPxSurfaceShape.mHasHistoryOnCreate )
830 historyPlug.setBool(
False )
832 thisObj = self.thisMObject()
833 dgNode = om.MFnDependencyNode( thisObj )
834 instObjGroups = dgNode.findPlug(
"instObjGroups",
True)
835 if plug == instObjGroups:
836 self.setMaterialDirty(
True)
838 return om.MPxNode.connectionBroken(self, plug, otherPlug, asSrc )
840 def shouldSave(self, plug):
851 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
852 if self.hasHistory():
856 result = om.MPxNode.shouldSave(self, plug)
861 elif plug == apiMesh.cachedSurface:
862 if self.hasHistory():
866 data = plug.asMObject()
867 result =
not data.isNull()
870 result = om.MPxNode.shouldSave(self, plug)
876 def componentToPlugs(self, component, list):
889 if component.hasFn(om.MFn.kSingleIndexedComponent):
890 fnVtxComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(component) )
891 thisNode = self.thisMObject()
892 plug = om.MPlug( thisNode, om.MPxSurfaceShape.mControlPoints )
896 self.convertToTweakNodePlug(plug)
898 for i
in xrange(fnVtxComp.elementCount):
899 plug.selectAncestorLogicalIndex(fnVtxComp.element(i), plug.attribute())
902 def matchComponent(self, item, spec, list):
926 result = om.MPxSurfaceShape.kMatchOk
928 dim = attrSpec.dimensions
934 if len(spec) == 1
and dim > 0
and attrSpec.name ==
"vtx":
935 numVertices = len(self.meshGeom().vertices)
936 attrIndex = attrSpec[0]
940 if attrIndex.hasLowerBound():
941 lower = attrIndex.getLower()
942 if attrIndex.hasUpperBound():
943 upper = attrIndex.getUpper()
947 if lower > upper
or upper >= numVertices:
948 result = om.MPxSurfaceShape.kMatchInvalidAttributeRange
951 path = item.getDagPath(0)
952 fnVtxComp = om.MFnSingleIndexedComponent()
953 vtxComp = fnVtxComp.create( om.MFn.kMeshVertComponent )
955 for i
in xrange(lower, upper+1):
956 fnVtxComp.addElement( i )
958 list.add( path, vtxComp )
962 result = om.MPxSurfaceShape.matchComponent(self, item, spec, list )
966 def match(self, mask, componentList):
987 if len(componentList) == 0:
988 result = mask.intersects( om.MSelectionMask.kSelectMeshes )
991 for comp
in componentList:
992 if comp.apiType() == om.MFn.kMeshVertComponent
and mask.intersects(om.MSelectionMask.kSelectMeshVerts):
1000 def createFullVertexGroup(self):
1015 fnComponent = om.MFnSingleIndexedComponent()
1016 fullComponent = fnComponent.create( om.MFn.kMeshVertComponent )
1021 numVertices = len(self.meshGeom().vertices)
1022 fnComponent.setCompleteData( numVertices )
1024 return fullComponent
1026 def getShapeSelectionMask(self):
1036 selType = om.MSelectionMask.kSelectMeshes
1037 return om.MSelectionMask( selType )
1039 def getComponentSelectionMask(self):
1049 selMask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
1050 selMask.addMask(om.MSelectionMask.kSelectMeshEdges)
1051 selMask.addMask(om.MSelectionMask.kSelectMeshFaces)
1054 def localShapeInAttr(self):
1067 return apiMesh.inputSurface
1069 def localShapeOutAttr(self):
1083 return apiMesh.outputSurface
1085 def worldShapeOutAttr(self):
1099 return apiMesh.outputSurface
1101 def cachedShapeAttr(self):
1113 return apiMesh.cachedSurface
1116 def geometryData(self):
1124 datablock = self.forceCache()
1125 handle = datablock.inputValue( apiMesh.inputSurface )
1126 return handle.data()
1128 def closestPoint(self, toThisPoint, theClosestPoint, tolerance):
1139 geometry = self.meshGeom()
1140 numVertices = len(geometry.vertices)
1141 for i
in xrange(numVertices):
1142 tryThisOne = geometry.vertices[i]
1146 theClosestPoint = geometry.vertices[0]
1150 def transformUsing(self, mat, componentList, cachingMode=om.MPxSurfaceShape.kNoPointCaching, pointCache=None):
1168 geometry = self.meshGeom()
1172 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1173 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1178 cacheLen = len(pointCache)
1183 if len(componentList) > 0:
1186 for comp
in componentList:
1187 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1188 elemCount = fnComp.elementCount
1190 for idx
in xrange(elementCount):
1191 elemIndex = fnComp.element(idx)
1192 geometry.vertices[elemIndex] = pointCache[cacheIndex]
1194 if cacheIndex >= cacheLen:
1197 if cacheIndex >= cacheLen:
1204 vertLen = len(geometry.vertices)
1205 for idx
in xrange(vertLen):
1206 geometry.vertices[idx] = pointCache[cacheIndex]
1208 if cacheIndex >= cacheLen:
1215 if len(componentList) > 0:
1218 setSizeIncrement =
True
1219 for comp
in componentList:
1220 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1221 elemCount = fnComp.elementCount
1223 if savePoints
and setSizeIncrement:
1224 pointCache.sizeIncrement = elemCount
1225 setSizeIncrement =
False
1227 for idx
in xrange(elemCount):
1228 elemIndex = fnComp.element(idx)
1230 pointCache.append(geometry.vertices[elemIndex])
1232 geometry.vertices[elemIndex] *= mat
1233 geometry.normals[idx] = geometry.normals[idx].transformAsNormal( mat )
1239 vertLen = len(geometry.vertices)
1241 pointCache.sizeIncrement = vertLen
1243 for idx
in xrange(vertLen):
1245 pointCache.append(geometry.vertices[idx])
1247 geometry.vertices[idx] *= mat
1248 geometry.normals[idx] = geometry.normals[idx].transformAsNormal( mat )
1251 self.updateCachedSurface( geometry, componentList )
1253 def tweakUsing(self, mat, componentList, cachingMode, pointCache, handle):
1274 geometry = self.meshGeom()
1278 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1279 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1280 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1282 builder = handle.builder()
1287 cacheLen = len(pointCache)
1292 if len(componentList) > 0:
1295 for comp
in componentList:
1296 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1297 elemCount = fnComp.elementCount
1299 for idx
in xrange(elementCount):
1300 elemIndex = fnComp.element(idx)
1301 cachePt = pointCache[cacheIndex]
1302 elem = builder.addElement( elemIndex )
1303 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1305 if cacheIndex >= cacheLen:
1308 if cacheIndex >= cacheLen:
1315 vertLen = len(geometry.vertices)
1316 for idx
in xrange(vertLen):
1317 cachePt = pointCache[cacheIndex]
1318 elem = builder.addElement( idx )
1319 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1321 if cacheIndex >= cacheLen:
1329 if len(componentList) > 0:
1330 setSizeIncrement =
True
1331 for comp
in componentList:
1332 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1333 elemCount = fnComp.elementCount
1335 if savePoints
and setSizeIncrement:
1336 pointCache.sizeIncrement = elemCount
1337 setSizeIncrement =
False
1339 for idx
in xrange(elementCount):
1340 elemIndex = fnComp.element(idx)
1341 currPt = newPt = geometry.vertices[elemIndex]
1343 delta = newPt - currPt
1344 elem = builder.addElement( elemIndex )
1345 elem.set3Double(delta.x, delta.y, delta.z)
1350 pointCache.append(delta*(-1.0))
1352 elif updatePoints
and cacheIndex < cacheLen:
1353 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1360 vertLen = len(geometry.vertices)
1362 pointCache.sizeIncrement = vertLen
1364 for idx
in xrange(vertLen):
1365 currPt = newPt = geometry.vertices[idx]
1367 delta = newPt - currPt
1368 elem = builder.addElement( idx )
1369 elem.set3Double(delta.x, delta.y, delta.z)
1374 pointCache.append(delta*(-1.0))
1376 elif updatePoints
and idx < cacheLen:
1377 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1387 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
1390 self.signalDirtyToViewport()
1394 def weightedTransformUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane):
1420 plg_useWeightedTransformUsingFunction = om.MPlug( self.thisMObject(), apiMesh.useWeightedTransformUsingFunction )
1421 val_useWeightedTransformUsingFunction = plg_useWeightedTransformUsingFunction.asBool()
1422 if not val_useWeightedTransformUsingFunction:
1423 om.MPxSurfaceShape.weightedTransformUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane)
1424 self.signalDirtyToViewport()
1429 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1430 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1431 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1432 transformOrigPoints = (cachingMode == om.MPxSurfaceShape.kTransformOriginalPoints
and pointCache
is not None)
1435 spaceInv = om.MMatrix()
1437 spaceInv = space.inverse()
1441 geometry = self.meshGeom()
1444 setSizeIncrement =
True
1446 for comp
in componentList:
1447 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1448 elemCount = fnComp.elementCount
1449 hasWeights = fnComp.hasWeights
1450 hasSeam = (freezePlane
is not None)
1452 if savePoints
and setSizeIncrement:
1453 pointCache.sizeIncrement = elemCount
1454 setSizeIncrement =
False
1456 for idx
in xrange(elementCount):
1457 elemIndex = fnComp.element( idx )
1460 perc = fnComp.weight(idx).influence()
1463 if perc > almostZero:
1466 geometry.vertices[elemIndex] = om.MVector( pointCache[pointCacheIndex] )
1467 pointCacheIndex += 1
1472 pointCache.append( geometry.vertices[elemIndex] )
1474 elif transformOrigPoints:
1475 geometry.vertices[elemIndex] = om.MVector( pointCache[pointCacheIndex] )
1478 pointCache[pointCacheIndex] = geometry.vertices[elemIndex]
1483 mat = xform.asMatrix()
1485 mat = space * xform.asMatrix(perc) * spaceInv
1487 mat = xform.asMatrix(perc)
1490 currPt = newPt = geometry.vertices[elemIndex]
1494 if hasSeam
and fnComp.weight(idx).seam() > 0.0:
1495 newPt += freezePlane.normal() * (fnComp.weight(idx).seam() * (freezePlane.directedDistance(currPt) - freezePlane.directedDistance(newPt)))
1498 geometry.vertices[elemIndex] = newPt
1499 pointCacheIndex += 1
1502 self.updateCachedSurface( geometry, componentList )
1504 def weightedTweakUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane, handle):
1535 plg_useWeightedTweakUsingFunction = om.MPlug( self.thisMObject(), apiMesh.useWeightedTweakUsingFunction )
1536 val_useWeightedTweakUsingFunction = plg_useWeightedTweakUsingFunction.asBool()
1537 if not val_useWeightedTweakUsingFunction:
1538 om.MPxSurfaceShape.weightedTweakUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane, handle)
1541 geometry = self.meshGeom()
1545 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1546 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1547 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1548 transformOrigPoints = (cachingMode == om.MPxSurfaceShape.kTransformOriginalPoints
and pointCache
is not None)
1550 builder = handle.builder()
1555 cacheLen = len(pointCache)
1562 for comp
in componentList:
1563 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1564 elemCount = fnComp.elementCount
1566 for idx
in xrange(elementCount):
1567 elemIndex = fnComp.element( idx )
1568 cachePt = pointCache[cacheIndex]
1569 elem = builder.addElement( elemIndex )
1570 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1572 if cacheIndex >= cacheLen:
1583 setSizeIncrement =
True
1584 spaceInv = om.MMatrix()
1586 spaceInv = space.inverse()
1588 for comp
in componentList:
1589 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1590 elemCount = fnComp.elementCount
1591 hasWeights = fnComp.hasWeights
1592 hasSeam = (freezePlane
is not None)
1594 if savePoints
and setSizeIncrement:
1595 pointCache.sizeIncrement = elemCount
1596 setSizeIncrement =
False
1598 for idx
in xrange(elementCount):
1599 elemIndex = fnComp.element( idx )
1602 perc = fnComp.weight(idx).influence()
1605 if perc > almostZero:
1611 mat = xform.asMatrix()
1613 mat = space * xform.asMatrix(perc) * spaceInv
1615 mat = xform.asMatrix(perc)
1620 if transformOrigPoints:
1621 geometry.vertices[elemIndex] = om.MVector( pointCache[cacheIndex] )
1625 currPt = newPt = geometry.vertices[elemIndex]
1630 if hasSeam
and fnComp.weight(idx).seam() > 0.0:
1631 newPt += freezePlane.normal() * (fnComp.weight(idx).seam() * (freezePlane.directedDistance(currPt) - freezePlane.directedDistance(newPt)))
1634 delta = newPt - currPt
1636 elem = builder.addElement( elemIndex )
1637 elem.set3Double(delta.x, delta.y, delta.z)
1642 pointCache.append(delta*(-1.0))
1643 elif updatePoints
and cacheIndex < cacheLen:
1644 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1654 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
1658 def vertexOffsetDirection(self, component, direction, mode, normalize):
1677 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(component) )
1678 if component.apiType() != om.MFn.kMeshVertComponent:
1681 geometry = self.meshGeom()
1688 normal = geometry.normals[ idx ]
1690 if mode == om.MPxSurfaceShape.kNormal:
1693 direction.append( normal )
1702 a = math.abs(normal[0])
1704 if a < math.abs(normal[1]):
1708 if a < math.abs(normal[2]):
1714 a = math.sqrt(normal[i]*normal[i] + normal[j]*normal[j])
1715 uAxis[i] = -normal[j]/a
1716 uAxis[j] = normal[i]/a
1718 vAxis = normal^uAxis
1720 if mode == om.MPxSurfaceShape.kUTangent
or mode == om.MPxSurfaceShape.kUVNTriad:
1723 direction.append( uAxis )
1725 if mode == om.MPxSurfaceShape.kVTangent
or mode == om.MPxSurfaceShape.kUVNTriad:
1728 direction.append( vAxis )
1730 if mode == om.MPxSurfaceShape.kUVNTriad:
1733 direction.append( normal )
1739 def isBounded(self):
1748 def boundingBox(self):
1755 if self.fShapeDirty:
1759 thisNode = self.thisMObject()
1760 c1Plug = om.MPlug( thisNode, apiMesh.bboxCorner1 )
1761 c2Plug = om.MPlug( thisNode, apiMesh.bboxCorner2 )
1762 corner1Object = c1Plug.asMObject()
1763 corner2Object = c2Plug.asMObject()
1765 fnData = om.MFnNumericData()
1766 fnData.setObject( corner1Object )
1767 corner1 = fnData.getData()
1769 fnData.setObject( corner2Object )
1770 corner2 = fnData.getData()
1772 corner1Point = om.MPoint( corner1[0], corner1[1], corner1[2] )
1773 corner2Point = om.MPoint( corner2[0], corner2[1], corner2[2] )
1775 return om.MBoundingBox( corner1Point, corner2Point )
1779 def geometryIteratorSetup(self, componentList, components, forReadOnly=False):
1796 if components.isNull():
1797 vtxComponents = om.MObjectArray([self.convertToVertexComponent(c)
for c
in componentList])
1798 return apiMeshGeomIterator( self.meshGeom(), vtxComponents )
1800 return apiMeshGeomIterator( self.meshGeom(), self.convertToVertexComponent(components) )
1802 def acceptsGeometryIterator(self, arg0, arg1=None, arg2=None):
1828 def hasHistory(self):
1834 return self.fHasHistoryOnCreate
1836 def shapeDirty(self):
1843 return self.fShapeDirty
1845 def resetShapeDirty(self):
1851 self.fShapeDirty =
False
1853 def materialDirty(self):
1860 return self.fMaterialDirty
1862 def setMaterialDirty(self, dirty):
1868 self.fMaterialDirty = dirty
1870 def computeInputSurface(self, plug, datablock):
1879 if self.hasHistory():
1880 inputHandle = datablock.inputValue( apiMesh.inputSurface )
1882 surf = inputHandle.asPluginData()
1883 if not isinstance(surf, apiMeshData):
1884 raise RuntimeError(
"computeInputSurface : invalid inputSurface data found")
1888 fnDataCreator = om.MFnPluginData()
1889 fnDataCreator.create( apiMeshData.id )
1891 newCachedData = fnDataCreator.data()
1892 if not isinstance(newCachedData, apiMeshData):
1893 raise RuntimeError(
"computeInputSurface : invalid proxy cached apiMeshData object")
1895 newCachedData.fGeometry.copy(surf.fGeometry)
1897 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
1898 if not isinstance(cachedHandle, om.MDataHandle):
1899 raise RuntimeError(
"computeInputSurface : invalid cachedSurface")
1901 cachedHandle.setMPxData( newCachedData )
1903 def computeOutputSurface(self, plug, datablock):
1918 self.computeInputSurface( plug, datablock )
1922 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
1923 if not isinstance(cachedHandle, om.MDataHandle):
1924 raise RuntimeError(
"computeOutputSurface : invalid cachedSurface")
1926 cached = cachedHandle.asPluginData()
1927 if not isinstance(cached, apiMeshData):
1928 raise RuntimeError(
"computeOutputSurface : invalid cachedSurface data found")
1930 datablock.setClean( plug )
1934 if self.hasHistory():
1935 self.applyTweaks( datablock, cached.fGeometry )
1938 cpHandle = datablock.inputArrayValue( om.MPxSurfaceShape.mControlPoints )
1939 cpHandle.setAllClean()
1943 fnDataCreator = om.MFnPluginData()
1944 fnDataCreator.create( apiMeshData.id )
1946 newData = fnDataCreator.data()
1947 if not isinstance(newData, apiMeshData):
1948 raise RuntimeError(
"computeOutputSurface : invalid proxy cached apiMeshData object")
1952 newData.fGeometry.copy(cached.fGeometry)
1956 outHandle = datablock.outputValue( apiMesh.outputSurface )
1957 outHandle.setMPxData( newData )
1961 self.computeBoundingBox( datablock )
1963 def computeWorldSurface(self, plug, datablock):
1970 self.computeOutputSurface( plug, datablock )
1971 inHandle = datablock.outputValue( apiMesh.outputSurface )
1972 outSurf = inHandle.asPluginData()
1973 if not isinstance(outSurf, apiMeshData):
1974 raise RuntimeError(
"computeWorldSurface : invalid outSurf")
1978 fnDataCreator = om.MFnPluginData()
1979 fnDataCreator.create( apiMeshData.id )
1981 newData = fnDataCreator.data()
1982 if not isinstance(newData, apiMeshData):
1983 raise RuntimeError(
"computeWorldSurface : invalid proxy cached apiMeshData object")
1986 worldMat = self.getWorldMatrix(datablock, 0)
1987 newData.matrix = worldMat
1991 newData.fGeometry.copy( outSurf.fGeometry )
1995 arrayIndex = plug.logicalIndex()
1997 worldHandle = datablock.outputArrayValue( apiMesh.worldSurface )
1998 builder = worldHandle.builder()
1999 outHandle = builder.addElement( arrayIndex )
2001 outHandle.setMPxData( newData )
2003 def computeBoundingBox(self, datablock):
2013 lowerHandle = datablock.outputValue( apiMesh.bboxCorner1 )
2014 upperHandle = datablock.outputValue( apiMesh.bboxCorner2 )
2016 geometry = self.meshGeom()
2017 cnt = len(geometry.vertices)
2023 tmppnt = geometry.vertices[0]
2024 lower = [ tmppnt[0], tmppnt[1], tmppnt[2] ]
2025 upper = [ tmppnt[0], tmppnt[1], tmppnt[2] ]
2027 for i
in xrange(cnt):
2028 pnt = geometry.vertices[i]
2030 if pnt[0] < lower[0]: lower[0] = pnt[0]
2031 if pnt[1] < lower[1]: lower[1] = pnt[1]
2032 if pnt[2] < lower[2]: lower[2] = pnt[2]
2034 if pnt[0] > upper[0]: upper[0] = pnt[0]
2035 if pnt[1] > upper[1]: upper[1] = pnt[1]
2036 if pnt[2] > upper[2]: upper[2] = pnt[2]
2038 lowerHandle.set3Double(lower[0], lower[1], lower[2])
2039 upperHandle.set3Double(upper[0], upper[1], upper[2])
2041 lowerHandle.setClean()
2042 upperHandle.setClean()
2046 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2048 def convertToVertexComponent(self, components):
2050 Converts edge and face components into vertex components. This
2051 allows applying transform offsets to the vertex when edge or faces
2057 srcComponent = om.MFnSingleIndexedComponent(components)
2058 srcComponentType = srcComponent.componentType
2062 if srcComponentType != om.MFn.kMeshVertComponent:
2063 srcIndices = set(srcComponent.getElements())
2064 retVal = srcComponent.create(om.MFn.kMeshVertComponent)
2065 vtxComponent = om.MFnSingleIndexedComponent(retVal)
2067 geomPtr = self.meshGeom()
2071 for faceIdx
in xrange(0, geomPtr.faceCount):
2073 numVerts = geomPtr.face_counts[faceIdx]
2075 for v
in xrange(0, numVerts):
2076 if srcComponentType == om.MFn.kMeshEdgeComponent:
2077 if edgeId
in srcIndices:
2078 vindex1 = base + (v % numVerts)
2079 vindex2 = base + ((v+1) % numVerts)
2081 vertexId1 = geomPtr.face_connects[vindex1]
2082 vertexId2 = geomPtr.face_connects[vindex2]
2084 vtxComponent.addElement(vertexId1)
2085 vtxComponent.addElement(vertexId2)
2090 if faceIdx
in srcIndices:
2091 vindex = base + (v % numVerts)
2092 vertexId = geomPtr.face_connects[vindex]
2093 vtxComponent.addElement(vertexId)
2099 def applyTweaks(self, datablock, geometry):
2107 cpHandle = datablock.inputArrayValue( om.MPxSurfaceShape.mControlPoints )
2111 while not cpHandle.isDone():
2112 elemIndex = cpHandle.elementLogicalIndex()
2113 pntHandle = cpHandle.outputValue()
2115 offset = pntHandle.asDouble3()
2119 geometry.vertices[elemIndex] += om.MPoint(offset[0],offset[1],offset[2])
2124 def updateCachedSurface(self, geometry, componentList):
2143 datablock = self.forceCache()
2145 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
2146 cached = cachedHandle.asPluginData()
2148 dHandle = datablock.outputValue( om.MPxSurfaceShape.mControlPoints )
2153 if self.hasHistory()
and cached:
2158 self.buildControlPoints( datablock, len(geometry.vertices) )
2160 cpHandle = om.MArrayDataHandle( dHandle )
2164 for comp
in componentList:
2165 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
2166 for elemIndex
in fnComp.getElements():
2167 cpHandle.jumpToLogicalElement( elemIndex )
2168 pntHandle = cpHandle.outputValue()
2170 pnt = pntHandle.asDouble3()
2172 oldPnt = cached.fGeometry.vertices[elemIndex]
2173 newPnt = geometry.vertices[elemIndex]
2174 offset = newPnt - oldPnt
2180 pntHandle.set3Double(pnt[0], pnt[1], pnt[2])
2185 cached.fGeometry.copy(geometry)
2187 pCPs = om.MPlug( self.thisMObject(), om.MPxSurfaceShape.mControlPoints)
2188 pCPs.setMDataHandle(dHandle)
2192 self.computeBoundingBox( datablock )
2197 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2200 self.signalDirtyToViewport()
2202 def getPointValue(self, pntInd):
2209 geometry = self.cachedGeom()
2211 return geometry.vertices[ pntInd ]
2215 def getChannelValue(self, pntInd, vlInd):
2222 geometry = self.cachedGeom()
2224 return geometry.vertices[ pntInd ][ vlInd ]
2228 def setPointValue(self, pntInd, val):
2235 geometry = self.cachedGeom()
2237 geometry.vertices[ pntInd ] = om.MPoint(val)
2239 self.verticesUpdated()
2241 def setChannelValue(self, pntInd, vlInd, val):
2248 geometry = self.cachedGeom()
2250 geometry.vertices[ pntInd ][ vlInd ] = val
2252 self.verticesUpdated()
2254 def meshObject(self):
2265 datablock = self.forceCache()
2271 handle = datablock.inputValue( apiMesh.outputSurface )
2272 return handle.data()
2281 fnData = om.MFnPluginData( self.meshObject() )
2282 data = fnData.data()
2283 if not isinstance(data, apiMeshData):
2284 raise RuntimeError(
"meshGeom : failed to get apiMeshData")
2286 return data.fGeometry
2288 def cachedObject(self):
2298 datablock = self.forceCache()
2299 handle = datablock.outputValue( apiMesh.cachedSurface )
2300 return handle.data()
2302 def cachedGeom(self):
2309 fnData = om.MFnPluginData( self.cachedObject() )
2310 data = fnData.data()
2311 if not isinstance(data, apiMeshData):
2312 raise RuntimeError(
"cachedGeom : failed to get apiMeshData")
2314 return data.fGeometry
2316 def buildControlPoints(self, datablock, count):
2324 cpH = datablock.outputArrayValue( om.MPxSurfaceShape.mControlPoints )
2326 oldBuilder = cpH.builder()
2327 if count != len(oldBuilder):
2330 builder = om.MArrayDataBuilder( oldBuilder )
2332 for vtx
in xrange(count):
2333 builder.addElement( vtx )
2339 def verticesUpdated(self):
2347 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2348 self.childChanged( om.MPxSurfaceShape.kObjectChanged )
2350 def setShapeDirty(self):
2351 self.fShapeDirty =
True
2353 def notifyViewport(self):
2354 omr.MRenderer.setGeometryDrawDirty(self.thisMObject())
2356 def signalDirtyToViewport(self):
2357 self.setShapeDirty()
2358 self.notifyViewport()
2368 class apiMeshUI(omui.MPxSurfaceShapeUI):
2375 omui.MPxSurfaceShapeUI.__init__(self)
2386 def drawUV(self, view, info):
2396 meshNode = self.surfaceShape()
2397 geom = meshNode.meshGeom()
2399 if geom.uvcoords.uvcount() > 0:
2400 view.setDrawColor( om.MColor( (1.0, 0.0, 0.0) ) )
2402 if info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawWireframe:
2403 self.drawUVWireframe( geom, view, info )
2405 elif info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawEverything
or info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawUVForSelect:
2406 self.drawUVWireframe( geom, view, info )
2407 self.drawUVMapCoordNum( geom, view, info,
True )
2410 self.drawUVWireframe( geom, view, info )
2412 def canDrawUV(self):
2418 meshNode = self.surfaceShape()
2419 geom = meshNode.meshGeom()
2420 return (geom.uvcoords.uvcount() > 0)
2424 def select(self, selectInfo, selectionList, worldSpaceSelectPts):
2438 componentSelected =
False
2441 hilited = (selectInfo.displayStatus() == omui.M3dView.kHilite)
2443 componentSelected = self.selectVertices( selectInfo, selectionList, worldSpaceSelectPts )
2444 selected = selected
or componentSelected
2447 meshNode = self.surfaceShape()
2454 priorityMask = om.MSelectionMask( om.MSelectionMask.kSelectNurbsSurfaces )
2456 item = om.MSelectionList()
2457 item.add( selectInfo.selectPath() )
2459 xformedPt = om.MPoint()
2460 if selectInfo.singleSelection():
2461 center = meshNode.boundingBox().center
2463 xformedPt *= selectInfo.selectPath().inclusiveMatrix()
2465 selectInfo.addSelection( item, xformedPt, selectionList, worldSpaceSelectPts, priorityMask,
False )
2475 def selectVertices(self, selectInfo, selectionList, worldSpaceSelectPts):
2489 view = selectInfo.view()
2490 path = selectInfo.multiPath()
2491 singleSelection = selectInfo.singleSelection()
2495 fnComponent = om.MFnSingleIndexedComponent()
2496 surfaceComponent = fnComponent.create( om.MFn.kMeshVertComponent )
2501 alignmentMatrix = om.MMatrix()
2503 alignmentMatrix = selectInfo.getAlignmentMatrix()
2505 singlePoint = om.MPoint()
2506 selectionPoint = om.MPoint()
2507 closestPointVertexIndex = -1
2512 meshNode = self.surfaceShape()
2513 geom = meshNode.meshGeom()
2518 for currentPoint
in geom.vertices:
2524 glBegin( GL_POINTS )
2525 glVertex3f( currentPoint[0], currentPoint[1], currentPoint[2] )
2528 if view.endSelect() > 0:
2532 xformedPoint = currentPoint
2533 xformedPoint.homogenize()
2534 xformedPoint *= alignmentMatrix
2536 if closestPointVertexIndex < 0
or z > previousZ:
2537 closestPointVertexIndex = vertexIndex
2538 singlePoint = currentPoint
2544 fnComponent.addElement( vertexIndex )
2548 if selected
and singleSelection:
2549 fnComponent.addElement(closestPointVertexIndex)
2553 selectionPoint = singlePoint
2554 selectionPoint *= path.inclusiveMatrix()
2559 selectionItem = om.MSelectionList()
2560 selectionItem.add( path, surfaceComponent )
2562 mask = om.MSelectionMask( om.MSelectionMask.kSelectComponentsMask )
2563 selectInfo.addSelection( selectionItem, selectionPoint, selectionList, worldSpaceSelectPts, mask,
True )
2567 def drawUVWireframe(self, geom, view, info):
2579 for i
in xrange(geom.faceCount):
2583 for v
in xrange(geom.face_counts[i]-1):
2584 uvId1 = geom.uvcoords.uvId(vid)
2585 uvId2 = geom.uvcoords.uvId(vid+1)
2587 uv1 = geom.uvcoords.getUV(uvId1)
2588 uv2 = geom.uvcoords.getUV(uvId2)
2590 glVertex3f( uv1[0], uv1[1], 0.0 )
2591 glVertex3f( uv2[0], uv2[1], 0.0 )
2594 uvId1 = geom.uvcoords.uvId(vid)
2595 uvId2 = geom.uvcoords.uvId(vid_start)
2597 uv1 = geom.uvcoords.getUV(uvId1)
2598 uv2 = geom.uvcoords.getUV(uvId2)
2600 glVertex3f( uv1[0], uv1[1], 0.0 )
2601 glVertex3f( uv2[0], uv2[1], 0.0 )
2608 def drawUVMapCoord(self, view, uvId, uv, drawNumbers):
2616 view.drawText( str(uvId), om.MPoint( uv[0], uv[1], 0 ), omui.M3dView.kCenter )
2618 glVertex3f( uv[0], uv[1], 0.0 )
2620 def drawUVMapCoordNum(self, geom, view, info, drawNumbers):
2628 ptSize = glGetFloatv( GL_POINT_SIZE )
2631 for uvId
in xrange(geom.uvcoords.uvcount()):
2632 uv = geom.uvcoords.getUV( uvId )
2633 self.drawUVMapCoord( view, uvId, uv, drawNumbers )
2635 glPointSize( ptSize )
2648 class apiMeshCreator(om.MPxNode):
2649 id = om.MTypeId(0x80089)
2659 outputSurface =
None
2663 return apiMeshCreator()
2667 typedAttr = om.MFnTypedAttribute()
2668 numericAttr = om.MFnNumericAttribute()
2669 enumAttr = om.MFnEnumAttribute()
2672 apiMeshCreator.size = numericAttr.create(
"size",
"sz", om.MFnNumericData.kDouble, 1 )
2673 numericAttr.array =
False
2674 numericAttr.usesArrayDataBuilder =
False
2675 numericAttr.hidden =
False
2676 numericAttr.keyable =
True
2677 om.MPxNode.addAttribute( apiMeshCreator.size )
2679 apiMeshCreator.shapeType = enumAttr.create(
"shapeType",
"st", 0 )
2680 enumAttr.addField(
"cube", 0 )
2681 enumAttr.addField(
"sphere", 1 )
2682 enumAttr.hidden =
False
2683 enumAttr.keyable =
True
2684 om.MPxNode.addAttribute( apiMeshCreator.shapeType )
2686 apiMeshCreator.inputMesh = typedAttr.create(
"inputMesh",
"im", om.MFnData.kMesh, om.MObject.kNullObj )
2687 typedAttr.hidden =
True
2688 om.MPxNode.addAttribute( apiMeshCreator.inputMesh )
2691 apiMeshCreator.outputSurface = typedAttr.create(
"outputSurface",
"os", apiMeshData.id, om.MObject.kNullObj )
2692 typedAttr.writable =
False
2693 om.MPxNode.addAttribute( apiMeshCreator.outputSurface )
2697 om.MPxNode.attributeAffects( apiMeshCreator.inputMesh, apiMeshCreator.outputSurface )
2698 om.MPxNode.attributeAffects( apiMeshCreator.size, apiMeshCreator.outputSurface )
2699 om.MPxNode.attributeAffects( apiMeshCreator.shapeType, apiMeshCreator.outputSurface )
2702 om.MPxNode.__init__(self)
2710 def compute(self, plug, datablock):
2718 if plug == apiMeshCreator.outputSurface:
2722 fnDataCreator = om.MFnPluginData()
2723 fnDataCreator.create( apiMeshData.id )
2725 newData = fnDataCreator.data()
2726 if not isinstance(newData, apiMeshData):
2727 raise RuntimeError(
"compute : invalid proxy cached apiMeshData object")
2729 geometry = newData.fGeometry
2734 hasHistory = self.computeInputMesh( plug, datablock, geometry )
2740 sizeHandle = datablock.inputValue( apiMeshCreator.size )
2741 shape_size = sizeHandle.asDouble()
2742 typeHandle = datablock.inputValue( apiMeshCreator.shapeType )
2743 shape_type = typeHandle.asShort()
2746 self.buildCube( shape_size, geometry )
2747 elif shape_type == 1:
2748 self.buildSphere( shape_size, 32, geometry )
2750 geometry.faceCount = len(geometry.face_counts)
2754 outHandle = datablock.outputValue( apiMeshCreator.outputSurface )
2755 outHandle.setMPxData( newData )
2756 datablock.setClean( plug )
2764 def computeInputMesh(self, plug, datablock, geometry):
2775 inputData = datablock.inputValue( apiMeshCreator.inputMesh )
2776 surf = inputData.asMesh()
2780 thisObj = self.thisMObject()
2781 surfPlug = om.MPlug( thisObj, apiMeshCreator.inputMesh )
2782 if not surfPlug.isConnected:
2783 datablock.setClean( plug )
2788 surfFn = om.MFnMesh(surf)
2789 geometry.vertices = surfFn.getPoints(om.MSpace.kObject)
2793 hasUVs = surfFn.numUVs() > 0
2794 uvs = surfFn.getUVs()
2795 geometry.uvcoords.ucoord = uvs[0]
2796 geometry.uvcoords.vcoord = uvs[1]
2798 for i
in xrange(surfFn.numPolygons()):
2799 polyVerts = surfFn.getPolygonVertices(i)
2801 pvc = len(polyVerts)
2802 geometry.face_counts.append( pvc )
2804 for v
in xrange(pvc):
2806 uvId = surfFn.getPolygonUVid(i, v)
2807 geometry.uvcoords.faceVertexIndex.append( uvId )
2808 geometry.face_connects.append( polyVerts[v] )
2810 for n
in xrange(len(geometry.vertices)):
2811 normal = surfFn.getVertexNormal(n)
2812 geometry.normals.append( normal )
2816 def buildCube(self, cube_size, geometry):
2823 geometry.vertices.clear()
2824 geometry.normals.clear()
2825 geometry.face_counts.clear()
2826 geometry.face_connects.clear()
2827 geometry.uvcoords.reset()
2829 geometry.vertices.append( om.MPoint( -cube_size, -cube_size, -cube_size ) )
2830 geometry.vertices.append( om.MPoint( cube_size, -cube_size, -cube_size ) )
2831 geometry.vertices.append( om.MPoint( cube_size, -cube_size, cube_size ) )
2832 geometry.vertices.append( om.MPoint( -cube_size, -cube_size, cube_size ) )
2833 geometry.vertices.append( om.MPoint( -cube_size, cube_size, -cube_size ) )
2834 geometry.vertices.append( om.MPoint( -cube_size, cube_size, cube_size ) )
2835 geometry.vertices.append( om.MPoint( cube_size, cube_size, cube_size ) )
2836 geometry.vertices.append( om.MPoint( cube_size, cube_size, -cube_size ) )
2838 normal_value = 0.5775
2839 geometry.normals.append( om.MVector( -normal_value, -normal_value, -normal_value ) )
2840 geometry.normals.append( om.MVector( normal_value, -normal_value, -normal_value ) )
2841 geometry.normals.append( om.MVector( normal_value, -normal_value, normal_value ) )
2842 geometry.normals.append( om.MVector( -normal_value, -normal_value, normal_value ) )
2843 geometry.normals.append( om.MVector( -normal_value, normal_value, -normal_value ) )
2844 geometry.normals.append( om.MVector( -normal_value, normal_value, normal_value ) )
2845 geometry.normals.append( om.MVector( normal_value, normal_value, normal_value ) )
2846 geometry.normals.append( om.MVector( normal_value, normal_value, -normal_value ) )
2851 uv_pts = [ [ 0.375, 0.0 ],
2868 num_face_connects = 24
2869 uv_fvid = [ 0, 1, 2, 3,
2876 for i
in xrange(uv_count):
2877 geometry.uvcoords.append_uv( uv_pts[i][0], uv_pts[i][1] )
2879 for i
in xrange(num_face_connects):
2880 geometry.uvcoords.faceVertexIndex.append( uv_fvid[i] )
2886 face_counts = [ 4, 4, 4, 4, 4, 4 ]
2888 for i
in xrange(num_faces):
2889 geometry.face_counts.append( face_counts[i] )
2893 face_connects = [ 0, 1, 2, 3,
2900 for i
in xrange(num_face_connects):
2901 geometry.face_connects.append( face_connects[i] )
2903 def buildSphere(self, radius, divisions, geometry):
2911 geometry.vertices.clear()
2912 geometry.normals.clear()
2913 geometry.face_counts.clear()
2914 geometry.face_connects.clear()
2915 geometry.uvcoords.reset()
2919 u_delta = math.pi / divisions
2920 v_delta = 2 * math.pi / divisions
2922 topPole = om.MPoint( 0.0, radius, 0.0 )
2923 botPole = om.MPoint( 0.0, -radius, 0.0 )
2927 geometry.vertices.append( botPole )
2928 geometry.normals.append( botPole - om.MPoint.kOrigin )
2930 for i
in xrange(divisions-1):
2934 for j
in xrange(divisions):
2935 x = radius * math.cos(u) * math.cos(v)
2936 y = radius * math.sin(u)
2937 z = radius * math.cos(u) * math.sin(v)
2939 pnt = om.MPoint( x, y, z )
2940 geometry.vertices.append( pnt )
2941 geometry.normals.append( pnt - om.MPoint.kOrigin )
2944 geometry.vertices.append( topPole )
2945 geometry.normals.append( topPole - om.MPoint.kOrigin )
2951 for i
in xrange(divisions):
2952 for j
in xrange(divisions):
2954 geometry.face_counts.append( 3 )
2956 geometry.face_connects.append( 0 )
2957 geometry.face_connects.append( j + vid )
2958 if j == divisions-1:
2959 geometry.face_connects.append( vid )
2961 geometry.face_connects.append( j + vid + 1 )
2963 elif i == divisions-1:
2964 geometry.face_counts.append( 3 )
2966 geometry.face_connects.append( j + vid + 1 - divisions )
2967 geometry.face_connects.append( vid + 1 )
2968 if j == divisions-1:
2969 geometry.face_connects.append( vid + 1 - divisions )
2971 geometry.face_connects.append( j + vid + 2 - divisions )
2974 geometry.face_counts.append( 4 )
2976 geometry.face_connects.append( j + vid + 1 - divisions )
2977 geometry.face_connects.append( j + vid + 1 )
2978 if j == divisions-1:
2979 geometry.face_connects.append( vid + 1 )
2980 geometry.face_connects.append( vid + 1 - divisions )
2982 geometry.face_connects.append( j + vid + 2 )
2983 geometry.face_connects.append( j + vid + 2 - divisions )
2990 class ShadedItemUserData(om.MUserData):
2991 def __init__(self, override):
2992 om.MUserData.__init__(self,
False)
2993 self.fOverride = override
2997 class apiMeshHWSelectionUserData(om.MUserData):
2999 om.MUserData.__init__(self,
True)
3000 self.fMeshGeom =
None
3014 class simpleComponentConverter_subsceneOverride(omr.MPxComponentConverter):
3015 def __init__(self, componentType, selectionType):
3016 omr.MPxComponentConverter.__init__(self)
3018 self.fComponentType = componentType
3019 self.fSelectionType = selectionType
3021 self.fComponent = om.MFnSingleIndexedComponent()
3022 self.fComponentObject = om.MObject.kNullObj
3023 self.fLookupTable = []
3025 def initialize(self, renderItem):
3027 self.fComponentObject = self.fComponent.create( self.fComponentType )
3032 if self.fComponentType == om.MFn.kMeshPolygonComponent:
3033 selectionData = renderItem.customData()
3034 if isinstance(selectionData, apiMeshHWSelectionUserData):
3035 meshGeom = selectionData.fMeshGeom
3039 for i
in xrange(meshGeom.faceCount):
3040 numVerts = meshGeom.face_counts[i]
3042 numTriangles += numVerts - 2
3043 self.fLookupTable = [0]*numTriangles
3047 for faceId
in xrange(meshGeom.faceCount):
3049 numVerts = meshGeom.face_counts[faceId]
3051 for v
in xrange(1, numVerts-1):
3052 self.fLookupTable[triId] = faceId
3055 def addIntersection(self, intersection):
3062 if self.fComponentType == om.MFn.kMeshEdgeComponent:
3065 if intersection.instanceID == 1
or intersection.instanceID == 3:
3068 idx = intersection.index
3070 if self.fComponentType == om.MFn.kMeshPolygonComponent:
3071 if idx >= 0
and idx < len(self.fLookupTable):
3072 idx = self.fLookupTable[idx]
3074 self.fComponent.addElement(idx)
3076 def component(self):
3078 return self.fComponentObject
3080 def selectionMask(self):
3082 return self.fSelectionType
3086 def creatorVertexSelection():
3087 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
3088 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
3089 return simpleComponentConverter_subsceneOverride(om.MFn.kMeshVertComponent, mask)
3093 def creatorEdgeSelection():
3094 return simpleComponentConverter_subsceneOverride(om.MFn.kMeshEdgeComponent, om.MSelectionMask.kSelectMeshEdges)
3098 def creatorFaceSelection():
3099 return simpleComponentConverter_subsceneOverride(om.MFn.kMeshPolygonComponent, om.MSelectionMask.kSelectMeshFaces)
3101 class apiMeshSubSceneOverride(omr.MPxSubSceneOverride):
3102 sWireName =
"apiMeshWire"
3103 sSelectName =
"apiMeshSelection"
3104 sBoxName =
"apiMeshBox"
3105 sSelectedBoxName =
"apiMeshBoxSelection"
3106 sShadedName =
"apiMeshShaded"
3107 sTexturedName =
"apiMeshTextured"
3109 sVertexSelectionName =
"apiMeshVertexSelection"
3110 sEdgeSelectionName =
"apiMeshEdgeSelection"
3111 sFaceSelectionName =
"apiMeshFaceSelection"
3113 sActiveVertexName =
"apiMeshActiveVertex"
3114 sActiveEdgeName =
"apiMeshActiveEdge"
3115 sActiveFaceName =
"apiMeshActiveFace"
3118 def __init__(self, transform, isSelected):
3119 self.fTransform = transform
3120 self.fIsSelected = isSelected
3124 return apiMeshSubSceneOverride(obj)
3127 def shadedItemLinkLost(userData):
3128 if not userData
is None and not userData.fOverride
is None:
3129 if not userData.fOverride.fMesh
is None:
3130 userData.fOverride.fMesh.setMaterialDirty(
True)
3131 userData.fOverride =
None
3134 def __init__(self, obj):
3135 omr.MPxSubSceneOverride.__init__(self, obj)
3137 node = om.MFnDependencyNode(obj)
3138 self.fMesh = node.userNode()
3139 self.fObject = om.MObject(obj)
3140 self.fWireShader =
None
3141 self.fThickWireShader =
None
3142 self.fSelectShader =
None
3143 self.fThickSelectShader =
None
3144 self.fShadedShader =
None
3145 self.fVertexComponentShader =
None
3146 self.fEdgeComponentShader =
None
3147 self.fFaceComponentShader =
None
3148 self.fPositionBuffer =
None
3149 self.fNormalBuffer =
None
3150 self.fBoxPositionBuffer =
None
3151 self.fWireIndexBuffer =
None
3152 self.fBoxIndexBuffer =
None
3153 self.fShadedIndexBuffer =
None
3154 self.fActiveVerticesIndexBuffer =
None
3155 self.fActiveEdgesIndexBuffer =
None
3156 self.fActiveFacesIndexBuffer =
None
3157 self.fThickLineWidth = -1.0
3158 self.fQueuedLineWidth = -1.0
3159 self.fNumInstances = 0
3160 self.fIsInstanceMode =
False
3161 self.fQueueUpdate =
False
3162 self.fUseQueuedLineUpdate =
False
3164 self.fInstanceInfoCache = collections.defaultdict(set)
3166 self.fActiveVerticesSet = set()
3167 self.fActiveEdgesSet = set()
3168 self.fActiveFacesSet = set()
3173 shaderMgr = omr.MRenderer.getShaderManager()
3175 if self.fWireShader:
3176 shaderMgr.releaseShader(self.fWireShader)
3177 self.fWireShader =
None
3179 if self.fThickWireShader:
3180 shaderMgr.releaseShader(self.fThickWireShader)
3181 self.fThickWireShader =
None
3183 if self.fSelectShader:
3184 shaderMgr.releaseShader(self.fSelectShader)
3185 self.fSelectShader =
None
3187 if self.fThickSelectShader:
3188 shaderMgr.releaseShader(self.fThickSelectShader)
3189 self.fThickSelectShader =
None
3191 if self.fShadedShader:
3192 shaderMgr.releaseShader(self.fShadedShader)
3193 self.fShadedShader =
None
3195 if self.fVertexComponentShader:
3196 shaderMgr.releaseShader(self.fVertexComponentShader)
3197 self.fVertexComponentShader =
None
3199 if self.fEdgeComponentShader:
3200 shaderMgr.releaseShader(self.fEdgeComponentShader)
3201 self.fEdgeComponentShader =
None
3203 if self.fFaceComponentShader:
3204 shaderMgr.releaseShader(self.fFaceComponentShader)
3205 self.fFaceComponentShader =
None
3209 def supportedDrawAPIs(self):
3211 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
3213 def requiresUpdate(self, container, frameContext):
3215 if len(container) == 0:
3222 def update(self, container, frameContext):
3224 self.manageRenderItems(container, frameContext, self.fMesh.shapeDirty()
or len(container) == 0)
3227 self.fMesh.resetShapeDirty()
3229 def furtherUpdateRequired(self, frameContext):
3230 if self.fUseQueuedLineUpdate:
3231 if not frameContext.inUserInteraction()
and not frameContext.userChangingViewContext():
3232 return self.fQueueUpdate
3236 def manageRenderItems(self, container, frameContext, updateGeometry):
3238 if not self.fMesh
or self.fObject.isNull():
3241 shaderMgr = omr.MRenderer.getShaderManager()
3245 node = om.MFnDagNode(self.fObject)
3246 instances = node.getAllPaths()
3247 if len(instances) == 0:
3251 sRed = [1.0, 0.0, 0.0, 1.0]
3252 sGreen = [0.0, 1.0, 0.0, 1.0]
3253 sWhite = [1.0, 1.0, 1.0, 1.0]
3256 if not self.fWireShader:
3257 self.fWireShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3258 self.fWireShader.setParameter(
"solidColor", sRed)
3260 if not self.fThickWireShader:
3261 self.fThickWireShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3262 self.fThickWireShader.setParameter(
"solidColor", sRed)
3264 if not self.fSelectShader:
3265 self.fSelectShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3266 self.fSelectShader.setParameter(
"solidColor", sGreen)
3268 if not self.fThickSelectShader:
3269 self.fThickSelectShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3270 self.fThickSelectShader.setParameter(
"solidColor", sGreen)
3272 if not self.fVertexComponentShader:
3273 self.fVertexComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dFatPointShader)
3274 self.fVertexComponentShader.setParameter(
"solidColor", sWhite)
3275 self.fVertexComponentShader.setParameter(
"pointSize", [5.0, 5.0])
3277 if not self.fEdgeComponentShader:
3278 self.fEdgeComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3279 self.fEdgeComponentShader.setParameter(
"solidColor", sWhite)
3280 self.fEdgeComponentShader.setParameter(
"lineWidth", [2.0, 2.0])
3282 if not self.fFaceComponentShader:
3283 self.fFaceComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3284 self.fFaceComponentShader.setParameter(
"solidColor", sWhite)
3286 if not self.fShadedShader:
3287 self.fShadedShader = shaderMgr.getStockShader(omr.MShaderManager.k3dBlinnShader)
3291 self.rebuildGeometryBuffers()
3293 if not all((self.fPositionBuffer, self.fNormalBuffer, self.fBoxPositionBuffer, self.fWireIndexBuffer, self.fBoxIndexBuffer, self.fShadedIndexBuffer)):
3294 print "At least one buffer is not set"
3297 selectedList = om.MGlobal.getActiveSelectionList()
3299 anyMatrixChanged =
False
3300 itemsChanged =
False
3301 instanceArrayLength = len(instances)
3302 numInstanceSelected = 0
3303 numInstanceUnselected = 0
3306 instanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3307 selectedInstanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3308 unselectedInstanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3310 for instance
in instances:
3316 if not instance.isValid
or not instance.isVisible:
3319 instanceNum = instance.instanceNumber()
3321 instanceInfo = apiMeshSubSceneOverride.InstanceInfo(instance.inclusiveMatrix(), useSelectHighlight(selectedList, instance))
3323 if instanceNum
not in self.fInstanceInfoCache
or self.fInstanceInfoCache[instanceNum].fIsSelected != instanceInfo.fIsSelected
or not self.fInstanceInfoCache[instanceNum].fTransform.isEquivalent(instanceInfo.fTransform):
3324 self.fInstanceInfoCache[instanceNum] = instanceInfo
3325 anyMatrixChanged =
True
3327 instanceMatrixArray[numInstances] = instanceInfo.fTransform
3329 if instanceInfo.fIsSelected:
3330 selectedInstanceMatrixArray[numInstanceSelected] = instanceInfo.fTransform
3331 numInstanceSelected += 1
3333 unselectedInstanceMatrixArray[numInstanceUnselected] = instanceInfo.fTransform
3334 numInstanceUnselected += 1
3336 instanceMatrixArray.setLength(numInstances)
3337 selectedInstanceMatrixArray.setLength(numInstanceSelected)
3338 unselectedInstanceMatrixArray.setLength(numInstanceUnselected)
3339 if self.fNumInstances != numInstances:
3340 anyMatrixChanged =
True
3341 self.fNumInstances = numInstances
3343 anyInstanceSelected = numInstanceSelected > 0
3344 anyInstanceUnselected = numInstanceUnselected > 0
3346 activeVerticesSet = set()
3347 activeEdgesSet = set()
3348 activeFacesSet = set()
3350 meshGeom = self.fMesh.meshGeom()
3351 if meshGeom
and self.fMesh.hasActiveComponents():
3352 activeComponents = self.fMesh.activeComponents()
3353 if len(activeComponents) > 0:
3354 fnComponent = om.MFnSingleIndexedComponent( activeComponents[0] )
3355 if fnComponent.elementCount > 0:
3356 activeIds = fnComponent.getElements()
3358 if fnComponent.componentType == om.MFn.kMeshVertComponent:
3359 activeVerticesSet = set(activeIds)
3361 elif fnComponent.componentType == om.MFn.kMeshEdgeComponent:
3362 activeEdgesSet = set(activeIds)
3364 elif fnComponent.componentType == om.MFn.kMeshPolygonComponent:
3365 activeFacesSet = set(activeIds)
3368 updateActiveItems = updateGeometry
or self.fActiveVerticesSet != activeVerticesSet
or self.fActiveEdgesSet != activeEdgesSet
or self.fActiveFacesSet != activeFacesSet
3369 self.fActiveVerticesSet = activeVerticesSet
3370 self.fActiveEdgesSet = activeEdgesSet
3371 self.fActiveFacesSet = activeFacesSet
3373 if updateActiveItems:
3374 self.rebuildActiveComponentIndexBuffers()
3376 anyVertexSelected = bool(self.fActiveVerticesSet)
3377 anyEdgeSelected = bool(self.fActiveEdgesSet)
3378 anyFaceSelected = bool(self.fActiveFacesSet)
3380 if (anyVertexSelected
and not self.fActiveVerticesIndexBuffer)
or (anyEdgeSelected
and not self.fActiveEdgesIndexBuffer)
or (anyFaceSelected
and not self.fActiveFacesIndexBuffer):
3385 wireItem = container.find(self.sWireName)
3386 if not wireItem
and anyInstanceUnselected:
3387 wireItem = omr.MRenderItem.create( self.sWireName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3388 wireItem.setDrawMode(omr.MGeometry.kWireframe)
3389 wireItem.setDepthPriority(omr.MRenderItem.sActiveWireDepthPriority)
3390 wireItem.setShader(self.fWireShader)
3391 container.add(wireItem)
3394 elif wireItem
and not anyInstanceUnselected:
3395 container.remove(self.sWireName)
3399 selectItem = container.find(self.sSelectName)
3400 if not selectItem
and anyInstanceSelected:
3401 selectItem = omr.MRenderItem.create( self.sSelectName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3402 selectItem.setDrawMode(omr.MGeometry.kWireframe | omr.MGeometry.kShaded | omr.MGeometry.kTextured)
3403 selectItem.setDepthPriority(omr.MRenderItem.sActiveWireDepthPriority)
3404 selectItem.setShader(self.fSelectShader)
3405 container.add(selectItem)
3408 elif selectItem
and not anyInstanceSelected:
3409 container.remove(self.sSelectName)
3413 boxItem = container.find(self.sBoxName)
3414 if not boxItem
and anyInstanceUnselected:
3415 boxItem = omr.MRenderItem.create( self.sBoxName, omr.MRenderItem.NonMaterialSceneItem, omr.MGeometry.kLines)
3416 boxItem.setDrawMode(omr.MGeometry.kBoundingBox)
3417 boxItem.setShader(self.fWireShader)
3418 container.add(boxItem)
3421 elif boxItem
and not anyInstanceUnselected:
3422 container.remove(self.sBoxName)
3426 selectedBoxItem = container.find(self.sSelectedBoxName)
3427 if not selectedBoxItem
and anyInstanceSelected:
3428 selectedBoxItem = omr.MRenderItem.create( self.sSelectedBoxName, omr.MRenderItem.NonMaterialSceneItem, omr.MGeometry.kLines)
3429 selectedBoxItem.setDrawMode(omr.MGeometry.kBoundingBox)
3430 selectedBoxItem.setShader(self.fSelectShader)
3431 container.add(selectedBoxItem)
3434 elif selectedBoxItem
and not anyInstanceSelected:
3435 container.remove(self.sSelectedBoxName)
3436 selectedBoxItem =
None
3439 shadedItem = container.find(self.sShadedName)
3442 shadedItem = omr.MRenderItem.create( self.sShadedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
3443 shadedItem.setDrawMode(omr.MGeometry.kShaded)
3444 shadedItem.setExcludedFromPostEffects(
False)
3445 shadedItem.setCastsShadows(
True)
3446 shadedItem.setReceivesShadows(
True)
3447 container.add(shadedItem)
3450 texturedItem = container.find(self.sTexturedName)
3451 if not texturedItem:
3453 texturedItem = omr.MRenderItem.create( self.sTexturedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
3454 texturedItem.setDrawMode(omr.MGeometry.kTextured)
3455 texturedItem.setExcludedFromPostEffects(
False)
3456 texturedItem.setCastsShadows(
True)
3457 texturedItem.setReceivesShadows(
True)
3458 container.add(texturedItem)
3465 connectedPlugs = om.MPlugArray()
3466 (sets, comps) = node.getConnectedSetsAndMembers(0,
True)
3468 dn = om.MFnDependencyNode(obj)
3469 shaderPlug = dn.findPlug(
"surfaceShader",
True)
3470 connectedPlugs = shaderPlug.connectedTo(
True,
False)
3471 if len(connectedPlugs) > 0:
3475 if self.fMesh.materialDirty()
or not shadedItem.isShaderFromNode():
3476 if len(connectedPlugs) == 0
or \
3477 not shadedItem.setShaderFromNode(connectedPlugs[0].node(),
3479 apiMeshSubSceneOverride.shadedItemLinkLost,
3480 ShadedItemUserData(self),
3482 shadedItem.setShader(self.fShadedShader)
3485 if self.fMesh.materialDirty()
or not texturedItem.isShaderFromNode():
3486 if len(connectedPlugs) == 0
or \
3487 not texturedItem.setShaderFromNode(connectedPlugs[0].node(),
3489 apiMeshSubSceneOverride.shadedItemLinkLost,
3490 ShadedItemUserData(self),
3492 texturedItem.setShader(self.fShadedShader)
3496 self.fMesh.setMaterialDirty(
False)
3501 vertexSelectionItem = container.find(self.sVertexSelectionName)
3502 if not vertexSelectionItem:
3503 vertexSelectionItem = omr.MRenderItem.create( self.sVertexSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
3505 vertexSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
3507 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
3508 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
3509 vertexSelectionItem.setSelectionMask( mask )
3511 vertexSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
3512 vertexSelectionItem.setShader(self.fVertexComponentShader)
3513 container.add(vertexSelectionItem)
3519 useDrawInstancingOnEdgeSelectionItem =
False
3522 edgeSelectionItem = container.find(self.sEdgeSelectionName)
3523 if not edgeSelectionItem:
3525 drawMode = omr.MGeometry.kSelectionOnly
3526 depthPriority = omr.MRenderItem.sSelectionDepthPriority
3527 if useDrawInstancingOnEdgeSelectionItem:
3529 drawMode = omr.MGeometry.kAll
3531 depthPriority = omr.MRenderItem.sActiveWireDepthPriority-1
3533 edgeSelectionItem = omr.MRenderItem.create( self.sEdgeSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3534 edgeSelectionItem.setDrawMode(drawMode)
3536 edgeSelectionItem.setDepthPriority(depthPriority)
3538 edgeSelectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshEdges )
3539 edgeSelectionItem.setShader(self.fWireShader)
3540 container.add(edgeSelectionItem)
3544 faceSelectionItem = container.find(self.sFaceSelectionName)
3545 if not faceSelectionItem:
3546 faceSelectionItem = omr.MRenderItem.create( self.sFaceSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
3548 faceSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
3550 faceSelectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshFaces )
3552 faceSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
3553 faceSelectionItem.setShader(self.fFaceComponentShader)
3554 container.add(faceSelectionItem)
3559 mySelectionData = apiMeshHWSelectionUserData()
3560 mySelectionData.fMeshGeom = self.fMesh.meshGeom()
3561 faceSelectionItem.setCustomData(mySelectionData)
3564 activeVertexItem = container.find(self.sActiveVertexName)
3565 if not activeVertexItem
and anyVertexSelected:
3566 activeVertexItem = omr.MRenderItem.create( self.sActiveVertexName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
3567 activeVertexItem.setDrawMode(omr.MGeometry.kAll)
3568 activeVertexItem.setDepthPriority(omr.MRenderItem.sActivePointDepthPriority)
3569 activeVertexItem.setShader(self.fVertexComponentShader)
3570 container.add(activeVertexItem)
3573 elif activeVertexItem
and not anyVertexSelected:
3574 container.remove(self.sActiveVertexName)
3575 activeVertexItem =
None
3579 activeEdgeItem = container.find(self.sActiveEdgeName)
3580 if not activeEdgeItem
and anyEdgeSelected:
3581 activeEdgeItem = omr.MRenderItem.create( self.sActiveEdgeName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3582 activeEdgeItem.setDrawMode(omr.MGeometry.kAll)
3583 activeEdgeItem.setDepthPriority(omr.MRenderItem.sActiveLineDepthPriority)
3584 activeEdgeItem.setShader(self.fEdgeComponentShader)
3585 container.add(activeEdgeItem)
3588 elif activeEdgeItem
and not anyEdgeSelected:
3589 container.remove(self.sActiveEdgeName)
3590 activeEdgeItem =
None
3594 activeFaceItem = container.find(self.sActiveFaceName)
3595 if not activeFaceItem
and anyFaceSelected:
3596 activeFaceItem = omr.MRenderItem.create( self.sActiveFaceName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
3597 activeFaceItem.setDrawMode(omr.MGeometry.kAll)
3598 activeFaceItem.setDepthPriority(omr.MRenderItem.sActiveLineDepthPriority)
3599 activeFaceItem.setShader(self.fFaceComponentShader)
3600 container.add(activeFaceItem)
3603 elif activeFaceItem
and not anyFaceSelected:
3604 container.remove(self.sActiveFaceName)
3605 activeFaceItem =
None
3609 lineWidth = frameContext.getGlobalLineWidth()
3610 userWidthChange =
not floatApproxEqual(lineWidth, self.fThickLineWidth)
3613 targetRefinedLineWidth = 50.0
3615 self.fThickLineWidth = lineWidth
3619 if self.fUseQueuedLineUpdate:
3620 self.fQueuedLineWidth = lineWidth
3621 if self.fQueuedLineWidth < targetRefinedLineWidth:
3622 self.fQueueUpdate =
True
3628 if self.fUseQueuedLineUpdate
and self.fQueueUpdate:
3629 if self.fQueuedLineWidth < targetRefinedLineWidth:
3630 lineWidth = self.fQueuedLineWidth
3631 self.fQueuedLineWidth += 1
3632 self.fQueueUpdate =
True
3637 self.fQueueUpdate =
False
3640 if not floatApproxEqual(lineWidth, 1.0):
3642 lineWidthArray = [ lineWidth, lineWidth ]
3643 self.fThickWireShader.setParameter(
"lineWidth", lineWidthArray)
3644 self.fThickSelectShader.setParameter(
"lineWidth", lineWidthArray)
3646 wireItem.setShader(self.fThickWireShader)
3648 selectItem.setShader(self.fThickSelectShader)
3652 wireItem.setShader(self.fWireShader)
3654 selectItem.setShader(self.fSelectShader)
3657 if itemsChanged
or updateGeometry:
3658 bounds = self.fMesh.boundingBox()
3660 wireBuffers = omr.MVertexBufferArray()
3661 wireBuffers.append(self.fPositionBuffer,
"positions")
3663 self.setGeometryForRenderItem(wireItem, wireBuffers, self.fWireIndexBuffer, bounds)
3665 self.setGeometryForRenderItem(selectItem, wireBuffers, self.fWireIndexBuffer, bounds)
3667 boxBuffers = omr.MVertexBufferArray()
3668 boxBuffers.append(self.fBoxPositionBuffer,
"positions")
3670 self.setGeometryForRenderItem(boxItem, boxBuffers, self.fBoxIndexBuffer, bounds)
3672 self.setGeometryForRenderItem(selectedBoxItem, boxBuffers, self.fBoxIndexBuffer, bounds)
3674 shadedBuffers = omr.MVertexBufferArray()
3675 shadedBuffers.append(self.fPositionBuffer,
"positions")
3676 shadedBuffers.append(self.fNormalBuffer,
"normals")
3677 self.setGeometryForRenderItem(shadedItem, shadedBuffers, self.fShadedIndexBuffer, bounds)
3678 self.setGeometryForRenderItem(texturedItem, shadedBuffers, self.fShadedIndexBuffer, bounds)
3681 self.setGeometryForRenderItem(vertexSelectionItem, wireBuffers, objectBox = bounds)
3682 self.setGeometryForRenderItem(edgeSelectionItem, wireBuffers, self.fWireIndexBuffer, bounds)
3683 self.setGeometryForRenderItem(faceSelectionItem, wireBuffers, self.fShadedIndexBuffer, bounds)
3686 if itemsChanged
or updateActiveItems:
3687 bounds = self.fMesh.boundingBox()
3689 vertexBuffer = omr.MVertexBufferArray()
3690 vertexBuffer.append(self.fPositionBuffer,
"positions")
3692 if activeVertexItem:
3693 self.setGeometryForRenderItem(activeVertexItem, vertexBuffer, self.fActiveVerticesIndexBuffer, bounds)
3695 self.setGeometryForRenderItem(activeEdgeItem, vertexBuffer, self.fActiveEdgesIndexBuffer, bounds)
3697 self.setGeometryForRenderItem(activeFaceItem, vertexBuffer, self.fActiveFacesIndexBuffer, bounds)
3700 if itemsChanged
or anyMatrixChanged:
3701 if not self.fIsInstanceMode
and numInstances == 1:
3704 objToWorld = instanceMatrixArray[0]
3707 wireItem.setMatrix(objToWorld)
3709 selectItem.setMatrix(objToWorld)
3711 boxItem.setMatrix(objToWorld)
3713 selectedBoxItem.setMatrix(objToWorld)
3714 shadedItem.setMatrix(objToWorld)
3715 texturedItem.setMatrix(objToWorld)
3717 vertexSelectionItem.setMatrix(objToWorld)
3718 edgeSelectionItem.setMatrix(objToWorld)
3719 faceSelectionItem.setMatrix(objToWorld)
3721 if useDrawInstancingOnEdgeSelectionItem:
3724 transform1 = objToWorld
3727 transform2 = objToWorld * 2
3730 transform3 = objToWorld * 3
3734 transforms = om.MMatrixArray((transform1, transform2, transform3))
3735 self.setInstanceTransformArray(edgeSelectionItem, transforms)
3740 self.removeAllInstances(edgeSelectionItem)
3744 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform1)
3745 print "newInstanceId " + str(newInstanceId)
3746 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform2)
3747 print "newInstanceId " + str(newInstanceId)
3748 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform3)
3749 print "newInstanceId " + str(newInstanceId)
3751 if activeVertexItem:
3752 activeVertexItem.setMatrix(objToWorld)
3754 activeEdgeItem.setMatrix(objToWorld)
3756 activeFaceItem.setMatrix(objToWorld)
3771 self.setInstanceTransformArray(wireItem, unselectedInstanceMatrixArray)
3773 self.setInstanceTransformArray(selectItem, selectedInstanceMatrixArray)
3775 self.setInstanceTransformArray(boxItem, unselectedInstanceMatrixArray)
3777 self.setInstanceTransformArray(selectedBoxItem, selectedInstanceMatrixArray)
3778 self.setInstanceTransformArray(shadedItem, instanceMatrixArray)
3779 self.setInstanceTransformArray(texturedItem, instanceMatrixArray)
3781 self.setInstanceTransformArray(vertexSelectionItem, instanceMatrixArray)
3782 self.setInstanceTransformArray(edgeSelectionItem, instanceMatrixArray)
3783 self.setInstanceTransformArray(faceSelectionItem, instanceMatrixArray)
3785 if activeVertexItem:
3786 self.setInstanceTransformArray(activeVertexItem, instanceMatrixArray)
3788 self.setInstanceTransformArray(activeEdgeItem, instanceMatrixArray)
3790 self.setInstanceTransformArray(activeFaceItem, instanceMatrixArray)
3795 self.fIsInstanceMode =
True
3797 if itemsChanged
or anyMatrixChanged
or updateGeometry:
3799 omr.MRenderer.setLightsAndShadowsDirty()
3801 def rebuildGeometryBuffers(self):
3803 meshGeom = self.fMesh.meshGeom()
3806 bounds = self.fMesh.boundingBox()
3809 self.clearGeometryBuffers()
3814 totalPoints = len(meshGeom.vertices)
3815 for i
in xrange(meshGeom.faceCount):
3816 numVerts = meshGeom.face_counts[i]
3818 numTriangles += numVerts - 2
3819 totalVerts += numVerts
3822 posDesc = omr.MVertexBufferDescriptor(
"", omr.MGeometry.kPosition, omr.MGeometry.kFloat, 3)
3823 normalDesc = omr.MVertexBufferDescriptor(
"", omr.MGeometry.kNormal, omr.MGeometry.kFloat, 3)
3825 self.fPositionBuffer = omr.MVertexBuffer(posDesc)
3826 self.fNormalBuffer = omr.MVertexBuffer(normalDesc)
3827 self.fBoxPositionBuffer = omr.MVertexBuffer(posDesc)
3829 positionDataAddress = self.fPositionBuffer.acquire(totalPoints,
True)
3830 normalDataAddress = self.fNormalBuffer.acquire(totalPoints,
True)
3831 boxPositionDataAddress = self.fBoxPositionBuffer.acquire(8,
True)
3834 self.fWireIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3835 self.fBoxIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3836 self.fShadedIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3838 wireBufferDataAddress = self.fWireIndexBuffer.acquire(2*totalVerts,
True)
3839 boxBufferDataAddress = self.fBoxIndexBuffer.acquire(24,
True)
3840 shadedBufferDataAddress = self.fShadedIndexBuffer.acquire(3*numTriangles,
True)
3843 if not all((positionDataAddress, normalDataAddress, boxPositionDataAddress, wireBufferDataAddress, boxBufferDataAddress, shadedBufferDataAddress)):
3844 print "At least one buffer data is not valid"
3845 self.clearGeometryBuffers()
3848 positionData = ((ctypes.c_float * 3)*totalPoints).from_address(positionDataAddress)
3849 normalData = ((ctypes.c_float * 3)*totalPoints).from_address(normalDataAddress)
3850 boxPositionData = ((ctypes.c_float * 3)*8).from_address(boxPositionDataAddress)
3852 wireBufferData = (ctypes.c_uint * (2*totalVerts)).from_address(wireBufferDataAddress)
3853 boxBufferData = (ctypes.c_uint * 24).from_address(boxBufferDataAddress)
3854 shadedBufferData = ((ctypes.c_uint * 3)*numTriangles).from_address(shadedBufferDataAddress)
3857 for vid,position
in enumerate(meshGeom.vertices):
3858 positionData[vid][0] = position[0]
3859 positionData[vid][1] = position[1]
3860 positionData[vid][2] = position[2]
3862 for vid,normal
in enumerate(meshGeom.normals):
3863 normalData[vid][0] = normal[0]
3864 normalData[vid][1] = normal[1]
3865 normalData[vid][2] = normal[2]
3867 self.fPositionBuffer.commit(positionDataAddress)
3868 positionDataAddress =
None
3869 self.fNormalBuffer.commit(normalDataAddress)
3870 normalDataAddress =
None
3875 boxPositionData[0][0] = bbmin.x
3876 boxPositionData[0][1] = bbmin.y
3877 boxPositionData[0][2] = bbmin.z
3879 boxPositionData[1][0] = bbmin.x
3880 boxPositionData[1][1] = bbmin.y
3881 boxPositionData[1][2] = bbmax.z
3883 boxPositionData[2][0] = bbmax.x
3884 boxPositionData[2][1] = bbmin.y
3885 boxPositionData[2][2] = bbmax.z
3887 boxPositionData[3][0] = bbmax.x
3888 boxPositionData[3][1] = bbmin.y
3889 boxPositionData[3][2] = bbmin.z
3891 boxPositionData[4][0] = bbmin.x
3892 boxPositionData[4][1] = bbmax.y
3893 boxPositionData[4][2] = bbmin.z
3895 boxPositionData[5][0] = bbmin.x
3896 boxPositionData[5][1] = bbmax.y
3897 boxPositionData[5][2] = bbmax.z
3899 boxPositionData[6][0] = bbmax.x
3900 boxPositionData[6][1] = bbmax.y
3901 boxPositionData[6][2] = bbmax.z
3903 boxPositionData[7][0] = bbmax.x
3904 boxPositionData[7][1] = bbmax.y
3905 boxPositionData[7][2] = bbmin.z
3907 self.fBoxPositionBuffer.commit(boxPositionDataAddress)
3908 boxPositionDataAddress =
None
3914 for i
in xrange(meshGeom.faceCount):
3916 numVerts = meshGeom.face_counts[i]
3919 for v
in xrange(numVerts-1):
3920 wireBufferData[idx] = meshGeom.face_connects[vid]
3923 wireBufferData[idx] = meshGeom.face_connects[vid]
3926 wireBufferData[idx] = meshGeom.face_connects[vid]
3929 wireBufferData[idx] = meshGeom.face_connects[first]
3935 self.fWireIndexBuffer.commit(wireBufferDataAddress)
3936 wireBufferDataAddress =
None
3939 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 ]
3940 for i
in xrange(24):
3941 boxBufferData[i] = indexData[i]
3943 self.fBoxIndexBuffer.commit(boxBufferDataAddress)
3944 boxBufferDataAddress =
None
3949 for i
in xrange(meshGeom.faceCount):
3951 numVerts = meshGeom.face_counts[i]
3953 for v
in xrange(1, numVerts-1):
3954 shadedBufferData[idx][0] = meshGeom.face_connects[base]
3955 shadedBufferData[idx][1] = meshGeom.face_connects[base+v]
3956 shadedBufferData[idx][2] = meshGeom.face_connects[base+v+1]
3961 self.fShadedIndexBuffer.commit(shadedBufferDataAddress)
3962 shadedBufferDataAddress =
None
3964 def rebuildActiveComponentIndexBuffers(self):
3966 meshGeom = self.fMesh.meshGeom()
3971 self.clearActiveComponentIndexBuffers()
3974 numActiveVertices = len(self.fActiveVerticesSet)
3975 if numActiveVertices > 0:
3976 self.fActiveVerticesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3977 activeVerticesDataAddress = self.fActiveVerticesIndexBuffer.acquire(numActiveVertices,
True)
3978 if activeVerticesDataAddress:
3979 activeVerticesData = (ctypes.c_uint*numActiveVertices).from_address(activeVerticesDataAddress)
3982 for vid
in self.fActiveVerticesSet:
3983 activeVerticesData[idx] = vid
3986 self.fActiveVerticesIndexBuffer.commit(activeVerticesDataAddress)
3987 activeVerticesDataAddress =
None
3990 numActiveEdges = len(self.fActiveEdgesSet)
3991 if numActiveEdges > 0:
3992 self.fActiveEdgesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3993 activeEdgesDataAddress = self.fActiveEdgesIndexBuffer.acquire(2*numActiveEdges,
True)
3994 if activeEdgesDataAddress:
3995 activeEdgesData = ((ctypes.c_uint * 2)*numActiveEdges).from_address(activeEdgesDataAddress)
4001 for i
in xrange(meshGeom.faceCount):
4003 numVerts = meshGeom.face_counts[i]
4006 for v
in xrange(numVerts-1):
4007 if eid
in self.fActiveEdgesSet:
4008 activeEdgesData[idx][0] = meshGeom.face_connects[vid]
4009 activeEdgesData[idx][1] = meshGeom.face_connects[vid + 1]
4014 if eid
in self.fActiveEdgesSet:
4015 activeEdgesData[idx][0] = meshGeom.face_connects[vid]
4016 activeEdgesData[idx][1] = meshGeom.face_connects[first]
4023 self.fActiveEdgesIndexBuffer.commit(activeEdgesDataAddress)
4024 activeEdgesDataAddress =
None
4027 numActiveFaces = len(self.fActiveFacesSet)
4028 if numActiveFaces > 0:
4029 numActiveFacesTriangles = 0
4030 for i
in xrange(meshGeom.faceCount):
4031 if i
in self.fActiveFacesSet:
4032 numVerts = meshGeom.face_counts[i]
4034 numActiveFacesTriangles += numVerts - 2
4036 self.fActiveFacesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
4037 activeFacesDataAddress = self.fActiveFacesIndexBuffer.acquire(3*numActiveFacesTriangles,
True)
4038 if activeFacesDataAddress:
4039 activeFacesData = ((ctypes.c_uint * 3)*numActiveFacesTriangles).from_address(activeFacesDataAddress)
4043 for i
in xrange(meshGeom.faceCount):
4044 numVerts = meshGeom.face_counts[i]
4046 if i
in self.fActiveFacesSet:
4047 for v
in xrange(1, numVerts-1):
4048 activeFacesData[idx][0] = meshGeom.face_connects[vid]
4049 activeFacesData[idx][1] = meshGeom.face_connects[vid+v]
4050 activeFacesData[idx][2] = meshGeom.face_connects[vid+v+1]
4055 self.fActiveFacesIndexBuffer.commit(activeFacesDataAddress)
4056 activeFacesDataAddress =
None
4058 def clearBuffers(self):
4059 self.clearGeometryBuffers()
4060 self.clearActiveComponentIndexBuffers()
4062 def clearGeometryBuffers(self):
4063 self.fPositionBuffer =
None
4064 self.fNormalBuffer =
None
4065 self.fBoxPositionBuffer =
None
4066 self.fWireIndexBuffer =
None
4067 self.fBoxIndexBuffer =
None
4068 self.fShadedIndexBuffer =
None
4070 def clearActiveComponentIndexBuffers(self):
4071 self.fActiveVerticesIndexBuffer =
None
4072 self.fActiveEdgesIndexBuffer =
None
4073 self.fActiveFacesIndexBuffer =
None
4075 def updateSelectionGranularity(self, path, selectionContext):
4086 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4087 if displayStatus == omr.MGeometryUtilities.kHilite:
4089 globalComponentMask = om.MGlobal.objectSelectionMask()
4090 if om.MGlobal.selectionMode() == om.MGlobal.kSelectComponentMode:
4091 globalComponentMask = om.MGlobal.componentSelectionMask()
4093 supportedComponentMask = om.MSelectionMask( om.MSelectionMask.kSelectMeshVerts )
4094 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshEdges )
4095 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshFaces )
4096 supportedComponentMask.addMask( om.MSelectionMask.kSelectPointsForGravity )
4098 if globalComponentMask.intersects(supportedComponentMask):
4099 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4100 elif omr.MPxSubSceneOverride.pointSnappingActive():
4101 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4113 class apiMeshUserData(om.MUserData):
4115 om.MUserData.__init__(self,
True)
4117 self.fNumModifications = 0
4120 def callbackDataPrint(context, renderItemList):
4121 for item
in renderItemList:
4123 path = item.sourceDagPath()
4124 print "\tITEM: '" + item.name() +
"' -- SOURCE: '" + path.fullPathName() +
"'"
4126 passCtx = context.getPassContext()
4127 passId = passCtx.passIdentifier()
4128 passSem = passCtx.passSemantics()
4129 print "\tAPI mesh drawing in pass[" + passId +
"], semantic[" + passSem +
"]"
4132 def apiMeshPreDrawCallback(context, renderItemList, shaderInstance):
4133 print "PRE-draw callback triggered for render item list with data:"
4134 callbackDataPrint(context, renderItemList)
4137 def apiMeshPostDrawCallback(context, renderItemList, shaderInstance):
4138 print "POST-draw callback triggered for render item list with data:"
4139 callbackDataPrint(context, renderItemList)
4143 class meshVertComponentConverter_geometryOverride(omr.MPxComponentConverter):
4145 omr.MPxComponentConverter.__init__(self)
4147 self.fComponent = om.MFnSingleIndexedComponent()
4148 self.fComponentObject = om.MObject.kNullObj
4151 def initialize(self, renderItem):
4153 self.fComponentObject = self.fComponent.create( om.MFn.kMeshVertComponent )
4159 selectionData = renderItem.customData()
4160 if isinstance(selectionData, apiMeshHWSelectionUserData):
4161 meshGeom = selectionData.fMeshGeom
4165 for i
in xrange(meshGeom.faceCount):
4166 numVerts = meshGeom.face_counts[i]
4168 numTriangles += numVerts - 2
4169 self.fVertices = [0]*(3*numTriangles)
4174 for faceIdx
in xrange(meshGeom.faceCount):
4176 numVerts = meshGeom.face_counts[faceIdx]
4178 for v
in xrange(1, numVerts-1):
4179 self.fVertices[idx] = meshGeom.face_connects[base]
4180 self.fVertices[idx+1] = meshGeom.face_connects[base+v]
4181 self.fVertices[idx+2] = meshGeom.face_connects[base+v+1]
4185 def addIntersection(self, intersection):
4188 rawIdx = intersection.index
4190 if rawIdx >= 0
and rawIdx < len(self.fVertices):
4191 idx = self.fVertices[rawIdx]
4192 self.fComponent.addElement(idx)
4194 def component(self):
4196 return self.fComponentObject
4198 def selectionMask(self):
4200 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
4201 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
4206 return meshVertComponentConverter_geometryOverride()
4210 class meshEdgeComponentConverter_geometryOverride(omr.MPxComponentConverter):
4212 omr.MPxComponentConverter.__init__(self)
4214 self.fComponent = om.MFnSingleIndexedComponent()
4215 self.fComponentObject = om.MObject.kNullObj
4218 def initialize(self, renderItem):
4220 self.fComponentObject = self.fComponent.create( om.MFn.kMeshEdgeComponent )
4232 selectionData = renderItem.customData()
4233 if isinstance(selectionData, apiMeshHWSelectionUserData):
4234 meshGeom = selectionData.fMeshGeom
4238 for i
in xrange(meshGeom.faceCount):
4239 numVerts = meshGeom.face_counts[i]
4241 totalVerts += numVerts
4242 self.fEdges = [0]*(totalVerts)
4247 for faceIdx
in xrange(meshGeom.faceCount):
4249 numVerts = meshGeom.face_counts[faceIdx]
4251 for v
in xrange(numVerts):
4252 self.fEdges[idx] = edgeId
4256 def addIntersection(self, intersection):
4259 rawIdx = intersection.index
4261 if rawIdx >= 0
and rawIdx < len(self.fEdges):
4262 idx = self.fEdges[rawIdx]
4263 self.fComponent.addElement(idx)
4265 def component(self):
4267 return self.fComponentObject
4269 def selectionMask(self):
4271 return om.MSelectionMask(om.MSelectionMask.kSelectMeshEdges)
4275 return meshEdgeComponentConverter_geometryOverride()
4279 class meshFaceComponentConverter_geometryOverride(omr.MPxComponentConverter):
4281 omr.MPxComponentConverter.__init__(self)
4283 self.fComponent = om.MFnSingleIndexedComponent()
4284 self.fComponentObject = om.MObject.kNullObj
4287 def initialize(self, renderItem):
4289 self.fComponentObject = self.fComponent.create( om.MFn.kMeshPolygonComponent )
4301 selectionData = renderItem.customData()
4302 if isinstance(selectionData, apiMeshHWSelectionUserData):
4303 meshGeom = selectionData.fMeshGeom
4307 for i
in xrange(meshGeom.faceCount):
4308 numVerts = meshGeom.face_counts[i]
4310 numTriangles += numVerts - 2
4311 self.fFaces = [0]*numTriangles
4315 for faceIdx
in xrange(meshGeom.faceCount):
4317 numVerts = meshGeom.face_counts[faceIdx]
4319 for v
in xrange(1, numVerts-1):
4320 self.fFaces[idx] = faceIdx
4323 def addIntersection(self, intersection):
4326 rawIdx = intersection.index
4328 if rawIdx >= 0
and rawIdx < len(self.fFaces):
4329 idx = self.fFaces[rawIdx]
4330 self.fComponent.addElement(idx)
4332 def component(self):
4334 return self.fComponentObject
4336 def selectionMask(self):
4338 return om.MSelectionMask(om.MSelectionMask.kSelectMeshFaces)
4342 return meshFaceComponentConverter_geometryOverride()
4344 class apiMeshGeometryOverride(omr.MPxGeometryOverride):
4346 sWireframeItemName =
"apiMeshWire"
4347 sShadedTemplateItemName =
"apiMeshShadedTemplateWire"
4348 sSelectedWireframeItemName =
"apiMeshSelectedWireFrame"
4349 sVertexItemName =
"apiMeshVertices"
4350 sEdgeSelectionItemName =
"apiMeshEdgeSelection"
4351 sFaceSelectionItemName =
"apiMeshFaceSelection"
4352 sActiveVertexItemName =
"apiMeshActiveVertices"
4353 sVertexIdItemName =
"apiMeshVertexIds"
4354 sVertexPositionItemName =
"apiMeshVertexPositions"
4355 sShadedModeFaceCenterItemName =
"apiMeshFaceCenterInShadedMode"
4356 sWireframeModeFaceCenterItemName =
"apiMeshFaceCenterInWireframeMode"
4357 sShadedProxyItemName =
"apiShadedProxy"
4358 sAffectedEdgeItemName =
"apiMeshAffectedEdges"
4359 sAffectedFaceItemName =
"apiMeshAffectedFaces"
4360 sActiveVertexStreamName =
"apiMeshSharedVertexStream"
4361 sFaceCenterStreamName =
"apiMeshFaceCenterStream"
4365 return apiMeshGeometryOverride(obj)
4367 def __init__(self, obj):
4368 omr.MPxGeometryOverride.__init__(self, obj)
4370 node = om.MFnDependencyNode(obj)
4371 self.fMesh = node.userNode()
4372 self.fMeshGeom =
None
4373 self.fColorRemapTexture =
None
4375 self.fActiveVertices = om.MIntArray()
4376 self.fActiveVerticesSet = set()
4377 self.fActiveEdgesSet = set()
4378 self.fActiveFacesSet = set()
4379 self.fCastsShadows =
False
4380 self.fReceivesShadows =
False
4386 self.fDrawSharedActiveVertices =
True
4388 self.fDrawActiveVerticesWithRamp =
False
4389 self.fLinearSampler =
None
4392 self.fDrawFaceCenters =
True
4394 if self.fDrawActiveVerticesWithRamp:
4395 self.fDrawFaceCenters =
False
4400 self.fUseCustomColors =
False
4411 self.fProxyShader = omr.MShaderManager.k3dCPVThickDashLineShader
4415 self.fInternalItems_NoShadowCast =
False
4416 self.fInternalItems_NoShadowReceive =
False
4417 self.fInternalItems_NoPostEffects =
False
4421 self.fExternalItems_NoShadowCast =
False
4422 self.fExternalItems_NoShadowReceive =
False
4423 self.fExternalItemsNonTri_NoShadowCast =
False
4424 self.fExternalItemsNonTri_NoShadowReceive =
False
4428 self.fExternalItems_NoPostEffects =
True
4429 self.fExternalItemsNonTri_NoPostEffects =
True
4433 self.fMeshGeom =
None
4435 if self.fColorRemapTexture:
4436 textureMgr = omr.MRenderer.getTextureManager()
4438 textureMgr.releaseTexture(self.fColorRemapTexture)
4439 self.fColorRemapTexture =
None
4441 if self.fLinearSampler:
4442 omr.MStateManager.releaseSamplerState(self.fLinearSampler)
4443 self.fLinearSampler =
None
4445 def supportedDrawAPIs(self):
4447 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
4452 self.fActiveVertices.clear()
4453 self.fActiveVerticesSet = set()
4454 self.fActiveEdgesSet = set()
4455 self.fActiveFacesSet = set()
4457 self.fMeshGeom = self.fMesh.meshGeom()
4459 if self.fMeshGeom
and self.fMesh.hasActiveComponents():
4460 activeComponents = self.fMesh.activeComponents()
4461 if len(activeComponents) > 0:
4462 fnComponent = om.MFnSingleIndexedComponent( activeComponents[0] )
4463 if fnComponent.elementCount > 0:
4464 activeIds = fnComponent.getElements()
4466 if fnComponent.componentType == om.MFn.kMeshVertComponent:
4467 self.fActiveVertices = activeIds
4468 self.fActiveVerticesSet = set(activeIds)
4470 elif fnComponent.componentType == om.MFn.kMeshEdgeComponent:
4471 self.fActiveEdgesSet = set(activeIds)
4473 elif fnComponent.componentType == om.MFn.kMeshPolygonComponent:
4474 self.fActiveFacesSet = set(activeIds)
4476 def updateRenderItems(self, path, list):
4480 shaderMgr = omr.MRenderer.getShaderManager()
4484 dagNode = om.MFnDagNode(path)
4485 castsShadowsPlug = dagNode.findPlug(
"castsShadows",
False)
4486 self.fCastsShadows = castsShadowsPlug.asBool()
4487 receiveShadowsPlug = dagNode.findPlug(
"receiveShadows",
False)
4488 self.fReceivesShadows = receiveShadowsPlug.asBool()
4491 self.updateDormantAndTemplateWireframeItems(path, list, shaderMgr)
4492 self.updateActiveWireframeItem(path, list, shaderMgr)
4495 self.updateDormantVerticesItem(path, list, shaderMgr)
4496 self.updateActiveVerticesItem(path, list, shaderMgr)
4499 self.updateVertexNumericItems(path, list, shaderMgr)
4502 if self.fDrawFaceCenters:
4503 self.updateWireframeModeFaceCenterItem(path, list, shaderMgr)
4504 self.updateShadedModeFaceCenterItem(path, list, shaderMgr)
4507 self.updateAffectedComponentItems(path, list, shaderMgr)
4510 self.updateSelectionComponentItems(path, list, shaderMgr)
4513 self.updateProxyShadedItem(path, list, shaderMgr)
4519 testShadedOverrides = self.fInternalItems_NoShadowCast
or self.fInternalItems_NoShadowReceive
or self.fInternalItems_NoPostEffects
4520 if testShadedOverrides:
4525 drawMode = item.drawMode()
4526 if drawMode == omr.MGeometry.kShaded
or drawMode == omr.MGeometry.kTextured:
4527 if item.name() != self.sShadedTemplateItemName:
4528 item.setCastsShadows(
not self.fInternalItems_NoShadowCast
and self.fCastsShadows )
4529 item.setReceivesShadows(
not self.fInternalItems_NoShadowReceive
and self.fReceivesShadows )
4530 item.setExcludedFromPostEffects( self.fInternalItems_NoPostEffects )
4532 def populateGeometry(self, requirements, renderItems, data):
4543 debugPopulateGeometry =
False
4544 if debugPopulateGeometry:
4545 print "> Begin populate geometry"
4548 activeVertexCount = len(self.fActiveVertices)
4553 for i
in xrange(self.fMeshGeom.faceCount):
4554 numVerts = self.fMeshGeom.face_counts[i]
4556 numTriangles += numVerts - 2
4557 totalVerts += numVerts
4560 self.updateGeometryRequirements(requirements, data, activeVertexCount, totalVerts, debugPopulateGeometry)
4563 wireIndexBuffer =
None
4565 for item
in renderItems:
4574 itemBuffers = item.requiredVertexBuffers()
4575 for desc
in itemBuffers:
4576 print "Buffer Required for Item '" + item.name() +
"':"
4577 print "\tBufferName: " + desc.name
4578 print "\tDataType: " + omr.MGeometry.dataTypeString(desc.dataType) +
" (dimension " + str(desc.dimension) +
")"
4579 print "\tSemantic: " + omr.MGeometry.semanticString(desc.semantic)
4584 myCustomData = item.customData()
4585 if isinstance(myCustomData, apiMeshUserData):
4586 print "Custom data '" + myCustomData.fMessage +
"', modified count='" + str(myCustomData.fNumModifications) +
"'"
4588 print "No custom data"
4592 if item.name() == self.sActiveVertexItemName:
4593 self.updateIndexingForVertices( item, data, numTriangles, activeVertexCount, debugPopulateGeometry)
4597 if self.fDrawFaceCenters
and (item.name() == self.sShadedModeFaceCenterItemName
or item.name() == self.sWireframeModeFaceCenterItemName):
4598 self.updateIndexingForFaceCenters( item, data, debugPopulateGeometry)
4602 elif item.name() == self.sVertexItemName
or item.name() == self.sVertexIdItemName
or item.name() == self.sVertexPositionItemName:
4603 self.updateIndexingForDormantVertices( item, data, numTriangles )
4607 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):
4608 self.updateIndexingForWireframeItems(wireIndexBuffer, item, data, totalVerts)
4614 elif item.name() == self.sAffectedEdgeItemName:
4615 self.updateIndexingForEdges(item, data, totalVerts,
True)
4616 elif item.name() == self.sEdgeSelectionItemName:
4617 self.updateIndexingForEdges(item, data, totalVerts,
False)
4623 elif item.name() == self.sAffectedFaceItemName:
4624 self.updateIndexingForFaces(item, data, numTriangles,
True)
4625 elif item.name() == self.sFaceSelectionItemName:
4626 self.updateIndexingForFaces(item, data, numTriangles,
False)
4630 elif item.primitive() == omr.MGeometry.kTriangles:
4631 self.updateIndexingForShadedTriangles(item, data, numTriangles)
4633 if debugPopulateGeometry:
4634 print "> End populate geometry"
4637 self.fMeshGeom =
None
4638 self.fActiveVertices.clear()
4639 self.fActiveVerticesSet = set()
4640 self.fActiveEdgesSet = set()
4641 self.fActiveFacesSet = set()
4643 def updateSelectionGranularity(self, path, selectionContext):
4655 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4656 if displayStatus == omr.MGeometryUtilities.kHilite:
4658 globalComponentMask = om.MGlobal.objectSelectionMask()
4659 if om.MGlobal.selectionMode() == om.MGlobal.kSelectComponentMode:
4660 globalComponentMask = om.MGlobal.componentSelectionMask()
4662 supportedComponentMask = om.MSelectionMask( om.MSelectionMask.kSelectMeshVerts )
4663 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshEdges )
4664 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshFaces )
4665 supportedComponentMask.addMask( om.MSelectionMask.kSelectPointsForGravity )
4667 if globalComponentMask.intersects(supportedComponentMask):
4668 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4669 elif omr.MPxGeometryOverride.pointSnappingActive():
4670 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4672 def printShader(self, shader):
4677 params = shader.parameterList()
4678 print "DEBUGGING SHADER, BEGIN PARAM LIST OF LENGTH " + str(len(params))
4680 for param
in params:
4681 paramType = shader.parameterType(param)
4682 isArray = shader.isArrayParameter(param)
4684 typeAsStr =
"Unknown"
4685 if paramType == omr.MShaderInstance.kInvalid:
4686 typeAsStr =
"Invalid"
4687 elif paramType == omr.MShaderInstance.kBoolean:
4688 typeAsStr =
"Boolean"
4689 elif paramType == omr.MShaderInstance.kInteger:
4690 typeAsStr =
"Integer"
4691 elif paramType == omr.MShaderInstance.kFloat:
4693 elif paramType == omr.MShaderInstance.kFloat2:
4694 typeAsStr =
"Float2"
4695 elif paramType == omr.MShaderInstance.kFloat3:
4696 typeAsStr =
"Float3"
4697 elif paramType == omr.MShaderInstance.kFloat4:
4698 typeAsStr =
"Float4"
4699 elif paramType == omr.MShaderInstance.kFloat4x4Row:
4700 typeAsStr =
"Float4x4Row"
4701 elif paramType == omr.MShaderInstance.kFloat4x4Col:
4702 typeAsStr =
"Float4x4Col"
4703 elif paramType == omr.MShaderInstance.kTexture1:
4704 typeAsStr =
"1D Texture"
4705 elif paramType == omr.MShaderInstance.kTexture2:
4706 typeAsStr =
"2D Texture"
4707 elif paramType == omr.MShaderInstance.kTexture3:
4708 typeAsStr =
"3D Texture"
4709 elif paramType == omr.MShaderInstance.kTextureCube:
4710 typeAsStr =
"Cube Texture"
4711 elif paramType == omr.MShaderInstance.kSampler:
4712 typeAsStr =
"Sampler"
4714 print "ParamName='" + param +
"', ParamType='" + typeAsStr +
"', IsArrayParameter:'" + str(isArray) +
"'"
4716 print "END PARAM LIST"
4718 def setSolidColor(self, shaderInstance, defaultColor, customColor=None):
4721 color = defaultColor
4722 if self.fUseCustomColors
and customColor:
4725 shaderInstance.setParameter(
"solidColor", color)
4729 def setSolidPointSize(self, shaderInstance, size):
4733 shaderInstance.setParameter(
"pointSize", [size, size])
4737 def setLineWidth(self, shaderInstance, width):
4741 shaderInstance.setParameter(
"lineWidth", [width, width])
4745 def enableActiveComponentDisplay(self, path):
4757 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4758 if displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
4764 if path.isTemplated():
4770 def updateDormantAndTemplateWireframeItems(self, path, list, shaderMgr):
4782 dormantColor = [ 0.0, 0.0, 1.0, 1.0 ]
4783 templateColor = [ 0.45, 0.45, 0.45, 1.0 ]
4784 activeTemplateColor = [ 1.0, 0.5, 0.5, 1.0 ]
4793 wireframeItem =
None
4794 index = list.indexOf(self.sWireframeItemName)
4796 wireframeItem = omr.MRenderItem.create( self.sWireframeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
4797 wireframeItem.setDrawMode(omr.MGeometry.kWireframe)
4801 wireframeItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
4803 list.append(wireframeItem)
4808 preCb = apiMeshPreDrawCallback
4809 postCb = apiMeshPostDrawCallback
4811 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader, preCb, postCb)
4814 wireframeItem.setShader(shader)
4818 self.printShader( shader )
4821 shaderMgr.releaseShader(shader)
4823 wireframeItem = list[index]
4827 shadedTemplateItem =
None
4828 index = list.indexOf(self.sShadedTemplateItemName)
4830 shadedTemplateItem = omr.MRenderItem.create( self.sShadedTemplateItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
4831 shadedTemplateItem.setDrawMode(omr.MGeometry.kAll)
4835 shadedTemplateItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
4837 list.append(shadedTemplateItem)
4839 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
4842 shadedTemplateItem.setShader(shader)
4846 self.printShader( shader )
4849 shaderMgr.releaseShader(shader)
4851 shadedTemplateItem = list[index]
4854 shadedTemplateItem.setCastsShadows(
not self.fExternalItemsNonTri_NoShadowCast )
4855 shadedTemplateItem.setReceivesShadows(
not self.fExternalItemsNonTri_NoShadowReceive )
4856 shadedTemplateItem.setExcludedFromPostEffects( self.fExternalItemsNonTri_NoPostEffects )
4858 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4859 wireColor = omr.MGeometryUtilities.wireframeColor(path)
4864 shader = wireframeItem.getShader()
4866 if displayStatus == omr.MGeometryUtilities.kTemplate:
4867 self.setSolidColor( shader, wireColor, templateColor)
4868 wireframeItem.enable(
True)
4870 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
4871 self.setSolidColor( shader, wireColor, activeTemplateColor)
4872 wireframeItem.enable(
True)
4874 elif displayStatus == omr.MGeometryUtilities.kDormant:
4875 self.setSolidColor( shader, wireColor, dormantColor)
4876 wireframeItem.enable(
True)
4878 elif displayStatus == omr.MGeometryUtilities.kActiveAffected:
4879 theColor = [ 0.5, 0.0, 1.0, 1.0 ]
4880 self.setSolidColor( shader, wireColor, theColor)
4881 wireframeItem.enable(
True)
4884 wireframeItem.enable(
False)
4888 if shadedTemplateItem:
4889 isTemplate = path.isTemplated()
4890 shader = shadedTemplateItem.getShader()
4892 if displayStatus == omr.MGeometryUtilities.kTemplate:
4893 self.setSolidColor( shader, wireColor, templateColor)
4894 shadedTemplateItem.enable(isTemplate)
4896 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
4897 self.setSolidColor( shader, wireColor, activeTemplateColor)
4898 shadedTemplateItem.enable(isTemplate)
4900 elif displayStatus == omr.MGeometryUtilities.kDormant:
4901 self.setSolidColor( shader, wireColor, dormantColor)
4902 shadedTemplateItem.enable(isTemplate)
4905 shadedTemplateItem.enable(
False)
4907 def updateActiveWireframeItem(self, path, list, shaderMgr):
4912 index = list.indexOf(self.sSelectedWireframeItemName)
4914 selectItem = omr.MRenderItem.create(self.sSelectedWireframeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
4915 selectItem.setDrawMode(omr.MGeometry.kAll)
4920 selectItem.setDepthPriority( omr.MRenderItem.sActiveWireDepthPriority )
4921 list.append(selectItem)
4926 shaderId = omr.MShaderManager.k3dSolidShader
4928 shaderId = omr.MShaderManager.k3dThickLineShader
4930 shader = shaderMgr.getStockShader(shaderId)
4933 selectItem.setShader(shader)
4935 shaderMgr.releaseShader(shader)
4937 selectItem = list[index]
4941 shader = selectItem.getShader()
4943 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4944 wireColor = omr.MGeometryUtilities.wireframeColor(path)
4946 if displayStatus == omr.MGeometryUtilities.kLead:
4947 theColor = [ 0.0, 0.8, 0.0, 1.0 ]
4948 self.setSolidColor( shader, wireColor, theColor)
4949 selectItem.enable(
True)
4951 elif displayStatus == omr.MGeometryUtilities.kActive:
4952 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
4953 self.setSolidColor( shader, wireColor, theColor)
4954 selectItem.enable(
True)
4956 elif displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
4957 theColor = [ 0.0, 0.5, 0.7, 1.0 ]
4958 self.setSolidColor( shader, wireColor, theColor)
4959 selectItem.enable(
True)
4962 selectItem.enable(
False)
4965 myCustomData = selectItem.customData()
4966 if not myCustomData:
4968 myCustomData = apiMeshUserData()
4969 myCustomData.fMessage =
"I'm custom data!"
4970 selectItem.setCustomData(myCustomData)
4973 myCustomData.fNumModifications += 1
4975 def updateWireframeModeFaceCenterItem(self, path, list, shaderMgr):
4979 wireframeModeFaceCenterItem =
None
4980 index = list.indexOf(self.sWireframeModeFaceCenterItemName)
4982 wireframeModeFaceCenterItem = omr.MRenderItem.create(self.sWireframeModeFaceCenterItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
4983 wireframeModeFaceCenterItem.setDrawMode(omr.MGeometry.kWireframe)
4984 wireframeModeFaceCenterItem.setDepthPriority( omr.MRenderItem.sActiveWireDepthPriority )
4986 list.append(wireframeModeFaceCenterItem)
4988 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
4992 self.setSolidPointSize( shader, pointSize )
4994 wireframeModeFaceCenterItem.setShader(shader, self.sFaceCenterStreamName )
4997 shaderMgr.releaseShader(shader)
4999 wireframeModeFaceCenterItem = list[index]
5001 if wireframeModeFaceCenterItem:
5002 shader = wireframeModeFaceCenterItem.getShader()
5005 theColor = [ 0.0, 0.0, 1.0, 1.0 ]
5006 self.setSolidColor( shader, theColor )
5009 isTemplate = path.isTemplated()
5010 wireframeModeFaceCenterItem.enable(
not isTemplate )
5012 def updateShadedModeFaceCenterItem(self, path, list, shaderMgr):
5016 shadedModeFaceCenterItem =
None
5017 index = list.indexOf(self.sShadedModeFaceCenterItemName)
5019 shadedModeFaceCenterItem = omr.MRenderItem.create( self.sShadedModeFaceCenterItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5020 shadedModeFaceCenterItem.setDrawMode(omr.MGeometry.kShaded | omr.MGeometry.kTextured)
5022 shadedModeFaceCenterItem.setDepthPriority(omr.MRenderItem.sActivePointDepthPriority)
5024 list.append(shadedModeFaceCenterItem)
5026 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
5030 self.setSolidPointSize( shader, pointSize )
5032 shadedModeFaceCenterItem.setShader(shader, self.sFaceCenterStreamName )
5035 shaderMgr.releaseShader(shader)
5037 shadedModeFaceCenterItem = list[index]
5039 if shadedModeFaceCenterItem:
5040 shadedModeFaceCenterItem.setExcludedFromPostEffects(
True)
5042 shader = shadedModeFaceCenterItem.getShader()
5043 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5047 self.setSolidColor( shader, wireColor )
5049 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5050 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:
5051 shadedModeFaceCenterItem.enable(
True)
5054 shadedModeFaceCenterItem.enable(
False)
5056 def updateDormantVerticesItem(self, path, list, shaderMgr):
5061 index = list.indexOf(self.sVertexItemName)
5063 vertexItem = omr.MRenderItem.create(self.sVertexItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5066 vertexItem.setDrawMode(omr.MGeometry.kAll)
5069 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
5070 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
5071 vertexItem.setSelectionMask( mask )
5076 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5077 list.append(vertexItem)
5079 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
5083 self.setSolidPointSize( shader, pointSize )
5086 vertexItem.setShader(shader)
5089 shaderMgr.releaseShader(shader)
5091 vertexItem = list[index]
5094 shader = vertexItem.getShader()
5096 theColor = [ 0.0, 0.0, 1.0, 1.0 ]
5097 self.setSolidColor( shader, theColor )
5099 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5103 if displayStatus == omr.MGeometryUtilities.kHilite
or omr.MPxGeometryOverride.pointSnappingActive():
5107 if path.isTemplated():
5108 vertexItem.enable(
False)
5110 vertexItem.enable(
True)
5112 vertexItem.enable(
False)
5114 mySelectionData = vertexItem.customData()
5115 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5117 mySelectionData = apiMeshHWSelectionUserData()
5118 vertexItem.setCustomData(mySelectionData)
5120 mySelectionData.fMeshGeom = self.fMeshGeom
5122 def updateActiveVerticesItem(self, path, list, shaderMgr):
5127 index = list.indexOf(self.sActiveVertexItemName)
5129 activeItem = omr.MRenderItem.create(self.sActiveVertexItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5130 activeItem.setDrawMode(omr.MGeometry.kAll)
5133 activeItem.setDepthPriority( omr.MRenderItem.sActivePointDepthPriority )
5134 list.append(activeItem)
5136 shaderId = omr.MShaderManager.k3dFatPointShader
5137 if self.fDrawActiveVerticesWithRamp:
5138 shaderId = omr.MShaderManager.k3dColorLookupFatPointShader
5140 shader = shaderMgr.getStockShader( shaderId )
5144 self.setSolidPointSize( shader, pointSize )
5148 if self.fDrawActiveVerticesWithRamp:
5149 textureMgr = omr.MRenderer.getTextureManager()
5152 if not self.fColorRemapTexture:
5154 colorArray = [ 1.0, 0.0, 0.0, 1.0,
5156 0.0, 0.0, 1.0, 1.0 ]
5159 textureDesc = omr.MTextureDescription()
5160 textureDesc.setToDefault2DTexture()
5161 textureDesc.fWidth = arrayLen
5162 textureDesc.fHeight = 1
5163 textureDesc.fDepth = 1
5164 textureDesc.fBytesPerSlice = textureDesc.fBytesPerRow = 24*arrayLen
5165 textureDesc.fMipmaps = 1
5166 textureDesc.fArraySlices = 1
5167 textureDesc.fTextureType = omr.MRenderer.kImage1D
5168 textureDesc.fFormat = omr.MRenderer.kR32G32B32A32_FLOAT
5169 self.fColorRemapTexture = textureMgr.acquireTexture(
"", textureDesc, colorArray,
False)
5171 if not self.fLinearSampler:
5172 samplerDesc = omr.MSamplerStateDesc()
5173 samplerDesc.addressU = omr.MSamplerState.kTexClamp
5174 samplerDesc.addressV = omr.MSamplerState.kTexClamp
5175 samplerDesc.addressW = omr.MSamplerState.kTexClamp
5176 samplerDesc.filter = omr.MSamplerState.kMinMagMipLinear
5177 fLinearSampler = omr.MStateManager.acquireSamplerState(samplerDesc)
5179 if self.fColorRemapTexture
and self.fLinearSampler:
5181 shader.setParameter(
"map", self.fColorRemapTexture)
5182 shader.setParameter(
"samp", self.fLinearSampler)
5186 rampValueRange = om.MFloatVector(0.0, 1.0)
5187 shader.setParameter(
"UVRange", rampValueRange)
5191 if self.fDrawSharedActiveVertices:
5192 activeItem.setShader(shader, self.sActiveVertexStreamName)
5194 activeItem.setShader(shader,
None)
5197 shaderMgr.releaseShader(shader)
5200 activeItem = list[index]
5203 shader = activeItem.getShader()
5206 theColor = [ 1.0, 1.0, 0.0, 1.0 ]
5207 self.setSolidColor( shader, theColor )
5209 enable = (bool(self.fActiveVerticesSet)
and self.enableActiveComponentDisplay(path))
5210 activeItem.enable( enable )
5212 def updateVertexNumericItems(self, path, list, shaderMgr):
5216 enableNumericDisplay =
False
5221 index = list.indexOf(self.sVertexIdItemName)
5223 vertexItem = omr.MRenderItem.create( self.sVertexIdItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5224 vertexItem.setDrawMode(omr.MGeometry.kAll)
5225 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5226 list.append(vertexItem)
5229 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dIntegerNumericShader )
5232 vertexItem.setShader(shader, self.sVertexIdItemName)
5233 shaderMgr.releaseShader(shader)
5235 vertexItem = list[index]
5238 shader = vertexItem.getShader()
5241 theColor = [ 1.0, 1.0, 0.0, 1.0 ]
5242 self.setSolidColor( shader, theColor )
5244 vertexItem.enable(enableNumericDisplay)
5249 index = list.indexOf(self.sVertexPositionItemName)
5251 vertexItem = omr.MRenderItem.create( self.sVertexPositionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5252 vertexItem.setDrawMode(omr.MGeometry.kAll)
5253 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5254 list.append(vertexItem)
5257 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFloat3NumericShader )
5260 vertexItem.setShader(shader, self.sVertexPositionItemName)
5261 shaderMgr.releaseShader(shader)
5263 vertexItem = list[index]
5266 shader = vertexItem.getShader()
5269 theColor = [ 0.0, 1.0, 1.0, 1.0 ]
5270 self.setSolidColor( shader, theColor)
5272 vertexItem.enable(enableNumericDisplay)
5274 def updateAffectedComponentItems(self, path, list, shaderMgr):
5281 componentItem =
None
5282 index = list.indexOf(self.sAffectedEdgeItemName)
5284 componentItem = omr.MRenderItem.create( self.sAffectedEdgeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5285 componentItem.setDrawMode(omr.MGeometry.kAll)
5289 componentItem.setDepthPriority( omr.MRenderItem.sActiveLineDepthPriority )
5290 list.append(componentItem)
5292 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dThickLineShader )
5296 self.setLineWidth( shader, lineSize )
5299 componentItem.setShader(shader,
None)
5302 shaderMgr.releaseShader(shader)
5304 componentItem = list[index]
5307 shader = componentItem.getShader()
5310 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5311 self.setSolidColor( shader, theColor )
5313 enable = ((bool(self.fActiveVerticesSet)
or bool(self.fActiveEdgesSet))
and self.enableActiveComponentDisplay(path))
5314 componentItem.enable( enable )
5320 componentItem =
None
5321 index = list.indexOf(self.sAffectedFaceItemName)
5323 componentItem = omr.MRenderItem.create( self.sAffectedFaceItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
5324 componentItem.setDrawMode(omr.MGeometry.kAll)
5327 componentItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
5328 list.append(componentItem)
5330 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dStippleShader )
5333 componentItem.setShader(shader,
None)
5336 shaderMgr.releaseShader(shader)
5338 componentItem = list[index]
5341 shader = componentItem.getShader()
5344 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5345 self.setSolidColor( shader, theColor )
5347 enable = ((bool(self.fActiveVerticesSet)
or bool(self.fActiveFacesSet))
and self.enableActiveComponentDisplay(path))
5348 componentItem.enable( enable )
5350 def updateSelectionComponentItems(self, path, list, shaderMgr):
5365 selectionItem =
None
5366 index = list.indexOf(self.sEdgeSelectionItemName)
5368 selectionItem = omr.MRenderItem.create( self.sEdgeSelectionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5371 selectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
5374 selectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshEdges )
5377 selectionItem.setDepthPriority( omr.MRenderItem.sSelectionDepthPriority )
5378 list.append(selectionItem)
5380 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
5383 selectionItem.setShader(shader,
None)
5386 shaderMgr.releaseShader(shader)
5388 selectionItem = list[index]
5391 selectionItem.enable(
True)
5393 mySelectionData = selectionItem.customData()
5394 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5396 mySelectionData = apiMeshHWSelectionUserData()
5397 selectionItem.setCustomData(mySelectionData)
5399 mySelectionData.fMeshGeom = self.fMeshGeom
5403 index = list.indexOf(self.sFaceSelectionItemName)
5405 selectionItem = omr.MRenderItem.create( self.sFaceSelectionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
5408 selectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
5411 selectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshFaces )
5414 selectionItem.setDepthPriority( omr.MRenderItem.sSelectionDepthPriority )
5415 list.append(selectionItem)
5417 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
5420 selectionItem.setShader(shader,
None)
5423 shaderMgr.releaseShader(shader)
5425 selectionItem = list[index]
5428 selectionItem.enable(
True)
5430 mySelectionData = selectionItem.customData()
5431 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5433 mySelectionData = apiMeshHWSelectionUserData()
5434 selectionItem.setCustomData(mySelectionData)
5436 mySelectionData.fMeshGeom = self.fMeshGeom
5438 def updateProxyShadedItem(self, path, list, shaderMgr):
5443 dormantColor = [ 0.0, 0.0, 1.0, 1.0 ]
5444 templateColor = [ 0.45, 0.45, 0.45, 1.0 ]
5445 activeTemplateColor = [ 1.0, 0.5, 0.5, 1.0 ]
5452 raiseAboveShaded =
True
5453 shadedDrawMode = omr.MGeometry.kShaded | omr.MGeometry.kTextured
5456 useFragmentShader = self.fProxyShader < 0
5457 if not useFragmentShader:
5458 shadedDrawMode |= omr.MGeometry.kWireframe
5463 itemType = omr.MRenderItem.NonMaterialSceneItem
5464 primitive = omr.MGeometry.kLines
5465 filledProxy = useFragmentShader
or self.fProxyShader == omr.MShaderManager.k3dStippleShader
5467 itemType = omr.MRenderItem.MaterialSceneItem
5468 primitive = omr.MGeometry.kTriangles
5470 depthPriority = omr.MRenderItem.sDormantWireDepthPriority
5471 if raiseAboveShaded:
5472 depthPriority = omr.MRenderItem.sActiveWireDepthPriority
5475 index = list.indexOf(self.sShadedProxyItemName)
5477 proxyItem = omr.MRenderItem.create( self.sShadedProxyItemName, itemType, primitive)
5478 proxyItem.setDrawMode(shadedDrawMode)
5479 proxyItem.setDepthPriority( depthPriority )
5481 proxyItem.setCastsShadows(
not self.fExternalItems_NoShadowCast
and self.fCastsShadows )
5482 proxyItem.setReceivesShadows(
not self.fExternalItems_NoShadowReceive
and self.fReceivesShadows )
5483 proxyItem.setExcludedFromPostEffects( self.fExternalItems_NoPostEffects )
5485 list.append(proxyItem)
5490 if useFragmentShader:
5491 shader = shaderMgr.getFragmentShader(
"mayaLambertSurface",
"outSurfaceFinal",
True)
5492 sBlue = [ 0.4, 0.4, 1.0 ]
5493 shader.setParameter(
"color", sBlue)
5494 shader.setIsTransparent(
False)
5496 shader = shaderMgr.getStockShader( self.fProxyShader )
5500 self.setLineWidth(shader, 10.0)
5503 proxyItem.setShader(shader)
5505 shaderMgr.releaseShader(shader)
5507 proxyItem = list[index]
5514 proxyItem.setCastsShadows(
not self.fExternalItems_NoShadowCast
and self.fCastsShadows )
5515 proxyItem.setReceivesShadows(
not self.fExternalItems_NoShadowReceive
and self.fReceivesShadows )
5516 proxyItem.setExcludedFromPostEffects( self.fExternalItems_NoPostEffects )
5521 haveShadedItems =
False
5525 drawMode = item.drawMode()
5526 if drawMode == omr.MGeometry.kShaded
or drawMode == omr.MGeometry.kTextured:
5527 if item.name() != self.sShadedTemplateItemName:
5528 haveShadedItems =
True
5531 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5532 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5539 shader = proxyItem.getShader()
5541 if displayStatus == omr.MGeometryUtilities.kTemplate:
5542 self.setSolidColor( shader, wireColor, templateColor )
5544 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
5545 self.setSolidColor( shader, wireColor, activeTemplateColor )
5547 elif displayStatus == omr.MGeometryUtilities.kDormant:
5548 self.setSolidColor( shader, wireColor, dormantColor )
5555 if path.isTemplated():
5556 proxyItem.enable(
False)
5558 proxyItem.enable(
not haveShadedItems)
5560 proxyItem.enable(
not haveShadedItems)
5563 def updateGeometryRequirements(self, requirements, data, activeVertexCount, totalVerts, debugPopulateGeometry):
5569 positionBuffer =
None
5570 positionDataAddress =
None
5573 vertexNumericIdBuffer =
None
5574 vertexNumericIdDataAddress =
None
5575 vertexNumericIdData =
None
5577 vertexNumericIdPositionBuffer =
None
5578 vertexNumericIdPositionDataAddress =
None
5579 vertexNumericIdPositionData =
None
5581 vertexNumericLocationBuffer =
None
5582 vertexNumericLocationDataAddress =
None
5583 vertexNumericLocationData =
None
5585 vertexNumericLocationPositionBuffer =
None
5586 vertexNumericLocationPositionDataAddress =
None
5587 vertexNumericLocationPositionData =
None
5589 activeVertexPositionBuffer =
None
5590 activeVertexPositionDataAddress =
None
5591 activeVertexPositionData =
None
5593 activeVertexUVBuffer =
None
5594 activeVertexUVDataAddress =
None
5595 activeVertexUVData =
None
5597 faceCenterPositionBuffer =
None
5598 faceCenterPositionDataAddress =
None
5599 faceCenterPositionData =
None
5602 normalDataAddress =
None
5606 cpvDataAddress =
None
5610 uvDataAddress =
None
5613 numUVs = self.fMeshGeom.uvcoords.uvcount()
5615 descList = requirements.vertexRequirements()
5616 satisfiedRequirements = [
False,] * len(descList)
5617 for i
in xrange(len(descList)):
5621 if self.fDrawSharedActiveVertices
and (desc.name == self.sActiveVertexStreamName):
5622 if desc.semantic == omr.MGeometry.kPosition:
5623 if not activeVertexPositionBuffer:
5624 activeVertexPositionBuffer = data.createVertexBuffer(desc)
5625 if activeVertexPositionBuffer:
5626 satisfiedRequirements[i] =
True
5627 if debugPopulateGeometry:
5628 print ">>> Fill in data for active vertex requirement '" + desc.name +
"'. Semantic = kPosition"
5629 activeVertexPositionDataAddress = activeVertexPositionBuffer.acquire(activeVertexCount,
True)
5630 if activeVertexPositionDataAddress:
5631 activeVertexPositionData = ((ctypes.c_float * 3)*activeVertexCount).from_address(activeVertexPositionDataAddress)
5633 elif desc.semantic == omr.MGeometry.kTexture:
5634 if not activeVertexUVBuffer:
5635 activeVertexUVBuffer = data.createVertexBuffer(desc)
5636 if activeVertexUVBuffer:
5637 satisfiedRequirements[i] =
True
5638 if debugPopulateGeometry:
5639 print ">>> Fill in data for active vertex requirement '" + desc.name +
"'. Semantic = kTexture"
5640 activeVertexUVDataAddress = activeVertexUVBuffer.acquire(activeVertexCount,
True)
5641 if activeVertexUVDataAddress:
5642 activeVertexUVData = ((ctypes.c_float * 3)*activeVertexCount).from_address(activeVertexUVDataAddress)
5649 elif self.fDrawFaceCenters
and desc.name == self.sFaceCenterStreamName:
5650 if desc.semantic == omr.MGeometry.kPosition:
5651 if not faceCenterPositionBuffer:
5652 faceCenterPositionBuffer = data.createVertexBuffer(desc)
5653 if faceCenterPositionBuffer:
5654 satisfiedRequirements[i] =
True
5655 if debugPopulateGeometry:
5656 print ">>> Fill in data for face center vertex requirement '" + desc.name +
"'. Semantic = kPosition"
5657 faceCenterPositionDataAddress = faceCenterPositionBuffer.acquire(self.fMeshGeom.faceCount,
True)
5658 if faceCenterPositionDataAddress:
5659 faceCenterPositionData = ((ctypes.c_float * 3)*self.fMeshGeom.faceCount).from_address(faceCenterPositionDataAddress)
5668 if desc.semantic == omr.MGeometry.kPosition:
5669 if desc.name == self.sVertexIdItemName:
5670 if not vertexNumericIdPositionBuffer:
5671 vertexNumericIdPositionBuffer = data.createVertexBuffer(desc)
5672 if vertexNumericIdPositionBuffer:
5673 satisfiedRequirements[i] =
True
5674 if debugPopulateGeometry:
5675 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition"
5676 print "Acquire 3loat-numeric position buffer"
5677 vertexNumericIdPositionDataAddress = vertexNumericIdPositionBuffer.acquire(totalVerts,
True)
5678 if vertexNumericIdPositionDataAddress:
5679 vertexNumericIdPositionData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericIdPositionDataAddress)
5681 elif desc.name == self.sVertexPositionItemName:
5682 if not vertexNumericLocationPositionBuffer:
5683 vertexNumericLocationPositionBuffer = data.createVertexBuffer(desc)
5684 if vertexNumericLocationPositionBuffer:
5685 satisfiedRequirements[i] =
True
5686 if debugPopulateGeometry:
5687 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition"
5688 print "Acquire 3loat-numeric position buffer"
5689 vertexNumericLocationPositionDataAddress = vertexNumericLocationPositionBuffer.acquire(totalVerts,
True)
5690 if vertexNumericLocationPositionDataAddress:
5691 vertexNumericLocationPositionData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericLocationPositionDataAddress)
5694 if not positionBuffer:
5695 positionBuffer = data.createVertexBuffer(desc)
5697 satisfiedRequirements[i] =
True
5698 if debugPopulateGeometry:
5699 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition"
5700 print "Acquire unnamed position buffer"
5701 positionDataAddress = positionBuffer.acquire(totalVerts,
True)
5702 if positionDataAddress:
5703 positionData = ((ctypes.c_float * 3)*totalVerts).from_address(positionDataAddress)
5705 elif desc.semantic == omr.MGeometry.kNormal:
5706 if not normalBuffer:
5707 normalBuffer = data.createVertexBuffer(desc)
5709 satisfiedRequirements[i] =
True
5710 if debugPopulateGeometry:
5711 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kNormal"
5712 normalDataAddress = normalBuffer.acquire(totalVerts,
True)
5713 if normalDataAddress:
5714 normalData = ((ctypes.c_float * 3)*totalVerts).from_address(normalDataAddress)
5716 elif desc.semantic == omr.MGeometry.kTexture:
5717 numericValue =
"numericvalue"
5718 numeric3Value =
"numeric3value"
5721 if desc.semanticName.lower() == numericValue
and desc.name == self.sVertexIdItemName:
5722 if not vertexNumericIdBuffer:
5723 vertexNumericIdBuffer = data.createVertexBuffer(desc)
5724 if vertexNumericIdBuffer:
5725 satisfiedRequirements[i] =
True
5726 if debugPopulateGeometry:
5727 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture"
5728 print "Acquire 1loat numeric buffer"
5729 vertexNumericIdDataAddress = vertexNumericIdBuffer.acquire(totalVerts,
True)
5730 if vertexNumericIdDataAddress:
5731 vertexNumericIdData = ((ctypes.c_float * 1)*totalVerts).from_address(vertexNumericIdDataAddress)
5734 elif desc.semanticName.lower() == numeric3Value
and desc.name == self.sVertexPositionItemName:
5735 if not vertexNumericLocationBuffer:
5736 vertexNumericLocationBuffer = data.createVertexBuffer(desc)
5737 if vertexNumericLocationBuffer:
5738 satisfiedRequirements[i] =
True
5739 if debugPopulateGeometry:
5740 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture"
5741 print "Acquire 3loat numeric location buffer"
5742 vertexNumericLocationDataAddress = vertexNumericLocationBuffer.acquire(totalVerts,
True)
5743 if vertexNumericLocationDataAddress:
5744 vertexNumericLocationData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericLocationDataAddress)
5747 elif desc.name != self.sVertexIdItemName
and desc.name != self.sVertexPositionItemName:
5749 uvBuffer = data.createVertexBuffer(desc)
5751 satisfiedRequirements[i] =
True
5752 if debugPopulateGeometry:
5753 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture"
5754 print "Acquire a uv buffer"
5755 uvDataAddress = uvBuffer.acquire(totalVerts,
True)
5757 uvData = ((ctypes.c_float * 2)*totalVerts).from_address(uvDataAddress)
5759 elif desc.semantic == omr.MGeometry.kColor:
5761 cpvBuffer = data.createVertexBuffer(desc)
5763 satisfiedRequirements[i] =
True
5764 if debugPopulateGeometry:
5765 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kColor"
5766 cpvDataAddress = cpvBuffer.acquire(totalVerts,
True)
5768 cpvData = ((ctypes.c_float * 4)*totalVerts).from_address(cpvDataAddress)
5779 for i
in xrange(self.fMeshGeom.faceCount):
5781 numVerts = self.fMeshGeom.face_counts[i]
5783 for v
in xrange(numVerts):
5784 if any((positionData, vertexNumericIdPositionData, vertexNumericLocationPositionData, vertexNumericLocationData)):
5785 position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
5788 positionData[pid][0] = position[0]
5789 positionData[pid][1] = position[1]
5790 positionData[pid][2] = position[2]
5793 if vertexNumericIdPositionData:
5794 vertexNumericIdPositionData[pid][0] = position[0]+1.0
5795 vertexNumericIdPositionData[pid][1] = position[1]+1.0
5796 vertexNumericIdPositionData[pid][2] = position[2]+1.0
5799 if vertexNumericLocationPositionData:
5800 vertexNumericLocationPositionData[pid][0] = position[0]+3.0
5801 vertexNumericLocationPositionData[pid][1] = position[1]+3.0
5802 vertexNumericLocationPositionData[pid][2] = position[2]+3.0
5805 if vertexNumericLocationData:
5806 vertexNumericLocationData[pid][0] = position[0]
5807 vertexNumericLocationData[pid][1] = position[1]
5808 vertexNumericLocationData[pid][2] = position[2]
5813 normal = self.fMeshGeom.normals[self.fMeshGeom.face_connects[vid]]
5814 normalData[nid][0] = normal[0]
5815 normalData[nid][1] = normal[1]
5816 normalData[nid][2] = normal[2]
5823 uvNum = self.fMeshGeom.uvcoords.uvId(vid)
5824 uv = self.fMeshGeom.uvcoords.getUV(uvNum)
5825 uvData[uvid][0] = uv[0]
5826 uvData[uvid][1] = uv[0]
5833 position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
5834 cpvData[cid][0] = position[0]
5835 cpvData[cid][1] = position[1]
5836 cpvData[cid][2] = position[2]
5837 cpvData[cid][3] = 1.0
5842 if vertexNumericIdData:
5843 vertexNumericIdData[vid] = fMeshGeom.face_connects[vid]
5851 if positionDataAddress:
5852 positionBuffer.commit(positionDataAddress)
5854 if normalDataAddress:
5855 normalBuffer.commit(normalDataAddress)
5858 uvBuffer.commit(uvDataAddress)
5861 cpvBuffer.commit(cpvDataAddress)
5863 if vertexNumericIdDataAddress:
5864 vertexNumericIdBuffer.commit(vertexNumericIdDataAddress)
5866 if vertexNumericIdPositionDataAddress:
5867 vertexNumericIdPositionBuffer.commit(vertexNumericIdPositionDataAddress)
5869 if vertexNumericLocationDataAddress:
5870 vertexNumericLocationBuffer.commit(vertexNumericLocationDataAddress)
5872 if vertexNumericLocationPositionDataAddress:
5873 vertexNumericLocationPositionBuffer.commit(vertexNumericLocationPositionDataAddress)
5878 if activeVertexPositionData:
5879 if debugPopulateGeometry:
5880 print ">>> Fill in the data for active vertex position buffer base on component list"
5884 if activeVertexCount > len(self.fMeshGeom.vertices):
5885 activeVertexCount = len(self.fMeshGeom.vertices)
5887 for i
in xrange(activeVertexCount):
5888 position = self.fMeshGeom.vertices[ self.fActiveVertices[i] ]
5889 activeVertexPositionData[i][0] = position[0]
5890 activeVertexPositionData[i][1] = position[1]
5891 activeVertexPositionData[i][2] = position[2]
5893 activeVertexPositionBuffer.commit(activeVertexPositionDataAddress)
5895 if activeVertexUVData:
5896 if debugPopulateGeometry:
5897 print ">>> Fill in the data for active vertex uv buffer base on component list"
5901 if activeVertexCount > len(self.fMeshGeom.vertices):
5902 activeVertexCount = len(self.fMeshGeom.vertices)
5904 for i
in xrange(activeVertexCount):
5905 activeVertexUVData[i] = i / activeVertexCount
5907 activeVertexUVBuffer.commit(activeVertexUVDataAddress)
5912 if faceCenterPositionData:
5913 if debugPopulateGeometry:
5914 print ">>> Fill in the data for face center position buffer"
5920 for faceId
in xrange(self.fMeshGeom.faceCount):
5926 faceCenterPosition = om.MPoint()
5929 numVerts = self.fMeshGeom.face_counts[faceId]
5931 for v
in xrange(numVerts):
5932 face_vertex_position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
5933 x += face_vertex_position[0]
5934 y += face_vertex_position[1]
5935 z += face_vertex_position[2]
5939 faceCenterPosition = om.MPoint(x, y, z) / numVerts
5944 faceCenterPositionData[faceId][0] = faceCenterPosition[0]
5945 faceCenterPositionData[faceId][1] = faceCenterPosition[1]
5946 faceCenterPositionData[faceId][2] = faceCenterPosition[2]
5948 faceCenterPositionBuffer.commit(faceCenterPositionDataAddress)
5952 for i
in xrange(len(descList)):
5953 if satisfiedRequirements[i]:
5956 if self.fDrawSharedActiveVertices
and (desc.name == self.sActiveVertexStreamName):
5957 if desc.semantic == omr.MGeometry.kPosition:
5958 satisfiedRequirements[i] =
True
5959 self.cloneVertexBuffer(activeVertexPositionBuffer, data, desc, activeVertexCount, debugPopulateGeometry)
5960 elif desc.semantic == omr.MGeometry.kTexture:
5961 satisfiedRequirements[i] =
True
5962 self.cloneVertexBuffer(activeVertexUVBuffer, data, desc, activeVertexCount, debugPopulateGeometry)
5963 elif self.fDrawFaceCenters
and desc.name == self.sFaceCenterStreamName:
5964 if desc.semantic == omr.MGeometry.kPosition:
5965 satisfiedRequirements[i] =
True
5966 self.cloneVertexBuffer(faceCenterPositionBuffer, data, desc, self.fMeshGeom.faceCount, debugPopulateGeometry)
5968 if desc.semantic == omr.MGeometry.kPosition:
5969 if desc.name == self.sVertexIdItemName:
5970 satisfiedRequirements[i] =
True
5971 self.cloneVertexBuffer(vertexNumericIdPositionBuffer, data, desc, totalVerts, debugPopulateGeometry)
5972 elif desc.name == self.sVertexPositionItemName:
5973 satisfiedRequirements[i] =
True
5974 self.cloneVertexBuffer(vertexNumericLocationPositionBuffer, data, desc, totalVerts, debugPopulateGeometry)
5976 satisfiedRequirements[i] =
True
5977 self.cloneVertexBuffer(positionBuffer, data, desc, totalVerts, debugPopulateGeometry)
5978 elif desc.semantic == omr.MGeometry.kNormal:
5979 satisfiedRequirements[i] =
True
5980 self.cloneVertexBuffer(normalBuffer, data, desc, totalVerts, debugPopulateGeometry)
5981 elif desc.semantic == omr.MGeometry.kTexture:
5982 numericValue =
"numericvalue"
5983 numeric3Value =
"numeric3value"
5984 if desc.semanticName.lower() == numericValue
and desc.name == self.sVertexIdItemName:
5985 satisfiedRequirements[i] =
True
5986 self.cloneVertexBuffer(vertexNumericIdBuffer, data, desc, totalVerts, debugPopulateGeometry)
5987 elif desc.semanticName.lower() == numeric3Value
and desc.name == self.sVertexPositionItemName:
5988 satisfiedRequirements[i] =
True
5989 self.cloneVertexBuffer(vertexNumericLocationBuffer, data, desc, totalVerts, debugPopulateGeometry)
5990 elif desc.name != self.sVertexIdItemName
and desc.name != self.sVertexPositionItemName:
5991 satisfiedRequirements[i] =
True
5992 self.cloneVertexBuffer(uvBuffer, data, desc, totalVerts, debugPopulateGeometry)
5993 elif desc.semantic == omr.MGeometry.kColor:
5994 satisfiedRequirements[i] =
True
5995 self.cloneVertexBuffer(cpvBuffer, data, desc, totalVerts, debugPopulateGeometry)
5997 if not satisfiedRequirements[i]:
6000 destBuffer = data.createVertexBuffer(desc)
6002 satisfiedRequirements[i] =
True
6003 if debugPopulateGeometry:
6004 print ">>> Fill in dummy requirement '%s'" % (desc.name, )
6005 destBufferDataAddress = destBuffer.acquire(totalVerts,
True)
6006 if destBufferDataAddress:
6007 destBufferData = ((ctypes.c_float * desc.dimension)*totalVerts).from_address(destBufferDataAddress)
6009 for j
in xrange(totalVerts):
6010 if desc.dimension == 4:
6011 destBufferData[j] = (1.0, 0.0, 0.0, 1.0)
6012 elif desc.dimension == 3:
6013 destBufferData[j] = (1.0, 0.0, 0.0)
6015 for k
in xrange(desc.dimension):
6016 destBufferData[j][k] = 0.0
6017 destBuffer.commit(destBufferDataAddress)
6022 def cloneVertexBuffer(self, srcBuffer, data, desc, dataSize, debugPopulateGeometry):
6024 destBuffer = data.createVertexBuffer(desc)
6026 if debugPopulateGeometry:
6027 print ">>> Cloning requirement '%s'" % (desc.name, )
6028 destBufferDataAddress = destBuffer.acquire(dataSize,
True)
6029 srcBufferDataAddress = srcBuffer.map()
6030 if destBufferDataAddress
and srcBufferDataAddress:
6031 destBufferData = ((ctypes.c_float * desc.dimension)*dataSize).from_address(destBufferDataAddress)
6032 srcBufferData = ((ctypes.c_float * desc.dimension)*dataSize).from_address(srcBufferDataAddress)
6033 if destBufferData
and srcBufferData:
6034 for j
in xrange(dataSize):
6035 for k
in xrange(desc.dimension):
6036 destBufferData[j][k] = srcBufferData[j][k]
6037 destBuffer.commit(destBufferDataAddress)
6041 def updateIndexingForWireframeItems(self, wireIndexBuffer, item, data, totalVerts):
6049 if not wireIndexBuffer:
6050 wireIndexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6052 dataAddress = wireIndexBuffer.acquire(2*totalVerts,
True)
6054 data = (ctypes.c_uint * (2*totalVerts)).from_address(dataAddress)
6058 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6060 numVerts = self.fMeshGeom.face_counts[faceIdx]
6063 for v
in xrange(numVerts-1):
6079 wireIndexBuffer.commit(dataAddress)
6083 item.associateWithIndexBuffer(wireIndexBuffer)
6085 def updateIndexingForDormantVertices(self, item, data, numTriangles):
6088 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6090 dataAddress = indexBuffer.acquire(3*numTriangles,
True)
6092 data = (ctypes.c_uint*(3*numTriangles)).from_address(dataAddress)
6097 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6099 numVerts = self.fMeshGeom.face_counts[faceIdx]
6101 for v
in xrange(1, numVerts-1):
6103 data[idx+1] = base+v
6104 data[idx+2] = base+v+1
6109 indexBuffer.commit(dataAddress)
6111 item.associateWithIndexBuffer(indexBuffer)
6113 def updateIndexingForFaceCenters(self, item, data, debugPopulateGeometry):
6116 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6118 dataAddress = indexBuffer.acquire(self.fMeshGeom.faceCount,
True)
6120 data = (ctypes.c_uint * self.fMeshGeom.faceCount).from_address(dataAddress)
6121 if debugPopulateGeometry:
6122 print ">>> Set up indexing for face centers"
6124 for i
in xrange(self.fMeshGeom.faceCount):
6129 for i
in xrange(self.fMeshGeom.faceCount):
6131 numVerts = self.fMeshGeom.face_counts[i]
6136 indexBuffer.commit(dataAddress)
6138 item.associateWithIndexBuffer(indexBuffer)
6140 def updateIndexingForVertices(self, item, data, numTriangles, activeVertexCount, debugPopulateGeometry):
6143 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6155 if self.fDrawSharedActiveVertices:
6156 dataAddress = indexBuffer.acquire(activeVertexCount,
True)
6158 data = (ctypes.c_uint*activeVertexCount).from_address(dataAddress)
6159 if debugPopulateGeometry:
6160 print ">>> Set up indexing for shared vertices"
6162 for i
in xrange(activeVertexCount):
6168 if debugPopulateGeometry:
6169 print ">>> Set up indexing for unshared vertices"
6171 vertexCount = 3*numTriangles
6172 dataAddress = indexBuffer.acquire(vertexCount,
True)
6174 data = (ctypes.c_uint*vertexCount).from_address(dataAddress)
6175 for i
in xrange(vertexCount):
6176 data[i] = vertexCount+1
6178 selectionIdSet = self.fActiveVerticesSet
6185 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6187 numVerts = self.fMeshGeom.face_counts[faceIdx]
6189 for v
in xrange(1, numVerts-1):
6190 vertexId = self.fMeshGeom.face_connects[base]
6191 if vertexId
in selectionIdSet:
6193 data[idx] = lastFound
6196 vertexId = self.fMeshGeom.face_connects[base+v]
6197 if vertexId
in selectionIdSet:
6199 data[idx] = lastFound
6202 vertexId = self.fMeshGeom.face_connects[base+v+1]
6203 if vertexId
in selectionIdSet:
6204 lastFound = base+v+1
6205 data[idx] = lastFound
6210 for i
in xrange(vertexCount):
6211 if data[i] == vertexCount+1:
6215 indexBuffer.commit(dataAddress)
6217 item.associateWithIndexBuffer(indexBuffer)
6219 def updateIndexingForEdges(self, item, data, totalVerts, fromSelection):
6222 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6224 totalEdges = 2*totalVerts
6225 totalEdgesP1 = 2*totalVerts+1
6226 dataAddress = indexBuffer.acquire(totalEdges,
True)
6228 data = (ctypes.c_uint*totalEdges).from_address(dataAddress)
6229 for i
in xrange(totalEdges):
6230 data[i] = totalEdgesP1
6233 displayAll =
not fromSelection
6234 displayActives = (
not displayAll
and bool(self.fActiveEdgesSet))
6235 displayAffected = (
not displayAll
and not displayActives)
6237 selectionIdSet =
None
6239 selectionIdSet = self.fActiveEdgesSet
6240 elif displayAffected:
6241 selectionIdSet = self.fActiveVerticesSet
6247 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6249 numVerts = self.fMeshGeom.face_counts[faceIdx]
6251 for v
in xrange(numVerts):
6252 enableEdge = displayAll
6253 vindex1 = base + (v % numVerts)
6254 vindex2 = base + ((v+1) % numVerts)
6260 vertexId = self.fMeshGeom.face_connects[vindex1]
6261 if vertexId
in selectionIdSet:
6266 vertexId2 = self.fMeshGeom.face_connects[vindex2]
6267 if vertexId2
in selectionIdSet:
6271 elif displayActives:
6274 if edgeId
in selectionIdSet:
6289 for i
in xrange(totalEdges):
6290 if data[i] == totalEdgesP1:
6293 indexBuffer.commit(dataAddress)
6295 item.associateWithIndexBuffer(indexBuffer)
6297 def updateIndexingForFaces(self, item, data, numTriangles, fromSelection):
6300 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6302 numTriangleVertices = 3*numTriangles
6303 dataAddress = indexBuffer.acquire(numTriangleVertices,
True)
6305 data = (ctypes.c_uint*numTriangleVertices).from_address(dataAddress)
6306 for i
in xrange(numTriangleVertices):
6307 data[i] = numTriangleVertices+1
6310 displayAll =
not fromSelection
6311 displayActives = (
not displayAll
and bool(self.fActiveFacesSet))
6312 displayAffected = (
not displayAll
and not displayActives)
6314 selectionIdSet =
None
6316 selectionIdSet = self.fActiveFacesSet
6317 elif displayAffected:
6318 selectionIdSet = self.fActiveVerticesSet
6323 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6325 numVerts = self.fMeshGeom.face_counts[faceIdx]
6327 enableFace = displayAll
6332 for v
in xrange(1, numVerts-1):
6333 vertexId = self.fMeshGeom.face_connects[base]
6334 if vertexId
in selectionIdSet:
6339 vertexId2 = self.fMeshGeom.face_connects[base+v]
6340 if vertexId2
in selectionIdSet:
6345 vertexId3 = self.fMeshGeom.face_connects[base+v+1]
6346 if vertexId3
in selectionIdSet:
6348 lastFound = base+v+1
6350 elif displayActives:
6353 if faceIdx
in selectionIdSet:
6361 for v
in xrange(1, numVerts-1):
6363 data[idx+1] = base+v
6364 data[idx+2] = base+v+1
6370 for i
in xrange(numTriangleVertices):
6371 if data[i] == numTriangleVertices+1:
6374 indexBuffer.commit(dataAddress)
6376 item.associateWithIndexBuffer(indexBuffer)
6378 def updateIndexingForShadedTriangles(self, item, data, numTriangles):
6382 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6384 dataAddress = indexBuffer.acquire(3*numTriangles,
True)
6386 data = (ctypes.c_uint * (3*numTriangles)).from_address(dataAddress)
6391 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6393 numVerts = self.fMeshGeom.face_counts[faceIdx]
6395 for v
in xrange(1, numVerts-1):
6397 data[idx+1] = base+v
6398 data[idx+2] = base+v+1
6403 indexBuffer.commit(dataAddress)
6405 item.associateWithIndexBuffer(indexBuffer)
6419 sUseSubSceneOverride =
False
6420 sDrawDbClassification =
"drawdb/geometry/apiMesh"
6421 if sUseSubSceneOverride:
6422 sDrawDbClassification =
"drawdb/subscene/apiMesh"
6423 sDrawRegistrantId =
"apiMeshPlugin"
6426 def initializePlugin(obj):
6427 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
6429 global sUseSubSceneOverride, sDrawDbClassification, sDrawRegistrantId
6432 plugin.registerData(
"apiMeshData", apiMeshData.id, apiMeshData.creator, om.MPxData.kGeometryData)
6434 sys.stderr.write(
"Failed to register data\n")
6438 plugin.registerShape(
"apiMesh", apiMesh.id, apiMesh.creator, apiMesh.initialize, apiMeshUI.creator, sDrawDbClassification)
6440 sys.stderr.write(
"Failed to register node\n")
6444 plugin.registerNode(
"apiMeshCreator", apiMeshCreator.id, apiMeshCreator.creator, apiMeshCreator.initialize)
6446 sys.stderr.write(
"Failed to register node\n")
6450 if sUseSubSceneOverride:
6451 omr.MDrawRegistry.registerSubSceneOverrideCreator(sDrawDbClassification, sDrawRegistrantId, apiMeshSubSceneOverride.creator)
6453 omr.MDrawRegistry.registerGeometryOverrideCreator(sDrawDbClassification, sDrawRegistrantId, apiMeshGeometryOverride.creator)
6455 sys.stderr.write(
"Failed to register override\n")
6459 if sUseSubSceneOverride:
6460 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sVertexSelectionName, simpleComponentConverter_subsceneOverride.creatorVertexSelection)
6461 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sEdgeSelectionName, simpleComponentConverter_subsceneOverride.creatorEdgeSelection)
6462 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sFaceSelectionName, simpleComponentConverter_subsceneOverride.creatorFaceSelection)
6464 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sVertexItemName, meshVertComponentConverter_geometryOverride.creator)
6465 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sEdgeSelectionItemName, meshEdgeComponentConverter_geometryOverride.creator)
6466 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sFaceSelectionItemName, meshFaceComponentConverter_geometryOverride.creator)
6468 sys.stderr.write(
"Failed to register component converters\n")
6471 def uninitializePlugin(obj):
6472 plugin = om.MFnPlugin(obj)
6474 global sUseSubSceneOverride, sDrawDbClassification, sDrawRegistrantId
6477 if sUseSubSceneOverride:
6478 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sVertexSelectionName)
6479 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sEdgeSelectionName)
6480 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sFaceSelectionName)
6482 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sVertexItemName)
6483 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sEdgeSelectionItemName)
6484 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sFaceSelectionItemName)
6486 sys.stderr.write(
"Failed to deregister component converters\n")
6490 if sUseSubSceneOverride:
6491 omr.MDrawRegistry.deregisterSubSceneOverrideCreator(sDrawDbClassification, sDrawRegistrantId)
6493 omr.MDrawRegistry.deregisterGeometryOverrideCreator(sDrawDbClassification, sDrawRegistrantId)
6495 sys.stderr.write(
"Failed to deregister override\n")
6499 plugin.deregisterNode(apiMeshCreator.id)
6501 sys.stderr.write(
"Failed to deregister node\n")
6505 plugin.deregisterNode(apiMesh.id)
6507 sys.stderr.write(
"Failed to deregister node\n")
6511 plugin.deregisterData(apiMeshData.id)
6513 sys.stderr.write(
"Failed to deregister data\n")