Grasshopper2 Fields

I know Grasshopper2 is still in Alpha stage. I’m not sure if it’s okay to report these minor bugs.

By the way, I ran into a quirky glitch in the SimplexScalarField. Looks like it’s having a bit of a hiccup with saving its data the right way. If you want to see it yourself, try adding a Field Iso Display to the canvas, then make a copy of it.
[video-to-gif output image]

This little bug seems to pop up for any field parameter containing internalised SimplexScalarField.

I’ve got another issue with the Field From Expressions component. It seems like the Ey and Ez inputs on this component are optional. I thought if you just put an expression in the Ex input, you’d get Scalar field. And if you fill in all three inputs, you’d get Vector Field, right? But, it looks like Field From Expressions always creates Vector Field no matter what.

I also tried creating an XyzExpressionField in the code. I noticed it has two constructors. I’m guessing the overload with just one argument is supposed to make a Scalar Field. But now I’m not sure if my guess is off or if there’s something else going on.

For a temporary fix, I’ve been using the Decompose Field component.

But just as an experiment, I tried creating an ExpressionField that only generates Scalar Field.

public class ExpressionField : ScalarField
{
    public ExpressionField(Expression exp) => Ex = exp;
    public ExpressionField(IReader reader) => Ex = reader.Storable<Expression>("Ex");
    public override void Store(IWriter writer) => writer.Storable("Ex", Ex);
    public override string Name => "Expression";
    public Expression Ex { get; }
    public override double ScalarAt(Point3d point) =>
        NumberLikeData.ToDouble(
        Ex.Evaluate(Resolver.Empty.Append("x", point.X).Append("y", point.Y).Append("z", point.Z)), 
        out var number) ? number : double.NaN;
}

4 Likes

Never to early to report stuff like that. I can repeat that simplex field bug, looking into it now.

Edit: fixed.

1 Like

Looking at the code trying to figure out what I was thinking. It definitely always outputs a vector field, but why on Earth did I make y and z optional?

Edit: I figured it out. The underlying field type can be both scalar or vector, but the component only makes vector fields. I should make another component which creates a scalar version out of expressions.

But I probably changed my mind in the middle of writing that and only half fixed it.

1 Like

I made all three inputs optional. If you do not specify an expression for a coordinate it just ends up being zero.

1 Like

That’s awesome! It’s gonna be one of the most useful fields components for me.