I’ve made multiple Hops and now I’ve made a script from them that I’m trying to run on Rhino Compute on a VM. It appears to work fine in Grasshopper connected to my VM but not when I call it via JavaScript. Can anyone see what’s potentially wrong (screenshot and code attached).
// Imports
function ProcessButton() {
const rhinoRef = useRef(null);
const definitionRef = useRef(null);
// ...
// Rhino setup
useEffect(() => {
(async () => {
const rhino = await window.rhino3dm();
rhinoRef.current = rhino;
RhinoCompute.url = import.meta.env.VITE_RHINO_COMPUTE_URL;
RhinoCompute.apiKey = import.meta.env.VITE_RHINO_COMPUTE_API_KEY;
RhinoCompute.authToken = import.meta.env.VITE_RHINO_COMPUTE_AUTH_TOKEN;
const definition = new Uint8Array(
await (await fetch("/definitions/building.gh")).arrayBuffer()
);
definitionRef.current = definition;
})();
}, []);
const handlePress = async () => {
// ...
// Using Rhino Compute
const trees = [new RhinoCompute.Grasshopper.DataTree("geojson")];
trees[0].append([0], [JSON.stringify(geojson)]);
console.log("Sending data to Rhino.Compute");
console.log("Trees:", trees);
const result = await RhinoCompute.Grasshopper.evaluateDefinition(
definitionRef.current,
trees
);
const meshes = Object.values(result.values[0].InnerTree)
.flat()
.map((entry) =>
rhinoRef.current.CommonObject.decode(JSON.parse(entry.data))
);
const loader = new THREE.BufferGeometryLoader();
const exporter = new OBJExporter();
const objs = meshes.map((mesh, index) => {
const geometry = loader.parse(mesh.toThreejsJSON());
const threeMesh = new THREE.Mesh(geometry);
threeMesh.name = `mesh-${index}`;
return exporter.parse(threeMesh);
});
console.log("OBJs:", objs);
setOBJs(objs);
};
return <Button onPress={handlePress}>Process</Button>;
}
export default ProcessButton;
Thanks!
