override Bounding Box calculation in custom display conduits

hi,

i have a custom display conduit (PreDrawObject), and i dont know how to override the bounding box calculation, to show my conduit geometry.

for now it works by drawing an big rectangle to push the clipping planes, but i would be happy to do it the clean way.

the code so far:

    public class MyConduit : Rhino.Display.DisplayConduit
    {
        protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
        {
            var bounds = e.Viewport.Bounds;
            var pt = new Rhino.Geometry.Point2d(bounds.Right - 50, bounds.Bottom - 10);
            e.Display.Draw2dText("some overlay text", System.Drawing.Color.FromArgb(180,180,180), pt, false);
        }

        
        protected override void CalculateBoundingBox(Rhino.Display.CalculateBoundingBoxEventArgs e) {
            base.CalculateBoundingBox(e);

//What to place here to override it?
        }

        protected override void PreDrawObject(Rhino.Display.DrawObjectEventArgs e)
        {
            base.PreDrawObject(e);            
            //draw a lot of points
            Color c = Color.FromArgb(0,255,0);
            Random r = new Random();
            for (int i = 0; i < 100000; i++)
            {
                e.Display.DrawPoint(new Point3d(r.NextDouble()*100, r.NextDouble()*100, r.NextDouble()*100), c);
            }
        }
    }

Views: 331

Replies to This Discussion

Hi Damjan,

Override the DisplayConduit-inherited class' CalculateBoundingBox member as such:

protected override void CalculateBoundingBox(
  Rhino.Display.CalculateBoundingBoxEventArgs e
  )
{
  // Union your bounding boxes with the pipelines here
  e.BoundingBox.Union...
}

Does this help?

 -- Dale

thanks, but it doesnt really work for me.. :/

just for testing i set a new boundingbox "b" with two extreme points (-100 / 100), and made the union, but still the points in the predraw dont show up?

did i get something wrong - is the boundingbox per draw pass?

protected override void CalculateBoundingBox(Rhino.Display.CalculateBoundingBoxEventArgs e)
{
base.CalculateBoundingBox(e);
BoundingBox b = new BoundingBox(new Point3d(-100, -100, -100), new Point3d(100, 100, 100));
e.BoundingBox.Union(b);
}

protected override void PreDrawObject(Rhino.Display.DrawObjectEventArgs e)
{
base.PreDrawObject(e);

Color c = Color.FromArgb(0,255,0);
Random r = new Random();

for (int i = 0; i < 100000; i++)
{
e.Display.DrawPoint(new Point3d(r.NextDouble()*100, r.NextDouble()*100, r.NextDouble()*100), c);
}
}

or you say i can access the bounding box of the predrawobject here and union it? how?

as you can see i am not really a programmer.. please explain a bit more :/

thank you

No, CalculateBoundingBox is not called per channel.

Why do you need to draw in PreDrawObject? Perhaps drawing in the overlay channel would work better for you?

 -- Dale

EDIT: works all fine with postdrawobjects! thanks!

not really, because later on i will need zbuffering.

you have an idea what is wrong with this code?: (is a cutout from the above snippet)

BoundingBox b = new BoundingBox(new Point3d(-100, -100, -100), new Point3d(100, 100, 100));
e.BoundingBox.Union(b);

sorry, but this seems to still not work for me - whatever numbers i type in the "b" boundingbox, clipping appears.

Further, if i add some points across the scene, it gets better with the far clipping, but near clipping still cuts off my geometry.

i placed all the draws in the PostdrawObjects override.

if i convert the union bbox to a string, it it always "1,0,0--1,0,0".

basically it is as if the union doesnt change anything. same goes if i try to union with a bunch of scattered points.

any ideas? thanks

Can you post some sample code that I can run here that reproduces the problem? Along with the code, please provide step-by-step instruction on how to reproduce what you are seeing.

Thanks,

 -- Dale

i attached a simple command and a screenshot - the bbox is by far bigger than the camera position, still i get clipping. and sometimes is near plane, sometimes far plane..

Attachments:

Hi Damjan,

Looks like I misspoke. In your CalculateBoundingBox override, instead of doing this:

  e.BoundingBox.Union(b);

do this:

  e.IncludeBoundingBox(b);

as e.BoundingBox returns struct on the stack which just get destroyed.

Here is a more detailed example:

https://gist.github.com/dalefugier/5007118

 -- Dale

RSS

Translate

© 2014   Created by McNeel Admin.

Badges  |  Report an Issue  |  Terms of Service