Is it possible to make Grasshopper preview a custom data type that can cast itself to geometry automatically?
The custom type, let’s call it CustomType
is wrapped inside a GH_Goo<CustomType>
which stores among its data a reference to a Curve
.
Here is the code I use to cast this to a curve, which works if it is connected to something that expects curves, but it does not preview the curves in Rhino’s viewport.
private Curve m_storedCurve;
public override bool CastTo<Q>(ref Q target) {
if (typeof(Q).IsAssignableFrom(typeof(CustomType))) {
if (Value is null)
target = default(Q);
else
target = (Q)(object)Value;
return true;
}
if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) {
if (Value is null)
target = default(Q);
else
target = (Q)(object)new GH_Curve(m_storedCurve);
return true;
}
target = default(Q);
return false;
}
public override bool CastFrom(object source) {
if (source is null) return false;
if (source is CustomType) {
this.Value = (CustomType)source;
return true;
}
return false;
}
Is it possible to make this preview automatically without drawing the curves myself in the DrawViewportWires
method?