Draw something over all the layers

Hello,

I need to draw in the Rhino document three arrows in order to let the user to see a custom reference system, beyond the Rhino default one.

How can I draw something, always visible and not clickable neither modifiable?

I though to draw the three arrows in a layer, and then lock it. But I don’t want to see such layer into the layers manager tool. I need to hide the existence of this layer but, at the same time, let the user to see the layer content, always.

I also look for a method to draw something outside any layer, as for the Rhino reference system or the Rhino grid but I did not find any solution.

Do you have any suggestion? I am open to each solution let me to draw something always visible and then keep it out from the user control.

Thank you!

Hi @margari,

You can use a CRhinoDisplayConduit to draw geometry and text that does not exist in the Rhino document. The Rhino SDK samples have a number of conduit samples that you can review.

Let me know if you can’t find what you need.

Thanks,

– Dale

Hi @dale,

thank you, CRhinoDisplayConduit seems to be perfect for my purpose.
I tried to implement an example, following some samples you linked me but I have two main problems now.

  1. I can’t see my geometry when I am in the ray-tracing mode.
    I suppose that CrhinoDisplayPipeline::DrawShadedBreps function it not enought for that but I don’t know what to do.

  2. I can’t see the whole geometry in wireframe, shaded, ghosted and x-ray mode. The portion nearest to the view point is clipped.
    It could be a CsupportChannels::SC_CALCBOUNDINGBOX problem but I don’t know exactly what I’m doing wrong.

The following is my CrhinoDisplayConduit extension…

class CSampleDrawReferenceSystemConduit : public CRhinoDisplayConduit
{
public:
  CSampleDrawReferenceSystemConduit()
    : CRhinoDisplayConduit(CSupportChannels::SC_CALCBOUNDINGBOX | CSupportChannels::SC_POSTDRAWOBJECTS)
  {
  }

  bool ExecConduit(CRhinoDisplayPipeline& dp, UINT nActiveChannel, bool& bTerminateChannel)
  {
    switch (nActiveChannel)
    {
      case CSupportChannels::SC_CALCBOUNDINGBOX:
      {
        for (int brepIdx = 0; brepIdx < m_breps.Count(); ++brepIdx)
        {
          ON_Brep* brep = m_breps[brepIdx];

          if (brep)
          {
            m_pChannelAttrs->m_BoundingBox.Union(brep->BoundingBox());
          }
        }
      }
      break;

      case CSupportChannels::SC_POSTDRAWOBJECTS:
      {
          ON_Material material;
          material.SetDiffuse(ON_Color(255, 0, 255));
          CDisplayPipelineMaterial* pipMat = new CDisplayPipelineMaterial(material);
          dp.DrawShadedBreps(m_breps, pipMat);
      }
      break;
    }

    return true;
  }

  void SetBreps(const ON_SimpleArray<ON_Brep*>& i_breps)
  {
    m_breps = i_breps;
  }

private:
  ON_SimpleArray<ON_Brep*> m_breps;
};

void Main ()
{
   CSampleDrawReferenceSystemConduit conduit;
   ON_Surface* surfaceSample;

   ON_PolyCurve squareSample;
   squareSample.AppendAndMatch(new ON_LineCurve(ON_3dPoint(0, 0, 0), ON_3dPoint(10, 0, 0)));
   squareSample.AppendAndMatch(new ON_LineCurve(ON_3dPoint(10, 0, 0), ON_3dPoint(10, 5, 0)));
   squareSample.AppendAndMatch(new ON_LineCurve(ON_3dPoint(10, 5, 0), ON_3dPoint(0, 5, 0)));
   squareSample.AppendAndMatch(new ON_LineCurve(ON_3dPoint(0, 5, 0), ON_3dPoint(0, 0, 0)));
   
   surfaceSample = RhinoExtrudeCurveStraight(&squareSample, ON_3dVector(0, 0, 30));   
   breps.Append(surfaceSample->BrepForm());
   
   m_conduit.SetBreps(breps);

   m_conduit.Enable();
}

Thank you in advance!

Hi @margari,

See if the attached sample provides you with any assistance.

cmdTestMargari.cpp (4.1 KB)

– Dale

Hello @dale,

Thank you for your support but unfortunately your code doesn’t work.
I noticed that the problem occurs when into the document is placed an object smaller then the conduit one.
You can reproduce the problem running the TestMargari command after to have opened the linked file.

