Grasshopper

algorithmic modeling for Rhino

Custom display (seemingly selective drawing of breps / curves / polyline curves) c#

Hello,

I have a stubborn problem that I need some help overcoming.  

I am building a custom display to show graphics over geometry.  I have been able to successfully build a component that updates on changes in the viewport camera location, zoom, etc. The behavior isn't as smooth as I'd like but it's ok. The problem comes in drawing some figures. It can successfully draw draw shaded 3d geometry from a model, brep edges from a model, points, and circles.

I am receiving strange behavior when trying to draw additional breps that are created on a custom plane (near - but in front of the camera location).  The plane that I have built is reliable and will constantly depict geometry like points or circles.  But it won't draw polylines, curves or breps, even when created from points that sit on the plane and render in the custom view.

Here is a good chunk of the code:

public override void DrawViewportMeshes(IGH_PreviewArgs args)
{

// Material definitions.

// Geometry drawing

//Brep geometry from model sits here inside a foreach loop. The code seems to work fine - all geometry draws relaible. The code used to draw a brep face is:

args.Display.DrawBrepShaded(element, material);

// Graphics drawing

// This sits inside a boolean toggle to switch on and off - the sample code that works reliably is. As mentioned point and circle drawing is fine. Code examples are:

args.Display.DrawPoint(displayAnchor,System.Drawing.Color.FromArgb(225, 0, 200));

args.Display.DrawCircle(cg,System.Drawing.Color.FromArgb(225, 0, 200));

// Problems emerge when drawing breps, be they single or multiple. Looping through lists or regular singular instances don't make a difference. Here is the code:

args.Display.DrawBrepShaded(graphicelelemnt, graphicmaterial);

}

What am I missing here? Why isn't this working?

I am working in Visual Studio or the native C# GH component - same results.

I test the geometry to see if it exists (it does) through a standard output (for example "A = ..." in the c# component or through a DA in the VS environment. The geometry is good it just won't draw through the IGH.

Views: 1744

Replies to This Discussion

Any examples that don't work? Might be lots easier to debug. Other than that, did you remember to add your geometry to the Viewbox boundingbox?


Are you also sure that your geometry is in front of the near frustrum clipping plane?

Arend,

I now see that I am getting a display pipeline error and I have not added geometry to the viewbox boundingbox. This is actually the first I've heard of the bounding box property. It hasn't appeared in any of the other online examples... Is it possible to point me to a correct example that I might apply to this work?  

I will post my code later today when I have some time to clean everything up - I will build a new clean file for you and the forum.

Thank you for the reply.

Arend,

Here is the clean file.  I would appreciate your help with finding an example of how to add geometry to the building box.

Attachments:

There's a lot of weird code there and since I don't know exactly what you're trying to draw, I figured I'd write up an example.

The attached C# component render points as crosses in 3D (i.e. they need to taken into account for the clipping box), and polylines and circles on the camera near-plane (i.e. they don't matter for the clipping).

I'm just populating a bunch of lists with brep vertices. If the vertex has a z>0.0 then a large circle is drawn, otherwise a small circle is drawn.

+ Your code has a lot of class level variables. Sometimes you need that, but in this case many of them can be converted to local variables and function arguments. 

+ You're overriding DrawViewportMeshes, but you're drawing wires in that method. You'll get a better result if you draw wires and points and text in DrawViewportWires instead.

+ You call this:

owner.ExpireSolution(true);

owner.OnPingDocument();

at the end of DrawViewportMeshes(). That's a big no-no. You didn't change the solution with your preview drawing so there's no need to start another solution. This is probably what's causing the bad performance and flickering in your code.

OnPingDocument() is only useful to call if you do something with the return value, there's no point in calling it just like that.

+ You seem to be using camera location and camera direction as a shorthand for figuring out projective geometry. This is insufficient. The transformation of world XYZ points to screen XY points is a 4x4 matrix which cannot be represented solely by as point and a vector. You should use the methods on the Viewport class for mapping points from world to screen. These methods work no matter what the projection is (parallel, perspective, two-point perspective...)

+ Your variable and function naming is not very helpful. Although I applaud the verbosity in your naming and you do a good job of using verbs in your method names, you can still make your code more readable by using different casing patterns. The .NET style guides recommend using lowercase names for variables with uppercase for secondary words (radius, circleRadius, offset, offsetDistance) and uppercasing the first letter of every word in methods (GetRadius, ComputeRadius, OffsetRadius). Although it is not recommended by Microsoft, I prefer to prefix all class level variables with an underbar. 

Hope this helps,

David

Attachments:

David,

I am sorry for not replying earlier to your excellent post - the description and code provided were very helpful!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service