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 setDependentsDirty(self, plug, plugArray):
611 if plug == apiMesh.inputSurface
or plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
612 self.signalDirtyToViewport()
614 def getInternalValueInContext(self, plug, handle, ctx):
640 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
648 if self.hasHistory():
649 return om.MPxNode.getInternalValueInContext(self, plug, handle, ctx)
652 if plug == om.MPxSurfaceShape.mControlPoints
and not plug.isArray():
653 index = plug.logicalIndex()
654 pnt = self.getPointValue(index)
655 handle.set3Double( pnt[0], pnt[1], pnt[2] )
657 elif plug == om.MPxSurfaceShape.mControlValueX:
658 parentPlug = plug.parent()
659 index = parentPlug.logicalIndex()
660 val = self.getChannelValue( index, 0 )
661 handle.setDouble( val )
663 elif plug == om.MPxSurfaceShape.mControlValueY:
664 parentPlug = plug.parent()
665 index = parentPlug.logicalIndex()
666 val = self.getChannelValue( index, 1 )
667 handle.setDouble( val )
669 elif plug == om.MPxSurfaceShape.mControlValueZ:
670 parentPlug = plug.parent()
671 index = parentPlug.logicalIndex()
672 val = self.getChannelValue( index, 2 )
673 handle.setDouble( val )
682 elif plug == om.MPxSurfaceShape.mHasHistoryOnCreate:
683 handle.setBool( self.fHasHistoryOnCreate )
686 isOk = om.MPxSurfaceShape.getInternalValueInContext(self, plug, handle, ctx)
690 def setInternalValueInContext(self, plug, handle, ctx):
716 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
726 if self.hasHistory():
727 self.verticesUpdated()
728 return om.MPxNode.setInternalValueInContext(self, plug, handle, ctx)
731 if plug == om.MPxSurfaceShape.mControlPoints
and not plug.isArray():
732 index = plug.logicalIndex()
733 self.setPointValue( index, handle.asDouble3() )
735 elif plug == om.MPxSurfaceShape.mControlValueX:
736 parentPlug = plug.parent()
737 index = parentPlug.logicalIndex()
738 self.setChannelValue( index, 0, handle.asDouble() )
740 elif plug == om.MPxSurfaceShape.mControlValueY:
741 parentPlug = plug.parent()
742 index = parentPlug.logicalIndex()
743 self.setChannelValue( index, 1, handle.asDouble() )
745 elif plug == om.MPxSurfaceShape.mControlValueZ:
746 parentPlug = plug.parent()
747 index = parentPlug.logicalIndex()
748 self.setChannelValue( index, 2, handle.asDouble() )
757 elif plug == om.MPxSurfaceShape.mHasHistoryOnCreate:
758 self.fHasHistoryOnCreate = handle.asBool()
761 isOk = om.MPxSurfaceShape.setInternalValueInContext(self, plug, handle, ctx)
765 def connectionMade(self, plug, otherPlug, asSrc):
773 if plug == apiMesh.inputSurface:
774 thisObj = self.thisMObject()
775 historyPlug = om.MPlug( thisObj, om.MPxSurfaceShape.mHasHistoryOnCreate )
776 historyPlug.setBool(
True )
778 thisObj = self.thisMObject()
779 dgNode = om.MFnDependencyNode( thisObj )
780 instObjGroups = dgNode.findPlug(
"instObjGroups",
True)
781 if plug == instObjGroups:
782 self.setMaterialDirty(
True)
784 return om.MPxNode.connectionMade(self, plug, otherPlug, asSrc )
786 def connectionBroken(self, plug, otherPlug, asSrc):
794 if plug == apiMesh.inputSurface:
795 thisObj = self.thisMObject()
796 historyPlug = om.MPlug( thisObj, om.MPxSurfaceShape.mHasHistoryOnCreate )
797 historyPlug.setBool(
False )
799 thisObj = self.thisMObject()
800 dgNode = om.MFnDependencyNode( thisObj )
801 instObjGroups = dgNode.findPlug(
"instObjGroups",
True)
802 if plug == instObjGroups:
803 self.setMaterialDirty(
True)
805 return om.MPxNode.connectionBroken(self, plug, otherPlug, asSrc )
807 def shouldSave(self, plug):
818 if plug == om.MPxSurfaceShape.mControlPoints
or plug == om.MPxSurfaceShape.mControlValueX
or plug == om.MPxSurfaceShape.mControlValueY
or plug == om.MPxSurfaceShape.mControlValueZ:
819 if self.hasHistory():
823 result = om.MPxNode.shouldSave(self, plug)
828 elif plug == apiMesh.cachedSurface:
829 if self.hasHistory():
833 data = plug.asMObject()
834 result =
not data.isNull()
837 result = om.MPxNode.shouldSave(self, plug)
843 def componentToPlugs(self, component, list):
856 if component.hasFn(om.MFn.kSingleIndexedComponent):
857 fnVtxComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(component) )
858 thisNode = self.thisMObject()
859 plug = om.MPlug( thisNode, om.MPxSurfaceShape.mControlPoints )
863 self.convertToTweakNodePlug(plug)
865 for i
in xrange(fnVtxComp.elementCount):
866 plug.selectAncestorLogicalIndex(fnVtxComp.element(i), plug.attribute())
869 def matchComponent(self, item, spec, list):
893 result = om.MPxSurfaceShape.kMatchOk
895 dim = attrSpec.dimensions
901 if len(spec) == 1
and dim > 0
and attrSpec.name ==
"vtx":
902 numVertices = len(self.meshGeom().vertices)
903 attrIndex = attrSpec[0]
907 if attrIndex.hasLowerBound():
908 lower = attrIndex.getLower()
909 if attrIndex.hasUpperBound():
910 upper = attrIndex.getUpper()
914 if lower > upper
or upper >= numVertices:
915 result = om.MPxSurfaceShape.kMatchInvalidAttributeRange
918 path = item.getDagPath(0)
919 fnVtxComp = om.MFnSingleIndexedComponent()
920 vtxComp = fnVtxComp.create( om.MFn.kMeshVertComponent )
922 for i
in xrange(lower, upper+1):
923 fnVtxComp.addElement( i )
925 list.add( path, vtxComp )
929 result = om.MPxSurfaceShape.matchComponent(self, item, spec, list )
933 def match(self, mask, componentList):
954 if len(componentList) == 0:
955 result = mask.intersects( om.MSelectionMask.kSelectMeshes )
958 for comp
in componentList:
959 if comp.apiType() == om.MFn.kMeshVertComponent
and mask.intersects(om.MSelectionMask.kSelectMeshVerts):
967 def createFullVertexGroup(self):
982 fnComponent = om.MFnSingleIndexedComponent()
983 fullComponent = fnComponent.create( om.MFn.kMeshVertComponent )
988 numVertices = len(self.meshGeom().vertices)
989 fnComponent.setCompleteData( numVertices )
993 def getShapeSelectionMask(self):
1003 selType = om.MSelectionMask.kSelectMeshes
1004 return om.MSelectionMask( selType )
1006 def getComponentSelectionMask(self):
1016 selMask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
1017 selMask.addMask(om.MSelectionMask.kSelectMeshEdges)
1018 selMask.addMask(om.MSelectionMask.kSelectMeshFaces)
1021 def localShapeInAttr(self):
1034 return apiMesh.inputSurface
1036 def localShapeOutAttr(self):
1050 return apiMesh.outputSurface
1052 def worldShapeOutAttr(self):
1066 return apiMesh.outputSurface
1068 def cachedShapeAttr(self):
1080 return apiMesh.cachedSurface
1083 def geometryData(self):
1091 datablock = self.forceCache()
1092 handle = datablock.inputValue( apiMesh.inputSurface )
1093 return handle.data()
1095 def closestPoint(self, toThisPoint, theClosestPoint, tolerance):
1106 geometry = self.meshGeom()
1107 numVertices = len(geometry.vertices)
1108 for i
in xrange(numVertices):
1109 tryThisOne = geometry.vertices[i]
1113 theClosestPoint = geometry.vertices[0]
1117 def transformUsing(self, mat, componentList, cachingMode=om.MPxSurfaceShape.kNoPointCaching, pointCache=None):
1135 geometry = self.meshGeom()
1139 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1140 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1145 cacheLen = len(pointCache)
1150 if len(componentList) > 0:
1153 for comp
in componentList:
1154 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1155 elemCount = fnComp.elementCount
1157 for idx
in xrange(elementCount):
1158 elemIndex = fnComp.element(idx)
1159 geometry.vertices[elemIndex] = pointCache[cacheIndex]
1161 if cacheIndex >= cacheLen:
1164 if cacheIndex >= cacheLen:
1171 vertLen = len(geometry.vertices)
1172 for idx
in xrange(vertLen):
1173 geometry.vertices[idx] = pointCache[cacheIndex]
1175 if cacheIndex >= cacheLen:
1182 if len(componentList) > 0:
1185 setSizeIncrement =
True
1186 for comp
in componentList:
1187 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1188 elemCount = fnComp.elementCount
1190 if savePoints
and setSizeIncrement:
1191 pointCache.sizeIncrement = elemCount
1192 setSizeIncrement =
False
1194 for idx
in xrange(elemCount):
1195 elemIndex = fnComp.element(idx)
1197 pointCache.append(geometry.vertices[elemIndex])
1199 geometry.vertices[elemIndex] *= mat
1200 geometry.normals[idx] = geometry.normals[idx].transformAsNormal( mat )
1206 vertLen = len(geometry.vertices)
1208 pointCache.sizeIncrement = vertLen
1210 for idx
in xrange(vertLen):
1212 pointCache.append(geometry.vertices[idx])
1214 geometry.vertices[idx] *= mat
1215 geometry.normals[idx] = geometry.normals[idx].transformAsNormal( mat )
1218 self.updateCachedSurface( geometry, componentList )
1220 def tweakUsing(self, mat, componentList, cachingMode, pointCache, handle):
1241 geometry = self.meshGeom()
1245 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1246 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1247 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1249 builder = handle.builder()
1254 cacheLen = len(pointCache)
1259 if len(componentList) > 0:
1262 for comp
in componentList:
1263 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1264 elemCount = fnComp.elementCount
1266 for idx
in xrange(elementCount):
1267 elemIndex = fnComp.element(idx)
1268 cachePt = pointCache[cacheIndex]
1269 elem = builder.addElement( elemIndex )
1270 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1272 if cacheIndex >= cacheLen:
1275 if cacheIndex >= cacheLen:
1282 vertLen = len(geometry.vertices)
1283 for idx
in xrange(vertLen):
1284 cachePt = pointCache[cacheIndex]
1285 elem = builder.addElement( idx )
1286 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1288 if cacheIndex >= cacheLen:
1296 if len(componentList) > 0:
1297 setSizeIncrement =
True
1298 for comp
in componentList:
1299 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1300 elemCount = fnComp.elementCount
1302 if savePoints
and setSizeIncrement:
1303 pointCache.sizeIncrement = elemCount
1304 setSizeIncrement =
False
1306 for idx
in xrange(elementCount):
1307 elemIndex = fnComp.element(idx)
1308 currPt = newPt = geometry.vertices[elemIndex]
1310 delta = newPt - currPt
1311 elem = builder.addElement( elemIndex )
1312 elem.set3Double(delta.x, delta.y, delta.z)
1317 pointCache.append(delta*(-1.0))
1319 elif updatePoints
and cacheIndex < cacheLen:
1320 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1327 vertLen = len(geometry.vertices)
1329 pointCache.sizeIncrement = vertLen
1331 for idx
in xrange(vertLen):
1332 currPt = newPt = geometry.vertices[idx]
1334 delta = newPt - currPt
1335 elem = builder.addElement( idx )
1336 elem.set3Double(delta.x, delta.y, delta.z)
1341 pointCache.append(delta*(-1.0))
1343 elif updatePoints
and idx < cacheLen:
1344 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1354 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
1357 self.signalDirtyToViewport()
1361 def weightedTransformUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane):
1387 plg_useWeightedTransformUsingFunction = om.MPlug( self.thisMObject(), apiMesh.useWeightedTransformUsingFunction )
1388 val_useWeightedTransformUsingFunction = plg_useWeightedTransformUsingFunction.asBool()
1389 if not val_useWeightedTransformUsingFunction:
1390 om.MPxSurfaceShape.weightedTransformUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane)
1391 self.signalDirtyToViewport()
1396 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1397 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1398 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1399 transformOrigPoints = (cachingMode == om.MPxSurfaceShape.kTransformOriginalPoints
and pointCache
is not None)
1402 spaceInv = om.MMatrix()
1404 spaceInv = space.inverse()
1408 geometry = self.meshGeom()
1411 setSizeIncrement =
True
1413 for comp
in componentList:
1414 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1415 elemCount = fnComp.elementCount
1416 hasWeights = fnComp.hasWeights
1417 hasSeam = (freezePlane
is not None)
1419 if savePoints
and setSizeIncrement:
1420 pointCache.sizeIncrement = elemCount
1421 setSizeIncrement =
False
1423 for idx
in xrange(elementCount):
1424 elemIndex = fnComp.element( idx )
1427 perc = fnComp.weight(idx).influence()
1430 if perc > almostZero:
1433 geometry.vertices[elemIndex] = om.MVector( pointCache[pointCacheIndex] )
1434 pointCacheIndex += 1
1439 pointCache.append( geometry.vertices[elemIndex] )
1441 elif transformOrigPoints:
1442 geometry.vertices[elemIndex] = om.MVector( pointCache[pointCacheIndex] )
1445 pointCache[pointCacheIndex] = geometry.vertices[elemIndex]
1450 mat = xform.asMatrix()
1452 mat = space * xform.asMatrix(perc) * spaceInv
1454 mat = xform.asMatrix(perc)
1457 currPt = newPt = geometry.vertices[elemIndex]
1461 if hasSeam
and fnComp.weight(idx).seam() > 0.0:
1462 newPt += freezePlane.normal() * (fnComp.weight(idx).seam() * (freezePlane.directedDistance(currPt) - freezePlane.directedDistance(newPt)))
1465 geometry.vertices[elemIndex] = newPt
1466 pointCacheIndex += 1
1469 self.updateCachedSurface( geometry, componentList )
1471 def weightedTweakUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane, handle):
1502 plg_useWeightedTweakUsingFunction = om.MPlug( self.thisMObject(), apiMesh.useWeightedTweakUsingFunction )
1503 val_useWeightedTweakUsingFunction = plg_useWeightedTweakUsingFunction.asBool()
1504 if not val_useWeightedTweakUsingFunction:
1505 om.MPxSurfaceShape.weightedTweakUsing(self, xform, space, componentList, cachingMode, pointCache, freezePlane, handle)
1508 geometry = self.meshGeom()
1512 savePoints = (cachingMode == om.MPxSurfaceShape.kSavePoints
and pointCache
is not None)
1513 updatePoints = (cachingMode == om.MPxSurfaceShape.kUpdatePoints
and pointCache
is not None)
1514 restorePoints = (cachingMode == om.MPxSurfaceShape.kRestorePoints
and pointCache
is not None)
1515 transformOrigPoints = (cachingMode == om.MPxSurfaceShape.kTransformOriginalPoints
and pointCache
is not None)
1517 builder = handle.builder()
1522 cacheLen = len(pointCache)
1529 for comp
in componentList:
1530 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1531 elemCount = fnComp.elementCount
1533 for idx
in xrange(elementCount):
1534 elemIndex = fnComp.element( idx )
1535 cachePt = pointCache[cacheIndex]
1536 elem = builder.addElement( elemIndex )
1537 elem.set3Double(cachePt.x, cachePt.y, cachePt.z)
1539 if cacheIndex >= cacheLen:
1550 setSizeIncrement =
True
1551 spaceInv = om.MMatrix()
1553 spaceInv = space.inverse()
1555 for comp
in componentList:
1556 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
1557 elemCount = fnComp.elementCount
1558 hasWeights = fnComp.hasWeights
1559 hasSeam = (freezePlane
is not None)
1561 if savePoints
and setSizeIncrement:
1562 pointCache.sizeIncrement = elemCount
1563 setSizeIncrement =
False
1565 for idx
in xrange(elementCount):
1566 elemIndex = fnComp.element( idx )
1569 perc = fnComp.weight(idx).influence()
1572 if perc > almostZero:
1578 mat = xform.asMatrix()
1580 mat = space * xform.asMatrix(perc) * spaceInv
1582 mat = xform.asMatrix(perc)
1587 if transformOrigPoints:
1588 geometry.vertices[elemIndex] = om.MVector( pointCache[cacheIndex] )
1592 currPt = newPt = geometry.vertices[elemIndex]
1597 if hasSeam
and fnComp.weight(idx).seam() > 0.0:
1598 newPt += freezePlane.normal() * (fnComp.weight(idx).seam() * (freezePlane.directedDistance(currPt) - freezePlane.directedDistance(newPt)))
1601 delta = newPt - currPt
1603 elem = builder.addElement( elemIndex )
1604 elem.set3Double(delta.x, delta.y, delta.z)
1609 pointCache.append(delta*(-1.0))
1610 elif updatePoints
and cacheIndex < cacheLen:
1611 pointCache[cacheIndex] = pointCache[cacheIndex] - delta
1621 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
1625 def vertexOffsetDirection(self, component, direction, mode, normalize):
1644 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(component) )
1645 if component.apiType() != om.MFn.kMeshVertComponent:
1648 geometry = self.meshGeom()
1655 normal = geometry.normals[ idx ]
1657 if mode == om.MPxSurfaceShape.kNormal:
1660 direction.append( normal )
1669 a = math.abs(normal[0])
1671 if a < math.abs(normal[1]):
1675 if a < math.abs(normal[2]):
1681 a = math.sqrt(normal[i]*normal[i] + normal[j]*normal[j])
1682 uAxis[i] = -normal[j]/a
1683 uAxis[j] = normal[i]/a
1685 vAxis = normal^uAxis
1687 if mode == om.MPxSurfaceShape.kUTangent
or mode == om.MPxSurfaceShape.kUVNTriad:
1690 direction.append( uAxis )
1692 if mode == om.MPxSurfaceShape.kVTangent
or mode == om.MPxSurfaceShape.kUVNTriad:
1695 direction.append( vAxis )
1697 if mode == om.MPxSurfaceShape.kUVNTriad:
1700 direction.append( normal )
1706 def isBounded(self):
1715 def boundingBox(self):
1722 if self.fShapeDirty:
1726 thisNode = self.thisMObject()
1727 c1Plug = om.MPlug( thisNode, apiMesh.bboxCorner1 )
1728 c2Plug = om.MPlug( thisNode, apiMesh.bboxCorner2 )
1729 corner1Object = c1Plug.asMObject()
1730 corner2Object = c2Plug.asMObject()
1732 fnData = om.MFnNumericData()
1733 fnData.setObject( corner1Object )
1734 corner1 = fnData.getData()
1736 fnData.setObject( corner2Object )
1737 corner2 = fnData.getData()
1739 corner1Point = om.MPoint( corner1[0], corner1[1], corner1[2] )
1740 corner2Point = om.MPoint( corner2[0], corner2[1], corner2[2] )
1742 return om.MBoundingBox( corner1Point, corner2Point )
1746 def geometryIteratorSetup(self, componentList, components, forReadOnly=False):
1763 if components.isNull():
1764 vtxComponents = om.MObjectArray([self.convertToVertexComponent(c)
for c
in componentList])
1765 return apiMeshGeomIterator( self.meshGeom(), vtxComponents )
1767 return apiMeshGeomIterator( self.meshGeom(), self.convertToVertexComponent(components) )
1769 def acceptsGeometryIterator(self, arg0, arg1=None, arg2=None):
1795 def hasHistory(self):
1801 return self.fHasHistoryOnCreate
1803 def shapeDirty(self):
1810 return self.fShapeDirty
1812 def resetShapeDirty(self):
1818 self.fShapeDirty =
False
1820 def materialDirty(self):
1827 return self.fMaterialDirty
1829 def setMaterialDirty(self, dirty):
1835 self.fMaterialDirty = dirty
1837 def computeInputSurface(self, plug, datablock):
1846 if self.hasHistory():
1847 inputHandle = datablock.inputValue( apiMesh.inputSurface )
1849 surf = inputHandle.asPluginData()
1850 if not isinstance(surf, apiMeshData):
1851 raise RuntimeError(
"computeInputSurface : invalid inputSurface data found")
1855 fnDataCreator = om.MFnPluginData()
1856 fnDataCreator.create( apiMeshData.id )
1858 newCachedData = fnDataCreator.data()
1859 if not isinstance(newCachedData, apiMeshData):
1860 raise RuntimeError(
"computeInputSurface : invalid proxy cached apiMeshData object")
1862 newCachedData.fGeometry.copy(surf.fGeometry)
1864 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
1865 if not isinstance(cachedHandle, om.MDataHandle):
1866 raise RuntimeError(
"computeInputSurface : invalid cachedSurface")
1868 cachedHandle.setMPxData( newCachedData )
1870 def computeOutputSurface(self, plug, datablock):
1885 self.computeInputSurface( plug, datablock )
1889 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
1890 if not isinstance(cachedHandle, om.MDataHandle):
1891 raise RuntimeError(
"computeOutputSurface : invalid cachedSurface")
1893 cached = cachedHandle.asPluginData()
1894 if not isinstance(cached, apiMeshData):
1895 raise RuntimeError(
"computeOutputSurface : invalid cachedSurface data found")
1897 datablock.setClean( plug )
1901 if self.hasHistory():
1902 self.applyTweaks( datablock, cached.fGeometry )
1905 cpHandle = datablock.inputArrayValue( om.MPxSurfaceShape.mControlPoints )
1906 cpHandle.setAllClean()
1910 fnDataCreator = om.MFnPluginData()
1911 fnDataCreator.create( apiMeshData.id )
1913 newData = fnDataCreator.data()
1914 if not isinstance(newData, apiMeshData):
1915 raise RuntimeError(
"computeOutputSurface : invalid proxy cached apiMeshData object")
1919 newData.fGeometry.copy(cached.fGeometry)
1923 outHandle = datablock.outputValue( apiMesh.outputSurface )
1924 outHandle.setMPxData( newData )
1928 self.computeBoundingBox( datablock )
1930 def computeWorldSurface(self, plug, datablock):
1937 self.computeOutputSurface( plug, datablock )
1938 inHandle = datablock.outputValue( apiMesh.outputSurface )
1939 outSurf = inHandle.asPluginData()
1940 if not isinstance(outSurf, apiMeshData):
1941 raise RuntimeError(
"computeWorldSurface : invalid outSurf")
1945 fnDataCreator = om.MFnPluginData()
1946 fnDataCreator.create( apiMeshData.id )
1948 newData = fnDataCreator.data()
1949 if not isinstance(newData, apiMeshData):
1950 raise RuntimeError(
"computeWorldSurface : invalid proxy cached apiMeshData object")
1953 worldMat = self.getWorldMatrix(datablock, 0)
1954 newData.matrix = worldMat
1958 newData.fGeometry.copy( outSurf.fGeometry )
1962 arrayIndex = plug.logicalIndex()
1964 worldHandle = datablock.outputArrayValue( apiMesh.worldSurface )
1965 builder = worldHandle.builder()
1966 outHandle = builder.addElement( arrayIndex )
1968 outHandle.setMPxData( newData )
1970 def computeBoundingBox(self, datablock):
1980 lowerHandle = datablock.outputValue( apiMesh.bboxCorner1 )
1981 upperHandle = datablock.outputValue( apiMesh.bboxCorner2 )
1983 geometry = self.meshGeom()
1984 cnt = len(geometry.vertices)
1990 tmppnt = geometry.vertices[0]
1991 lower = [ tmppnt[0], tmppnt[1], tmppnt[2] ]
1992 upper = [ tmppnt[0], tmppnt[1], tmppnt[2] ]
1994 for i
in xrange(cnt):
1995 pnt = geometry.vertices[i]
1997 if pnt[0] < lower[0]: lower[0] = pnt[0]
1998 if pnt[1] < lower[1]: lower[1] = pnt[1]
1999 if pnt[2] < lower[2]: lower[2] = pnt[2]
2001 if pnt[0] > upper[0]: upper[0] = pnt[0]
2002 if pnt[1] > upper[1]: upper[1] = pnt[1]
2003 if pnt[2] > upper[2]: upper[2] = pnt[2]
2005 lowerHandle.set3Double(lower[0], lower[1], lower[2])
2006 upperHandle.set3Double(upper[0], upper[1], upper[2])
2008 lowerHandle.setClean()
2009 upperHandle.setClean()
2013 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2015 def convertToVertexComponent(self, components):
2017 Converts edge and face components into vertex components. This
2018 allows applying transform offsets to the vertex when edge or faces
2024 srcComponent = om.MFnSingleIndexedComponent(components)
2025 srcComponentType = srcComponent.componentType
2029 if srcComponentType != om.MFn.kMeshVertComponent:
2030 srcIndices = set(srcComponent.getElements())
2031 retVal = srcComponent.create(om.MFn.kMeshVertComponent)
2032 vtxComponent = om.MFnSingleIndexedComponent(retVal)
2034 geomPtr = self.meshGeom()
2038 for faceIdx
in xrange(0, geomPtr.faceCount):
2040 numVerts = geomPtr.face_counts[faceIdx]
2042 for v
in xrange(0, numVerts):
2043 if srcComponentType == om.MFn.kMeshEdgeComponent:
2044 if edgeId
in srcIndices:
2045 vindex1 = base + (v % numVerts)
2046 vindex2 = base + ((v+1) % numVerts)
2048 vertexId1 = geomPtr.face_connects[vindex1]
2049 vertexId2 = geomPtr.face_connects[vindex2]
2051 vtxComponent.addElement(vertexId1)
2052 vtxComponent.addElement(vertexId2)
2057 if faceIdx
in srcIndices:
2058 vindex = base + (v % numVerts)
2059 vertexId = geomPtr.face_connects[vindex]
2060 vtxComponent.addElement(vertexId)
2066 def applyTweaks(self, datablock, geometry):
2074 cpHandle = datablock.inputArrayValue( om.MPxSurfaceShape.mControlPoints )
2078 while not cpHandle.isDone():
2079 elemIndex = cpHandle.elementLogicalIndex()
2080 pntHandle = cpHandle.outputValue()
2082 offset = pntHandle.asDouble3()
2086 geometry.vertices[elemIndex] += om.MPoint(offset[0],offset[1],offset[2])
2091 def updateCachedSurface(self, geometry, componentList):
2110 datablock = self.forceCache()
2112 cachedHandle = datablock.outputValue( apiMesh.cachedSurface )
2113 cached = cachedHandle.asPluginData()
2115 dHandle = datablock.outputValue( om.MPxSurfaceShape.mControlPoints )
2120 if self.hasHistory()
and cached:
2125 self.buildControlPoints( datablock, len(geometry.vertices) )
2127 cpHandle = om.MArrayDataHandle( dHandle )
2131 for comp
in componentList:
2132 fnComp = om.MFnSingleIndexedComponent( self.convertToVertexComponent(comp) )
2133 for elemIndex
in fnComp.getElements():
2134 cpHandle.jumpToLogicalElement( elemIndex )
2135 pntHandle = cpHandle.outputValue()
2137 pnt = pntHandle.asDouble3()
2139 oldPnt = cached.fGeometry.vertices[elemIndex]
2140 newPnt = geometry.vertices[elemIndex]
2141 offset = newPnt - oldPnt
2147 pntHandle.set3Double(pnt[0], pnt[1], pnt[2])
2152 cached.fGeometry.copy(geometry)
2154 pCPs = om.MPlug( self.thisMObject(), om.MPxSurfaceShape.mControlPoints)
2155 pCPs.setMDataHandle(dHandle)
2159 self.computeBoundingBox( datablock )
2164 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2167 self.signalDirtyToViewport()
2169 def getPointValue(self, pntInd):
2176 geometry = self.cachedGeom()
2178 return geometry.vertices[ pntInd ]
2182 def getChannelValue(self, pntInd, vlInd):
2189 geometry = self.cachedGeom()
2191 return geometry.vertices[ pntInd ][ vlInd ]
2195 def setPointValue(self, pntInd, val):
2202 geometry = self.cachedGeom()
2204 geometry.vertices[ pntInd ] = om.MPoint(val)
2206 self.verticesUpdated()
2208 def setChannelValue(self, pntInd, vlInd, val):
2215 geometry = self.cachedGeom()
2217 geometry.vertices[ pntInd ][ vlInd ] = val
2219 self.verticesUpdated()
2221 def meshObject(self):
2232 datablock = self.forceCache()
2238 handle = datablock.inputValue( apiMesh.outputSurface )
2239 return handle.data()
2248 fnData = om.MFnPluginData( self.meshObject() )
2249 data = fnData.data()
2250 if not isinstance(data, apiMeshData):
2251 raise RuntimeError(
"meshGeom : failed to get apiMeshData")
2253 return data.fGeometry
2255 def cachedObject(self):
2265 datablock = self.forceCache()
2266 handle = datablock.outputValue( apiMesh.cachedSurface )
2267 return handle.data()
2269 def cachedGeom(self):
2276 fnData = om.MFnPluginData( self.cachedObject() )
2277 data = fnData.data()
2278 if not isinstance(data, apiMeshData):
2279 raise RuntimeError(
"cachedGeom : failed to get apiMeshData")
2281 return data.fGeometry
2283 def buildControlPoints(self, datablock, count):
2291 cpH = datablock.outputArrayValue( om.MPxSurfaceShape.mControlPoints )
2293 oldBuilder = cpH.builder()
2294 if count != len(oldBuilder):
2297 builder = om.MArrayDataBuilder( oldBuilder )
2299 for vtx
in xrange(count):
2300 builder.addElement( vtx )
2306 def verticesUpdated(self):
2314 self.childChanged( om.MPxSurfaceShape.kBoundingBoxChanged )
2315 self.childChanged( om.MPxSurfaceShape.kObjectChanged )
2317 def signalDirtyToViewport(self):
2318 self.fShapeDirty =
True
2319 omr.MRenderer.setGeometryDrawDirty(self.thisMObject())
2329 class apiMeshUI(omui.MPxSurfaceShapeUI):
2336 omui.MPxSurfaceShapeUI.__init__(self)
2347 def drawUV(self, view, info):
2357 meshNode = self.surfaceShape()
2358 geom = meshNode.meshGeom()
2360 if geom.uvcoords.uvcount() > 0:
2361 view.setDrawColor( om.MColor( (1.0, 0.0, 0.0) ) )
2363 if info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawWireframe:
2364 self.drawUVWireframe( geom, view, info )
2366 elif info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawEverything
or info.drawingFunction == omui.MTextureEditorDrawInfo.kDrawUVForSelect:
2367 self.drawUVWireframe( geom, view, info )
2368 self.drawUVMapCoordNum( geom, view, info,
True )
2371 self.drawUVWireframe( geom, view, info )
2373 def canDrawUV(self):
2379 meshNode = self.surfaceShape()
2380 geom = meshNode.meshGeom()
2381 return (geom.uvcoords.uvcount() > 0)
2385 def select(self, selectInfo, selectionList, worldSpaceSelectPts):
2399 componentSelected =
False
2402 hilited = (selectInfo.displayStatus() == omui.M3dView.kHilite)
2404 componentSelected = self.selectVertices( selectInfo, selectionList, worldSpaceSelectPts )
2405 selected = selected
or componentSelected
2408 meshNode = self.surfaceShape()
2415 priorityMask = om.MSelectionMask( om.MSelectionMask.kSelectNurbsSurfaces )
2417 item = om.MSelectionList()
2418 item.add( selectInfo.selectPath() )
2420 xformedPt = om.MPoint()
2421 if selectInfo.singleSelection():
2422 center = meshNode.boundingBox().center
2424 xformedPt *= selectInfo.selectPath().inclusiveMatrix()
2426 selectInfo.addSelection( item, xformedPt, selectionList, worldSpaceSelectPts, priorityMask,
False )
2436 def selectVertices(self, selectInfo, selectionList, worldSpaceSelectPts):
2450 view = selectInfo.view()
2451 path = selectInfo.multiPath()
2452 singleSelection = selectInfo.singleSelection()
2456 fnComponent = om.MFnSingleIndexedComponent()
2457 surfaceComponent = fnComponent.create( om.MFn.kMeshVertComponent )
2462 alignmentMatrix = om.MMatrix()
2464 alignmentMatrix = selectInfo.getAlignmentMatrix()
2466 singlePoint = om.MPoint()
2467 selectionPoint = om.MPoint()
2468 closestPointVertexIndex = -1
2473 meshNode = self.surfaceShape()
2474 geom = meshNode.meshGeom()
2479 for currentPoint
in geom.vertices:
2485 glBegin( GL_POINTS )
2486 glVertex3f( currentPoint[0], currentPoint[1], currentPoint[2] )
2489 if view.endSelect() > 0:
2493 xformedPoint = currentPoint
2494 xformedPoint.homogenize()
2495 xformedPoint *= alignmentMatrix
2497 if closestPointVertexIndex < 0
or z > previousZ:
2498 closestPointVertexIndex = vertexIndex
2499 singlePoint = currentPoint
2505 fnComponent.addElement( vertexIndex )
2509 if selected
and singleSelection:
2510 fnComponent.addElement(closestPointVertexIndex)
2514 selectionPoint = singlePoint
2515 selectionPoint *= path.inclusiveMatrix()
2520 selectionItem = om.MSelectionList()
2521 selectionItem.add( path, surfaceComponent )
2523 mask = om.MSelectionMask( om.MSelectionMask.kSelectComponentsMask )
2524 selectInfo.addSelection( selectionItem, selectionPoint, selectionList, worldSpaceSelectPts, mask,
True )
2528 def drawUVWireframe(self, geom, view, info):
2540 for i
in xrange(geom.faceCount):
2544 for v
in xrange(geom.face_counts[i]-1):
2545 uvId1 = geom.uvcoords.uvId(vid)
2546 uvId2 = geom.uvcoords.uvId(vid+1)
2548 uv1 = geom.uvcoords.getUV(uvId1)
2549 uv2 = geom.uvcoords.getUV(uvId2)
2551 glVertex3f( uv1[0], uv1[1], 0.0 )
2552 glVertex3f( uv2[0], uv2[1], 0.0 )
2555 uvId1 = geom.uvcoords.uvId(vid)
2556 uvId2 = geom.uvcoords.uvId(vid_start)
2558 uv1 = geom.uvcoords.getUV(uvId1)
2559 uv2 = geom.uvcoords.getUV(uvId2)
2561 glVertex3f( uv1[0], uv1[1], 0.0 )
2562 glVertex3f( uv2[0], uv2[1], 0.0 )
2569 def drawUVMapCoord(self, view, uvId, uv, drawNumbers):
2577 view.drawText( str(uvId), om.MPoint( uv[0], uv[1], 0 ), omui.M3dView.kCenter )
2579 glVertex3f( uv[0], uv[1], 0.0 )
2581 def drawUVMapCoordNum(self, geom, view, info, drawNumbers):
2589 ptSize = glGetFloatv( GL_POINT_SIZE )
2592 for uvId
in xrange(geom.uvcoords.uvcount()):
2593 uv = geom.uvcoords.getUV( uvId )
2594 self.drawUVMapCoord( view, uvId, uv, drawNumbers )
2596 glPointSize( ptSize )
2609 class apiMeshCreator(om.MPxNode):
2610 id = om.MTypeId(0x80089)
2620 outputSurface =
None
2624 return apiMeshCreator()
2628 typedAttr = om.MFnTypedAttribute()
2629 numericAttr = om.MFnNumericAttribute()
2630 enumAttr = om.MFnEnumAttribute()
2633 apiMeshCreator.size = numericAttr.create(
"size",
"sz", om.MFnNumericData.kDouble, 1 )
2634 numericAttr.array =
False
2635 numericAttr.usesArrayDataBuilder =
False
2636 numericAttr.hidden =
False
2637 numericAttr.keyable =
True
2638 om.MPxNode.addAttribute( apiMeshCreator.size )
2640 apiMeshCreator.shapeType = enumAttr.create(
"shapeType",
"st", 0 )
2641 enumAttr.addField(
"cube", 0 )
2642 enumAttr.addField(
"sphere", 1 )
2643 enumAttr.hidden =
False
2644 enumAttr.keyable =
True
2645 om.MPxNode.addAttribute( apiMeshCreator.shapeType )
2647 apiMeshCreator.inputMesh = typedAttr.create(
"inputMesh",
"im", om.MFnData.kMesh, om.MObject.kNullObj )
2648 typedAttr.hidden =
True
2649 om.MPxNode.addAttribute( apiMeshCreator.inputMesh )
2652 apiMeshCreator.outputSurface = typedAttr.create(
"outputSurface",
"os", apiMeshData.id, om.MObject.kNullObj )
2653 typedAttr.writable =
False
2654 om.MPxNode.addAttribute( apiMeshCreator.outputSurface )
2658 om.MPxNode.attributeAffects( apiMeshCreator.inputMesh, apiMeshCreator.outputSurface )
2659 om.MPxNode.attributeAffects( apiMeshCreator.size, apiMeshCreator.outputSurface )
2660 om.MPxNode.attributeAffects( apiMeshCreator.shapeType, apiMeshCreator.outputSurface )
2663 om.MPxNode.__init__(self)
2671 def compute(self, plug, datablock):
2679 if plug == apiMeshCreator.outputSurface:
2683 fnDataCreator = om.MFnPluginData()
2684 fnDataCreator.create( apiMeshData.id )
2686 newData = fnDataCreator.data()
2687 if not isinstance(newData, apiMeshData):
2688 raise RuntimeError(
"compute : invalid proxy cached apiMeshData object")
2690 geometry = newData.fGeometry
2695 hasHistory = self.computeInputMesh( plug, datablock, geometry )
2701 sizeHandle = datablock.inputValue( apiMeshCreator.size )
2702 shape_size = sizeHandle.asDouble()
2703 typeHandle = datablock.inputValue( apiMeshCreator.shapeType )
2704 shape_type = typeHandle.asShort()
2707 self.buildCube( shape_size, geometry )
2708 elif shape_type == 1:
2709 self.buildSphere( shape_size, 32, geometry )
2711 geometry.faceCount = len(geometry.face_counts)
2715 outHandle = datablock.outputValue( apiMeshCreator.outputSurface )
2716 outHandle.setMPxData( newData )
2717 datablock.setClean( plug )
2725 def computeInputMesh(self, plug, datablock, geometry):
2736 inputData = datablock.inputValue( apiMeshCreator.inputMesh )
2737 surf = inputData.asMesh()
2741 thisObj = self.thisMObject()
2742 surfPlug = om.MPlug( thisObj, apiMeshCreator.inputMesh )
2743 if not surfPlug.isConnected:
2744 datablock.setClean( plug )
2749 surfFn = om.MFnMesh(surf)
2750 geometry.vertices = surfFn.getPoints(om.MSpace.kObject)
2754 hasUVs = surfFn.numUVs() > 0
2755 uvs = surfFn.getUVs()
2756 geometry.uvcoords.ucoord = uvs[0]
2757 geometry.uvcoords.vcoord = uvs[1]
2759 for i
in xrange(surfFn.numPolygons()):
2760 polyVerts = surfFn.getPolygonVertices(i)
2762 pvc = len(polyVerts)
2763 geometry.face_counts.append( pvc )
2765 for v
in xrange(pvc):
2767 uvId = surfFn.getPolygonUVid(i, v)
2768 geometry.uvcoords.faceVertexIndex.append( uvId )
2769 geometry.face_connects.append( polyVerts[v] )
2771 for n
in xrange(len(geometry.vertices)):
2772 normal = surfFn.getVertexNormal(n)
2773 geometry.normals.append( normal )
2777 def buildCube(self, cube_size, geometry):
2784 geometry.vertices.clear()
2785 geometry.normals.clear()
2786 geometry.face_counts.clear()
2787 geometry.face_connects.clear()
2788 geometry.uvcoords.reset()
2790 geometry.vertices.append( om.MPoint( -cube_size, -cube_size, -cube_size ) )
2791 geometry.vertices.append( om.MPoint( cube_size, -cube_size, -cube_size ) )
2792 geometry.vertices.append( om.MPoint( cube_size, -cube_size, cube_size ) )
2793 geometry.vertices.append( om.MPoint( -cube_size, -cube_size, cube_size ) )
2794 geometry.vertices.append( om.MPoint( -cube_size, cube_size, -cube_size ) )
2795 geometry.vertices.append( om.MPoint( -cube_size, cube_size, cube_size ) )
2796 geometry.vertices.append( om.MPoint( cube_size, cube_size, cube_size ) )
2797 geometry.vertices.append( om.MPoint( cube_size, cube_size, -cube_size ) )
2799 normal_value = 0.5775
2800 geometry.normals.append( om.MVector( -normal_value, -normal_value, -normal_value ) )
2801 geometry.normals.append( om.MVector( normal_value, -normal_value, -normal_value ) )
2802 geometry.normals.append( om.MVector( normal_value, -normal_value, normal_value ) )
2803 geometry.normals.append( om.MVector( -normal_value, -normal_value, normal_value ) )
2804 geometry.normals.append( om.MVector( -normal_value, normal_value, -normal_value ) )
2805 geometry.normals.append( om.MVector( -normal_value, normal_value, normal_value ) )
2806 geometry.normals.append( om.MVector( normal_value, normal_value, normal_value ) )
2807 geometry.normals.append( om.MVector( normal_value, normal_value, -normal_value ) )
2812 uv_pts = [ [ 0.375, 0.0 ],
2829 num_face_connects = 24
2830 uv_fvid = [ 0, 1, 2, 3,
2837 for i
in xrange(uv_count):
2838 geometry.uvcoords.append_uv( uv_pts[i][0], uv_pts[i][1] )
2840 for i
in xrange(num_face_connects):
2841 geometry.uvcoords.faceVertexIndex.append( uv_fvid[i] )
2847 face_counts = [ 4, 4, 4, 4, 4, 4 ]
2849 for i
in xrange(num_faces):
2850 geometry.face_counts.append( face_counts[i] )
2854 face_connects = [ 0, 1, 2, 3,
2861 for i
in xrange(num_face_connects):
2862 geometry.face_connects.append( face_connects[i] )
2864 def buildSphere(self, radius, divisions, geometry):
2872 geometry.vertices.clear()
2873 geometry.normals.clear()
2874 geometry.face_counts.clear()
2875 geometry.face_connects.clear()
2876 geometry.uvcoords.reset()
2880 u_delta = math.pi / divisions
2881 v_delta = 2 * math.pi / divisions
2883 topPole = om.MPoint( 0.0, radius, 0.0 )
2884 botPole = om.MPoint( 0.0, -radius, 0.0 )
2888 geometry.vertices.append( botPole )
2889 geometry.normals.append( botPole - om.MPoint.kOrigin )
2891 for i
in xrange(divisions-1):
2895 for j
in xrange(divisions):
2896 x = radius * math.cos(u) * math.cos(v)
2897 y = radius * math.sin(u)
2898 z = radius * math.cos(u) * math.sin(v)
2900 pnt = om.MPoint( x, y, z )
2901 geometry.vertices.append( pnt )
2902 geometry.normals.append( pnt - om.MPoint.kOrigin )
2905 geometry.vertices.append( topPole )
2906 geometry.normals.append( topPole - om.MPoint.kOrigin )
2912 for i
in xrange(divisions):
2913 for j
in xrange(divisions):
2915 geometry.face_counts.append( 3 )
2917 geometry.face_connects.append( 0 )
2918 geometry.face_connects.append( j + vid )
2919 if j == divisions-1:
2920 geometry.face_connects.append( vid )
2922 geometry.face_connects.append( j + vid + 1 )
2924 elif i == divisions-1:
2925 geometry.face_counts.append( 3 )
2927 geometry.face_connects.append( j + vid + 1 - divisions )
2928 geometry.face_connects.append( vid + 1 )
2929 if j == divisions-1:
2930 geometry.face_connects.append( vid + 1 - divisions )
2932 geometry.face_connects.append( j + vid + 2 - divisions )
2935 geometry.face_counts.append( 4 )
2937 geometry.face_connects.append( j + vid + 1 - divisions )
2938 geometry.face_connects.append( j + vid + 1 )
2939 if j == divisions-1:
2940 geometry.face_connects.append( vid + 1 )
2941 geometry.face_connects.append( vid + 1 - divisions )
2943 geometry.face_connects.append( j + vid + 2 )
2944 geometry.face_connects.append( j + vid + 2 - divisions )
2951 class ShadedItemUserData(om.MUserData):
2952 def __init__(self, override):
2953 om.MUserData.__init__(self,
False)
2954 self.fOverride = override
2958 class apiMeshHWSelectionUserData(om.MUserData):
2960 om.MUserData.__init__(self,
True)
2961 self.fMeshGeom =
None
2975 class simpleComponentConverter_subsceneOverride(omr.MPxComponentConverter):
2976 def __init__(self, componentType, selectionType):
2977 omr.MPxComponentConverter.__init__(self)
2979 self.fComponentType = componentType
2980 self.fSelectionType = selectionType
2982 self.fComponent = om.MFnSingleIndexedComponent()
2983 self.fComponentObject = om.MObject.kNullObj
2984 self.fLookupTable = []
2986 def initialize(self, renderItem):
2988 self.fComponentObject = self.fComponent.create( self.fComponentType )
2993 if self.fComponentType == om.MFn.kMeshPolygonComponent:
2994 selectionData = renderItem.customData()
2995 if isinstance(selectionData, apiMeshHWSelectionUserData):
2996 meshGeom = selectionData.fMeshGeom
3000 for i
in xrange(meshGeom.faceCount):
3001 numVerts = meshGeom.face_counts[i]
3003 numTriangles += numVerts - 2
3004 self.fLookupTable = [0]*numTriangles
3008 for faceId
in xrange(meshGeom.faceCount):
3010 numVerts = meshGeom.face_counts[faceId]
3012 for v
in xrange(1, numVerts-1):
3013 self.fLookupTable[triId] = faceId
3016 def addIntersection(self, intersection):
3023 if self.fComponentType == om.MFn.kMeshEdgeComponent:
3026 if intersection.instanceID == 1
or intersection.instanceID == 3:
3029 idx = intersection.index
3031 if self.fComponentType == om.MFn.kMeshPolygonComponent:
3032 if idx >= 0
and idx < len(self.fLookupTable):
3033 idx = self.fLookupTable[idx]
3035 self.fComponent.addElement(idx)
3037 def component(self):
3039 return self.fComponentObject
3041 def selectionMask(self):
3043 return self.fSelectionType
3047 def creatorVertexSelection():
3048 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
3049 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
3050 return simpleComponentConverter_subsceneOverride(om.MFn.kMeshVertComponent, mask)
3054 def creatorEdgeSelection():
3055 return simpleComponentConverter_subsceneOverride(om.MFn.kMeshEdgeComponent, om.MSelectionMask.kSelectMeshEdges)
3059 def creatorFaceSelection():
3060 return simpleComponentConverter_subsceneOverride(om.MFn.kMeshPolygonComponent, om.MSelectionMask.kSelectMeshFaces)
3062 class apiMeshSubSceneOverride(omr.MPxSubSceneOverride):
3063 sWireName =
"apiMeshWire"
3064 sSelectName =
"apiMeshSelection"
3065 sBoxName =
"apiMeshBox"
3066 sSelectedBoxName =
"apiMeshBoxSelection"
3067 sShadedName =
"apiMeshShaded"
3068 sTexturedName =
"apiMeshTextured"
3070 sVertexSelectionName =
"apiMeshVertexSelection"
3071 sEdgeSelectionName =
"apiMeshEdgeSelection"
3072 sFaceSelectionName =
"apiMeshFaceSelection"
3074 sActiveVertexName =
"apiMeshActiveVertex"
3075 sActiveEdgeName =
"apiMeshActiveEdge"
3076 sActiveFaceName =
"apiMeshActiveFace"
3079 def __init__(self, transform, isSelected):
3080 self.fTransform = transform
3081 self.fIsSelected = isSelected
3085 return apiMeshSubSceneOverride(obj)
3088 def shadedItemLinkLost(userData):
3089 if not userData
is None and not userData.fOverride
is None:
3090 if not userData.fOverride.fMesh
is None:
3091 userData.fOverride.fMesh.setMaterialDirty(
True)
3092 userData.fOverride =
None
3095 def __init__(self, obj):
3096 omr.MPxSubSceneOverride.__init__(self, obj)
3098 node = om.MFnDependencyNode(obj)
3099 self.fMesh = node.userNode()
3100 self.fObject = om.MObject(obj)
3101 self.fWireShader =
None
3102 self.fThickWireShader =
None
3103 self.fSelectShader =
None
3104 self.fThickSelectShader =
None
3105 self.fShadedShader =
None
3106 self.fVertexComponentShader =
None
3107 self.fEdgeComponentShader =
None
3108 self.fFaceComponentShader =
None
3109 self.fPositionBuffer =
None
3110 self.fNormalBuffer =
None
3111 self.fBoxPositionBuffer =
None
3112 self.fWireIndexBuffer =
None
3113 self.fBoxIndexBuffer =
None
3114 self.fShadedIndexBuffer =
None
3115 self.fActiveVerticesIndexBuffer =
None
3116 self.fActiveEdgesIndexBuffer =
None
3117 self.fActiveFacesIndexBuffer =
None
3118 self.fThickLineWidth = -1.0
3119 self.fQueuedLineWidth = -1.0
3120 self.fNumInstances = 0
3121 self.fIsInstanceMode =
False
3122 self.fQueueUpdate =
False
3123 self.fUseQueuedLineUpdate =
False
3125 self.fInstanceInfoCache = collections.defaultdict(set)
3127 self.fActiveVerticesSet = set()
3128 self.fActiveEdgesSet = set()
3129 self.fActiveFacesSet = set()
3134 shaderMgr = omr.MRenderer.getShaderManager()
3136 if self.fWireShader:
3137 shaderMgr.releaseShader(self.fWireShader)
3138 self.fWireShader =
None
3140 if self.fThickWireShader:
3141 shaderMgr.releaseShader(self.fThickWireShader)
3142 self.fThickWireShader =
None
3144 if self.fSelectShader:
3145 shaderMgr.releaseShader(self.fSelectShader)
3146 self.fSelectShader =
None
3148 if self.fThickSelectShader:
3149 shaderMgr.releaseShader(self.fThickSelectShader)
3150 self.fThickSelectShader =
None
3152 if self.fShadedShader:
3153 shaderMgr.releaseShader(self.fShadedShader)
3154 self.fShadedShader =
None
3156 if self.fVertexComponentShader:
3157 shaderMgr.releaseShader(self.fVertexComponentShader)
3158 self.fVertexComponentShader =
None
3160 if self.fEdgeComponentShader:
3161 shaderMgr.releaseShader(self.fEdgeComponentShader)
3162 self.fEdgeComponentShader =
None
3164 if self.fFaceComponentShader:
3165 shaderMgr.releaseShader(self.fFaceComponentShader)
3166 self.fFaceComponentShader =
None
3170 def supportedDrawAPIs(self):
3172 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
3174 def requiresUpdate(self, container, frameContext):
3176 if len(container) == 0:
3183 def update(self, container, frameContext):
3185 self.manageRenderItems(container, frameContext, self.fMesh.shapeDirty()
or len(container) == 0)
3188 self.fMesh.resetShapeDirty()
3190 def furtherUpdateRequired(self, frameContext):
3191 if self.fUseQueuedLineUpdate:
3192 if not frameContext.inUserInteraction()
and not frameContext.userChangingViewContext():
3193 return self.fQueueUpdate
3197 def manageRenderItems(self, container, frameContext, updateGeometry):
3199 if not self.fMesh
or self.fObject.isNull():
3202 shaderMgr = omr.MRenderer.getShaderManager()
3206 node = om.MFnDagNode(self.fObject)
3207 instances = node.getAllPaths()
3208 if len(instances) == 0:
3212 sRed = [1.0, 0.0, 0.0, 1.0]
3213 sGreen = [0.0, 1.0, 0.0, 1.0]
3214 sWhite = [1.0, 1.0, 1.0, 1.0]
3217 if not self.fWireShader:
3218 self.fWireShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3219 self.fWireShader.setParameter(
"solidColor", sRed)
3221 if not self.fThickWireShader:
3222 self.fThickWireShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3223 self.fThickWireShader.setParameter(
"solidColor", sRed)
3225 if not self.fSelectShader:
3226 self.fSelectShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3227 self.fSelectShader.setParameter(
"solidColor", sGreen)
3229 if not self.fThickSelectShader:
3230 self.fThickSelectShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3231 self.fThickSelectShader.setParameter(
"solidColor", sGreen)
3233 if not self.fVertexComponentShader:
3234 self.fVertexComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dFatPointShader)
3235 self.fVertexComponentShader.setParameter(
"solidColor", sWhite)
3236 self.fVertexComponentShader.setParameter(
"pointSize", [5.0, 5.0])
3238 if not self.fEdgeComponentShader:
3239 self.fEdgeComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
3240 self.fEdgeComponentShader.setParameter(
"solidColor", sWhite)
3241 self.fEdgeComponentShader.setParameter(
"lineWidth", [2.0, 2.0])
3243 if not self.fFaceComponentShader:
3244 self.fFaceComponentShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
3245 self.fFaceComponentShader.setParameter(
"solidColor", sWhite)
3247 if not self.fShadedShader:
3248 self.fShadedShader = shaderMgr.getStockShader(omr.MShaderManager.k3dBlinnShader)
3252 self.rebuildGeometryBuffers()
3254 if not all((self.fPositionBuffer, self.fNormalBuffer, self.fBoxPositionBuffer, self.fWireIndexBuffer, self.fBoxIndexBuffer, self.fShadedIndexBuffer)):
3255 print "At least one buffer is not set"
3258 selectedList = om.MGlobal.getActiveSelectionList()
3260 anyMatrixChanged =
False
3261 itemsChanged =
False
3262 instanceArrayLength = len(instances)
3263 numInstanceSelected = 0
3264 numInstanceUnselected = 0
3267 instanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3268 selectedInstanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3269 unselectedInstanceMatrixArray = om.MMatrixArray(instanceArrayLength)
3271 for instance
in instances:
3277 if not instance.isValid
or not instance.isVisible:
3280 instanceNum = instance.instanceNumber()
3282 instanceInfo = apiMeshSubSceneOverride.InstanceInfo(instance.inclusiveMatrix(), useSelectHighlight(selectedList, instance))
3284 if instanceNum
not in self.fInstanceInfoCache
or self.fInstanceInfoCache[instanceNum].fIsSelected != instanceInfo.fIsSelected
or not self.fInstanceInfoCache[instanceNum].fTransform.isEquivalent(instanceInfo.fTransform):
3285 self.fInstanceInfoCache[instanceNum] = instanceInfo
3286 anyMatrixChanged =
True
3288 instanceMatrixArray[numInstances] = instanceInfo.fTransform
3290 if instanceInfo.fIsSelected:
3291 selectedInstanceMatrixArray[numInstanceSelected] = instanceInfo.fTransform
3292 numInstanceSelected += 1
3294 unselectedInstanceMatrixArray[numInstanceUnselected] = instanceInfo.fTransform
3295 numInstanceUnselected += 1
3297 instanceMatrixArray.setLength(numInstances)
3298 selectedInstanceMatrixArray.setLength(numInstanceSelected)
3299 unselectedInstanceMatrixArray.setLength(numInstanceUnselected)
3300 if self.fNumInstances != numInstances:
3301 anyMatrixChanged =
True
3302 self.fNumInstances = numInstances
3304 anyInstanceSelected = numInstanceSelected > 0
3305 anyInstanceUnselected = numInstanceUnselected > 0
3307 activeVerticesSet = set()
3308 activeEdgesSet = set()
3309 activeFacesSet = set()
3311 meshGeom = self.fMesh.meshGeom()
3312 if meshGeom
and self.fMesh.hasActiveComponents():
3313 activeComponents = self.fMesh.activeComponents()
3314 if len(activeComponents) > 0:
3315 fnComponent = om.MFnSingleIndexedComponent( activeComponents[0] )
3316 if fnComponent.elementCount > 0:
3317 activeIds = fnComponent.getElements()
3319 if fnComponent.componentType == om.MFn.kMeshVertComponent:
3320 activeVerticesSet = set(activeIds)
3322 elif fnComponent.componentType == om.MFn.kMeshEdgeComponent:
3323 activeEdgesSet = set(activeIds)
3325 elif fnComponent.componentType == om.MFn.kMeshPolygonComponent:
3326 activeFacesSet = set(activeIds)
3329 updateActiveItems = updateGeometry
or self.fActiveVerticesSet != activeVerticesSet
or self.fActiveEdgesSet != activeEdgesSet
or self.fActiveFacesSet != activeFacesSet
3330 self.fActiveVerticesSet = activeVerticesSet
3331 self.fActiveEdgesSet = activeEdgesSet
3332 self.fActiveFacesSet = activeFacesSet
3334 if updateActiveItems:
3335 self.rebuildActiveComponentIndexBuffers()
3337 anyVertexSelected = bool(self.fActiveVerticesSet)
3338 anyEdgeSelected = bool(self.fActiveEdgesSet)
3339 anyFaceSelected = bool(self.fActiveFacesSet)
3341 if (anyVertexSelected
and not self.fActiveVerticesIndexBuffer)
or (anyEdgeSelected
and not self.fActiveEdgesIndexBuffer)
or (anyFaceSelected
and not self.fActiveFacesIndexBuffer):
3346 wireItem = container.find(self.sWireName)
3347 if not wireItem
and anyInstanceUnselected:
3348 wireItem = omr.MRenderItem.create( self.sWireName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3349 wireItem.setDrawMode(omr.MGeometry.kWireframe)
3350 wireItem.setDepthPriority(omr.MRenderItem.sActiveWireDepthPriority)
3351 wireItem.setShader(self.fWireShader)
3352 container.add(wireItem)
3355 elif wireItem
and not anyInstanceUnselected:
3356 container.remove(self.sWireName)
3360 selectItem = container.find(self.sSelectName)
3361 if not selectItem
and anyInstanceSelected:
3362 selectItem = omr.MRenderItem.create( self.sSelectName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3363 selectItem.setDrawMode(omr.MGeometry.kWireframe | omr.MGeometry.kShaded | omr.MGeometry.kTextured)
3364 selectItem.setDepthPriority(omr.MRenderItem.sActiveWireDepthPriority)
3365 selectItem.setShader(self.fSelectShader)
3366 container.add(selectItem)
3369 elif selectItem
and not anyInstanceSelected:
3370 container.remove(self.sSelectName)
3374 boxItem = container.find(self.sBoxName)
3375 if not boxItem
and anyInstanceUnselected:
3376 boxItem = omr.MRenderItem.create( self.sBoxName, omr.MRenderItem.NonMaterialSceneItem, omr.MGeometry.kLines)
3377 boxItem.setDrawMode(omr.MGeometry.kBoundingBox)
3378 boxItem.setShader(self.fWireShader)
3379 container.add(boxItem)
3382 elif boxItem
and not anyInstanceUnselected:
3383 container.remove(self.sBoxName)
3387 selectedBoxItem = container.find(self.sSelectedBoxName)
3388 if not selectedBoxItem
and anyInstanceSelected:
3389 selectedBoxItem = omr.MRenderItem.create( self.sSelectedBoxName, omr.MRenderItem.NonMaterialSceneItem, omr.MGeometry.kLines)
3390 selectedBoxItem.setDrawMode(omr.MGeometry.kBoundingBox)
3391 selectedBoxItem.setShader(self.fSelectShader)
3392 container.add(selectedBoxItem)
3395 elif selectedBoxItem
and not anyInstanceSelected:
3396 container.remove(self.sSelectedBoxName)
3397 selectedBoxItem =
None
3400 shadedItem = container.find(self.sShadedName)
3403 shadedItem = omr.MRenderItem.create( self.sShadedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
3404 shadedItem.setDrawMode(omr.MGeometry.kShaded)
3405 shadedItem.setExcludedFromPostEffects(
False)
3406 shadedItem.setCastsShadows(
True)
3407 shadedItem.setReceivesShadows(
True)
3408 container.add(shadedItem)
3411 texturedItem = container.find(self.sTexturedName)
3412 if not texturedItem:
3414 texturedItem = omr.MRenderItem.create( self.sTexturedName, omr.MRenderItem.MaterialSceneItem, omr.MGeometry.kTriangles)
3415 texturedItem.setDrawMode(omr.MGeometry.kTextured)
3416 texturedItem.setExcludedFromPostEffects(
False)
3417 texturedItem.setCastsShadows(
True)
3418 texturedItem.setReceivesShadows(
True)
3419 container.add(texturedItem)
3426 connectedPlugs = om.MPlugArray()
3427 (sets, comps) = node.getConnectedSetsAndMembers(0,
True)
3429 dn = om.MFnDependencyNode(obj)
3430 shaderPlug = dn.findPlug(
"surfaceShader",
True)
3431 connectedPlugs = shaderPlug.connectedTo(
True,
False)
3432 if len(connectedPlugs) > 0:
3436 if self.fMesh.materialDirty()
or not shadedItem.isShaderFromNode():
3437 if len(connectedPlugs) == 0
or \
3438 not shadedItem.setShaderFromNode(connectedPlugs[0].node(),
3440 apiMeshSubSceneOverride.shadedItemLinkLost,
3441 ShadedItemUserData(self),
3443 shadedItem.setShader(self.fShadedShader)
3446 if self.fMesh.materialDirty()
or not texturedItem.isShaderFromNode():
3447 if len(connectedPlugs) == 0
or \
3448 not texturedItem.setShaderFromNode(connectedPlugs[0].node(),
3450 apiMeshSubSceneOverride.shadedItemLinkLost,
3451 ShadedItemUserData(self),
3453 texturedItem.setShader(self.fShadedShader)
3457 self.fMesh.setMaterialDirty(
False)
3462 vertexSelectionItem = container.find(self.sVertexSelectionName)
3463 if not vertexSelectionItem:
3464 vertexSelectionItem = omr.MRenderItem.create( self.sVertexSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
3466 vertexSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
3468 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
3469 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
3470 vertexSelectionItem.setSelectionMask( mask )
3472 vertexSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
3473 vertexSelectionItem.setShader(self.fVertexComponentShader)
3474 container.add(vertexSelectionItem)
3480 useDrawInstancingOnEdgeSelectionItem =
False
3483 edgeSelectionItem = container.find(self.sEdgeSelectionName)
3484 if not edgeSelectionItem:
3486 drawMode = omr.MGeometry.kSelectionOnly
3487 depthPriority = omr.MRenderItem.sSelectionDepthPriority
3488 if useDrawInstancingOnEdgeSelectionItem:
3490 drawMode = omr.MGeometry.kAll
3492 depthPriority = omr.MRenderItem.sActiveWireDepthPriority-1
3494 edgeSelectionItem = omr.MRenderItem.create( self.sEdgeSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3495 edgeSelectionItem.setDrawMode(drawMode)
3497 edgeSelectionItem.setDepthPriority(depthPriority)
3499 edgeSelectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshEdges )
3500 edgeSelectionItem.setShader(self.fWireShader)
3501 container.add(edgeSelectionItem)
3505 faceSelectionItem = container.find(self.sFaceSelectionName)
3506 if not faceSelectionItem:
3507 faceSelectionItem = omr.MRenderItem.create( self.sFaceSelectionName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
3509 faceSelectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
3511 faceSelectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshFaces )
3513 faceSelectionItem.setDepthPriority(omr.MRenderItem.sSelectionDepthPriority)
3514 faceSelectionItem.setShader(self.fFaceComponentShader)
3515 container.add(faceSelectionItem)
3520 mySelectionData = apiMeshHWSelectionUserData()
3521 mySelectionData.fMeshGeom = self.fMesh.meshGeom()
3522 faceSelectionItem.setCustomData(mySelectionData)
3525 activeVertexItem = container.find(self.sActiveVertexName)
3526 if not activeVertexItem
and anyVertexSelected:
3527 activeVertexItem = omr.MRenderItem.create( self.sActiveVertexName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
3528 activeVertexItem.setDrawMode(omr.MGeometry.kAll)
3529 activeVertexItem.setDepthPriority(omr.MRenderItem.sActivePointDepthPriority)
3530 activeVertexItem.setShader(self.fVertexComponentShader)
3531 container.add(activeVertexItem)
3534 elif activeVertexItem
and not anyVertexSelected:
3535 container.remove(self.sActiveVertexName)
3536 activeVertexItem =
None
3540 activeEdgeItem = container.find(self.sActiveEdgeName)
3541 if not activeEdgeItem
and anyEdgeSelected:
3542 activeEdgeItem = omr.MRenderItem.create( self.sActiveEdgeName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
3543 activeEdgeItem.setDrawMode(omr.MGeometry.kAll)
3544 activeEdgeItem.setDepthPriority(omr.MRenderItem.sActiveLineDepthPriority)
3545 activeEdgeItem.setShader(self.fEdgeComponentShader)
3546 container.add(activeEdgeItem)
3549 elif activeEdgeItem
and not anyEdgeSelected:
3550 container.remove(self.sActiveEdgeName)
3551 activeEdgeItem =
None
3555 activeFaceItem = container.find(self.sActiveFaceName)
3556 if not activeFaceItem
and anyFaceSelected:
3557 activeFaceItem = omr.MRenderItem.create( self.sActiveFaceName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
3558 activeFaceItem.setDrawMode(omr.MGeometry.kAll)
3559 activeFaceItem.setDepthPriority(omr.MRenderItem.sActiveLineDepthPriority)
3560 activeFaceItem.setShader(self.fFaceComponentShader)
3561 container.add(activeFaceItem)
3564 elif activeFaceItem
and not anyFaceSelected:
3565 container.remove(self.sActiveFaceName)
3566 activeFaceItem =
None
3570 lineWidth = frameContext.getGlobalLineWidth()
3571 userWidthChange =
not floatApproxEqual(lineWidth, self.fThickLineWidth)
3574 targetRefinedLineWidth = 50.0
3576 self.fThickLineWidth = lineWidth
3580 if self.fUseQueuedLineUpdate:
3581 self.fQueuedLineWidth = lineWidth
3582 if self.fQueuedLineWidth < targetRefinedLineWidth:
3583 self.fQueueUpdate =
True
3589 if self.fUseQueuedLineUpdate
and self.fQueueUpdate:
3590 if self.fQueuedLineWidth < targetRefinedLineWidth:
3591 lineWidth = self.fQueuedLineWidth
3592 self.fQueuedLineWidth += 1
3593 self.fQueueUpdate =
True
3598 self.fQueueUpdate =
False
3601 if not floatApproxEqual(lineWidth, 1.0):
3603 lineWidthArray = [ lineWidth, lineWidth ]
3604 self.fThickWireShader.setParameter(
"lineWidth", lineWidthArray)
3605 self.fThickSelectShader.setParameter(
"lineWidth", lineWidthArray)
3607 wireItem.setShader(self.fThickWireShader)
3609 selectItem.setShader(self.fThickSelectShader)
3613 wireItem.setShader(self.fWireShader)
3615 selectItem.setShader(self.fSelectShader)
3618 if itemsChanged
or updateGeometry:
3619 bounds = self.fMesh.boundingBox()
3621 wireBuffers = omr.MVertexBufferArray()
3622 wireBuffers.append(self.fPositionBuffer,
"positions")
3624 self.setGeometryForRenderItem(wireItem, wireBuffers, self.fWireIndexBuffer, bounds)
3626 self.setGeometryForRenderItem(selectItem, wireBuffers, self.fWireIndexBuffer, bounds)
3628 boxBuffers = omr.MVertexBufferArray()
3629 boxBuffers.append(self.fBoxPositionBuffer,
"positions")
3631 self.setGeometryForRenderItem(boxItem, boxBuffers, self.fBoxIndexBuffer, bounds)
3633 self.setGeometryForRenderItem(selectedBoxItem, boxBuffers, self.fBoxIndexBuffer, bounds)
3635 shadedBuffers = omr.MVertexBufferArray()
3636 shadedBuffers.append(self.fPositionBuffer,
"positions")
3637 shadedBuffers.append(self.fNormalBuffer,
"normals")
3638 self.setGeometryForRenderItem(shadedItem, shadedBuffers, self.fShadedIndexBuffer, bounds)
3639 self.setGeometryForRenderItem(texturedItem, shadedBuffers, self.fShadedIndexBuffer, bounds)
3642 self.setGeometryForRenderItem(vertexSelectionItem, wireBuffers, objectBox = bounds)
3643 self.setGeometryForRenderItem(edgeSelectionItem, wireBuffers, self.fWireIndexBuffer, bounds)
3644 self.setGeometryForRenderItem(faceSelectionItem, wireBuffers, self.fShadedIndexBuffer, bounds)
3647 if itemsChanged
or updateActiveItems:
3648 bounds = self.fMesh.boundingBox()
3650 vertexBuffer = omr.MVertexBufferArray()
3651 vertexBuffer.append(self.fPositionBuffer,
"positions")
3653 if activeVertexItem:
3654 self.setGeometryForRenderItem(activeVertexItem, vertexBuffer, self.fActiveVerticesIndexBuffer, bounds)
3656 self.setGeometryForRenderItem(activeEdgeItem, vertexBuffer, self.fActiveEdgesIndexBuffer, bounds)
3658 self.setGeometryForRenderItem(activeFaceItem, vertexBuffer, self.fActiveFacesIndexBuffer, bounds)
3661 if itemsChanged
or anyMatrixChanged:
3662 if not self.fIsInstanceMode
and numInstances == 1:
3665 objToWorld = instanceMatrixArray[0]
3668 wireItem.setMatrix(objToWorld)
3670 selectItem.setMatrix(objToWorld)
3672 boxItem.setMatrix(objToWorld)
3674 selectedBoxItem.setMatrix(objToWorld)
3675 shadedItem.setMatrix(objToWorld)
3676 texturedItem.setMatrix(objToWorld)
3678 vertexSelectionItem.setMatrix(objToWorld)
3679 edgeSelectionItem.setMatrix(objToWorld)
3680 faceSelectionItem.setMatrix(objToWorld)
3682 if useDrawInstancingOnEdgeSelectionItem:
3685 transform1 = objToWorld
3688 transform2 = objToWorld * 2
3691 transform3 = objToWorld * 3
3695 transforms = om.MMatrixArray((transform1, transform2, transform3))
3696 self.setInstanceTransformArray(edgeSelectionItem, transforms)
3701 self.removeAllInstances(edgeSelectionItem)
3705 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform1)
3706 print "newInstanceId " + str(newInstanceId)
3707 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform2)
3708 print "newInstanceId " + str(newInstanceId)
3709 newInstanceId = self.addInstanceTransform(edgeSelectionItem, transform3)
3710 print "newInstanceId " + str(newInstanceId)
3712 if activeVertexItem:
3713 activeVertexItem.setMatrix(objToWorld)
3715 activeEdgeItem.setMatrix(objToWorld)
3717 activeFaceItem.setMatrix(objToWorld)
3732 self.setInstanceTransformArray(wireItem, unselectedInstanceMatrixArray)
3734 self.setInstanceTransformArray(selectItem, selectedInstanceMatrixArray)
3736 self.setInstanceTransformArray(boxItem, unselectedInstanceMatrixArray)
3738 self.setInstanceTransformArray(selectedBoxItem, selectedInstanceMatrixArray)
3739 self.setInstanceTransformArray(shadedItem, instanceMatrixArray)
3740 self.setInstanceTransformArray(texturedItem, instanceMatrixArray)
3742 self.setInstanceTransformArray(vertexSelectionItem, instanceMatrixArray)
3743 self.setInstanceTransformArray(edgeSelectionItem, instanceMatrixArray)
3744 self.setInstanceTransformArray(faceSelectionItem, instanceMatrixArray)
3746 if activeVertexItem:
3747 self.setInstanceTransformArray(activeVertexItem, instanceMatrixArray)
3749 self.setInstanceTransformArray(activeEdgeItem, instanceMatrixArray)
3751 self.setInstanceTransformArray(activeFaceItem, instanceMatrixArray)
3756 self.fIsInstanceMode =
True
3758 if itemsChanged
or anyMatrixChanged
or updateGeometry:
3760 omr.MRenderer.setLightsAndShadowsDirty()
3762 def rebuildGeometryBuffers(self):
3764 meshGeom = self.fMesh.meshGeom()
3767 bounds = self.fMesh.boundingBox()
3770 self.clearGeometryBuffers()
3775 totalPoints = len(meshGeom.vertices)
3776 for i
in xrange(meshGeom.faceCount):
3777 numVerts = meshGeom.face_counts[i]
3779 numTriangles += numVerts - 2
3780 totalVerts += numVerts
3783 posDesc = omr.MVertexBufferDescriptor(
"", omr.MGeometry.kPosition, omr.MGeometry.kFloat, 3)
3784 normalDesc = omr.MVertexBufferDescriptor(
"", omr.MGeometry.kNormal, omr.MGeometry.kFloat, 3)
3786 self.fPositionBuffer = omr.MVertexBuffer(posDesc)
3787 self.fNormalBuffer = omr.MVertexBuffer(normalDesc)
3788 self.fBoxPositionBuffer = omr.MVertexBuffer(posDesc)
3790 positionDataAddress = self.fPositionBuffer.acquire(totalPoints,
True)
3791 normalDataAddress = self.fNormalBuffer.acquire(totalPoints,
True)
3792 boxPositionDataAddress = self.fBoxPositionBuffer.acquire(8,
True)
3795 self.fWireIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3796 self.fBoxIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3797 self.fShadedIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3799 wireBufferDataAddress = self.fWireIndexBuffer.acquire(2*totalVerts,
True)
3800 boxBufferDataAddress = self.fBoxIndexBuffer.acquire(24,
True)
3801 shadedBufferDataAddress = self.fShadedIndexBuffer.acquire(3*numTriangles,
True)
3804 if not all((positionDataAddress, normalDataAddress, boxPositionDataAddress, wireBufferDataAddress, boxBufferDataAddress, shadedBufferDataAddress)):
3805 print "At least one buffer data is not valid"
3806 self.clearGeometryBuffers()
3809 positionData = ((ctypes.c_float * 3)*totalPoints).from_address(positionDataAddress)
3810 normalData = ((ctypes.c_float * 3)*totalPoints).from_address(normalDataAddress)
3811 boxPositionData = ((ctypes.c_float * 3)*8).from_address(boxPositionDataAddress)
3813 wireBufferData = (ctypes.c_uint * (2*totalVerts)).from_address(wireBufferDataAddress)
3814 boxBufferData = (ctypes.c_uint * 24).from_address(boxBufferDataAddress)
3815 shadedBufferData = ((ctypes.c_uint * 3)*numTriangles).from_address(shadedBufferDataAddress)
3818 for vid,position
in enumerate(meshGeom.vertices):
3819 positionData[vid][0] = position[0]
3820 positionData[vid][1] = position[1]
3821 positionData[vid][2] = position[2]
3823 for vid,normal
in enumerate(meshGeom.normals):
3824 normalData[vid][0] = normal[0]
3825 normalData[vid][1] = normal[1]
3826 normalData[vid][2] = normal[2]
3828 self.fPositionBuffer.commit(positionDataAddress)
3829 positionDataAddress =
None
3830 self.fNormalBuffer.commit(normalDataAddress)
3831 normalDataAddress =
None
3836 boxPositionData[0][0] = bbmin.x
3837 boxPositionData[0][1] = bbmin.y
3838 boxPositionData[0][2] = bbmin.z
3840 boxPositionData[1][0] = bbmin.x
3841 boxPositionData[1][1] = bbmin.y
3842 boxPositionData[1][2] = bbmax.z
3844 boxPositionData[2][0] = bbmax.x
3845 boxPositionData[2][1] = bbmin.y
3846 boxPositionData[2][2] = bbmax.z
3848 boxPositionData[3][0] = bbmax.x
3849 boxPositionData[3][1] = bbmin.y
3850 boxPositionData[3][2] = bbmin.z
3852 boxPositionData[4][0] = bbmin.x
3853 boxPositionData[4][1] = bbmax.y
3854 boxPositionData[4][2] = bbmin.z
3856 boxPositionData[5][0] = bbmin.x
3857 boxPositionData[5][1] = bbmax.y
3858 boxPositionData[5][2] = bbmax.z
3860 boxPositionData[6][0] = bbmax.x
3861 boxPositionData[6][1] = bbmax.y
3862 boxPositionData[6][2] = bbmax.z
3864 boxPositionData[7][0] = bbmax.x
3865 boxPositionData[7][1] = bbmax.y
3866 boxPositionData[7][2] = bbmin.z
3868 self.fBoxPositionBuffer.commit(boxPositionDataAddress)
3869 boxPositionDataAddress =
None
3875 for i
in xrange(meshGeom.faceCount):
3877 numVerts = meshGeom.face_counts[i]
3880 for v
in xrange(numVerts-1):
3881 wireBufferData[idx] = meshGeom.face_connects[vid]
3884 wireBufferData[idx] = meshGeom.face_connects[vid]
3887 wireBufferData[idx] = meshGeom.face_connects[vid]
3890 wireBufferData[idx] = meshGeom.face_connects[first]
3896 self.fWireIndexBuffer.commit(wireBufferDataAddress)
3897 wireBufferDataAddress =
None
3900 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 ]
3901 for i
in xrange(24):
3902 boxBufferData[i] = indexData[i]
3904 self.fBoxIndexBuffer.commit(boxBufferDataAddress)
3905 boxBufferDataAddress =
None
3910 for i
in xrange(meshGeom.faceCount):
3912 numVerts = meshGeom.face_counts[i]
3914 for v
in xrange(1, numVerts-1):
3915 shadedBufferData[idx][0] = meshGeom.face_connects[base]
3916 shadedBufferData[idx][1] = meshGeom.face_connects[base+v]
3917 shadedBufferData[idx][2] = meshGeom.face_connects[base+v+1]
3922 self.fShadedIndexBuffer.commit(shadedBufferDataAddress)
3923 shadedBufferDataAddress =
None
3925 def rebuildActiveComponentIndexBuffers(self):
3927 meshGeom = self.fMesh.meshGeom()
3932 self.clearActiveComponentIndexBuffers()
3935 numActiveVertices = len(self.fActiveVerticesSet)
3936 if numActiveVertices > 0:
3937 self.fActiveVerticesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3938 activeVerticesDataAddress = self.fActiveVerticesIndexBuffer.acquire(numActiveVertices,
True)
3939 if activeVerticesDataAddress:
3940 activeVerticesData = (ctypes.c_uint*numActiveVertices).from_address(activeVerticesDataAddress)
3943 for vid
in self.fActiveVerticesSet:
3944 activeVerticesData[idx] = vid
3947 self.fActiveVerticesIndexBuffer.commit(activeVerticesDataAddress)
3948 activeVerticesDataAddress =
None
3951 numActiveEdges = len(self.fActiveEdgesSet)
3952 if numActiveEdges > 0:
3953 self.fActiveEdgesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3954 activeEdgesDataAddress = self.fActiveEdgesIndexBuffer.acquire(2*numActiveEdges,
True)
3955 if activeEdgesDataAddress:
3956 activeEdgesData = ((ctypes.c_uint * 2)*numActiveEdges).from_address(activeEdgesDataAddress)
3962 for i
in xrange(meshGeom.faceCount):
3964 numVerts = meshGeom.face_counts[i]
3967 for v
in xrange(numVerts-1):
3968 if eid
in self.fActiveEdgesSet:
3969 activeEdgesData[idx][0] = meshGeom.face_connects[vid]
3970 activeEdgesData[idx][1] = meshGeom.face_connects[vid + 1]
3975 if eid
in self.fActiveEdgesSet:
3976 activeEdgesData[idx][0] = meshGeom.face_connects[vid]
3977 activeEdgesData[idx][1] = meshGeom.face_connects[first]
3984 self.fActiveEdgesIndexBuffer.commit(activeEdgesDataAddress)
3985 activeEdgesDataAddress =
None
3988 numActiveFaces = len(self.fActiveFacesSet)
3989 if numActiveFaces > 0:
3990 numActiveFacesTriangles = 0
3991 for i
in xrange(meshGeom.faceCount):
3992 if i
in self.fActiveFacesSet:
3993 numVerts = meshGeom.face_counts[i]
3995 numActiveFacesTriangles += numVerts - 2
3997 self.fActiveFacesIndexBuffer = omr.MIndexBuffer(omr.MGeometry.kUnsignedInt32)
3998 activeFacesDataAddress = self.fActiveFacesIndexBuffer.acquire(3*numActiveFacesTriangles,
True)
3999 if activeFacesDataAddress:
4000 activeFacesData = ((ctypes.c_uint * 3)*numActiveFacesTriangles).from_address(activeFacesDataAddress)
4004 for i
in xrange(meshGeom.faceCount):
4005 numVerts = meshGeom.face_counts[i]
4007 if i
in self.fActiveFacesSet:
4008 for v
in xrange(1, numVerts-1):
4009 activeFacesData[idx][0] = meshGeom.face_connects[vid]
4010 activeFacesData[idx][1] = meshGeom.face_connects[vid+v]
4011 activeFacesData[idx][2] = meshGeom.face_connects[vid+v+1]
4016 self.fActiveFacesIndexBuffer.commit(activeFacesDataAddress)
4017 activeFacesDataAddress =
None
4019 def clearBuffers(self):
4020 self.clearGeometryBuffers()
4021 self.clearActiveComponentIndexBuffers()
4023 def clearGeometryBuffers(self):
4024 self.fPositionBuffer =
None
4025 self.fNormalBuffer =
None
4026 self.fBoxPositionBuffer =
None
4027 self.fWireIndexBuffer =
None
4028 self.fBoxIndexBuffer =
None
4029 self.fShadedIndexBuffer =
None
4031 def clearActiveComponentIndexBuffers(self):
4032 self.fActiveVerticesIndexBuffer =
None
4033 self.fActiveEdgesIndexBuffer =
None
4034 self.fActiveFacesIndexBuffer =
None
4036 def updateSelectionGranularity(self, path, selectionContext):
4047 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4048 if displayStatus == omr.MGeometryUtilities.kHilite:
4050 globalComponentMask = om.MGlobal.objectSelectionMask()
4051 if om.MGlobal.selectionMode() == om.MGlobal.kSelectComponentMode:
4052 globalComponentMask = om.MGlobal.componentSelectionMask()
4054 supportedComponentMask = om.MSelectionMask( om.MSelectionMask.kSelectMeshVerts )
4055 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshEdges )
4056 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshFaces )
4057 supportedComponentMask.addMask( om.MSelectionMask.kSelectPointsForGravity )
4059 if globalComponentMask.intersects(supportedComponentMask):
4060 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4061 elif omr.MPxSubSceneOverride.pointSnappingActive():
4062 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4074 class apiMeshUserData(om.MUserData):
4076 om.MUserData.__init__(self,
True)
4078 self.fNumModifications = 0
4081 def callbackDataPrint(context, renderItemList):
4082 for item
in renderItemList:
4084 path = item.sourceDagPath()
4085 print "\tITEM: '" + item.name() +
"' -- SOURCE: '" + path.fullPathName() +
"'"
4087 passCtx = context.getPassContext()
4088 passId = passCtx.passIdentifier()
4089 passSem = passCtx.passSemantics()
4090 print "\tAPI mesh drawing in pass[" + passId +
"], semantic[" + passSem +
"]"
4093 def apiMeshPreDrawCallback(context, renderItemList, shaderInstance):
4094 print "PRE-draw callback triggered for render item list with data:"
4095 callbackDataPrint(context, renderItemList)
4098 def apiMeshPostDrawCallback(context, renderItemList, shaderInstance):
4099 print "POST-draw callback triggered for render item list with data:"
4100 callbackDataPrint(context, renderItemList)
4104 class meshVertComponentConverter_geometryOverride(omr.MPxComponentConverter):
4106 omr.MPxComponentConverter.__init__(self)
4108 self.fComponent = om.MFnSingleIndexedComponent()
4109 self.fComponentObject = om.MObject.kNullObj
4112 def initialize(self, renderItem):
4114 self.fComponentObject = self.fComponent.create( om.MFn.kMeshVertComponent )
4120 selectionData = renderItem.customData()
4121 if isinstance(selectionData, apiMeshHWSelectionUserData):
4122 meshGeom = selectionData.fMeshGeom
4126 for i
in xrange(meshGeom.faceCount):
4127 numVerts = meshGeom.face_counts[i]
4129 numTriangles += numVerts - 2
4130 self.fVertices = [0]*(3*numTriangles)
4135 for faceIdx
in xrange(meshGeom.faceCount):
4137 numVerts = meshGeom.face_counts[faceIdx]
4139 for v
in xrange(1, numVerts-1):
4140 self.fVertices[idx] = meshGeom.face_connects[base]
4141 self.fVertices[idx+1] = meshGeom.face_connects[base+v]
4142 self.fVertices[idx+2] = meshGeom.face_connects[base+v+1]
4146 def addIntersection(self, intersection):
4149 rawIdx = intersection.index
4151 if rawIdx >= 0
and rawIdx < len(self.fVertices):
4152 idx = self.fVertices[rawIdx]
4153 self.fComponent.addElement(idx)
4155 def component(self):
4157 return self.fComponentObject
4159 def selectionMask(self):
4161 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
4162 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
4167 return meshVertComponentConverter_geometryOverride()
4171 class meshEdgeComponentConverter_geometryOverride(omr.MPxComponentConverter):
4173 omr.MPxComponentConverter.__init__(self)
4175 self.fComponent = om.MFnSingleIndexedComponent()
4176 self.fComponentObject = om.MObject.kNullObj
4179 def initialize(self, renderItem):
4181 self.fComponentObject = self.fComponent.create( om.MFn.kMeshEdgeComponent )
4193 selectionData = renderItem.customData()
4194 if isinstance(selectionData, apiMeshHWSelectionUserData):
4195 meshGeom = selectionData.fMeshGeom
4199 for i
in xrange(meshGeom.faceCount):
4200 numVerts = meshGeom.face_counts[i]
4202 totalVerts += numVerts
4203 self.fEdges = [0]*(totalVerts)
4208 for faceIdx
in xrange(meshGeom.faceCount):
4210 numVerts = meshGeom.face_counts[faceIdx]
4212 for v
in xrange(numVerts):
4213 self.fEdges[idx] = edgeId
4217 def addIntersection(self, intersection):
4220 rawIdx = intersection.index
4222 if rawIdx >= 0
and rawIdx < len(self.fEdges):
4223 idx = self.fEdges[rawIdx]
4224 self.fComponent.addElement(idx)
4226 def component(self):
4228 return self.fComponentObject
4230 def selectionMask(self):
4232 return om.MSelectionMask(om.MSelectionMask.kSelectMeshEdges)
4236 return meshEdgeComponentConverter_geometryOverride()
4240 class meshFaceComponentConverter_geometryOverride(omr.MPxComponentConverter):
4242 omr.MPxComponentConverter.__init__(self)
4244 self.fComponent = om.MFnSingleIndexedComponent()
4245 self.fComponentObject = om.MObject.kNullObj
4248 def initialize(self, renderItem):
4250 self.fComponentObject = self.fComponent.create( om.MFn.kMeshPolygonComponent )
4262 selectionData = renderItem.customData()
4263 if isinstance(selectionData, apiMeshHWSelectionUserData):
4264 meshGeom = selectionData.fMeshGeom
4268 for i
in xrange(meshGeom.faceCount):
4269 numVerts = meshGeom.face_counts[i]
4271 numTriangles += numVerts - 2
4272 self.fFaces = [0]*numTriangles
4276 for faceIdx
in xrange(meshGeom.faceCount):
4278 numVerts = meshGeom.face_counts[faceIdx]
4280 for v
in xrange(1, numVerts-1):
4281 self.fFaces[idx] = faceIdx
4284 def addIntersection(self, intersection):
4287 rawIdx = intersection.index
4289 if rawIdx >= 0
and rawIdx < len(self.fFaces):
4290 idx = self.fFaces[rawIdx]
4291 self.fComponent.addElement(idx)
4293 def component(self):
4295 return self.fComponentObject
4297 def selectionMask(self):
4299 return om.MSelectionMask(om.MSelectionMask.kSelectMeshFaces)
4303 return meshFaceComponentConverter_geometryOverride()
4305 class apiMeshGeometryOverride(omr.MPxGeometryOverride):
4307 sWireframeItemName =
"apiMeshWire"
4308 sShadedTemplateItemName =
"apiMeshShadedTemplateWire"
4309 sSelectedWireframeItemName =
"apiMeshSelectedWireFrame"
4310 sVertexItemName =
"apiMeshVertices"
4311 sEdgeSelectionItemName =
"apiMeshEdgeSelection"
4312 sFaceSelectionItemName =
"apiMeshFaceSelection"
4313 sActiveVertexItemName =
"apiMeshActiveVertices"
4314 sVertexIdItemName =
"apiMeshVertexIds"
4315 sVertexPositionItemName =
"apiMeshVertexPositions"
4316 sShadedModeFaceCenterItemName =
"apiMeshFaceCenterInShadedMode"
4317 sWireframeModeFaceCenterItemName =
"apiMeshFaceCenterInWireframeMode"
4318 sShadedProxyItemName =
"apiShadedProxy"
4319 sAffectedEdgeItemName =
"apiMeshAffectedEdges"
4320 sAffectedFaceItemName =
"apiMeshAffectedFaces"
4321 sActiveVertexStreamName =
"apiMeshSharedVertexStream"
4322 sFaceCenterStreamName =
"apiMeshFaceCenterStream"
4326 return apiMeshGeometryOverride(obj)
4328 def __init__(self, obj):
4329 omr.MPxGeometryOverride.__init__(self, obj)
4331 node = om.MFnDependencyNode(obj)
4332 self.fMesh = node.userNode()
4333 self.fMeshGeom =
None
4334 self.fColorRemapTexture =
None
4336 self.fActiveVertices = om.MIntArray()
4337 self.fActiveVerticesSet = set()
4338 self.fActiveEdgesSet = set()
4339 self.fActiveFacesSet = set()
4340 self.fCastsShadows =
False
4341 self.fReceivesShadows =
False
4347 self.fDrawSharedActiveVertices =
True
4349 self.fDrawActiveVerticesWithRamp =
False
4350 self.fLinearSampler =
None
4353 self.fDrawFaceCenters =
True
4355 if self.fDrawActiveVerticesWithRamp:
4356 self.fDrawFaceCenters =
False
4361 self.fUseCustomColors =
False
4372 self.fProxyShader = omr.MShaderManager.k3dCPVThickDashLineShader
4376 self.fInternalItems_NoShadowCast =
False
4377 self.fInternalItems_NoShadowReceive =
False
4378 self.fInternalItems_NoPostEffects =
False
4382 self.fExternalItems_NoShadowCast =
False
4383 self.fExternalItems_NoShadowReceive =
False
4384 self.fExternalItemsNonTri_NoShadowCast =
False
4385 self.fExternalItemsNonTri_NoShadowReceive =
False
4389 self.fExternalItems_NoPostEffects =
True
4390 self.fExternalItemsNonTri_NoPostEffects =
True
4394 self.fMeshGeom =
None
4396 if self.fColorRemapTexture:
4397 textureMgr = omr.MRenderer.getTextureManager()
4399 textureMgr.releaseTexture(self.fColorRemapTexture)
4400 self.fColorRemapTexture =
None
4402 if self.fLinearSampler:
4403 omr.MStateManager.releaseSamplerState(self.fLinearSampler)
4404 self.fLinearSampler =
None
4406 def supportedDrawAPIs(self):
4408 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
4413 self.fActiveVertices.clear()
4414 self.fActiveVerticesSet = set()
4415 self.fActiveEdgesSet = set()
4416 self.fActiveFacesSet = set()
4418 self.fMeshGeom = self.fMesh.meshGeom()
4420 if self.fMeshGeom
and self.fMesh.hasActiveComponents():
4421 activeComponents = self.fMesh.activeComponents()
4422 if len(activeComponents) > 0:
4423 fnComponent = om.MFnSingleIndexedComponent( activeComponents[0] )
4424 if fnComponent.elementCount > 0:
4425 activeIds = fnComponent.getElements()
4427 if fnComponent.componentType == om.MFn.kMeshVertComponent:
4428 self.fActiveVertices = activeIds
4429 self.fActiveVerticesSet = set(activeIds)
4431 elif fnComponent.componentType == om.MFn.kMeshEdgeComponent:
4432 self.fActiveEdgesSet = set(activeIds)
4434 elif fnComponent.componentType == om.MFn.kMeshPolygonComponent:
4435 self.fActiveFacesSet = set(activeIds)
4437 def updateRenderItems(self, path, list):
4441 shaderMgr = omr.MRenderer.getShaderManager()
4445 dagNode = om.MFnDagNode(path)
4446 castsShadowsPlug = dagNode.findPlug(
"castsShadows",
False)
4447 self.fCastsShadows = castsShadowsPlug.asBool()
4448 receiveShadowsPlug = dagNode.findPlug(
"receiveShadows",
False)
4449 self.fReceivesShadows = receiveShadowsPlug.asBool()
4452 self.updateDormantAndTemplateWireframeItems(path, list, shaderMgr)
4453 self.updateActiveWireframeItem(path, list, shaderMgr)
4456 self.updateDormantVerticesItem(path, list, shaderMgr)
4457 self.updateActiveVerticesItem(path, list, shaderMgr)
4460 self.updateVertexNumericItems(path, list, shaderMgr)
4463 if self.fDrawFaceCenters:
4464 self.updateWireframeModeFaceCenterItem(path, list, shaderMgr)
4465 self.updateShadedModeFaceCenterItem(path, list, shaderMgr)
4468 self.updateAffectedComponentItems(path, list, shaderMgr)
4471 self.updateSelectionComponentItems(path, list, shaderMgr)
4474 self.updateProxyShadedItem(path, list, shaderMgr)
4480 testShadedOverrides = self.fInternalItems_NoShadowCast
or self.fInternalItems_NoShadowReceive
or self.fInternalItems_NoPostEffects
4481 if testShadedOverrides:
4486 drawMode = item.drawMode()
4487 if drawMode == omr.MGeometry.kShaded
or drawMode == omr.MGeometry.kTextured:
4488 if item.name() != self.sShadedTemplateItemName:
4489 item.setCastsShadows(
not self.fInternalItems_NoShadowCast
and self.fCastsShadows )
4490 item.setReceivesShadows(
not self.fInternalItems_NoShadowReceive
and self.fReceivesShadows )
4491 item.setExcludedFromPostEffects( self.fInternalItems_NoPostEffects )
4493 def populateGeometry(self, requirements, renderItems, data):
4504 debugPopulateGeometry =
False
4505 if debugPopulateGeometry:
4506 print "> Begin populate geometry"
4509 activeVertexCount = len(self.fActiveVertices)
4514 for i
in xrange(self.fMeshGeom.faceCount):
4515 numVerts = self.fMeshGeom.face_counts[i]
4517 numTriangles += numVerts - 2
4518 totalVerts += numVerts
4521 self.updateGeometryRequirements(requirements, data, activeVertexCount, totalVerts, debugPopulateGeometry)
4524 wireIndexBuffer =
None
4526 for item
in renderItems:
4535 itemBuffers = item.requiredVertexBuffers()
4536 for desc
in itemBuffers:
4537 print "Buffer Required for Item '" + item.name() +
"':"
4538 print "\tBufferName: " + desc.name
4539 print "\tDataType: " + omr.MGeometry.dataTypeString(desc.dataType) +
" (dimension " + str(desc.dimension) +
")"
4540 print "\tSemantic: " + omr.MGeometry.semanticString(desc.semantic)
4545 myCustomData = item.customData()
4546 if isinstance(myCustomData, apiMeshUserData):
4547 print "Custom data '" + myCustomData.fMessage +
"', modified count='" + str(myCustomData.fNumModifications) +
"'"
4549 print "No custom data"
4553 if item.name() == self.sActiveVertexItemName:
4554 self.updateIndexingForVertices( item, data, numTriangles, activeVertexCount, debugPopulateGeometry)
4558 if self.fDrawFaceCenters
and (item.name() == self.sShadedModeFaceCenterItemName
or item.name() == self.sWireframeModeFaceCenterItemName):
4559 self.updateIndexingForFaceCenters( item, data, debugPopulateGeometry)
4563 elif item.name() == self.sVertexItemName
or item.name() == self.sVertexIdItemName
or item.name() == self.sVertexPositionItemName:
4564 self.updateIndexingForDormantVertices( item, data, numTriangles )
4568 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):
4569 self.updateIndexingForWireframeItems(wireIndexBuffer, item, data, totalVerts)
4575 elif item.name() == self.sAffectedEdgeItemName:
4576 self.updateIndexingForEdges(item, data, totalVerts,
True)
4577 elif item.name() == self.sEdgeSelectionItemName:
4578 self.updateIndexingForEdges(item, data, totalVerts,
False)
4584 elif item.name() == self.sAffectedFaceItemName:
4585 self.updateIndexingForFaces(item, data, numTriangles,
True)
4586 elif item.name() == self.sFaceSelectionItemName:
4587 self.updateIndexingForFaces(item, data, numTriangles,
False)
4591 elif item.primitive() == omr.MGeometry.kTriangles:
4592 self.updateIndexingForShadedTriangles(item, data, numTriangles)
4594 if debugPopulateGeometry:
4595 print "> End populate geometry"
4598 self.fMeshGeom =
None
4599 self.fActiveVertices.clear()
4600 self.fActiveVerticesSet = set()
4601 self.fActiveEdgesSet = set()
4602 self.fActiveFacesSet = set()
4604 def updateSelectionGranularity(self, path, selectionContext):
4616 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4617 if displayStatus == omr.MGeometryUtilities.kHilite:
4619 globalComponentMask = om.MGlobal.objectSelectionMask()
4620 if om.MGlobal.selectionMode() == om.MGlobal.kSelectComponentMode:
4621 globalComponentMask = om.MGlobal.componentSelectionMask()
4623 supportedComponentMask = om.MSelectionMask( om.MSelectionMask.kSelectMeshVerts )
4624 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshEdges )
4625 supportedComponentMask.addMask( om.MSelectionMask.kSelectMeshFaces )
4626 supportedComponentMask.addMask( om.MSelectionMask.kSelectPointsForGravity )
4628 if globalComponentMask.intersects(supportedComponentMask):
4629 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4630 elif omr.MPxGeometryOverride.pointSnappingActive():
4631 selectionContext.selectionLevel = omr.MSelectionContext.kComponent
4633 def printShader(self, shader):
4638 params = shader.parameterList()
4639 print "DEBUGGING SHADER, BEGIN PARAM LIST OF LENGTH " + str(len(params))
4641 for param
in params:
4642 paramType = shader.parameterType(param)
4643 isArray = shader.isArrayParameter(param)
4645 typeAsStr =
"Unknown"
4646 if paramType == omr.MShaderInstance.kInvalid:
4647 typeAsStr =
"Invalid"
4648 elif paramType == omr.MShaderInstance.kBoolean:
4649 typeAsStr =
"Boolean"
4650 elif paramType == omr.MShaderInstance.kInteger:
4651 typeAsStr =
"Integer"
4652 elif paramType == omr.MShaderInstance.kFloat:
4654 elif paramType == omr.MShaderInstance.kFloat2:
4655 typeAsStr =
"Float2"
4656 elif paramType == omr.MShaderInstance.kFloat3:
4657 typeAsStr =
"Float3"
4658 elif paramType == omr.MShaderInstance.kFloat4:
4659 typeAsStr =
"Float4"
4660 elif paramType == omr.MShaderInstance.kFloat4x4Row:
4661 typeAsStr =
"Float4x4Row"
4662 elif paramType == omr.MShaderInstance.kFloat4x4Col:
4663 typeAsStr =
"Float4x4Col"
4664 elif paramType == omr.MShaderInstance.kTexture1:
4665 typeAsStr =
"1D Texture"
4666 elif paramType == omr.MShaderInstance.kTexture2:
4667 typeAsStr =
"2D Texture"
4668 elif paramType == omr.MShaderInstance.kTexture3:
4669 typeAsStr =
"3D Texture"
4670 elif paramType == omr.MShaderInstance.kTextureCube:
4671 typeAsStr =
"Cube Texture"
4672 elif paramType == omr.MShaderInstance.kSampler:
4673 typeAsStr =
"Sampler"
4675 print "ParamName='" + param +
"', ParamType='" + typeAsStr +
"', IsArrayParameter:'" + str(isArray) +
"'"
4677 print "END PARAM LIST"
4679 def setSolidColor(self, shaderInstance, defaultColor, customColor=None):
4682 color = defaultColor
4683 if self.fUseCustomColors
and customColor:
4686 shaderInstance.setParameter(
"solidColor", color)
4690 def setSolidPointSize(self, shaderInstance, size):
4694 shaderInstance.setParameter(
"pointSize", [size, size])
4698 def setLineWidth(self, shaderInstance, width):
4702 shaderInstance.setParameter(
"lineWidth", [width, width])
4706 def enableActiveComponentDisplay(self, path):
4718 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4719 if displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
4725 if path.isTemplated():
4731 def updateDormantAndTemplateWireframeItems(self, path, list, shaderMgr):
4743 dormantColor = [ 0.0, 0.0, 1.0, 1.0 ]
4744 templateColor = [ 0.45, 0.45, 0.45, 1.0 ]
4745 activeTemplateColor = [ 1.0, 0.5, 0.5, 1.0 ]
4754 wireframeItem =
None
4755 index = list.indexOf(self.sWireframeItemName)
4757 wireframeItem = omr.MRenderItem.create( self.sWireframeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
4758 wireframeItem.setDrawMode(omr.MGeometry.kWireframe)
4762 wireframeItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
4764 list.append(wireframeItem)
4769 preCb = apiMeshPreDrawCallback
4770 postCb = apiMeshPostDrawCallback
4772 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader, preCb, postCb)
4775 wireframeItem.setShader(shader)
4779 self.printShader( shader )
4782 shaderMgr.releaseShader(shader)
4784 wireframeItem = list[index]
4788 shadedTemplateItem =
None
4789 index = list.indexOf(self.sShadedTemplateItemName)
4791 shadedTemplateItem = omr.MRenderItem.create( self.sShadedTemplateItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
4792 shadedTemplateItem.setDrawMode(omr.MGeometry.kAll)
4796 shadedTemplateItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
4798 list.append(shadedTemplateItem)
4800 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
4803 shadedTemplateItem.setShader(shader)
4807 self.printShader( shader )
4810 shaderMgr.releaseShader(shader)
4812 shadedTemplateItem = list[index]
4815 shadedTemplateItem.setCastsShadows(
not self.fExternalItemsNonTri_NoShadowCast )
4816 shadedTemplateItem.setReceivesShadows(
not self.fExternalItemsNonTri_NoShadowReceive )
4817 shadedTemplateItem.setExcludedFromPostEffects( self.fExternalItemsNonTri_NoPostEffects )
4819 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4820 wireColor = omr.MGeometryUtilities.wireframeColor(path)
4825 shader = wireframeItem.getShader()
4827 if displayStatus == omr.MGeometryUtilities.kTemplate:
4828 self.setSolidColor( shader, wireColor, templateColor)
4829 wireframeItem.enable(
True)
4831 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
4832 self.setSolidColor( shader, wireColor, activeTemplateColor)
4833 wireframeItem.enable(
True)
4835 elif displayStatus == omr.MGeometryUtilities.kDormant:
4836 self.setSolidColor( shader, wireColor, dormantColor)
4837 wireframeItem.enable(
True)
4839 elif displayStatus == omr.MGeometryUtilities.kActiveAffected:
4840 theColor = [ 0.5, 0.0, 1.0, 1.0 ]
4841 self.setSolidColor( shader, wireColor, theColor)
4842 wireframeItem.enable(
True)
4845 wireframeItem.enable(
False)
4849 if shadedTemplateItem:
4850 isTemplate = path.isTemplated()
4851 shader = shadedTemplateItem.getShader()
4853 if displayStatus == omr.MGeometryUtilities.kTemplate:
4854 self.setSolidColor( shader, wireColor, templateColor)
4855 shadedTemplateItem.enable(isTemplate)
4857 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
4858 self.setSolidColor( shader, wireColor, activeTemplateColor)
4859 shadedTemplateItem.enable(isTemplate)
4861 elif displayStatus == omr.MGeometryUtilities.kDormant:
4862 self.setSolidColor( shader, wireColor, dormantColor)
4863 shadedTemplateItem.enable(isTemplate)
4866 shadedTemplateItem.enable(
False)
4868 def updateActiveWireframeItem(self, path, list, shaderMgr):
4873 index = list.indexOf(self.sSelectedWireframeItemName)
4875 selectItem = omr.MRenderItem.create(self.sSelectedWireframeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
4876 selectItem.setDrawMode(omr.MGeometry.kAll)
4881 selectItem.setDepthPriority( omr.MRenderItem.sActiveWireDepthPriority )
4882 list.append(selectItem)
4887 shaderId = omr.MShaderManager.k3dSolidShader
4889 shaderId = omr.MShaderManager.k3dThickLineShader
4891 shader = shaderMgr.getStockShader(shaderId)
4894 selectItem.setShader(shader)
4896 shaderMgr.releaseShader(shader)
4898 selectItem = list[index]
4902 shader = selectItem.getShader()
4904 displayStatus = omr.MGeometryUtilities.displayStatus(path)
4905 wireColor = omr.MGeometryUtilities.wireframeColor(path)
4907 if displayStatus == omr.MGeometryUtilities.kLead:
4908 theColor = [ 0.0, 0.8, 0.0, 1.0 ]
4909 self.setSolidColor( shader, wireColor, theColor)
4910 selectItem.enable(
True)
4912 elif displayStatus == omr.MGeometryUtilities.kActive:
4913 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
4914 self.setSolidColor( shader, wireColor, theColor)
4915 selectItem.enable(
True)
4917 elif displayStatus == omr.MGeometryUtilities.kHilite
or displayStatus == omr.MGeometryUtilities.kActiveComponent:
4918 theColor = [ 0.0, 0.5, 0.7, 1.0 ]
4919 self.setSolidColor( shader, wireColor, theColor)
4920 selectItem.enable(
True)
4923 selectItem.enable(
False)
4926 myCustomData = selectItem.customData()
4927 if not myCustomData:
4929 myCustomData = apiMeshUserData()
4930 myCustomData.fMessage =
"I'm custom data!"
4931 selectItem.setCustomData(myCustomData)
4934 myCustomData.fNumModifications += 1
4936 def updateWireframeModeFaceCenterItem(self, path, list, shaderMgr):
4940 wireframeModeFaceCenterItem =
None
4941 index = list.indexOf(self.sWireframeModeFaceCenterItemName)
4943 wireframeModeFaceCenterItem = omr.MRenderItem.create(self.sWireframeModeFaceCenterItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
4944 wireframeModeFaceCenterItem.setDrawMode(omr.MGeometry.kWireframe)
4945 wireframeModeFaceCenterItem.setDepthPriority( omr.MRenderItem.sActiveWireDepthPriority )
4947 list.append(wireframeModeFaceCenterItem)
4949 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
4953 self.setSolidPointSize( shader, pointSize )
4955 wireframeModeFaceCenterItem.setShader(shader, self.sFaceCenterStreamName )
4958 shaderMgr.releaseShader(shader)
4960 wireframeModeFaceCenterItem = list[index]
4962 if wireframeModeFaceCenterItem:
4963 shader = wireframeModeFaceCenterItem.getShader()
4966 theColor = [ 0.0, 0.0, 1.0, 1.0 ]
4967 self.setSolidColor( shader, theColor )
4970 isTemplate = path.isTemplated()
4971 wireframeModeFaceCenterItem.enable(
not isTemplate )
4973 def updateShadedModeFaceCenterItem(self, path, list, shaderMgr):
4977 shadedModeFaceCenterItem =
None
4978 index = list.indexOf(self.sShadedModeFaceCenterItemName)
4980 shadedModeFaceCenterItem = omr.MRenderItem.create( self.sShadedModeFaceCenterItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
4981 shadedModeFaceCenterItem.setDrawMode(omr.MGeometry.kShaded | omr.MGeometry.kTextured)
4983 shadedModeFaceCenterItem.setDepthPriority(omr.MRenderItem.sActivePointDepthPriority)
4985 list.append(shadedModeFaceCenterItem)
4987 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
4991 self.setSolidPointSize( shader, pointSize )
4993 shadedModeFaceCenterItem.setShader(shader, self.sFaceCenterStreamName )
4996 shaderMgr.releaseShader(shader)
4998 shadedModeFaceCenterItem = list[index]
5000 if shadedModeFaceCenterItem:
5001 shadedModeFaceCenterItem.setExcludedFromPostEffects(
True)
5003 shader = shadedModeFaceCenterItem.getShader()
5004 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5008 self.setSolidColor( shader, wireColor )
5010 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5011 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:
5012 shadedModeFaceCenterItem.enable(
True)
5015 shadedModeFaceCenterItem.enable(
False)
5017 def updateDormantVerticesItem(self, path, list, shaderMgr):
5022 index = list.indexOf(self.sVertexItemName)
5024 vertexItem = omr.MRenderItem.create(self.sVertexItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5027 vertexItem.setDrawMode(omr.MGeometry.kAll)
5030 mask = om.MSelectionMask(om.MSelectionMask.kSelectMeshVerts)
5031 mask.addMask(om.MSelectionMask.kSelectPointsForGravity)
5032 vertexItem.setSelectionMask( mask )
5037 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5038 list.append(vertexItem)
5040 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFatPointShader )
5044 self.setSolidPointSize( shader, pointSize )
5047 vertexItem.setShader(shader)
5050 shaderMgr.releaseShader(shader)
5052 vertexItem = list[index]
5055 shader = vertexItem.getShader()
5057 theColor = [ 0.0, 0.0, 1.0, 1.0 ]
5058 self.setSolidColor( shader, theColor )
5060 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5064 if displayStatus == omr.MGeometryUtilities.kHilite
or omr.MPxGeometryOverride.pointSnappingActive():
5068 if path.isTemplated():
5069 vertexItem.enable(
False)
5071 vertexItem.enable(
True)
5073 vertexItem.enable(
False)
5075 mySelectionData = vertexItem.customData()
5076 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5078 mySelectionData = apiMeshHWSelectionUserData()
5079 vertexItem.setCustomData(mySelectionData)
5081 mySelectionData.fMeshGeom = self.fMeshGeom
5083 def updateActiveVerticesItem(self, path, list, shaderMgr):
5088 index = list.indexOf(self.sActiveVertexItemName)
5090 activeItem = omr.MRenderItem.create(self.sActiveVertexItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5091 activeItem.setDrawMode(omr.MGeometry.kAll)
5094 activeItem.setDepthPriority( omr.MRenderItem.sActivePointDepthPriority )
5095 list.append(activeItem)
5097 shaderId = omr.MShaderManager.k3dFatPointShader
5098 if self.fDrawActiveVerticesWithRamp:
5099 shaderId = omr.MShaderManager.k3dColorLookupFatPointShader
5101 shader = shaderMgr.getStockShader( shaderId )
5105 self.setSolidPointSize( shader, pointSize )
5109 if self.fDrawActiveVerticesWithRamp:
5110 textureMgr = omr.MRenderer.getTextureManager()
5113 if not self.fColorRemapTexture:
5115 colorArray = [ 1.0, 0.0, 0.0, 1.0,
5117 0.0, 0.0, 1.0, 1.0 ]
5120 textureDesc = omr.MTextureDescription()
5121 textureDesc.setToDefault2DTexture()
5122 textureDesc.fWidth = arrayLen
5123 textureDesc.fHeight = 1
5124 textureDesc.fDepth = 1
5125 textureDesc.fBytesPerSlice = textureDesc.fBytesPerRow = 24*arrayLen
5126 textureDesc.fMipmaps = 1
5127 textureDesc.fArraySlices = 1
5128 textureDesc.fTextureType = omr.MRenderer.kImage1D
5129 textureDesc.fFormat = omr.MRenderer.kR32G32B32A32_FLOAT
5130 self.fColorRemapTexture = textureMgr.acquireTexture(
"", textureDesc, colorArray,
False)
5132 if not self.fLinearSampler:
5133 samplerDesc = omr.MSamplerStateDesc()
5134 samplerDesc.addressU = omr.MSamplerState.kTexClamp
5135 samplerDesc.addressV = omr.MSamplerState.kTexClamp
5136 samplerDesc.addressW = omr.MSamplerState.kTexClamp
5137 samplerDesc.filter = omr.MSamplerState.kMinMagMipLinear
5138 fLinearSampler = omr.MStateManager.acquireSamplerState(samplerDesc)
5140 if self.fColorRemapTexture
and self.fLinearSampler:
5142 shader.setParameter(
"map", self.fColorRemapTexture)
5143 shader.setParameter(
"samp", self.fLinearSampler)
5147 rampValueRange = om.MFloatVector(0.0, 1.0)
5148 shader.setParameter(
"UVRange", rampValueRange)
5152 if self.fDrawSharedActiveVertices:
5153 activeItem.setShader(shader, self.sActiveVertexStreamName)
5155 activeItem.setShader(shader,
None)
5158 shaderMgr.releaseShader(shader)
5161 activeItem = list[index]
5164 shader = activeItem.getShader()
5167 theColor = [ 1.0, 1.0, 0.0, 1.0 ]
5168 self.setSolidColor( shader, theColor )
5170 enable = (bool(self.fActiveVerticesSet)
and self.enableActiveComponentDisplay(path))
5171 activeItem.enable( enable )
5173 def updateVertexNumericItems(self, path, list, shaderMgr):
5177 enableNumericDisplay =
False
5182 index = list.indexOf(self.sVertexIdItemName)
5184 vertexItem = omr.MRenderItem.create( self.sVertexIdItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5185 vertexItem.setDrawMode(omr.MGeometry.kAll)
5186 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5187 list.append(vertexItem)
5190 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dIntegerNumericShader )
5193 vertexItem.setShader(shader, self.sVertexIdItemName)
5194 shaderMgr.releaseShader(shader)
5196 vertexItem = list[index]
5199 shader = vertexItem.getShader()
5202 theColor = [ 1.0, 1.0, 0.0, 1.0 ]
5203 self.setSolidColor( shader, theColor )
5205 vertexItem.enable(enableNumericDisplay)
5210 index = list.indexOf(self.sVertexPositionItemName)
5212 vertexItem = omr.MRenderItem.create( self.sVertexPositionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kPoints)
5213 vertexItem.setDrawMode(omr.MGeometry.kAll)
5214 vertexItem.setDepthPriority( omr.MRenderItem.sDormantPointDepthPriority )
5215 list.append(vertexItem)
5218 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dFloat3NumericShader )
5221 vertexItem.setShader(shader, self.sVertexPositionItemName)
5222 shaderMgr.releaseShader(shader)
5224 vertexItem = list[index]
5227 shader = vertexItem.getShader()
5230 theColor = [ 0.0, 1.0, 1.0, 1.0 ]
5231 self.setSolidColor( shader, theColor)
5233 vertexItem.enable(enableNumericDisplay)
5235 def updateAffectedComponentItems(self, path, list, shaderMgr):
5242 componentItem =
None
5243 index = list.indexOf(self.sAffectedEdgeItemName)
5245 componentItem = omr.MRenderItem.create( self.sAffectedEdgeItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5246 componentItem.setDrawMode(omr.MGeometry.kAll)
5250 componentItem.setDepthPriority( omr.MRenderItem.sActiveLineDepthPriority )
5251 list.append(componentItem)
5253 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dThickLineShader )
5257 self.setLineWidth( shader, lineSize )
5260 componentItem.setShader(shader,
None)
5263 shaderMgr.releaseShader(shader)
5265 componentItem = list[index]
5268 shader = componentItem.getShader()
5271 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5272 self.setSolidColor( shader, theColor )
5274 enable = ((bool(self.fActiveVerticesSet)
or bool(self.fActiveEdgesSet))
and self.enableActiveComponentDisplay(path))
5275 componentItem.enable( enable )
5281 componentItem =
None
5282 index = list.indexOf(self.sAffectedFaceItemName)
5284 componentItem = omr.MRenderItem.create( self.sAffectedFaceItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
5285 componentItem.setDrawMode(omr.MGeometry.kAll)
5288 componentItem.setDepthPriority( omr.MRenderItem.sDormantWireDepthPriority )
5289 list.append(componentItem)
5291 shader = shaderMgr.getStockShader( omr.MShaderManager.k3dStippleShader )
5294 componentItem.setShader(shader,
None)
5297 shaderMgr.releaseShader(shader)
5299 componentItem = list[index]
5302 shader = componentItem.getShader()
5305 theColor = [ 1.0, 1.0, 1.0, 1.0 ]
5306 self.setSolidColor( shader, theColor )
5308 enable = ((bool(self.fActiveVerticesSet)
or bool(self.fActiveFacesSet))
and self.enableActiveComponentDisplay(path))
5309 componentItem.enable( enable )
5311 def updateSelectionComponentItems(self, path, list, shaderMgr):
5326 selectionItem =
None
5327 index = list.indexOf(self.sEdgeSelectionItemName)
5329 selectionItem = omr.MRenderItem.create( self.sEdgeSelectionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kLines)
5332 selectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
5335 selectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshEdges )
5338 selectionItem.setDepthPriority( omr.MRenderItem.sSelectionDepthPriority )
5339 list.append(selectionItem)
5341 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dThickLineShader)
5344 selectionItem.setShader(shader,
None)
5347 shaderMgr.releaseShader(shader)
5349 selectionItem = list[index]
5352 selectionItem.enable(
True)
5354 mySelectionData = selectionItem.customData()
5355 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5357 mySelectionData = apiMeshHWSelectionUserData()
5358 selectionItem.setCustomData(mySelectionData)
5360 mySelectionData.fMeshGeom = self.fMeshGeom
5364 index = list.indexOf(self.sFaceSelectionItemName)
5366 selectionItem = omr.MRenderItem.create( self.sFaceSelectionItemName, omr.MRenderItem.DecorationItem, omr.MGeometry.kTriangles)
5369 selectionItem.setDrawMode(omr.MGeometry.kSelectionOnly)
5372 selectionItem.setSelectionMask( om.MSelectionMask.kSelectMeshFaces )
5375 selectionItem.setDepthPriority( omr.MRenderItem.sSelectionDepthPriority )
5376 list.append(selectionItem)
5378 shader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
5381 selectionItem.setShader(shader,
None)
5384 shaderMgr.releaseShader(shader)
5386 selectionItem = list[index]
5389 selectionItem.enable(
True)
5391 mySelectionData = selectionItem.customData()
5392 if not isinstance(mySelectionData, apiMeshHWSelectionUserData):
5394 mySelectionData = apiMeshHWSelectionUserData()
5395 selectionItem.setCustomData(mySelectionData)
5397 mySelectionData.fMeshGeom = self.fMeshGeom
5399 def updateProxyShadedItem(self, path, list, shaderMgr):
5404 dormantColor = [ 0.0, 0.0, 1.0, 1.0 ]
5405 templateColor = [ 0.45, 0.45, 0.45, 1.0 ]
5406 activeTemplateColor = [ 1.0, 0.5, 0.5, 1.0 ]
5413 raiseAboveShaded =
True
5414 shadedDrawMode = omr.MGeometry.kShaded | omr.MGeometry.kTextured
5417 useFragmentShader = self.fProxyShader < 0
5418 if not useFragmentShader:
5419 shadedDrawMode |= omr.MGeometry.kWireframe
5424 itemType = omr.MRenderItem.NonMaterialSceneItem
5425 primitive = omr.MGeometry.kLines
5426 filledProxy = useFragmentShader
or self.fProxyShader == omr.MShaderManager.k3dStippleShader
5428 itemType = omr.MRenderItem.MaterialSceneItem
5429 primitive = omr.MGeometry.kTriangles
5431 depthPriority = omr.MRenderItem.sDormantWireDepthPriority
5432 if raiseAboveShaded:
5433 depthPriority = omr.MRenderItem.sActiveWireDepthPriority
5436 index = list.indexOf(self.sShadedProxyItemName)
5438 proxyItem = omr.MRenderItem.create( self.sShadedProxyItemName, itemType, primitive)
5439 proxyItem.setDrawMode(shadedDrawMode)
5440 proxyItem.setDepthPriority( depthPriority )
5442 proxyItem.setCastsShadows(
not self.fExternalItems_NoShadowCast
and self.fCastsShadows )
5443 proxyItem.setReceivesShadows(
not self.fExternalItems_NoShadowReceive
and self.fReceivesShadows )
5444 proxyItem.setExcludedFromPostEffects( self.fExternalItems_NoPostEffects )
5446 list.append(proxyItem)
5451 if useFragmentShader:
5452 shader = shaderMgr.getFragmentShader(
"mayaLambertSurface",
"outSurfaceFinal",
True)
5453 sBlue = [ 0.4, 0.4, 1.0 ]
5454 shader.setParameter(
"color", sBlue)
5455 shader.setIsTransparent(
False)
5457 shader = shaderMgr.getStockShader( self.fProxyShader )
5461 self.setLineWidth(shader, 10.0)
5464 proxyItem.setShader(shader)
5466 shaderMgr.releaseShader(shader)
5468 proxyItem = list[index]
5475 proxyItem.setCastsShadows(
not self.fExternalItems_NoShadowCast
and self.fCastsShadows )
5476 proxyItem.setReceivesShadows(
not self.fExternalItems_NoShadowReceive
and self.fReceivesShadows )
5477 proxyItem.setExcludedFromPostEffects( self.fExternalItems_NoPostEffects )
5482 haveShadedItems =
False
5486 drawMode = item.drawMode()
5487 if drawMode == omr.MGeometry.kShaded
or drawMode == omr.MGeometry.kTextured:
5488 if item.name() != self.sShadedTemplateItemName:
5489 haveShadedItems =
True
5492 displayStatus = omr.MGeometryUtilities.displayStatus(path)
5493 wireColor = omr.MGeometryUtilities.wireframeColor(path)
5500 shader = proxyItem.getShader()
5502 if displayStatus == omr.MGeometryUtilities.kTemplate:
5503 self.setSolidColor( shader, wireColor, templateColor )
5505 elif displayStatus == omr.MGeometryUtilities.kActiveTemplate:
5506 self.setSolidColor( shader, wireColor, activeTemplateColor )
5508 elif displayStatus == omr.MGeometryUtilities.kDormant:
5509 self.setSolidColor( shader, wireColor, dormantColor )
5516 if path.isTemplated():
5517 proxyItem.enable(
False)
5519 proxyItem.enable(
not haveShadedItems)
5521 proxyItem.enable(
not haveShadedItems)
5524 def updateGeometryRequirements(self, requirements, data, activeVertexCount, totalVerts, debugPopulateGeometry):
5530 positionBuffer =
None
5531 positionDataAddress =
None
5534 vertexNumericIdBuffer =
None
5535 vertexNumericIdDataAddress =
None
5536 vertexNumericIdData =
None
5538 vertexNumericIdPositionBuffer =
None
5539 vertexNumericIdPositionDataAddress =
None
5540 vertexNumericIdPositionData =
None
5542 vertexNumericLocationBuffer =
None
5543 vertexNumericLocationDataAddress =
None
5544 vertexNumericLocationData =
None
5546 vertexNumericLocationPositionBuffer =
None
5547 vertexNumericLocationPositionDataAddress =
None
5548 vertexNumericLocationPositionData =
None
5550 activeVertexPositionBuffer =
None
5551 activeVertexPositionDataAddress =
None
5552 activeVertexPositionData =
None
5554 activeVertexUVBuffer =
None
5555 activeVertexUVDataAddress =
None
5556 activeVertexUVData =
None
5558 faceCenterPositionBuffer =
None
5559 faceCenterPositionDataAddress =
None
5560 faceCenterPositionData =
None
5563 normalDataAddress =
None
5567 cpvDataAddress =
None
5571 uvDataAddress =
None
5574 numUVs = self.fMeshGeom.uvcoords.uvcount()
5576 descList = requirements.vertexRequirements()
5577 satisfiedRequirements = [
False,] * len(descList)
5578 for i
in xrange(len(descList)):
5582 if self.fDrawSharedActiveVertices
and (desc.name == self.sActiveVertexStreamName):
5583 if desc.semantic == omr.MGeometry.kPosition:
5584 if not activeVertexPositionBuffer:
5585 activeVertexPositionBuffer = data.createVertexBuffer(desc)
5586 if activeVertexPositionBuffer:
5587 satisfiedRequirements[i] =
True
5588 if debugPopulateGeometry:
5589 print ">>> Fill in data for active vertex requirement '" + desc.name +
"'. Semantic = kPosition"
5590 activeVertexPositionDataAddress = activeVertexPositionBuffer.acquire(activeVertexCount,
True)
5591 if activeVertexPositionDataAddress:
5592 activeVertexPositionData = ((ctypes.c_float * 3)*activeVertexCount).from_address(activeVertexPositionDataAddress)
5594 elif desc.semantic == omr.MGeometry.kTexture:
5595 if not activeVertexUVBuffer:
5596 activeVertexUVBuffer = data.createVertexBuffer(desc)
5597 if activeVertexUVBuffer:
5598 satisfiedRequirements[i] =
True
5599 if debugPopulateGeometry:
5600 print ">>> Fill in data for active vertex requirement '" + desc.name +
"'. Semantic = kTexture"
5601 activeVertexUVDataAddress = activeVertexUVBuffer.acquire(activeVertexCount,
True)
5602 if activeVertexUVDataAddress:
5603 activeVertexUVData = ((ctypes.c_float * 3)*activeVertexCount).from_address(activeVertexUVDataAddress)
5610 elif self.fDrawFaceCenters
and desc.name == self.sFaceCenterStreamName:
5611 if desc.semantic == omr.MGeometry.kPosition:
5612 if not faceCenterPositionBuffer:
5613 faceCenterPositionBuffer = data.createVertexBuffer(desc)
5614 if faceCenterPositionBuffer:
5615 satisfiedRequirements[i] =
True
5616 if debugPopulateGeometry:
5617 print ">>> Fill in data for face center vertex requirement '" + desc.name +
"'. Semantic = kPosition"
5618 faceCenterPositionDataAddress = faceCenterPositionBuffer.acquire(self.fMeshGeom.faceCount,
True)
5619 if faceCenterPositionDataAddress:
5620 faceCenterPositionData = ((ctypes.c_float * 3)*self.fMeshGeom.faceCount).from_address(faceCenterPositionDataAddress)
5629 if desc.semantic == omr.MGeometry.kPosition:
5630 if desc.name == self.sVertexIdItemName:
5631 if not vertexNumericIdPositionBuffer:
5632 vertexNumericIdPositionBuffer = data.createVertexBuffer(desc)
5633 if vertexNumericIdPositionBuffer:
5634 satisfiedRequirements[i] =
True
5635 if debugPopulateGeometry:
5636 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition"
5637 print "Acquire 3loat-numeric position buffer"
5638 vertexNumericIdPositionDataAddress = vertexNumericIdPositionBuffer.acquire(totalVerts,
True)
5639 if vertexNumericIdPositionDataAddress:
5640 vertexNumericIdPositionData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericIdPositionDataAddress)
5642 elif desc.name == self.sVertexPositionItemName:
5643 if not vertexNumericLocationPositionBuffer:
5644 vertexNumericLocationPositionBuffer = data.createVertexBuffer(desc)
5645 if vertexNumericLocationPositionBuffer:
5646 satisfiedRequirements[i] =
True
5647 if debugPopulateGeometry:
5648 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition"
5649 print "Acquire 3loat-numeric position buffer"
5650 vertexNumericLocationPositionDataAddress = vertexNumericLocationPositionBuffer.acquire(totalVerts,
True)
5651 if vertexNumericLocationPositionDataAddress:
5652 vertexNumericLocationPositionData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericLocationPositionDataAddress)
5655 if not positionBuffer:
5656 positionBuffer = data.createVertexBuffer(desc)
5658 satisfiedRequirements[i] =
True
5659 if debugPopulateGeometry:
5660 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kPosition"
5661 print "Acquire unnamed position buffer"
5662 positionDataAddress = positionBuffer.acquire(totalVerts,
True)
5663 if positionDataAddress:
5664 positionData = ((ctypes.c_float * 3)*totalVerts).from_address(positionDataAddress)
5666 elif desc.semantic == omr.MGeometry.kNormal:
5667 if not normalBuffer:
5668 normalBuffer = data.createVertexBuffer(desc)
5670 satisfiedRequirements[i] =
True
5671 if debugPopulateGeometry:
5672 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kNormal"
5673 normalDataAddress = normalBuffer.acquire(totalVerts,
True)
5674 if normalDataAddress:
5675 normalData = ((ctypes.c_float * 3)*totalVerts).from_address(normalDataAddress)
5677 elif desc.semantic == omr.MGeometry.kTexture:
5678 numericValue =
"numericvalue"
5679 numeric3Value =
"numeric3value"
5682 if desc.semanticName.lower() == numericValue
and desc.name == self.sVertexIdItemName:
5683 if not vertexNumericIdBuffer:
5684 vertexNumericIdBuffer = data.createVertexBuffer(desc)
5685 if vertexNumericIdBuffer:
5686 satisfiedRequirements[i] =
True
5687 if debugPopulateGeometry:
5688 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture"
5689 print "Acquire 1loat numeric buffer"
5690 vertexNumericIdDataAddress = vertexNumericIdBuffer.acquire(totalVerts,
True)
5691 if vertexNumericIdDataAddress:
5692 vertexNumericIdData = ((ctypes.c_float * 1)*totalVerts).from_address(vertexNumericIdDataAddress)
5695 elif desc.semanticName.lower() == numeric3Value
and desc.name == self.sVertexPositionItemName:
5696 if not vertexNumericLocationBuffer:
5697 vertexNumericLocationBuffer = data.createVertexBuffer(desc)
5698 if vertexNumericLocationBuffer:
5699 satisfiedRequirements[i] =
True
5700 if debugPopulateGeometry:
5701 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture"
5702 print "Acquire 3loat numeric location buffer"
5703 vertexNumericLocationDataAddress = vertexNumericLocationBuffer.acquire(totalVerts,
True)
5704 if vertexNumericLocationDataAddress:
5705 vertexNumericLocationData = ((ctypes.c_float * 3)*totalVerts).from_address(vertexNumericLocationDataAddress)
5708 elif desc.name != self.sVertexIdItemName
and desc.name != self.sVertexPositionItemName:
5710 uvBuffer = data.createVertexBuffer(desc)
5712 satisfiedRequirements[i] =
True
5713 if debugPopulateGeometry:
5714 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kTexture"
5715 print "Acquire a uv buffer"
5716 uvDataAddress = uvBuffer.acquire(totalVerts,
True)
5718 uvData = ((ctypes.c_float * 2)*totalVerts).from_address(uvDataAddress)
5720 elif desc.semantic == omr.MGeometry.kColor:
5722 cpvBuffer = data.createVertexBuffer(desc)
5724 satisfiedRequirements[i] =
True
5725 if debugPopulateGeometry:
5726 print ">>> Fill in data for requirement '" + desc.name +
"'. Semantic = kColor"
5727 cpvDataAddress = cpvBuffer.acquire(totalVerts,
True)
5729 cpvData = ((ctypes.c_float * 4)*totalVerts).from_address(cpvDataAddress)
5740 for i
in xrange(self.fMeshGeom.faceCount):
5742 numVerts = self.fMeshGeom.face_counts[i]
5744 for v
in xrange(numVerts):
5745 if any((positionData, vertexNumericIdPositionData, vertexNumericLocationPositionData, vertexNumericLocationData)):
5746 position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
5749 positionData[pid][0] = position[0]
5750 positionData[pid][1] = position[1]
5751 positionData[pid][2] = position[2]
5754 if vertexNumericIdPositionData:
5755 vertexNumericIdPositionData[pid][0] = position[0]+1.0
5756 vertexNumericIdPositionData[pid][1] = position[1]+1.0
5757 vertexNumericIdPositionData[pid][2] = position[2]+1.0
5760 if vertexNumericLocationPositionData:
5761 vertexNumericLocationPositionData[pid][0] = position[0]+3.0
5762 vertexNumericLocationPositionData[pid][1] = position[1]+3.0
5763 vertexNumericLocationPositionData[pid][2] = position[2]+3.0
5766 if vertexNumericLocationData:
5767 vertexNumericLocationData[pid][0] = position[0]
5768 vertexNumericLocationData[pid][1] = position[1]
5769 vertexNumericLocationData[pid][2] = position[2]
5774 normal = self.fMeshGeom.normals[self.fMeshGeom.face_connects[vid]]
5775 normalData[nid][0] = normal[0]
5776 normalData[nid][1] = normal[1]
5777 normalData[nid][2] = normal[2]
5784 uvNum = self.fMeshGeom.uvcoords.uvId(vid)
5785 uv = self.fMeshGeom.uvcoords.getUV(uvNum)
5786 uvData[uvid][0] = uv[0]
5787 uvData[uvid][1] = uv[0]
5794 position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
5795 cpvData[cid][0] = position[0]
5796 cpvData[cid][1] = position[1]
5797 cpvData[cid][2] = position[2]
5798 cpvData[cid][3] = 1.0
5803 if vertexNumericIdData:
5804 vertexNumericIdData[vid] = fMeshGeom.face_connects[vid]
5812 if positionDataAddress:
5813 positionBuffer.commit(positionDataAddress)
5815 if normalDataAddress:
5816 normalBuffer.commit(normalDataAddress)
5819 uvBuffer.commit(uvDataAddress)
5822 cpvBuffer.commit(cpvDataAddress)
5824 if vertexNumericIdDataAddress:
5825 vertexNumericIdBuffer.commit(vertexNumericIdDataAddress)
5827 if vertexNumericIdPositionDataAddress:
5828 vertexNumericIdPositionBuffer.commit(vertexNumericIdPositionDataAddress)
5830 if vertexNumericLocationDataAddress:
5831 vertexNumericLocationBuffer.commit(vertexNumericLocationDataAddress)
5833 if vertexNumericLocationPositionDataAddress:
5834 vertexNumericLocationPositionBuffer.commit(vertexNumericLocationPositionDataAddress)
5839 if activeVertexPositionData:
5840 if debugPopulateGeometry:
5841 print ">>> Fill in the data for active vertex position buffer base on component list"
5845 if activeVertexCount > len(self.fMeshGeom.vertices):
5846 activeVertexCount = len(self.fMeshGeom.vertices)
5848 for i
in xrange(activeVertexCount):
5849 position = self.fMeshGeom.vertices[ self.fActiveVertices[i] ]
5850 activeVertexPositionData[i][0] = position[0]
5851 activeVertexPositionData[i][1] = position[1]
5852 activeVertexPositionData[i][2] = position[2]
5854 activeVertexPositionBuffer.commit(activeVertexPositionDataAddress)
5856 if activeVertexUVData:
5857 if debugPopulateGeometry:
5858 print ">>> Fill in the data for active vertex uv buffer base on component list"
5862 if activeVertexCount > len(self.fMeshGeom.vertices):
5863 activeVertexCount = len(self.fMeshGeom.vertices)
5865 for i
in xrange(activeVertexCount):
5866 activeVertexUVData[i] = i / activeVertexCount
5868 activeVertexUVBuffer.commit(activeVertexUVDataAddress)
5873 if faceCenterPositionData:
5874 if debugPopulateGeometry:
5875 print ">>> Fill in the data for face center position buffer"
5881 for faceId
in xrange(self.fMeshGeom.faceCount):
5887 faceCenterPosition = om.MPoint()
5890 numVerts = self.fMeshGeom.face_counts[faceId]
5892 for v
in xrange(numVerts):
5893 face_vertex_position = self.fMeshGeom.vertices[self.fMeshGeom.face_connects[vid]]
5894 x += face_vertex_position[0]
5895 y += face_vertex_position[1]
5896 z += face_vertex_position[2]
5900 faceCenterPosition = om.MPoint(x, y, z) / numVerts
5905 faceCenterPositionData[faceId][0] = faceCenterPosition[0]
5906 faceCenterPositionData[faceId][1] = faceCenterPosition[1]
5907 faceCenterPositionData[faceId][2] = faceCenterPosition[2]
5909 faceCenterPositionBuffer.commit(faceCenterPositionDataAddress)
5913 for i
in xrange(len(descList)):
5914 if satisfiedRequirements[i]:
5917 if self.fDrawSharedActiveVertices
and (desc.name == self.sActiveVertexStreamName):
5918 if desc.semantic == omr.MGeometry.kPosition:
5919 satisfiedRequirements[i] =
True
5920 self.cloneVertexBuffer(activeVertexPositionBuffer, data, desc, activeVertexCount, debugPopulateGeometry)
5921 elif desc.semantic == omr.MGeometry.kTexture:
5922 satisfiedRequirements[i] =
True
5923 self.cloneVertexBuffer(activeVertexUVBuffer, data, desc, activeVertexCount, debugPopulateGeometry)
5924 elif self.fDrawFaceCenters
and desc.name == self.sFaceCenterStreamName:
5925 if desc.semantic == omr.MGeometry.kPosition:
5926 satisfiedRequirements[i] =
True
5927 self.cloneVertexBuffer(faceCenterPositionBuffer, data, desc, self.fMeshGeom.faceCount, debugPopulateGeometry)
5929 if desc.semantic == omr.MGeometry.kPosition:
5930 if desc.name == self.sVertexIdItemName:
5931 satisfiedRequirements[i] =
True
5932 self.cloneVertexBuffer(vertexNumericIdPositionBuffer, data, desc, totalVerts, debugPopulateGeometry)
5933 elif desc.name == self.sVertexPositionItemName:
5934 satisfiedRequirements[i] =
True
5935 self.cloneVertexBuffer(vertexNumericLocationPositionBuffer, data, desc, totalVerts, debugPopulateGeometry)
5937 satisfiedRequirements[i] =
True
5938 self.cloneVertexBuffer(positionBuffer, data, desc, totalVerts, debugPopulateGeometry)
5939 elif desc.semantic == omr.MGeometry.kNormal:
5940 satisfiedRequirements[i] =
True
5941 self.cloneVertexBuffer(normalBuffer, data, desc, totalVerts, debugPopulateGeometry)
5942 elif desc.semantic == omr.MGeometry.kTexture:
5943 numericValue =
"numericvalue"
5944 numeric3Value =
"numeric3value"
5945 if desc.semanticName.lower() == numericValue
and desc.name == self.sVertexIdItemName:
5946 satisfiedRequirements[i] =
True
5947 self.cloneVertexBuffer(vertexNumericIdBuffer, data, desc, totalVerts, debugPopulateGeometry)
5948 elif desc.semanticName.lower() == numeric3Value
and desc.name == self.sVertexPositionItemName:
5949 satisfiedRequirements[i] =
True
5950 self.cloneVertexBuffer(vertexNumericLocationBuffer, data, desc, totalVerts, debugPopulateGeometry)
5951 elif desc.name != self.sVertexIdItemName
and desc.name != self.sVertexPositionItemName:
5952 satisfiedRequirements[i] =
True
5953 self.cloneVertexBuffer(uvBuffer, data, desc, totalVerts, debugPopulateGeometry)
5954 elif desc.semantic == omr.MGeometry.kColor:
5955 satisfiedRequirements[i] =
True
5956 self.cloneVertexBuffer(cpvBuffer, data, desc, totalVerts, debugPopulateGeometry)
5958 if not satisfiedRequirements[i]:
5961 destBuffer = data.createVertexBuffer(desc)
5963 satisfiedRequirements[i] =
True
5964 if debugPopulateGeometry:
5965 print ">>> Fill in dummy requirement '%s'" % (desc.name, )
5966 destBufferDataAddress = destBuffer.acquire(totalVerts,
True)
5967 if destBufferDataAddress:
5968 destBufferData = ((ctypes.c_float * desc.dimension)*totalVerts).from_address(destBufferDataAddress)
5970 for j
in xrange(totalVerts):
5971 if desc.dimension == 4:
5972 destBufferData[j] = (1.0, 0.0, 0.0, 1.0)
5973 elif desc.dimension == 3:
5974 destBufferData[j] = (1.0, 0.0, 0.0)
5976 for k
in xrange(desc.dimension):
5977 destBufferData[j][k] = 0.0
5978 destBuffer.commit(destBufferDataAddress)
5983 def cloneVertexBuffer(self, srcBuffer, data, desc, dataSize, debugPopulateGeometry):
5985 destBuffer = data.createVertexBuffer(desc)
5987 if debugPopulateGeometry:
5988 print ">>> Cloning requirement '%s'" % (desc.name, )
5989 destBufferDataAddress = destBuffer.acquire(dataSize,
True)
5990 srcBufferDataAddress = srcBuffer.map()
5991 if destBufferDataAddress
and srcBufferDataAddress:
5992 destBufferData = ((ctypes.c_float * desc.dimension)*dataSize).from_address(destBufferDataAddress)
5993 srcBufferData = ((ctypes.c_float * desc.dimension)*dataSize).from_address(srcBufferDataAddress)
5994 if destBufferData
and srcBufferData:
5995 for j
in xrange(dataSize):
5996 for k
in xrange(desc.dimension):
5997 destBufferData[j][k] = srcBufferData[j][k]
5998 destBuffer.commit(destBufferDataAddress)
6002 def updateIndexingForWireframeItems(self, wireIndexBuffer, item, data, totalVerts):
6010 if not wireIndexBuffer:
6011 wireIndexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6013 dataAddress = wireIndexBuffer.acquire(2*totalVerts,
True)
6015 data = (ctypes.c_uint * (2*totalVerts)).from_address(dataAddress)
6019 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6021 numVerts = self.fMeshGeom.face_counts[faceIdx]
6024 for v
in xrange(numVerts-1):
6040 wireIndexBuffer.commit(dataAddress)
6044 item.associateWithIndexBuffer(wireIndexBuffer)
6046 def updateIndexingForDormantVertices(self, item, data, numTriangles):
6049 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6051 dataAddress = indexBuffer.acquire(3*numTriangles,
True)
6053 data = (ctypes.c_uint*(3*numTriangles)).from_address(dataAddress)
6058 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6060 numVerts = self.fMeshGeom.face_counts[faceIdx]
6062 for v
in xrange(1, numVerts-1):
6064 data[idx+1] = base+v
6065 data[idx+2] = base+v+1
6070 indexBuffer.commit(dataAddress)
6072 item.associateWithIndexBuffer(indexBuffer)
6074 def updateIndexingForFaceCenters(self, item, data, debugPopulateGeometry):
6077 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6079 dataAddress = indexBuffer.acquire(self.fMeshGeom.faceCount,
True)
6081 data = (ctypes.c_uint * self.fMeshGeom.faceCount).from_address(dataAddress)
6082 if debugPopulateGeometry:
6083 print ">>> Set up indexing for face centers"
6085 for i
in xrange(self.fMeshGeom.faceCount):
6090 for i
in xrange(self.fMeshGeom.faceCount):
6092 numVerts = self.fMeshGeom.face_counts[i]
6097 indexBuffer.commit(dataAddress)
6099 item.associateWithIndexBuffer(indexBuffer)
6101 def updateIndexingForVertices(self, item, data, numTriangles, activeVertexCount, debugPopulateGeometry):
6104 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6116 if self.fDrawSharedActiveVertices:
6117 dataAddress = indexBuffer.acquire(activeVertexCount,
True)
6119 data = (ctypes.c_uint*activeVertexCount).from_address(dataAddress)
6120 if debugPopulateGeometry:
6121 print ">>> Set up indexing for shared vertices"
6123 for i
in xrange(activeVertexCount):
6129 if debugPopulateGeometry:
6130 print ">>> Set up indexing for unshared vertices"
6132 vertexCount = 3*numTriangles
6133 dataAddress = indexBuffer.acquire(vertexCount,
True)
6135 data = (ctypes.c_uint*vertexCount).from_address(dataAddress)
6136 for i
in xrange(vertexCount):
6137 data[i] = vertexCount+1
6139 selectionIdSet = self.fActiveVerticesSet
6146 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6148 numVerts = self.fMeshGeom.face_counts[faceIdx]
6150 for v
in xrange(1, numVerts-1):
6151 vertexId = self.fMeshGeom.face_connects[base]
6152 if vertexId
in selectionIdSet:
6154 data[idx] = lastFound
6157 vertexId = self.fMeshGeom.face_connects[base+v]
6158 if vertexId
in selectionIdSet:
6160 data[idx] = lastFound
6163 vertexId = self.fMeshGeom.face_connects[base+v+1]
6164 if vertexId
in selectionIdSet:
6165 lastFound = base+v+1
6166 data[idx] = lastFound
6171 for i
in xrange(vertexCount):
6172 if data[i] == vertexCount+1:
6176 indexBuffer.commit(dataAddress)
6178 item.associateWithIndexBuffer(indexBuffer)
6180 def updateIndexingForEdges(self, item, data, totalVerts, fromSelection):
6183 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6185 totalEdges = 2*totalVerts
6186 totalEdgesP1 = 2*totalVerts+1
6187 dataAddress = indexBuffer.acquire(totalEdges,
True)
6189 data = (ctypes.c_uint*totalEdges).from_address(dataAddress)
6190 for i
in xrange(totalEdges):
6191 data[i] = totalEdgesP1
6194 displayAll =
not fromSelection
6195 displayActives = (
not displayAll
and bool(self.fActiveEdgesSet))
6196 displayAffected = (
not displayAll
and not displayActives)
6198 selectionIdSet =
None
6200 selectionIdSet = self.fActiveEdgesSet
6201 elif displayAffected:
6202 selectionIdSet = self.fActiveVerticesSet
6208 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6210 numVerts = self.fMeshGeom.face_counts[faceIdx]
6212 for v
in xrange(numVerts):
6213 enableEdge = displayAll
6214 vindex1 = base + (v % numVerts)
6215 vindex2 = base + ((v+1) % numVerts)
6221 vertexId = self.fMeshGeom.face_connects[vindex1]
6222 if vertexId
in selectionIdSet:
6227 vertexId2 = self.fMeshGeom.face_connects[vindex2]
6228 if vertexId2
in selectionIdSet:
6232 elif displayActives:
6235 if edgeId
in selectionIdSet:
6250 for i
in xrange(totalEdges):
6251 if data[i] == totalEdgesP1:
6254 indexBuffer.commit(dataAddress)
6256 item.associateWithIndexBuffer(indexBuffer)
6258 def updateIndexingForFaces(self, item, data, numTriangles, fromSelection):
6261 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6263 numTriangleVertices = 3*numTriangles
6264 dataAddress = indexBuffer.acquire(numTriangleVertices,
True)
6266 data = (ctypes.c_uint*numTriangleVertices).from_address(dataAddress)
6267 for i
in xrange(numTriangleVertices):
6268 data[i] = numTriangleVertices+1
6271 displayAll =
not fromSelection
6272 displayActives = (
not displayAll
and bool(self.fActiveFacesSet))
6273 displayAffected = (
not displayAll
and not displayActives)
6275 selectionIdSet =
None
6277 selectionIdSet = self.fActiveFacesSet
6278 elif displayAffected:
6279 selectionIdSet = self.fActiveVerticesSet
6284 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6286 numVerts = self.fMeshGeom.face_counts[faceIdx]
6288 enableFace = displayAll
6293 for v
in xrange(1, numVerts-1):
6294 vertexId = self.fMeshGeom.face_connects[base]
6295 if vertexId
in selectionIdSet:
6300 vertexId2 = self.fMeshGeom.face_connects[base+v]
6301 if vertexId2
in selectionIdSet:
6306 vertexId3 = self.fMeshGeom.face_connects[base+v+1]
6307 if vertexId3
in selectionIdSet:
6309 lastFound = base+v+1
6311 elif displayActives:
6314 if faceIdx
in selectionIdSet:
6322 for v
in xrange(1, numVerts-1):
6324 data[idx+1] = base+v
6325 data[idx+2] = base+v+1
6331 for i
in xrange(numTriangleVertices):
6332 if data[i] == numTriangleVertices+1:
6335 indexBuffer.commit(dataAddress)
6337 item.associateWithIndexBuffer(indexBuffer)
6339 def updateIndexingForShadedTriangles(self, item, data, numTriangles):
6343 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
6345 dataAddress = indexBuffer.acquire(3*numTriangles,
True)
6347 data = (ctypes.c_uint * (3*numTriangles)).from_address(dataAddress)
6352 for faceIdx
in xrange(self.fMeshGeom.faceCount):
6354 numVerts = self.fMeshGeom.face_counts[faceIdx]
6356 for v
in xrange(1, numVerts-1):
6358 data[idx+1] = base+v
6359 data[idx+2] = base+v+1
6364 indexBuffer.commit(dataAddress)
6366 item.associateWithIndexBuffer(indexBuffer)
6380 sUseSubSceneOverride =
False
6381 sDrawDbClassification =
"drawdb/geometry/apiMesh"
6382 if sUseSubSceneOverride:
6383 sDrawDbClassification =
"drawdb/subscene/apiMesh"
6384 sDrawRegistrantId =
"apiMeshPlugin"
6387 def initializePlugin(obj):
6388 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
6390 global sUseSubSceneOverride, sDrawDbClassification, sDrawRegistrantId
6393 plugin.registerData(
"apiMeshData", apiMeshData.id, apiMeshData.creator, om.MPxData.kGeometryData)
6395 sys.stderr.write(
"Failed to register data\n")
6399 plugin.registerShape(
"apiMesh", apiMesh.id, apiMesh.creator, apiMesh.initialize, apiMeshUI.creator, sDrawDbClassification)
6401 sys.stderr.write(
"Failed to register node\n")
6405 plugin.registerNode(
"apiMeshCreator", apiMeshCreator.id, apiMeshCreator.creator, apiMeshCreator.initialize)
6407 sys.stderr.write(
"Failed to register node\n")
6411 if sUseSubSceneOverride:
6412 omr.MDrawRegistry.registerSubSceneOverrideCreator(sDrawDbClassification, sDrawRegistrantId, apiMeshSubSceneOverride.creator)
6414 omr.MDrawRegistry.registerGeometryOverrideCreator(sDrawDbClassification, sDrawRegistrantId, apiMeshGeometryOverride.creator)
6416 sys.stderr.write(
"Failed to register override\n")
6420 if sUseSubSceneOverride:
6421 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sVertexSelectionName, simpleComponentConverter_subsceneOverride.creatorVertexSelection)
6422 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sEdgeSelectionName, simpleComponentConverter_subsceneOverride.creatorEdgeSelection)
6423 omr.MDrawRegistry.registerComponentConverter(apiMeshSubSceneOverride.sFaceSelectionName, simpleComponentConverter_subsceneOverride.creatorFaceSelection)
6425 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sVertexItemName, meshVertComponentConverter_geometryOverride.creator)
6426 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sEdgeSelectionItemName, meshEdgeComponentConverter_geometryOverride.creator)
6427 omr.MDrawRegistry.registerComponentConverter(apiMeshGeometryOverride.sFaceSelectionItemName, meshFaceComponentConverter_geometryOverride.creator)
6429 sys.stderr.write(
"Failed to register component converters\n")
6432 def uninitializePlugin(obj):
6433 plugin = om.MFnPlugin(obj)
6435 global sUseSubSceneOverride, sDrawDbClassification, sDrawRegistrantId
6438 if sUseSubSceneOverride:
6439 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sVertexSelectionName)
6440 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sEdgeSelectionName)
6441 omr.MDrawRegistry.deregisterComponentConverter(apiMeshSubSceneOverride.sFaceSelectionName)
6443 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sVertexItemName)
6444 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sEdgeSelectionItemName)
6445 omr.MDrawRegistry.deregisterComponentConverter(apiMeshGeometryOverride.sFaceSelectionItemName)
6447 sys.stderr.write(
"Failed to deregister component converters\n")
6451 if sUseSubSceneOverride:
6452 omr.MDrawRegistry.deregisterSubSceneOverrideCreator(sDrawDbClassification, sDrawRegistrantId)
6454 omr.MDrawRegistry.deregisterGeometryOverrideCreator(sDrawDbClassification, sDrawRegistrantId)
6456 sys.stderr.write(
"Failed to deregister override\n")
6460 plugin.deregisterNode(apiMeshCreator.id)
6462 sys.stderr.write(
"Failed to deregister node\n")
6466 plugin.deregisterNode(apiMesh.id)
6468 sys.stderr.write(
"Failed to deregister node\n")
6472 plugin.deregisterData(apiMeshData.id)
6474 sys.stderr.write(
"Failed to deregister data\n")