RepliCAD

Форк
0
46 строк · 1.2 Кб
1
import opencascade from "replicad-opencascadejs/src/replicad_single.js";
2
import opencascadeWasm from "replicad-opencascadejs/src/replicad_single.wasm?url";
3
import { setOC } from "replicad";
4
import { expose } from "comlink";
5

6
// We import our model as a simple function
7
import { drawBox } from "./cad";
8

9
// This is the logic to load the web assembly code into replicad
10
let loaded = false;
11
const init = async () => {
12
  if (loaded) return Promise.resolve(true);
13

14
  const OC = await opencascade({
15
    locateFile: () => opencascadeWasm,
16
  });
17

18
  loaded = true;
19
  setOC(OC);
20

21
  return true;
22
};
23
const started = init();
24

25
function createBlob(thickness) {
26
  // note that you might want to do some caching for more complex models
27
  return started.then(() => {
28
    return drawBox(thickness).blobSTL();
29
  });
30
}
31

32
function createMesh(thickness) {
33
  return started.then(() => {
34
    const box = drawBox(thickness);
35
    // This is how you get the data structure that the replica-three-helper
36
    // can synchronise with three BufferGeometry
37
    return {
38
      faces: box.mesh(),
39
      edges: 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.
46
expose({ createBlob, createMesh });
47

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.