Passing geometry from worker to program #75
Replies: 3 comments 5 replies
-
I'm still interested in learning more about this, but I came up with a solution which is to store the geometry in a library in the worker and pass back and forth IDs to access the library. It seems like it should work great. The only downside is that it means that I can't use multiple workers in parallel to speed up processing which would be nice :) |
Beta Was this translation helpful? Give feedback.
-
I think that your solution of storing geometries in the worker is the way to go unless you to learn a lot about both how webassembly memory works and workers. Note that you would need to learn the same things if you try to work in different workers. If this is the way you want to go anyway, I would start here and follow the links to emscripten stuff - and tell me about all the replicad bugs related to multithreading (because there will be some for sure). |
Beta Was this translation helpful? Give feedback.
-
I've narrowed down the issue with geometry being automatically deleted to a very specific case and I modified the replicad app example file to make a very minimal test case where it happens. replicad-app-example-minimal.zip Basically what it comes down to is that 3D geometry saves just fine, but 2D geometry is automatically deleted. The way the test case works is that cad.js just creates a 2d rounded rectangle. import { drawRoundedRectangle } from "replicad";
// The replicad code! Not much there!
export function drawBox(thickness) {
return drawRoundedRectangle(30, 50)
.sketchOnPlane();
} And then in worker.js we can write that 2d rectangle to a variable and then read it back: var savedRectangle = null; //This will be used to store the box
function writeBox(thickness) {
return started.then(() => {
savedRectangle = drawBox(thickness);
});
}
function readBox() {
return started.then(() => {
return {
faces: savedRectangle.extrude(5).mesh(),
edges: savedRectangle.extrude(5).meshEdges(),
};
});
} And it won't be there when we read it back: Now if we move the .extrude into the cad.js file so that we are saving 3D geometry to the variable everything works beautifully. What do you think? Is this the correct behavior, or a bug, or am I doing something silly? 🤔 |
Beta Was this translation helpful? Give feedback.
-
I'm working on a flow type interface for Replicad (think like how Grasshopper works for Rhino)
The basic app example was super helpful to get started (Thank You!), but now I've run into a more complex issue. I'm running into
Uncaught (in promise) TypeError: Unserializable return value
when I try to return geometry from the worker.It makes sense that geometry can't be serialized directly, but is there any way to pass geometry to and from the worker? The idea would be that each node on the graph could generate it's geometry and display values in the worker, but then hold onto that value locally to be passed around between nodes if that makes sense.
Basically my question is, Is there a way to serialize geometry?
JSON.stringify(sketchCircle(10))
or something?Beta Was this translation helpful? Give feedback.
All reactions