Hi, i’am cutomizing ghpython components preview geometry overriding DrawViewportWires() methods. As used @piac in this example
I’am previewing lines, points, meshes and texts using displayPipeline methods available.
I found that when drawing massive quantity of elements, methods like DrawLines() or DrawPoints() are particularly efficient, but with other methods i.e. DrawText() since it takes one element on each call, I need to iterate thousands of time inside DrawVieportWires() what results in a poor navigation performance.
def DrawViewportWires(self,args): MAX_MESH = 500 MAX_TEXT = 500 POINT_SIZE = 5 TEXT_COLOR = System.Drawing.Color.Black POINT_STYLE = Rhino.Display.PointStyle.RoundSimple #try: i = 0 for value in sorted(self.byValueDict.keys()): color = self.colors[i] args.Display.DrawPoints(self.byValueDict[value]['points'],POINT_STYLE,POINT_SIZE,color) t=0 if self.showValue: for pos in self.byValueDict[value]['textPos']: # this iteration slows performance # even with values as low as t=500 if t<MAX_TEXT: args.Display.Draw2dText(str(value),self.colors[i],pos,True,12,"Arial") t += 1 q = 0 if self.showMesh: for mesh in self.byValueDict[value]['mesh']: if q<MAX_MESH: args.Display.DrawMeshShaded(mesh,Rhino.Display.DisplayMaterial(color)) q += 1 i +=1
I have tried to take off from DrawViewportWires() as much operations as possible, but I cant figure out how to optimize this further: the iteration that still remains inside seems to be unavoidable.
Am I making a bad use of DrawViewportWires()? How does grasshopper components achieve much better results when previewing geometry? Can I expect to have such a good performance (somehow) using python?