Grasshopper

algorithmic modeling for Rhino

Hi to all.

I am making a Grasshopper component with c# for KUKA APP. 

I've being reading several threads about display conduit and GH pipeline, but I can't resolve my problem. I try to rotate the model but models are created overlap. How can I refresh it?

Reference : http://mkmra2.blogspot.de/2014/02/rhino-3dm-file-load-draw-bake.html

It is code for conduit class .

namespace ROBOT
{
public class MyConduit : Rhino.Display.DisplayConduit
{
Rhino.FileIO.File3dmObjectTable drawObjs;
BoundingBox drawObjsBox;
public Plane drawPlane;
;
public MyConduit(Rhino.FileIO.File3dmObjectTable drawObjs)
{

this.drawObjs = drawObjs;
this.drawObjsBox = new BoundingBox(new Point3d(-1, -1, -1), new Point3d(1, 1, 1));

foreach (Rhino.FileIO.File3dmObject item in drawObjs)
{
BoundingBox bbox = item.Geometry.GetBoundingBox(true);
if (bbox.IsValid)
{
drawObjsBox.Union(bbox);
}
}
}


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

e.IncludeBoundingBox(drawObjsBox);
e.BoundingBox.Union(new Point3d(0, 0, 0));

}


protected override void CalculateBoundingBoxZoomExtents(CalculateBoundingBoxEventArgs e)
{

base.CalculateBoundingBoxZoomExtents(e);
e.IncludeBoundingBox(drawObjsBox);
}

protected override void PreDrawObjects(DrawEventArgs e)
{
base.PreDrawObjects(e);

DisplayMaterial _Material = new DisplayMaterial();


Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)), drawPlane);

e.Display.PushModelTransform(xform);

foreach (Rhino.FileIO.File3dmObject item in drawObjs)
{
if (item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Brep)
{
var rotated_geo = item.Geometry;

e.Display.DrawBrepShaded(rotated_geo as Brep, _Material);

}

}

e.Display.PopModelTransform();
}
}
}

Views: 912

Attachments:

Replies to This Discussion

If you're using Visual Studio to create your own GH_Component files, then I recommend using the Grasshopper display routines rather than implementing your own pipeline. This will make it easier to determine when you're supposed to draw your geometry, and it also helps prevent multiple instances of conduits. You'll need to override the ClippingBox, DrawViewportWires and DrawViewportMeshes methods on GH_Component to participate in the drawing.

If you're using the C# script components, then I recommend using the overloads the editor provides (same benefits as above). You can insert the correct overrides by clicking on the eye icon in the top right corner of the C# code editor.

If you don't want to rely on the Grasshopper preview conduit logic, then the simplest solution is to create a Rhino.Display.CustomDisplay object and populate it with your preview geometry. You can Clear() this instance every time you need to repopulate it, or you can create new instances.

I can't see the problem with your code above, I'm guessing you're creating new conduits all the time and not getting rid of the old ones? I would recommend drawing in PostDrawObjects, not PreDrawObjects, but that's a minor point.

This is risky:

Transform xform = Transform.PlaneToPlane(new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)), drawPlane);

The plane constructor which takes an origin point and a normal vector is underconstrained since it can rotate the plane around the z-axis freely. I'd recommend:

Transform xform = Transform.PlaneToPlane(Plane.WorldXY, drawPlane);

Is there a reason you're storing all your breps inside a File3dmObjectTable rather than just an array (or list) of breps? Is it to do with materials and colours?

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service