G2 Need for Brep-related Tools

Having been testing Grasshopper2 for a few weeks, one of the more obvious gaps I’ve encountered is the support for Brep objects.

  • On the UI/component side, Brep operations are largely missing - including the basic Brep Param type along with the familiar operations like ‘Deconstruct Brep’ or Join.
  • On the developer side, inputs and outputs to a component plugin cannot directly specify a Brep/Polysurface object type.

Presently, the following workaround for using ‘generic’ inputs/outputs works okay. To process a Brep in some way, you need to cast the generic object to a Brep and go from there.

Add a generic input

protected override void AddInputs(InputAdder inputs)
{
    inputs.AddGeneric("Brep", "B", "A Brep input.");
}

Cast the generic object to Brep during process…

protected override void Process(IDataAccess access)
{
    access.GetItem(0, out object obj);

    Brep brep = (Brep)obj;
    // then do stuff to the brep 
}

For what it’s worth: the Deconstruct Brep is Surface Explode

I don’t think there is anything like Surface Join yet.

Ah yes - indeed. Thanks for that. I remember when it was originally called ‘Explode’ in Grasshopper. Then it was renamed as “Deconstruct Brep” in later versions.

I also see now that that the “Surface” parameter object is intended to be used for Breps. So perhaps a nomenclature alignment would be helpful for G2 and Rhino: The ‘Surface’ type is a distinct type from a ‘Brep’ or a ‘Polysurface’ in Rhino and the Rhinocommon SDK.

When coding with G2, this can be especially confusing…

Say we set an input using AddSurface… (which we can now assume accepts Breps)

protected override void AddInputs(InputAdder inputs)
{
     inputs.AddSurface("Some Surface", "S", "An input surface.");
}

If the input uses AddSurface but access.GetItem attempts to cast it as Surface (the Rhino type), the component will fail to collect that data.

protected override void Process(IDataAccess access)
{
     access.GetItem(0, out Surface obj);
      
     access.SetItem(0, srf);
}

So instead, access.GetItem would need to assume a Brep (even though G2 nomenclature considers Breps as Surfaces)

protected override void Process(IDataAccess access)
{
     access.GetItem(0, out Brep obj);
      
     access.SetItem(0, srf);
}

1 Like