|
1 | | -import { MathBitByBit, Logic, Lists, TextBitByBit, Vector, Point, Transforms, Color, GeometryHelper, Line, Polyline } from "@bitbybit-dev/base"; |
2 | | -import { JSONBitByBit, CSVBitByBit, Verb } from "@bitbybit-dev/core"; |
3 | | -import { Jscad } from "@bitbybit-dev/jscad"; |
4 | | -import { ManifoldService } from "@bitbybit-dev/manifold"; |
5 | | -import { OCCTService, OccHelper, VectorHelperService, ShapesHelperService } from "@bitbybit-dev/occt"; |
6 | | -import Module from "manifold-3d"; |
7 | | -import { JSONPath } from "jsonpath-plus"; |
8 | | -import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/node.js"; |
9 | | -import * as vrb from "verb-nurbs-web"; |
| 1 | +import { createRequire } from "module"; |
| 2 | +import { OCCTService } from "@bitbybit-dev/occt/lib/occ-service.js"; |
| 3 | +import { OccHelper } from "@bitbybit-dev/occt/lib/occ-helper.js"; |
| 4 | +import { VectorHelperService } from "@bitbybit-dev/occt/lib/api/vector-helper.service.js"; |
| 5 | +import { ShapesHelperService } from "@bitbybit-dev/occt/lib/api/shapes-helper.service.js"; |
| 6 | +import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/index.js"; |
| 7 | + |
| 8 | +const require = createRequire(import.meta.url); |
10 | 9 |
|
11 | 10 | export class BitByBitBase { |
12 | | - public math: MathBitByBit; |
13 | | - public logic: Logic; |
14 | | - public lists: Lists; |
15 | | - public json: JSONBitByBit; |
16 | | - public csv: CSVBitByBit; |
17 | | - public vector: Vector; |
18 | | - public point: Point; |
19 | | - public line: Line; |
20 | | - public transforms: Transforms; |
21 | | - public polyline: Polyline; |
22 | | - public verb: Verb; |
23 | | - public jscad: Jscad; |
24 | | - public manifold: ManifoldService; |
25 | | - public text: TextBitByBit; |
26 | | - public occt: OCCTService; |
27 | | - public color: Color; |
| 11 | + public occt!: OCCTService; |
28 | 12 |
|
29 | 13 | constructor() { |
30 | 14 | } |
31 | 15 |
|
32 | 16 | async init() { |
33 | | - const occ = await initOpenCascade(); |
34 | | - const s = await import("@bitbybit-dev/jscad/jscad-generated.js"); |
35 | | - const jscad = s.default(); |
36 | | - this.jscad = new Jscad(jscad); |
37 | | - const wasm = await Module({ |
38 | | - locateFile: () => { |
39 | | - return "./manifold-3-3-2.wasm"; |
40 | | - }, |
| 17 | + // For Node.js, we need to specify the path to the WASM file |
| 18 | + const wasmPath = require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.5e93f201.wasm"); |
| 19 | + |
| 20 | + const occ = await initOpenCascade({ |
| 21 | + locateFile: (path: string) => { |
| 22 | + if (path.endsWith(".wasm")) { |
| 23 | + return wasmPath; |
| 24 | + } |
| 25 | + return path; |
| 26 | + } |
41 | 27 | }); |
42 | | - wasm.setup(); |
43 | | - this.manifold = new ManifoldService(wasm); |
44 | | - const geometryHelper = new GeometryHelper(); |
45 | | - this.math = new MathBitByBit(); |
46 | | - this.lists = new Lists(); |
47 | | - this.vector = new Vector(this.math, geometryHelper); |
48 | | - this.color = new Color(this.math); |
49 | | - this.transforms = new Transforms(this.vector, this.math); |
50 | | - this.point = new Point(geometryHelper, this.transforms, this.vector, this.lists); |
51 | | - const verb = { geom: vrb.geom, core: vrb.core }; |
52 | | - this.verb = new Verb({ verb } as any, geometryHelper, this.math); |
53 | | - this.line = new Line(this.vector, this.point, geometryHelper); |
54 | | - this.polyline = new Polyline(this.vector, this.point, this.line, geometryHelper); |
| 28 | + |
55 | 29 | const vecHelper = new VectorHelperService(); |
56 | 30 | const shapesHelper = new ShapesHelperService(); |
57 | 31 | const occHelper = new OccHelper(vecHelper, shapesHelper, occ); |
58 | 32 | this.occt = new OCCTService(occ, occHelper); |
59 | | - this.logic = new Logic(); |
60 | | - this.json = new JSONBitByBit({ jsonpath: JSONPath } as any); |
61 | | - this.csv = new CSVBitByBit(); |
62 | | - this.text = new TextBitByBit(this.point); |
63 | 33 | } |
64 | 34 | } |
0 commit comments