Geometry encoding for Compute

Could you show how you create this input data? I’ve got an error when I’m trying to pass Points using this method:

let x = new this._rhino.Point([-5, 5, 0]);
let dataD = {
      definition: "test.gh",
      inputs: { X: x.encode() },
    };

    let jsonData = JSON.stringify(dataD);

    const request = {
      method: "POST",
      body: jsonData,
      headers: { "Content-Type": "application/json" },
    };

When I create points as string like that:
'{"X":' + 80 + ',"Y":' + 200 + ',"Z":' + 0 + "}",
everything works fine…

Yes, that’s how you should be doing it.

Check out this sample: https://github.com/mcneel/rhino3dm/blob/master/docs/javascript/samples/compute/RESTHopper/DelaunayMesh/app.js#L41-L58

Could you tell me how I should create more sophisticated objects like (for example) curve, polyline, polygon, etc. Is there any documentation about that?

Most of what we have online can be found here: https://github.com/mcneel/rhino3dm/tree/master/docs/javascript/samples

Yes, this repo help me a lot, but I didn’t find info how to sens for example curve to rhino.compute as RH_IN parametr using this convention like in example with Pointa.

Curves derive from the GeometryBase class and thus needs to be encoded to be sent to compute. Points and other structs are sent a bit differently. We’re still trying to work this out so it is less confusing. For a curve you could do:

const curvePoints = new rhino.Point3dList()
curvePoints.add( 0, 0, 0 )
curvePoints.add( 5, 5, 0)
curvePoints.add( 10, -5, 0 )
curvePoints.add( 15, 5, 0 )
curvePoints.add( 20, 0, 0 )

const nurbsCurve = rhino.NurbsCurve.create( false, 3, curvePoints )

//this is what you should send to compute
const curveDataToCompute = JSON.stringify( nurbsCurve.encode() )
console.log( curveDataToCompute )

Thanks for advice! But… I think I’m close, but still Rhino Compute is throwing an error

Data which I’m sending to Rhino:

Can you provide example code and definition to test? Also, how are you running compute?

This is a more complete example that is working for me: https://github.com/mcneel/rhino3dm/tree/master/docs/javascript/samples/compute/RESTHopper/worm

Unfortunately I cannot show the definition file… but it turns out that your solution works! The problem is when I want to use the same code in a solution based on compute.appserver. So I will look for discrepancies in the coming days. Additionally, I had a problem on the Rhino Compute side, where I got an error:

Ok. It would have been good to know how you were calling compute. For appserver it would be similar:

Note: the worm.gh is in /src/files https://github.com/mcneel/compute.rhino3d.appserver/tree/examples/src/files

Hi Luis!

Your responses have been very helpful! Thanks.
Could you kindly advise on how to send an entire Rhino document to the evaluate definition?
In the image below, I hope to send a rhino document to the “RH_IN:rhinoFile” node.


The samples on Github first parses through the objects, and then sends extracted data to definition. I prefer to control this logic in Grasshopper instead.
image
My current setback is that the “RH_IN:rhinoFile” node is unable to accept the document that I’m feeding it. I’ve tried encoding and JSON.stringify() the rhino document, but I am still unsuccessful. You may reference my 2 failed attempts below.

How do I send a grasshopper definition an entire rhino model as input?

Thanks in advance,
Reggie

Have you seen this post?
You can probably read a rhino3dm file in a similar way with a headless document

2 Likes

Thanks Martin Borst! This might actually work. Thanks for forwarding this to me. Cheers!

Hey,

I have a similar problem. Since the thread is already some time old, I wanted to inquire whether there is anything new.

I have a computer server running that is passed a Grasshopper definition using Python. The Grasshopper definition is then supposed to process 3dm files automatically (the files have always the same structure).

Currently, I am trying to open the .3dm files using the rhino3dm library and pass the geometries to Compute like in the samples on Github.
However, I fail because these geometries are diverse (points, curves, and breps). In Grasshopper, I seem to be bound to use e.g. “Curve” components as RH_IN:xxx, for for curves.

Could the AppServer solve this problem or do you have another idea?

Maybe I misunderstand your actual problem, but what about using a geometry component instead of a curve component for your “RH_IN”?

Hey Martin,
Thank you for your fast reply.

Of course, that was my first idea too. However, no geometry is passed to the grasshopper definition at all, and no error message is returned. That’s why I thought that the geometry component is not a valid input.

Johannes

Maybe I’m missing the point of the question, but in general, rhino.compute runs a headless version of Rhino which means there is no existing document to pull geometry from. If you want to include geometry (and you’re using Hops) then I would recommend using the Get Geometry component (Params/Util). This component (when used in Hops) will serialize the geometry that gets passed into the input as a JSON string… which compute will then deserialize and rebuild as actual geometry. So, that is typically the way this would get handled. Does that help? Or did I misunderstand the question. Can you provide a simplified example of where things are failing for you?

1 Like