Grasshopper

algorithmic modeling for Rhino

How to clear up things drawn by the displayPipeline?

Hi,

I'm using 

Rhino.Display.DisplayPipeline.DrawForeground += new EventHandler<Rhino.Display.DrawEventArgs>(OnDrawForeground);

to draw preview some animations in the viewport.

Is it possible to clear up what have been drawn?

Thanks,

-Jerome

Views: 1268

Replies to This Discussion

Hi Jerome,

if you want to draw your own geometry, I recommend PostDrawObjects, not DrawForeGround.

What exactly do you mean by "clear up"? 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi, David.

The geometry I draw using DrawForeGround always stays in the viewport. Is it possible to make these geometries disappear from the viewport?

By the way, what is the difference and advantages of PostDrawObjects and is there an example to use it?


Thanks!

-Jerome

I think the best is to handle this is by ref. When you can dispose what you have done. Else you drawings will be in Rhino till closing of application. If this is the problem...

Rhino.Display.CustomDisplay my_disp = new Rhino.Display.CustomDisplay (true);

my_function_i_will_do_something(my_disp);

my_dis.dispose();

my_function_i_will_do_something(ref Rhino.Display.CustomDisplay my_pass_throught)

{

do what ever .... paint play etc...

}

CustomDisplay does indeed have that problem, but when you draw it yourself using methods like PostDrawObjects() then you have to keep drawing your geometry on every viewport refresh.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks, Michael

I've never used CustomDisplay before and I will have a try on it. It looks like there are less methods than those of DisplayPipeline. 

Thanks!

-Jerome

DrawForeground is specifically designed to draw stuff on top of the viewport. There's no Z-testing anymore either.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks, David.

I tried PostDrawObjects() on every refresh of my animation and it works pretty good! I read the article of the display conduit on the rhino page and still haven't got a good idea about the Z-tesing. Is it the same thing as the depth testing? Could you explain it a little?

If I use PostDrawObjects(), is it still necessary to use CalculateBoundingBox to ensure that nothing will be clipped in the viewport?

Thanks a lot!

-Jerome 

Z-testing and depth-testing is the same thing. OpenGL tends to draw a z-buffer image along with the regular image. It's easiest to think of a z-buffer as a greyscale image where black represents the furthest possible distance from the camera and white the smallest possible distance. Every pixel of every object that is drawn is compared against the z-buffer and only allowed to be really drawn if it's closer to the camera than the z-buffer pixel was. This is how OpenGL figures out which parts of objects are occluded by other objects.

It is possible to disable the depth-testing, which means that everything you draw, no matter how far away, will always be visible. It is also possible to disable depth-writing, which allows you to draw pixels at a depth that remain unknown to the z-buffer.

When I say "furthest possible distance" and "smallest possible distance" I do not mean infinity and zero. Indeed, there are only so many unique shades of grey between black and white so the tighter this range from black to white the better the depth-clipping will work. This is where CalculateBoundingBox comes in. Before the black-white range is assigned, CalculateBoundingBox is used to determine the size of the entire scene to be drawn. If you want to draw geometry outside of the scene boundingbox then you run into problems with the z-buffer, because there is no colour (darker than black and brighter than white are not possible) that can possibly represent your pixels. So, yes, you do need to handle CalculateBoundingBox when you intend to draw depth-clipped geometry.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks, David

Your introduction to the z-buffer is quite thorough and clear. It almost cover everything I previously got confused when I need my things properly drawn in the viewport.

Thank you so much!

-Jerome

Hi Jerome,

if you on the other hand are meaning "how to deregister the paint delegate"?

That is then:

Rhino.Display.DisplayPipeline.DrawForeground -= new EventHandler<Rhino.Display.DrawEventArgs>(OnDrawForeground);

Delegates are considered equal if they point to the same instance (if any) and same method.

- Giulio
______________
giulio@mcneel.com

Thanks, Giulio

I added that deregister line in my code originally and perhaps not in a good place. Everytime I start my animation use a boolean toggle, it will clear those things drawn previously and start a new animation, which is the case I wanted. However, after I clicked into the c# component and clicked OK to exit, then I clicked the boolean toggle to start the animation, the old objects will be still there. Maybe there's something wrong with the logic of my code and I will look into it. 

Thank you for your help!

-Jerome

Yes, you might want to keep track of which one was the last callback that you registered, and before adding a new one, always de-register at least the previous one.

Does that make sense?

- Giulio
_______________
giulio@mcneel.com

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service