Here’s my attempt so far with a python component and while this does handle the solid fill portion, I can’t seem to get the draw order to bring itself to the foreground.
Graph Space:
Model Space:
Python:
from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper
import System
from System.Drawing import Color
import Rhino as rh
class CustomDisplayDrawOrder(component):
def RunScript(self, M, C):
self.meshes = M # M is a list of meshes
# Set Display Color
self.material = rh.Display.DisplayMaterial(Color.Black)
self.material.Emission = C
# Add event handlers for drawing
rh.Display.DisplayPipeline.CalculateBoundingBox += self.CalculateBoundingBox
rh.Display.DisplayPipeline.PostDrawObjects += self.DrawViewportMeshes
def CalculateBoundingBox(self, sender, e):
for mesh in self.meshes:
e.IncludeBoundingBox(mesh.GetBoundingBox(True))
def DrawViewportMeshes(self, sender, e):
for mesh in self.meshes:
e.Display.DrawMeshShaded(mesh, self.material)
def __del__(self):
# Remove event handlers when the component is deleted
rh.Display.DisplayPipeline.CalculateBoundingBox -= self.CalculateBoundingBox
rh.Display.DisplayPipeline.PostDrawObjects -= self.DrawViewportMeshes
def __exit__(self):
# Handle Draw Order
rh.Display.DisplayPipeline.DrawForeground -= self.DrawViewportMeshes
def __enter__(self):
# Handle Draw Order - Draw In Foreground
rh.Display.DisplayPipeline.DrawForeground += self.DrawViewportMeshes
@AndersDeleuran I cannibalized bits of your code from this post and then tried to utilize the draw foreground method you shared with me in this post here but can’t seem to get it to apply properly to this implementation above. I also attempted to clear the display with this method you shared but I think I’m just muddying the logic trying to combine everything…
I also found this “DepthMode” method but can’t seem to get it to work either:
https://developer.rhino3d.com/api/rhinocommon/rhino.display.depthmode
Essentially I am looking to mimic the “shaded” functionality of a color input with a custom preview component while controlling the draw order to the foreground or background.
Any help is greatly appreciated, thank you all!