Sebas
(Sebas)
March 2, 2023, 10:17am
1
I’m using threejs to load some scan, but I want to send that geometry to Rhino compute with the GH definition using the component Get Geometry.
Anyone know how I have to parse my data from Threejs to send to that component?
I’m doing like that in my ts code:
// Convert Three.js mesh to Rhino mesh
const response = await this.rhinoService.solve(
[
{
name: “Option_1”,
value: 0
},
{
name: “geometry”,
value: this.mesh.geometry
}
]
);
Really thanks
fraguada
(Luis Fraguada)
March 2, 2023, 11:51am
2
You can do this with the rhino3dm.js library:
const rhinoMesh = rhino.Mesh.createFromThreejsJSON( { data: mesh.geometry } )
Where mesh
is a threejs mesh.
See: rhino-developer-samples/script.js at 7 · mcneel/rhino-developer-samples · GitHub
Sebas
(Sebas)
March 2, 2023, 2:17pm
3
Hi Luis,
I’ve tried that but wihout luck, It looks like the conversion to rhino mesh works:
But I still get the error on the rhino compute:
More code:
Blockquote
const response = await this.rhinoService.solve(
[{
name: “Elevar Arco Interno”,
value: this.productGenerator.archModification
},
{
name: “Texto”,
value: “Test \n test \n 1 \n 2”
},
{
name: “Tipo De Agujeros”,
value: 1
},
{
name: “Nervios Talón”,
value: 0
},
{
name: “geometry”,
value: rhino.Mesh.createFromThreejsJSON( { data: this.mesh.geometry } )
}
]
);
const responseJson = await response.json();
Solve function
async solve(inputs: { name: string, value: any } ) {
compute.url = “http://localhost:8081/ ”;
compute.apiKey = “”;
let GrasshopperFile = “https:xxxx.gh”;
// this.firstVersion.map((input) => {
// this.addDataTree(input.name, input.value);
// })
// Convert Three.js mesh to Rhino mesh
inputs.map((input) => {
this.addDataTree(input.name, input.value);
})
const RhinoResponse = await compute.Grasshopper.evaluateDefinition(GrasshopperFile, this.trees, false);
console.log('Received response from server:', RhinoResponse);
return RhinoResponse;
}
addDataTree(key, value): void {
let param = new compute.Grasshopper.DataTree(key)
param.append([0], Array.isArray(value) ? value : [value])
this.trees.push(param)
}
}
fraguada
(Luis Fraguada)
March 2, 2023, 2:43pm
4
You still need to format the result. Look at this example: rhino-developer-samples/script.js at 7 · mcneel/rhino-developer-samples · GitHub
convert from threejs to 3dm and encode:
const rhinoMesh = rhino.Mesh.createFromThreejsJSON( { data: mainSphere } )
const rhinoMeshData = JSON.stringify( rhinoMesh.encode() )
prep to send to compute:
// format data
let param1 = new RhinoCompute.Grasshopper.DataTree('mainMesh')
param1.append([0], [rhinoMeshData] )
...
// Add all params to an array
let trees = []
trees.push( param1 )
send to compute
const res = await RhinoCompute.Grasshopper.evaluateDefinition(definition, trees)
Sebas
(Sebas)
March 2, 2023, 3:20pm
5
Hi @fraguada , it looks now is doing somehting,
But I’m getting other erros:
When I use directly an stl from the local directory on grasshopper that doesn’t happens, and I’m loading the exact same file, but when I send it from threejs it fails and generates something weid:
Threejs result(with error, the object it’s strange because it finishes with errors)
Normal functionality:
What can cause that?
I think the mesh is not arriving correctly to rhino/GH because it’s generating this result because the mesh is empty.
Really appreciate your help!
fraguada
(Luis Fraguada)
March 2, 2023, 8:55pm
6
I’d need some sample geometry to attempt to diagnose this.
Sebas
(Sebas)
March 3, 2023, 6:27am
7
For sure,
Maybe the problem it’s because I use STL instead OBJ?
I’ve tried to just return the same mesh, ignoring the other processes and it still fails.
I attach you the STL
stl_convert.stl (1.9 MB)