I’m trying to program a curve based object in Rhino, using the CustomCurveObject abstract class as base class. It seems promising, until a user for example runs the command Flip on the custom curve object in Rhino. Then, the custom object is deleted and a new CurveObject is created instead. It does not recreate an object of the same custom class.
What’s the best way of solving this issue? I did create an event listener which intersects the delete and add events, to create the CustomCurveObject instead of the CurveObject, but it seems a bit of a hack. I hope you have a better solution.
If you really need a custom curve object, then consider implementing in in C++. Custom objects, exposed in RhinoCommon, are not nearly as full-featured. We hope to remedy this in the Rhino 8.x timeframe.
Thanks for the feedback. My plan was to use CustomCurveObject to create a simple section tool. The idea was to put at a lot of the functionality into this object, such as updates on events and display of graphics and so on. In the end I gave up this approach, but still use UserData to keep track of and update a clipping plane per section.
@dale Has there been any significant development on custom objects in rhinocommon for R8 yet?
We’d really like to improve the behavior of our C# custom objects without needing to move to cpp. We have a custom curve object (that represents an extrusion/beam) and we use a display conduit to draw a mesh along the curve. It would be great to be able to make this display mesh somewhat interactive (select the curve object by clicking on the display mesh, snap to vertices on the display mesh, etc.).
Thanks @dale, OnPick was exactly what I was looking for. We have this working great now, with one exception–we can’t figure out how to handle occlusion.
Is there an efficient way within RhinoCommon to determine if a point is occluded in a view?
Or, alternatively, get the z depth at a screen coordinate? We can create a ZBufferCapture, but that’s not a quick thing to do inside the OnPick method.
@dale Another issue we’ve noticed. Our picking appears to be working well. But some operations on the CustomCurveObject after picking do not work (Trim, for example, does not have an affect on the CustomCurveObject when our OnPick override is implemented). Do you see any issues with this implementation:
protected override IEnumerable<ObjRef> OnPick(PickContext context)
{
var viewport = context.View.MainViewport;
var shaded = viewport.DisplayMode.SupportsShading;
var meshPickStyle = shaded ? PickContext.MeshPickStyle.ShadedModePicking : PickContext.MeshPickStyle.WireframePicking;
if (context.PickFrustumTest(this.MemberMesh, meshPickStyle, out Point3d hitPoint, out double depth, out double distance, out PickContext.MeshHitFlag hitFlag, out int hitIndex))
{
return [new ObjRef(this)];
}
return base.OnPick(context);
}