Hello!
I've written a custom locator that changes its shape depending on a string in an attribute called "mapTyp".
I've compared the speed to a regular locator and it's much much slower. Is there some way to make this more efficient? Eventually I'll need hundreds of these.
class MapLocator(OpenMayaMPx.MPxLocatorNode):
mapTyp = OpenMaya.MObject()
name = OpenMaya.MObject()
beschreibung = OpenMaya.MObject()
datum = OpenMaya.MObject()
pathCoords = OpenMaya.MObject()
media = OpenMaya.MObject()
drawLoc = OpenMaya.MObject()
drawText = OpenMaya.MObject()
def __init__(self):
OpenMayaMPx.MPxLocatorNode.__init__(self)
def boundingBox(self):
p1 = OpenMaya.MPoint(-1,-1,-1)
p2 = OpenMaya.MPoint(1,1,1)
return OpenMaya.MBoundingBox(p1,p2)
def getAttr(self, attrName, typ = 'string'):
obj = self.thisMObject()
depNode = OpenMaya.MFnDependencyNode(obj)
plug = depNode.findPlug(attrName)
if typ == 'string':
return plug.asString()
if typ == 'bool':
return plug.asBool()
def draw(self, view, path, style, status):
doDraw = self.getAttr('drawLoc', typ = 'bool')
if not doDraw:
return
mapTypText = self.getAttr('mapTyp', typ = 'string')
nameText = self.getAttr('name', typ = 'string')
beschText = self.getAttr('beschreibung', typ = 'string')
drawText = self.getAttr('drawText', typ = 'bool')
view.beginGL()
if mapTypText in ['ereignis', 'text']:
self.drawEreignisType()
if not drawText:
return
glFT.glPushAttrib(OpenMayaRender.MGL_CURRENT_BIT)
glFT.glPushAttrib(OpenMayaRender.MGL_ALL_ATTRIB_BITS)
if mapTypText == 'ereignis':
glFT.glColor4f(0, 1, 0, 1)
drawText = nameText
else:
glFT.glColor4f(0, 1, 1, 1)
drawText = beschText
if status == OpenMayaUI.M3dView.kLead:
view.drawText( drawText, OpenMaya.MPoint(0.5,0,0), OpenMayaUI.M3dView.kLeft )
else:
view.drawText( drawText[:3], OpenMaya.MPoint(0.5,0,0), OpenMayaUI.M3dView.kLeft )
glFT.glPopAttrib()
glFT.glPopAttrib()
elif [other types.............]
view.endGL()
def drawArray(self, pointArray):
glFT.glBegin(OpenMayaRender.MGL_LINES)
for i in range(len(pointArray)-1):
x1,y1,z1 = pointArray[i]
x2,y2,z2 = pointArray[i+1]
glFT.glVertex3f(x1,y1,z1)
glFT.glVertex3f(x2,y2,z2)
glFT.glEnd()
def drawCircle(self, center = (0,0), radius = 0.5,step = 4, rotate = (45,1,1,0)):
glFT.glRotatef(*rotate)
glFT.glBegin(OpenMayaRender.MGL_LINE_LOOP)
for i in range(0,360, step):
degInRad = math.radians(i)
glFT.glVertex3f(math.cos(degInRad)*radius,math.sin(degInRad)*radius, 0)
glFT.glEnd()
def drawEreignisType(self):
self.drawCircle(rotate = (45,1,1,0))
self.drawCircle(rotate = (-90,1,1,0))
return
Any help would be much appreciated!