RepliCAD
46 строк · 1.2 Кб
1import opencascade from "replicad-opencascadejs/src/replicad_single.js";2import opencascadeWasm from "replicad-opencascadejs/src/replicad_single.wasm?url";3import { setOC } from "replicad";4import { expose } from "comlink";5
6// We import our model as a simple function
7import { drawBox } from "./cad";8
9// This is the logic to load the web assembly code into replicad
10let loaded = false;11const init = async () => {12if (loaded) return Promise.resolve(true);13
14const OC = await opencascade({15locateFile: () => opencascadeWasm,16});17
18loaded = true;19setOC(OC);20
21return true;22};23const started = init();24
25function createBlob(thickness) {26// note that you might want to do some caching for more complex models27return started.then(() => {28return drawBox(thickness).blobSTL();29});30}
31
32function createMesh(thickness) {33return started.then(() => {34const box = drawBox(thickness);35// This is how you get the data structure that the replica-three-helper36// can synchronise with three BufferGeometry37return {38faces: box.mesh(),39edges: box.meshEdges(),40};41});42}
43
44// comlink is great to expose your functions within the worker as a simple API
45// to your app.
46expose({ createBlob, createMesh });47