docTestMargari.3dm (30.5 KB)

I forgot to tell you that the clipping issue is only in the perspective view.
I’d also like to draw the brep in the ray-tracing rendering but I don’t know how.

Thanks,
Margari

HI @margari,

Sorry, but I cannot repeat the issues you are reporting. Here is a view capture of the perspective view in raytraced display mode.

test

Can you run the SystemInfo command and upload the results to a reply?

Thanks,

– Dale

Hello @dale,

Here is my SystemInfo command output. My work mate and I have the same issue with two different PCs:

Rhino 6 SR20 2019-11-18 (Rhino 6, 6.20.19322.20361, Git hash:master @ f60ce76e397bba419469ae5277fc1578641caa3a)

License type: Not For Resale Lab, build 2019-11-18
License details: Stand-Alone

Windows 10.0 SR0.0 or greater (Physical RAM: 16Gb)
Machine name: PC-MARGARI

Non-hybrid graphics.
Primary display and OpenGL: NVIDIA GeForce GTX 1050 (NVidia) Memory: 2GB, Driver date: 10-27-2017 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 388.13

Secondary graphics devices.
  Intel(R) HD Graphics 4600 (Intel) Memory: 1GB, Driver date: 10-16-2017 (M-D-Y).

OpenGL Settings
  Safe mode: Off
  Use accelerated hardware modes: On
  Redraw scene when viewports are exposed: On
  
  Anti-alias mode: 4x
  Mip Map Filtering: Linear
  Anisotropic Filtering Mode: Height
  
  Vendor Name: NVIDIA Corporation
  Render version: 4.6
  Shading Language: 4.60 NVIDIA
  Driver Date: 10-27-2017
  Driver Version: 23.21.13.8813
  Maximum Texture size: 32768 x 32768
  Z-Buffer depth: 24 bits
  Maximum Viewport size: 32768 x 32768
  Total Video Memory: 2 GB

Rhino plugins
  C:\Program Files\Rhino 6\Plug-ins\Commands.rhp	"Commands"	6.20.19322.20361
  C:\Program Files\Rhino 6\Plug-ins\rdk.rhp	"Renderer Development Kit"	
  C:\Program Files\Rhino 6\Plug-ins\RhinoRender.rhp	"Rhino Render"	
  C:\Program Files\Rhino 6\Plug-ins\rdk_etoui.rhp	"RDK_EtoUI"	6.20.19322.20361
  C:\Program Files\Rhino 6\Plug-ins\rdk_ui.rhp	"Renderer Development Kit UI"	
  C:\Program Files\Rhino 6\Plug-ins\NamedSnapshots.rhp	"Snapshots"	
  C:\Program Files\Rhino 6\Plug-ins\RhinoCycles.rhp	"RhinoCycles"	6.20.19322.20361
  C:\Program Files\Rhino 6\Plug-ins\Toolbars\Toolbars.rhp	"Toolbars"	6.20.19322.20361
  C:\Program Files\Rhino 6\Plug-ins\3dxrhino.rhp	"3Dconnexion 3D Mouse"	
  C:\Program Files\Rhino 6\Plug-ins\Displacement.rhp	"Displacement"	
  C:\Program Files\Rhino 6\Plug-ins\LABUtility\Mosaix\Mosaix.rhp	"Mosaix"	
  C:\Program Files\Rhino 6\Plug-ins\LABUtility\RhinoNC\RhinoNC.rhp	"RhinoNC"	
  C:\Program Files\Rhino 6\Plug-ins\RPC.rhp	"RPC"	
  C:\Program Files\Rhino 6\Plug-ins\RhinoBonusTools.rhp	"Rhino Bonus Tools"	
  C:\Program Files\Rhino 6\Plug-ins\AnimationTools.rhp	"AnimationTools"	

Here is a perspective view in wireframe mode:
Wireframe

Here is a perspective view in shaded mode:
Shaded

If I move the object in the scene, the visualized part of the conduit changes…
Shaded2

Here is a perspective view in rendered mode (It is well visualized):

Here is a perspective view in raytraced mode:
Raytraced
When I switch to the raytraced mode from an other one, I can see the raytraced conduit for half a second, the it disappears.

Thanks

Hi @margari,

Both of these video drivers are pretty old. Can you see to updating them and then try again?

