Grasshopper

algorithmic modeling for Rhino

Hi all, 

If I am using a C# scripting component, and I have inserted the preview overrides, I have figured out how to draw shapes within those methods. What I can't figure out how to do is use some data that was brought in with the RunScript method. Say, for instance, I had a bunch of points brought in as an Input Parameter, but I wanted to use some of these points in the Preview Overrides? Because RunScript is private, I can't get information over from one to the other. 

Preemptive thanks.

Views: 689

Replies to This Discussion

You have to declare a class level variable to cache all the data you wish to draw. You wipe these variables using the Before hook, then you fill up these variables during all RunScript calls, and finally access them during the display hooks. See attached.

Attachments:

Thanks, David! Awesome, as always! Your help is always greatly appreciated.  

One last thing, what is the point of the clipping box/bounding box? If I take your script but return an empty bounding box, as is the default for preview overrides, it doesn't seem to effect what is showing up in Rhino. 

3D drawing apis like OpenGL (what Rhino uses) and DirectX figure out what objects obscure what other objects by maintaining a depth buffer (or 'z-buffer'). Each pixel drawn into a viewport is depth-tested against the current pixel depth, and if it turns out to be closer to the camera then it gets drawn, if not, it gets omitted.

The depth-buffer can be thought of as a greyscale image, with black being the furthest away and white being the closest to the camera. Because there are only a limited number of distinct greys in between black and white, it is important that the black and the white are 'scaled' to tightly fit the actual geometry we wish to draw. However if we set the black and white distances too tight, then some geometry will be blacker than black (ie. further away than expected) or whiter than white (ie. closer than expected) and it won't get drawn at all.

Every component which draws preview geometry must also provide the bounding box within which that geometry will be drawn, otherwise near or far clipping mistakes will be made. In this particular case it may work because the points that serve as inputs for our circles have the same clipping box. However if we were to draw the circles not facing the camera but just flat, then you'd start to get clipping errors.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service