CustomMeshObject OnDraw method problem with Rhino Sun light ON

Hello,

I have a strange problem.
The plugin creates its own CustomMesh and overwrites the OnDraw method.

Inside OnDraw the plugin draws 1 box. Works fine.
But if I change the viewport mode to “Rendered”, and I turn On Rhino Sun light, it draws two boxes:
Like this:

If I move around the viewport, the intentionally drawn box follows the viewport orientation change as it should. But not the other box.

But if I change the Sun location, the orientation of the other box changes. So it is linked somehow to the Sun, but I don’t understand why.

Any idea?

Márton

Hi @marton.parlagh,

Any chance you can throw together a simple sample that allows us to repeat this here?

Thanks,

– Dale

Here is a simple code:

namespace TestCommands
{
   public class TestCustMesh : Rhino.Commands.Command
   {
      public override string EnglishName => "TestCustMesh";
      protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
      {
         var m = Rhino.Geometry.Mesh.CreateFromBox(new Rhino.Geometry.BoundingBox(Rhino.Geometry.Point3d.Origin, new Rhino.Geometry.Point3d(10, 10, 10)), 2, 2, 2);
         TestMeshObject mesObj = new TestMeshObject(m);
         doc.Objects.AddRhinoObject(mesObj);
         return Rhino.Commands.Result.Success;
      }
      public class TestMeshObject : Rhino.DocObjects.Custom.CustomMeshObject
		{
         public TestMeshObject(Rhino.Geometry.Mesh m) : base(m)  {}
         public TestMeshObject()
         {
            // required
         }
         protected override void OnDraw(Rhino.Display.DrawEventArgs e)
         {
            e.Display.DrawBox(MeshGeometry.GetBoundingBox(true), System.Drawing.Color.Red);
            //In case we return here (without calling base.OnDraw(e)), this strange effect is more visible
            //If base.OnDraw(e) was called, we have to click select/unselect inside the viewport to see this.
            //return;
            base.OnDraw(e);
         }
      }
   }
}

When you un-comment the line with //return before base.OnDraw(e), you can see this problem easier. Otherwise you have to select/unselect the object to see it.

Steps:

  1. new scene
  2. call command TestCustMesh
  3. change viewport to “Rendered”
  4. Sun panel -> turn ON sun
  5. click select/unselect object

Hello Dale,

Were you able to reproduce it?

I have another strange effect with CustomObject onDraw method.
This one happens in case viewport mode is “Rendered”. (In this case sun on/off doesn’t matter)

I use
e.Display.DrawMeshShaded(…)

So viewport is rendered and object is not selected:

This looks ok.

But if I select the object

The object is not drawn in normal shaded mode, but I can see the background environment image through it (or overlayed on it?).

Márton

Hi @marton.parlagh,

This seems to work better:

protected override void OnDraw(Rhino.Display.DrawEventArgs e)
{
  base.OnDraw(e);

  if (e.Display.DrawingWires)
    e.Display.DrawBox(MeshGeometry.GetBoundingBox(true), Color.Red);
}

– Dale

Ohhh thanks!!!

I was drawing at the wrong pipeline state. - OK

It Works!
Thanks,
Márton