Change Brep opacity, color, etc. in C++?


(NathanM) #1

Hi,

Within a custom CRhinoBrepObject I need to change its transparency inside Draw(). I’ve tried something like this:

        CDisplayPipelineMaterial material = dp.DisplayAttrs()->m_pMaterial->m_FrontMaterial;
	material.m_FrontMaterial.SetTransparency(1.0);
        dp.DrawShadedBrep(*const_cast<ON_Brep*>(Brep()), &material);

However my Brep keeps being opaque:

Though something must be well done, when I translate it looks transparent:

Seems like Rhino will always draw my object on top depth with the opaque default color? How can I manipulate it?

Thx
Nathan


(Dale Fugier) #4

Hi @NathanM1994,

You are not going to be able to override CRhinoBrepObject::Draw and draw a Brep transparently.

The perception that something is transparent is accomplished by very specific drawing rules.

  1. All transparent objects must be drawn AFTER all opaque objects.
  2. All transparent objects must be drawn back-to-front.
  3. All transparent objects must have their front and back faces drawn with the proper depth writing and depth testing flags set properly.

Thus, setting a material on a Brep and calling Draw isn’t going to work.

Your best bet, from a plug-in is to try drawing your Breps from a display conduit in the PostDrawObjects channel.

– Dale


(NathanM) #5

Hi @dale, I see.

Let me describe what I’m looking for: my custom Brep is actually a polysurface. In “normal” mode, when I have any grips off, it’s drawn with Rhino default material like this:

Then, I have my custom grips which allow me to select each of the Brep faces and move them separately. The problem comes with the display: I want to draw the selected face with the selected color material.
I manage to do so by overriding the grips Draw(), but the original Brep polysurface keeps being drawn with default material which overlaps the unit faces, see:

Do you recall an efficient way to do this? If possible, could we restrict to Draw() methods? I have very little experience with conduits…

Thx
Nathan