NVIDIA GeForce GTX 1050 (NVidia) Memory: 2GB, Driver date: 10-27-2017 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 388.13
Intel(R) HD Graphics 4600 (Intel) Memory: 1GB, Driver date: 10-16-2017 (M-D-Y).

Thanks,

– Dale

Hi @dale,

I updated both the drivers to the latest available versions but I the issues are still there:

Non-hybrid graphics.
Primary display and OpenGL: NVIDIA GeForce GTX 1050 (NVidia) Memory: 2GB, Driver date: 7-24-2019 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 432.00

Secondary graphics devices.
  Intel(R) HD Graphics 4600 (Intel) Memory: 1GB, Driver date: 10-29-2018 (M-D-Y).

I saw that also @stevebaer bumped into the same problem but I don’t think his solution will be fine also for me:

Many thanks,
Margari

I don’t know if it can help but I don’t have the clipping issue running Rhino in Safe Mode but I have the following issue if I zoom a lot.
The vertical edge on the left should go from the base corner towards the top of the image.
Wireframe_SafeMode

I also tried to run the same command on Rhino5 – 64bit and it works well.
Of course, I had to modify some calls in order to use Rhino5 SDK:

const ON_Color color(255, 0, 255);
const CDisplayPipelineAttributes* attributes = dp.DisplayAttrs();
if (nullptr != attributes && attributes->m_bShadeSurface)
{
  CDisplayPipelineMaterial material;
  dp.SetupDisplayMaterial(material, color);
  dp.DrawShadedBrep(*m_brep, &material);
}
dp.DrawBrep(*m_brep, color, 1);

Hello,

I’m not sure if this is the same issue, but there was something similar in this thread

Make sure in this case that you properly grow your bounding box in the CSupportChannels::SC_CALCBOUNDINGBOX channel.

Pablo

In the debugger are you getting the bounding box that you are expecting in the calcboundingbox conduit?

These are my bounding box building steps:

case CSupportChannels::SC_CALCBOUNDINGBOX:
case CSupportChannels::SC_VIEWEXTENTS:
{
  if (nullptr != m_brep)
  {
    ON_BoundingBox bbox;
    m_brep->GetBoundingBox(bbox, false);    // returns bbox with m_min={x=0.0 y=0.0 z=0.0} m_max={x=10.0 y=5.0 z=30.0} as expected
    // Here m_pChannelAttrs->m_BoundingBox is m_min={x=1.0 y=0.0 z=0.0} m_max={x=-1.0 y=0.0 z=0.0}, I don't know if it is correct
    m_pChannelAttrs->m_BoundingBox.Union(bbox); 
    // Here m_pChannelAttrs->m_BoundingBox is m_min={x=0.0 y=0.0 z=0.0} m_max={x=10.0 y=5.0 z=30.0} as expected
  }
}
break;

Thank you!

Thank you @pagarcia,

I’m growing my bounding box but probably not in the right manner. I can’t find where the error is.

Hello @dale and @stevebaer,

Debugging the program, I noticed that, also if I set the m_pChannelAttrs->m_BoundingBox member during the SC_CALCBOUNDINGBOX step, during the following SC_POSTDRAWOBJECTS step that member is as I have never modified it.

Do you have any suggestions?

I also noticed that the frustum doesn’t change its near and far planes, after I set the bounding box.
Is it correct? I expected it to grow up in order to contain my brep.

Thanks,
Margari

Hi @margari,

I have tried the sample (that I posted above) on two different systems and it works perfectly. Please verify that you’ve had tried running this code without modification.

If are unable to make the code I posted work for you, then please send me the code to your plug-in project.

Thanks,

– Dale

Hi @Dale,

I tried running your code without modifications but no luck.
I only include your command in my solution.

I got around the problem using a phantom object in order to place an invisible box just around my conduit object. In this way the frustum near and far planes are automatically computed well.

Thanks

Hi @margari,

You shouldn’t have to do this.

I don’t believe there is a bug here - the code presented works for me on two different systems. But I’ve logged an issue so @stevebaer can have a closer look at this.

https://mcneel.myjetbrains.com/youtrack/issue/RH-56283

– Dale

Thank you!

I suspect it could be a conflict between your command and another plugin of mine but I’m not sure.
I’ll investigate next week and I’ll let you know as soon as possible.

Margari

Are those your plug-ins? If these can be disabled for testing, I would try that