How to apply display attributes to a custom mesh object?

I have a custom mesh class that is working pretty well. When I create the class, I set the meshes I want to display and the object then gets added to the document. However, I would also like to control how this mesh looks (i.e. set a display material for this object, prevent the wires from being rendered, etc).

I know how to do this in the OnDraw function using a display conduit, but I want to actually change the doc object’s attributes.

Btw, modifying the custom mesh’s attributes and then adding it to the doc didn’t seem to work.

Hi Daniel,

Rhino objects draw themselves. Thus, if you want your custom mesh object to draw different than MeshObject, then you will need to override the OnDraw() virtual function and draw the mesh. Contained in the DrawEventArgs passed to this function a reference to display pipeline which contains routines to help you draw the mesh.

I am not sure what this means. What attribute(s) did you modify? What did you expect to happen after you modified? Is there code that we can see that repeats this?

Hi Dale,

My mistake - all is working normally now. I simply had to modify the properties of:

MyCustomMesh.Attributes

Not sure why this wasn’t working when I posted the question. It had probably just been a long day!

Hi @dale,
Is it possible to provide an example for drawing DrawBrepShaded or DrawMeshShaded?

Here I create a transparent material, but there is an issue that it hides (see through) other geometries behind it.

protected override void OnDraw(DrawEventArgs e)
{
    base.OnDraw(e);
    var m = new DisplayMaterial(Color.Red, 0.3);
    e.Display.DrawBrepShaded(this.BrepGeometry, m);
}

I also tried with following that you mentioned in another post, but still doesn’t work right.

protected override void OnDraw(DrawEventArgs e)
{
    base.OnDraw(e);
    e.Display.PushDepthTesting(true);
    e.Display.PushDepthWriting(true);
    var m = new DisplayMaterial(Color.Red, 0.3);
    e.Display.DrawBrepShaded(this.BrepGeometry, m);
    e.Display.PopDepthWriting();
    e.Display.PopDepthTesting();
}