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);
}
}
}
Tags:
Permalink Reply by Dale Fugier on January 31, 2013 at 5:12pm 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
Permalink Reply by damjan fio on January 31, 2013 at 5:30pm 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
Permalink Reply by Dale Fugier on February 1, 2013 at 8:17am 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
Permalink Reply by damjan fio on February 2, 2013 at 4:01am 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);
Permalink Reply by damjan fio on February 20, 2013 at 8:05am 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
Permalink Reply by Dale Fugier on February 20, 2013 at 9:53am 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
Permalink Reply by damjan fio on February 21, 2013 at 7:26am
Permalink Reply by Dale Fugier on February 21, 2013 at 10:58am 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
© 2013 Created by McNeel Admin.
