@bitbybit-dev/create-app 1.3.2 → 1.4.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -124
- package/dist/index.js +253 -21
- package/dist/index.js.map +1 -1
- package/dist/scaffold.d.ts +30 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +107 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +4 -3
- package/src/index.test.ts +309 -8
- package/src/index.ts +285 -24
- package/src/scaffold.test.ts +177 -0
- package/src/scaffold.ts +99 -0
- package/templates/_agent/AGENTS.md +39 -0
- package/templates/_agent/CLAUDE.md +1 -0
- package/templates/_agent/_dot-cursor/mcp.json +5 -0
- package/templates/_agent/_dot-gitignore +7 -0
- package/templates/_agent/_dot-mcp.json +5 -0
- package/templates/_agent/_dot-vscode/mcp.json +5 -0
- package/templates/apps/drone-assembly/AGENTS.section.md +20 -0
- package/templates/apps/drone-assembly/README.md +35 -0
- package/templates/apps/drone-assembly/eslint.config.js +47 -0
- package/templates/apps/drone-assembly/index.html +17 -0
- package/templates/apps/drone-assembly/package.json +31 -0
- package/templates/apps/drone-assembly/public/favicon.ico +0 -0
- package/templates/apps/drone-assembly/public/logo.png +0 -0
- package/templates/apps/drone-assembly/scripts/smoke.ts +172 -0
- package/templates/apps/drone-assembly/src/assembly.ts +99 -0
- package/templates/apps/drone-assembly/src/exports.ts +10 -0
- package/templates/apps/drone-assembly/src/kernel.ts +14 -0
- package/templates/apps/drone-assembly/src/main.ts +298 -0
- package/templates/apps/drone-assembly/src/materials.ts +58 -0
- package/templates/apps/drone-assembly/src/model.ts +280 -0
- package/templates/apps/drone-assembly/src/parts.ts +343 -0
- package/templates/apps/drone-assembly/src/style.css +219 -0
- package/templates/apps/drone-assembly/src/ui.ts +180 -0
- package/templates/apps/drone-assembly/src/vite-env.d.ts +1 -0
- package/templates/apps/drone-assembly/tsconfig.json +29 -0
- package/templates/apps/laser-cut-box/AGENTS.section.md +17 -0
- package/templates/apps/laser-cut-box/README.md +34 -0
- package/templates/apps/laser-cut-box/eslint.config.js +47 -0
- package/templates/apps/laser-cut-box/index.html +17 -0
- package/templates/apps/laser-cut-box/package.json +30 -0
- package/templates/apps/laser-cut-box/public/favicon.ico +0 -0
- package/templates/apps/laser-cut-box/public/logo.png +0 -0
- package/templates/apps/laser-cut-box/scripts/smoke.ts +106 -0
- package/templates/apps/laser-cut-box/src/exports.ts +28 -0
- package/templates/apps/laser-cut-box/src/main.ts +176 -0
- package/templates/apps/laser-cut-box/src/model.ts +92 -0
- package/templates/apps/laser-cut-box/src/panels.ts +229 -0
- package/templates/apps/laser-cut-box/src/style.css +223 -0
- package/templates/apps/laser-cut-box/src/ui.ts +136 -0
- package/templates/apps/laser-cut-box/src/vite-env.d.ts +1 -0
- package/templates/apps/laser-cut-box/tsconfig.json +29 -0
- package/templates/apps/product-configurator/AGENTS.section.md +19 -0
- package/templates/apps/product-configurator/README.md +33 -0
- package/templates/apps/product-configurator/eslint.config.js +47 -0
- package/templates/apps/product-configurator/index.html +17 -0
- package/templates/apps/product-configurator/package.json +30 -0
- package/templates/apps/product-configurator/public/favicon.ico +0 -0
- package/templates/apps/product-configurator/public/logo.png +0 -0
- package/templates/apps/product-configurator/scripts/smoke.ts +69 -0
- package/templates/apps/product-configurator/src/catalog.ts +56 -0
- package/templates/apps/product-configurator/src/exports.ts +19 -0
- package/templates/apps/product-configurator/src/main.ts +134 -0
- package/templates/apps/product-configurator/src/model.ts +153 -0
- package/templates/apps/product-configurator/src/style.css +177 -0
- package/templates/apps/product-configurator/src/ui.ts +150 -0
- package/templates/apps/product-configurator/src/vite-env.d.ts +1 -0
- package/templates/apps/product-configurator/tsconfig.json +29 -0
- package/templates/apps/sheet-metal-unfold/AGENTS.section.md +26 -0
- package/templates/apps/sheet-metal-unfold/README.md +41 -0
- package/templates/apps/sheet-metal-unfold/backend/_dot-env.example +5 -0
- package/templates/apps/sheet-metal-unfold/backend/eslint.config.js +47 -0
- package/templates/apps/sheet-metal-unfold/backend/package.json +28 -0
- package/templates/apps/sheet-metal-unfold/backend/scripts/smoke.ts +52 -0
- package/templates/apps/sheet-metal-unfold/backend/src/app.ts +65 -0
- package/templates/apps/sheet-metal-unfold/backend/src/cloud.ts +42 -0
- package/templates/apps/sheet-metal-unfold/backend/src/index.ts +13 -0
- package/templates/apps/sheet-metal-unfold/backend/tsconfig.build.json +9 -0
- package/templates/apps/sheet-metal-unfold/backend/tsconfig.json +27 -0
- package/templates/apps/sheet-metal-unfold/frontend/eslint.config.js +47 -0
- package/templates/apps/sheet-metal-unfold/frontend/index.html +17 -0
- package/templates/apps/sheet-metal-unfold/frontend/package.json +30 -0
- package/templates/apps/sheet-metal-unfold/frontend/public/favicon.ico +0 -0
- package/templates/apps/sheet-metal-unfold/frontend/public/logo.png +0 -0
- package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +84 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/cloud-access.ts +37 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/exports.ts +10 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/flat.ts +71 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/main.ts +193 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/model.ts +166 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/style.css +291 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/ui.ts +150 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/vite-env.d.ts +1 -0
- package/templates/apps/sheet-metal-unfold/frontend/tsconfig.json +29 -0
- package/templates/apps/sheet-metal-unfold/frontend/vite.config.ts +9 -0
- package/templates/apps/sheet-metal-unfold/package.json +18 -0
- package/templates/apps/step-to-gltf-cli/AGENTS.section.md +20 -0
- package/templates/apps/step-to-gltf-cli/README.md +34 -0
- package/templates/apps/step-to-gltf-cli/eslint.config.js +47 -0
- package/templates/apps/step-to-gltf-cli/package.json +26 -0
- package/templates/apps/step-to-gltf-cli/samples/bracket.step +2545 -0
- package/templates/apps/step-to-gltf-cli/scripts/smoke.ts +49 -0
- package/templates/apps/step-to-gltf-cli/src/cli.ts +106 -0
- package/templates/apps/step-to-gltf-cli/src/cloud.ts +34 -0
- package/templates/apps/step-to-gltf-cli/src/convert.ts +65 -0
- package/templates/apps/step-to-gltf-cli/src/kernel.ts +14 -0
- package/templates/apps/step-to-gltf-cli/tsconfig.json +27 -0
- package/templates/cloud/AGENTS.section.md +22 -0
- package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +22 -50
- package/templates/cloud/backends/dotnet-rest/Program.cs +1 -11
- package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +4 -1
- package/templates/cloud/backends/hono-rest/eslint.config.js +47 -0
- package/templates/cloud/backends/hono-rest/package.json +11 -4
- package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +34 -45
- package/templates/cloud/backends/hono-rest/src/index.ts +1 -11
- package/templates/cloud/backends/hono-rest/tsconfig.json +19 -8
- package/templates/cloud/backends/hono-sdk/eslint.config.js +47 -0
- package/templates/cloud/backends/hono-sdk/package.json +12 -5
- package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +6 -37
- package/templates/cloud/backends/hono-sdk/src/index.ts +1 -12
- package/templates/cloud/backends/hono-sdk/tsconfig.json +19 -8
- package/templates/cloud/backends/nodejs-rest/eslint.config.js +47 -0
- package/templates/cloud/backends/nodejs-rest/package.json +12 -5
- package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +6 -35
- package/templates/cloud/backends/nodejs-rest/src/index.ts +6 -16
- package/templates/cloud/backends/nodejs-rest/tsconfig.build.json +9 -0
- package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -7
- package/templates/cloud/backends/nodejs-sdk/eslint.config.js +47 -0
- package/templates/cloud/backends/nodejs-sdk/package.json +14 -7
- package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +8 -33
- package/templates/cloud/backends/nodejs-sdk/src/index.ts +5 -16
- package/templates/cloud/backends/nodejs-sdk/tsconfig.build.json +9 -0
- package/templates/cloud/backends/nodejs-sdk/tsconfig.json +19 -9
- package/templates/cloud/frontend/eslint.config.js +50 -0
- package/templates/cloud/frontend/index.html +3 -1
- package/templates/cloud/frontend/package.json +13 -4
- package/templates/cloud/frontend/public/favicon.ico +0 -0
- package/templates/cloud/frontend/public/logo.png +0 -0
- package/templates/cloud/frontend/src/App.tsx +11 -9
- package/templates/cloud/frontend/src/api.ts +31 -0
- package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +28 -25
- package/templates/cloud/frontend/src/components/Header.tsx +4 -2
- package/templates/cloud/frontend/src/components/Tabs.tsx +4 -3
- package/templates/cloud/frontend/src/components/Viewer.tsx +57 -77
- package/templates/cloud/frontend/src/main.tsx +6 -1
- package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +65 -73
- package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +82 -83
- package/templates/cloud/frontend/src/vite-env.d.ts +1 -0
- package/templates/cloud/frontend/tsconfig.json +19 -7
- package/templates/vite/babylonjs/typescript/AGENTS.section.md +13 -0
- package/templates/vite/babylonjs/typescript/eslint.config.js +47 -0
- package/templates/vite/babylonjs/typescript/index.html +4 -2
- package/templates/vite/babylonjs/typescript/package.json +14 -4
- package/templates/vite/babylonjs/typescript/public/favicon.ico +0 -0
- package/templates/vite/babylonjs/typescript/public/logo.png +0 -0
- package/templates/vite/babylonjs/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/babylonjs/typescript/src/main.ts +8 -17
- package/templates/vite/babylonjs/typescript/src/model.ts +24 -0
- package/templates/vite/babylonjs/typescript/tsconfig.json +16 -12
- package/templates/vite/playcanvas/typescript/AGENTS.section.md +13 -0
- package/templates/vite/playcanvas/typescript/eslint.config.js +47 -0
- package/templates/vite/playcanvas/typescript/index.html +4 -2
- package/templates/vite/playcanvas/typescript/package.json +14 -4
- package/templates/vite/playcanvas/typescript/public/favicon.ico +0 -0
- package/templates/vite/playcanvas/typescript/public/logo.png +0 -0
- package/templates/vite/playcanvas/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/playcanvas/typescript/src/main.ts +11 -22
- package/templates/vite/playcanvas/typescript/src/model.ts +24 -0
- package/templates/vite/playcanvas/typescript/tsconfig.json +16 -12
- package/templates/vite/threejs/typescript/AGENTS.section.md +13 -0
- package/templates/vite/threejs/typescript/eslint.config.js +47 -0
- package/templates/vite/threejs/typescript/index.html +4 -2
- package/templates/vite/threejs/typescript/package.json +16 -6
- package/templates/vite/threejs/typescript/public/favicon.ico +0 -0
- package/templates/vite/threejs/typescript/public/logo.png +0 -0
- package/templates/vite/threejs/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/threejs/typescript/src/main.ts +11 -22
- package/templates/vite/threejs/typescript/src/model.ts +24 -0
- package/templates/vite/threejs/typescript/tsconfig.json +16 -12
- package/templates/vite/babylonjs/typescript/public/vite.svg +0 -1
- package/templates/vite/playcanvas/typescript/public/vite.svg +0 -1
- package/templates/vite/threejs/typescript/public/vite.svg +0 -1
- /package/templates/cloud/backends/dotnet-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/hono-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/hono-sdk/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/nodejs-rest/{.env.example → _dot-env.example} +0 -0
- /package/templates/cloud/backends/nodejs-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/nodejs-sdk/{.env.example → _dot-env.example} +0 -0
- /package/templates/cloud/backends/nodejs-sdk/{_gitignore → _dot-gitignore} +0 -0
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
interface Download {
|
|
4
|
-
format: string;
|
|
5
|
-
downloadUrl: string;
|
|
6
|
-
filename: string;
|
|
7
|
-
}
|
|
1
|
+
import { useEffect, useState, type ReactElement } from "react";
|
|
2
|
+
import { downloadsOf, readJson, stringOf, type Download } from "../api";
|
|
8
3
|
|
|
9
4
|
interface PipelineResult {
|
|
10
5
|
taskId?: string;
|
|
11
|
-
|
|
6
|
+
status?: string;
|
|
12
7
|
downloadUrl?: string;
|
|
8
|
+
downloads: Download[];
|
|
9
|
+
raw: Record<string, unknown>;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
interface PipelinesPanelProps {
|
|
@@ -18,123 +15,126 @@ interface PipelinesPanelProps {
|
|
|
18
15
|
onLoadModel: (url: string) => void;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
function
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
function pipelineResultOf(data: Record<string, unknown>): PipelineResult {
|
|
19
|
+
const result: PipelineResult = { downloads: downloadsOf(data["downloads"]), raw: data };
|
|
20
|
+
const taskId = stringOf(data, "taskId");
|
|
21
|
+
if (taskId !== undefined) result.taskId = taskId;
|
|
22
|
+
const status = stringOf(data, "status");
|
|
23
|
+
if (status !== undefined) result.status = status;
|
|
24
|
+
const downloadUrl = stringOf(data, "downloadUrl");
|
|
25
|
+
if (downloadUrl !== undefined) result.downloadUrl = downloadUrl;
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function findGlbUrl(result: PipelineResult): string | undefined {
|
|
30
|
+
const glb = result.downloads.find((download) => download.format === "glb" || download.format === "gltf");
|
|
31
|
+
return glb?.downloadUrl ?? result.downloadUrl ?? result.downloads[0]?.downloadUrl;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
function setTaskInUrl(taskId: string) {
|
|
34
|
+
function setTaskInUrl(taskId: string): void {
|
|
27
35
|
const url = new URL(window.location.href);
|
|
28
36
|
url.searchParams.set("pipeline-task", taskId);
|
|
29
37
|
window.history.replaceState({}, "", url.toString());
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
const taskFromUrl = (): string | null => new URLSearchParams(window.location.search).get("pipeline-task");
|
|
41
|
+
|
|
42
|
+
export function PipelinesPanel({ active, modelLoaded, onLoadModel }: PipelinesPanelProps): ReactElement {
|
|
43
|
+
const [existingTaskId] = useState(taskFromUrl);
|
|
44
|
+
const [status, setStatus] = useState(existingTaskId ? "Fetching the existing pipeline result..." : "");
|
|
34
45
|
const [error, setError] = useState(false);
|
|
35
|
-
const [loading, setLoading] = useState(
|
|
46
|
+
const [loading, setLoading] = useState(existingTaskId !== null);
|
|
36
47
|
const [result, setResult] = useState<PipelineResult | null>(null);
|
|
37
48
|
const [showRawJson, setShowRawJson] = useState(false);
|
|
38
49
|
const [activePipeline, setActivePipeline] = useState<string | null>(null);
|
|
39
50
|
|
|
40
|
-
// On mount, check for ?pipeline-task= and fetch existing result
|
|
41
51
|
useEffect(() => {
|
|
42
|
-
const params = new URLSearchParams(window.location.search);
|
|
43
|
-
const existingTaskId = params.get("pipeline-task");
|
|
44
52
|
if (!existingTaskId) return;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
setStatus(`Task still ${data.status} — run a pipeline to try again.`);
|
|
53
|
+
let cancelled = false;
|
|
54
|
+
const load = async (): Promise<void> => {
|
|
55
|
+
try {
|
|
56
|
+
const data = pipelineResultOf(await readJson(await fetch(`/api/task/${encodeURIComponent(existingTaskId)}`)));
|
|
57
|
+
if (cancelled) return;
|
|
58
|
+
if (data.status !== undefined && data.status !== "completed") {
|
|
59
|
+
setStatus(`Task still ${data.status} - run a pipeline to try again.`);
|
|
53
60
|
return;
|
|
54
61
|
}
|
|
55
62
|
setResult(data);
|
|
56
63
|
const glbUrl = findGlbUrl(data);
|
|
57
64
|
if (glbUrl) {
|
|
58
65
|
onLoadModel(glbUrl);
|
|
59
|
-
setStatus("Pipeline result loaded from URL
|
|
66
|
+
setStatus("Pipeline result loaded from the URL.");
|
|
60
67
|
} else {
|
|
61
|
-
setStatus("Pipeline result loaded
|
|
68
|
+
setStatus("Pipeline result loaded - no 3D preview available.");
|
|
62
69
|
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
setStatus(
|
|
70
|
+
} catch (caught: unknown) {
|
|
71
|
+
if (cancelled) return;
|
|
72
|
+
setStatus(caught instanceof Error ? caught.message : "Failed to fetch the task");
|
|
66
73
|
setError(true);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
} finally {
|
|
75
|
+
if (!cancelled) setLoading(false);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
void load();
|
|
79
|
+
return () => { cancelled = true; };
|
|
80
|
+
}, [existingTaskId, onLoadModel]);
|
|
70
81
|
|
|
71
|
-
const runPipeline = async (endpoint: string, label: string,
|
|
82
|
+
const runPipeline = async (endpoint: string, label: string, stepFile?: File): Promise<void> => {
|
|
72
83
|
setLoading(true);
|
|
73
84
|
setError(false);
|
|
74
85
|
setResult(null);
|
|
75
86
|
setShowRawJson(false);
|
|
76
87
|
setActivePipeline(endpoint);
|
|
77
|
-
setStatus(`Running ${label}
|
|
88
|
+
setStatus(`Running ${label}...`);
|
|
78
89
|
try {
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} else {
|
|
85
|
-
res = await fetch(endpoint, { method: "POST" });
|
|
86
|
-
}
|
|
87
|
-
if (!res.ok) throw new Error(`Server error: ${res.status}`);
|
|
88
|
-
const data: PipelineResult = await res.json();
|
|
90
|
+
const formData = new FormData();
|
|
91
|
+
if (stepFile) formData.append("file", stepFile);
|
|
92
|
+
const response = await fetch(endpoint, stepFile ? { method: "POST", body: formData } : { method: "POST" });
|
|
93
|
+
if (!response.ok) throw new Error(`Server error: ${response.status}`);
|
|
94
|
+
const data = pipelineResultOf(await readJson(response));
|
|
89
95
|
setResult(data);
|
|
90
96
|
|
|
91
|
-
if (data.taskId)
|
|
92
|
-
setTaskInUrl(data.taskId);
|
|
93
|
-
}
|
|
97
|
+
if (data.taskId) setTaskInUrl(data.taskId);
|
|
94
98
|
|
|
95
99
|
const glbUrl = findGlbUrl(data);
|
|
96
100
|
if (glbUrl) {
|
|
97
101
|
onLoadModel(glbUrl);
|
|
98
|
-
setStatus(`${label} complete
|
|
102
|
+
setStatus(`${label} complete - model loaded!`);
|
|
99
103
|
} else {
|
|
100
|
-
setStatus(`${label} complete
|
|
104
|
+
setStatus(`${label} complete - see the result below`);
|
|
101
105
|
}
|
|
102
|
-
} catch (
|
|
103
|
-
|
|
104
|
-
setStatus(msg);
|
|
106
|
+
} catch (caught: unknown) {
|
|
107
|
+
setStatus(caught instanceof Error ? caught.message : "Unknown error");
|
|
105
108
|
setError(true);
|
|
106
109
|
} finally {
|
|
107
110
|
setLoading(false);
|
|
108
111
|
}
|
|
109
112
|
};
|
|
110
113
|
|
|
111
|
-
const handleFileInput = () => {
|
|
114
|
+
const handleFileInput = (): void => {
|
|
112
115
|
const input = document.createElement("input");
|
|
113
116
|
input.type = "file";
|
|
114
117
|
input.accept = ".step,.stp";
|
|
115
118
|
input.onchange = () => {
|
|
116
119
|
const file = input.files?.[0];
|
|
117
|
-
if (file)
|
|
118
|
-
runPipeline("/api/pipeline/file-input", "File Input Pipeline", file);
|
|
119
|
-
}
|
|
120
|
+
if (file) void runPipeline("/api/pipeline/file-input", "File Input Pipeline", file);
|
|
120
121
|
};
|
|
121
122
|
input.click();
|
|
122
123
|
};
|
|
123
124
|
|
|
124
|
-
const downloadFile = async (url: string, filename: string) => {
|
|
125
|
+
const downloadFile = async (url: string, filename: string): Promise<void> => {
|
|
125
126
|
try {
|
|
126
127
|
const proxyUrl = `/api/proxy-download?url=${encodeURIComponent(url)}`;
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
const blob = await
|
|
128
|
+
const response = await fetch(proxyUrl);
|
|
129
|
+
if (!response.ok) throw new Error(`Download failed: ${response.status}`);
|
|
130
|
+
const blob = await response.blob();
|
|
130
131
|
const blobUrl = URL.createObjectURL(blob);
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
const link = document.createElement("a");
|
|
133
|
+
link.href = blobUrl;
|
|
134
|
+
link.download = filename;
|
|
135
|
+
link.click();
|
|
135
136
|
URL.revokeObjectURL(blobUrl);
|
|
136
137
|
} catch {
|
|
137
|
-
// Fallback to direct link
|
|
138
138
|
window.open(url, "_blank");
|
|
139
139
|
}
|
|
140
140
|
};
|
|
@@ -143,26 +143,25 @@ export function PipelinesPanel({ active, modelLoaded, onLoadModel }: PipelinesPa
|
|
|
143
143
|
? `${window.location.origin}${window.location.pathname}?pipeline-task=${result.taskId}`
|
|
144
144
|
: null;
|
|
145
145
|
|
|
146
|
-
const btnClass = (endpoint: string) =>
|
|
147
|
-
`btn${activePipeline === endpoint ? "" : " btn-outline"}`;
|
|
146
|
+
const btnClass = (endpoint: string): string => `btn${activePipeline === endpoint ? "" : " btn-outline"}`;
|
|
148
147
|
|
|
149
148
|
return (
|
|
150
149
|
<div className={`panel ${active ? "" : "hidden"} ${modelLoaded ? "minimized" : ""}`}>
|
|
151
150
|
<div className="actions">
|
|
152
|
-
<button className={btnClass("/api/pipeline/translate-union-fillet")} disabled={loading} onClick={() => runPipeline("/api/pipeline/translate-union-fillet", "Translate, Union + Fillet")}>
|
|
151
|
+
<button className={btnClass("/api/pipeline/translate-union-fillet")} disabled={loading} onClick={() => { void runPipeline("/api/pipeline/translate-union-fillet", "Translate, Union + Fillet"); }}>
|
|
153
152
|
Translate, Union + Fillet
|
|
154
153
|
</button>
|
|
155
|
-
<button className={btnClass("/api/pipeline/map-cylinders")} disabled={loading} onClick={() => runPipeline("/api/pipeline/map-cylinders", "Map Cylinders")}>
|
|
154
|
+
<button className={btnClass("/api/pipeline/map-cylinders")} disabled={loading} onClick={() => { void runPipeline("/api/pipeline/map-cylinders", "Map Cylinders"); }}>
|
|
156
155
|
Map: Cylinders at Positions
|
|
157
156
|
</button>
|
|
158
|
-
<button className={btnClass("/api/pipeline/map-spheres")} disabled={loading} onClick={() => runPipeline("/api/pipeline/map-spheres", "Map Spheres")}>
|
|
157
|
+
<button className={btnClass("/api/pipeline/map-spheres")} disabled={loading} onClick={() => { void runPipeline("/api/pipeline/map-spheres", "Map Spheres"); }}>
|
|
159
158
|
Map: Spheres at Different Radii
|
|
160
159
|
</button>
|
|
161
|
-
<button className={btnClass("/api/pipeline/choice")} disabled={loading} onClick={() => runPipeline("/api/pipeline/choice", "Choice Conditional")}>
|
|
160
|
+
<button className={btnClass("/api/pipeline/choice")} disabled={loading} onClick={() => { void runPipeline("/api/pipeline/choice", "Choice Conditional"); }}>
|
|
162
161
|
Choice: Conditional Shape
|
|
163
162
|
</button>
|
|
164
163
|
<button className={btnClass("/api/pipeline/file-input")} disabled={loading} onClick={handleFileInput}>
|
|
165
|
-
File Input: STEP
|
|
164
|
+
File Input: STEP to Fillet
|
|
166
165
|
</button>
|
|
167
166
|
</div>
|
|
168
167
|
<p className={`status ${error ? "error" : ""}`}>{status}</p>
|
|
@@ -180,32 +179,32 @@ export function PipelinesPanel({ active, modelLoaded, onLoadModel }: PipelinesPa
|
|
|
180
179
|
<a className="result-link" href={taskUrl}>{taskUrl}</a>
|
|
181
180
|
</div>
|
|
182
181
|
)}
|
|
183
|
-
{result.downloads
|
|
182
|
+
{result.downloads.length > 0 && (
|
|
184
183
|
<table className="result-table">
|
|
185
184
|
<thead>
|
|
186
185
|
<tr><th>Format</th><th>Filename</th><th></th></tr>
|
|
187
186
|
</thead>
|
|
188
187
|
<tbody>
|
|
189
|
-
{result.downloads.map((
|
|
190
|
-
<tr key={
|
|
191
|
-
<td><code>{
|
|
192
|
-
<td>{
|
|
193
|
-
<td><a className="result-link" href="#" onClick={(
|
|
188
|
+
{result.downloads.map((download) => (
|
|
189
|
+
<tr key={download.downloadUrl}>
|
|
190
|
+
<td><code>{download.format}</code></td>
|
|
191
|
+
<td>{download.filename}</td>
|
|
192
|
+
<td><a className="result-link" href="#" onClick={(event) => { event.preventDefault(); void downloadFile(download.downloadUrl, download.filename); }}>Download</a></td>
|
|
194
193
|
</tr>
|
|
195
194
|
))}
|
|
196
195
|
</tbody>
|
|
197
196
|
</table>
|
|
198
197
|
)}
|
|
199
|
-
{result.downloadUrl &&
|
|
198
|
+
{result.downloadUrl && result.downloads.length === 0 && (
|
|
200
199
|
<div className="result-row">
|
|
201
200
|
<span className="result-label">Download</span>
|
|
202
201
|
<a className="result-link" href={result.downloadUrl} target="_blank" rel="noopener noreferrer">Download result</a>
|
|
203
202
|
</div>
|
|
204
203
|
)}
|
|
205
|
-
<button className="btn-raw-toggle" onClick={() => setShowRawJson((
|
|
204
|
+
<button className="btn-raw-toggle" onClick={() => { setShowRawJson((shown) => !shown); }}>
|
|
206
205
|
{showRawJson ? "Hide" : "Show"} raw JSON
|
|
207
206
|
</button>
|
|
208
|
-
{showRawJson && <pre className="json-preview">{JSON.stringify(result, null, 2)}</pre>}
|
|
207
|
+
{showRawJson && <pre className="json-preview">{JSON.stringify(result.raw, null, 2)}</pre>}
|
|
209
208
|
</div>
|
|
210
209
|
)}
|
|
211
210
|
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2022",
|
|
4
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
4
|
"module": "ESNext",
|
|
6
5
|
"moduleResolution": "bundler",
|
|
7
|
-
"
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
8
7
|
"jsx": "react-jsx",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"moduleDetection": "force",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"exactOptionalPropertyTypes": true,
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noImplicitOverride": true,
|
|
16
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"useUnknownInCatchVariables": true,
|
|
11
21
|
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
22
|
"isolatedModules": true,
|
|
14
|
-
"
|
|
23
|
+
"verbatimModuleSyntax": true,
|
|
24
|
+
"erasableSyntaxOnly": true,
|
|
25
|
+
"noUncheckedSideEffectImports": true,
|
|
26
|
+
"skipLibCheck": true
|
|
15
27
|
},
|
|
16
|
-
"include": ["src"]
|
|
28
|
+
"include": ["src", "vite.config.ts"]
|
|
17
29
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## This template: Vite + Babylon.js
|
|
2
|
+
|
|
3
|
+
- `src/model.ts` is the geometry. `buildModel(occt, params)` builds the OCCT shape from `ModelParams` and returns it. It knows nothing about rendering, and every kernel call is awaited, so the same function runs in the browser (through the OCCT worker, whose calls return promises) and in Node (in-process, whose calls return values). Put new geometry here, and new parameters in `ModelParams` with a default in `defaultParams`.
|
|
4
|
+
- `src/main.ts` is the wiring: it starts the Babylon.js scene, initialises Bitbybit, calls `buildModel` and draws the result. The Manifold and JSCAD demonstrations live here as well. Keep geometry out of this file.
|
|
5
|
+
- `scripts/smoke.ts` loads the OCCT kernel in Node, runs `buildModel` with `defaultParams` and prints one JSON line with the field names `template`, `params`, `valid`, `faces`, `edges`, `volume`, `area` and `bbox`. It exits 1 when the shape is not a valid solid or has no volume. Add an assertion here when a change to the model has a fact worth pinning, such as a face count or a bounding box.
|
|
6
|
+
|
|
7
|
+
Commands:
|
|
8
|
+
|
|
9
|
+
- `npm run dev` serves the app at http://localhost:5173
|
|
10
|
+
- `npm run build` typechecks and bundles for production; `npm run typecheck` and `npm run lint` run alone as well
|
|
11
|
+
- `npm run smoke` typechecks, lints, then builds the model headlessly and prints the summary line; the kernel loads from `node_modules`, so nothing is downloaded: it is the same WebAssembly the browser runs inside a worker, loaded in-process, its content-hashed `.wasm` found beside the loader. The smoke script types the in-process kernel as the same `Occt` the browser code sees, through one `inProcess` cast, and awaits every call, so `buildModel` runs exactly as it does in the browser and `scripts/` is typechecked with the rest.
|
|
12
|
+
|
|
13
|
+
The OCCT kernel runs in a web worker in the browser, so the objects `buildModel` handles there are pointers to shapes held by the worker, not the shapes themselves. That is why geometry is built entirely inside `buildModel` and only the result is drawn.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
+
import eslint from "@eslint/js";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
import noComments from "eslint-plugin-no-comments";
|
|
5
|
+
|
|
6
|
+
const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
|
|
10
|
+
{
|
|
11
|
+
files: ["**/*.ts"],
|
|
12
|
+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
|
|
13
|
+
plugins: { "no-comments": noComments },
|
|
14
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
15
|
+
rules: {
|
|
16
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
17
|
+
semi: ["error", "always"],
|
|
18
|
+
eqeqeq: ["error", "always"],
|
|
19
|
+
curly: ["error", "multi-line"],
|
|
20
|
+
"prefer-const": "error",
|
|
21
|
+
"no-var": "error",
|
|
22
|
+
"max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
|
|
23
|
+
"no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
|
|
24
|
+
"no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
|
|
25
|
+
"no-restricted-syntax": ["error", { selector: DOUBLE_ASSERTION, message: "A double assertion replaces a type instead of narrowing it: write a type predicate, constrain a generic to the union, or fix the type this is arguing with." }],
|
|
26
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
|
|
27
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
28
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
29
|
+
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
|
|
30
|
+
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
|
|
31
|
+
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
|
|
32
|
+
"@typescript-eslint/naming-convention": [
|
|
33
|
+
"error",
|
|
34
|
+
{ selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
35
|
+
{ selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
|
|
36
|
+
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
37
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
38
|
+
{ selector: "property", format: null },
|
|
39
|
+
{ selector: "method", format: ["camelCase"] },
|
|
40
|
+
{ selector: "import", format: null },
|
|
41
|
+
],
|
|
42
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
43
|
+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
|
|
44
|
+
"@typescript-eslint/non-nullable-type-assertion-style": "off",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon"
|
|
5
|
+
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
|
6
|
+
<link rel="icon" type="image/png" href="/logo.png" sizes="150x150" />
|
|
7
|
+
<link rel="apple-touch-icon" href="/logo.png" />
|
|
6
8
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
9
|
<title>Bitbybit & Babylon.js Project</title>
|
|
8
10
|
</head>
|
|
@@ -15,7 +17,7 @@
|
|
|
15
17
|
>
|
|
16
18
|
<img
|
|
17
19
|
alt="Logo of Bit by bit developers company"
|
|
18
|
-
src="
|
|
20
|
+
src="/logo.png"
|
|
19
21
|
/>
|
|
20
22
|
<div>bitbybit.dev</div>
|
|
21
23
|
<br />
|
|
@@ -5,14 +5,24 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
8
|
-
"build": "
|
|
9
|
-
"preview": "vite preview"
|
|
8
|
+
"build": "npm run typecheck && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"smoke": "npm run typecheck && npm run lint && tsx scripts/smoke.ts",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint . --max-warnings 0"
|
|
10
13
|
},
|
|
11
14
|
"dependencies": {
|
|
12
|
-
"@bitbybit-dev/babylonjs": "1.
|
|
15
|
+
"@bitbybit-dev/babylonjs": "1.4.0-rc.0"
|
|
13
16
|
},
|
|
14
17
|
"devDependencies": {
|
|
15
|
-
"
|
|
18
|
+
"@bitbybit-dev/occt": "1.4.0-rc.0",
|
|
19
|
+
"@eslint/js": "10.0.1",
|
|
20
|
+
"@types/node": "22.20.1",
|
|
21
|
+
"eslint": "10.10.0",
|
|
22
|
+
"eslint-plugin-no-comments": "1.2.1",
|
|
23
|
+
"tsx": "^4.19.0",
|
|
24
|
+
"typescript": "5.9.3",
|
|
25
|
+
"typescript-eslint": "8.70.0",
|
|
16
26
|
"vite": "^6.3.2"
|
|
17
27
|
}
|
|
18
28
|
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readdirSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/index.js";
|
|
5
|
+
import { OCCTService, OccHelper, VectorHelperService, ShapesHelperService } from "@bitbybit-dev/occt";
|
|
6
|
+
import { buildModel, defaultParams, type Occt } from "../src/model.ts";
|
|
7
|
+
|
|
8
|
+
function inProcess(service: object): Occt {
|
|
9
|
+
return service as Occt;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
const kernelDir = dirname(require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/index.js"));
|
|
14
|
+
const wasmFile = readdirSync(kernelDir).find((file) => file.endsWith(".wasm"));
|
|
15
|
+
if (!wasmFile) throw new Error(`no OCCT kernel (.wasm) found in ${kernelDir}`);
|
|
16
|
+
const occ = await initOpenCascade({ locateFile: (file: string) => (file.endsWith(".wasm") ? join(kernelDir, wasmFile) : file) });
|
|
17
|
+
const occt = inProcess(new OCCTService(occ, new OccHelper(new VectorHelperService(), new ShapesHelperService(), occ)));
|
|
18
|
+
|
|
19
|
+
const shape = await buildModel(occt, defaultParams);
|
|
20
|
+
const info = await occt.shapes.solid.debugInfo({ shape });
|
|
21
|
+
const bbox = await occt.operations.boundingBoxOfShape({ shape });
|
|
22
|
+
const round = (n: number): number => Math.round(n * 1000) / 1000;
|
|
23
|
+
|
|
24
|
+
console.log(JSON.stringify({
|
|
25
|
+
template: "vite-babylonjs",
|
|
26
|
+
params: defaultParams,
|
|
27
|
+
valid: info.valid,
|
|
28
|
+
faces: info.nbFaces,
|
|
29
|
+
edges: info.nbEdges,
|
|
30
|
+
volume: round(info.volume),
|
|
31
|
+
area: round(info.area),
|
|
32
|
+
bbox: { min: bbox.min.map(round), max: bbox.max.map(round) },
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
const problems: string[] = [];
|
|
36
|
+
if (!info.valid) problems.push("the model is not a valid solid");
|
|
37
|
+
if (!(info.volume > 0)) problems.push("the model has no volume");
|
|
38
|
+
if (problems.length) {
|
|
39
|
+
console.error(`smoke: ${problems.join("; ")}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
2
|
import { BitByBitBase, Inputs, initBitByBit, initBabylonJS, type InitBitByBitOptions } from "@bitbybit-dev/babylonjs";
|
|
3
|
+
import { buildModel, defaultParams } from "./model";
|
|
3
4
|
|
|
4
|
-
start();
|
|
5
|
+
void start();
|
|
5
6
|
|
|
6
|
-
async function start() {
|
|
7
|
+
async function start(): Promise<void> {
|
|
7
8
|
const sceneOptions = new Inputs.BabylonJSScene.InitBabylonJSDto();
|
|
8
9
|
sceneOptions.canvasId = "babylon-canvas";
|
|
9
10
|
sceneOptions.sceneSize = 10;
|
|
@@ -38,18 +39,8 @@ async function start() {
|
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
async function createOCCTGeometry(bitbybit: BitByBitBase, color: string) {
|
|
42
|
-
const
|
|
43
|
-
cubeOptions.size = 2.5;
|
|
44
|
-
cubeOptions.center = [0, 1.25, 0];
|
|
45
|
-
|
|
46
|
-
const cube = await bitbybit.occt.shapes.solid.createCube(cubeOptions);
|
|
47
|
-
|
|
48
|
-
const filletOptions =
|
|
49
|
-
new Inputs.OCCT.FilletDto<Inputs.OCCT.TopoDSShapePointer>();
|
|
50
|
-
filletOptions.shape = cube;
|
|
51
|
-
filletOptions.radius = 0.4;
|
|
52
|
-
const roundedCube = await bitbybit.occt.fillets.filletEdges(filletOptions);
|
|
42
|
+
async function createOCCTGeometry(bitbybit: BitByBitBase, color: string): Promise<void> {
|
|
43
|
+
const roundedCube = await buildModel(bitbybit.occt, defaultParams);
|
|
53
44
|
|
|
54
45
|
const drawOptions = new Inputs.Draw.DrawOcctShapeOptions();
|
|
55
46
|
drawOptions.edgeWidth = 0.5;
|
|
@@ -63,7 +54,7 @@ async function createOCCTGeometry(bitbybit: BitByBitBase, color: string) {
|
|
|
63
54
|
});
|
|
64
55
|
}
|
|
65
56
|
|
|
66
|
-
async function createManifoldGeometry(bitbybit: BitByBitBase, color: string) {
|
|
57
|
+
async function createManifoldGeometry(bitbybit: BitByBitBase, color: string): Promise<void> {
|
|
67
58
|
const sphereOptions = new Inputs.Manifold.SphereDto();
|
|
68
59
|
sphereOptions.radius = 1.5;
|
|
69
60
|
sphereOptions.circularSegments = 32;
|
|
@@ -81,7 +72,7 @@ async function createManifoldGeometry(bitbybit: BitByBitBase, color: string) {
|
|
|
81
72
|
const translationOptions =
|
|
82
73
|
new Inputs.Manifold.TranslateDto<Inputs.Manifold.ManifoldPointer>();
|
|
83
74
|
translationOptions.manifold = diffedShape;
|
|
84
|
-
translationOptions.vector = [0, 1.25, -4];
|
|
75
|
+
translationOptions.vector = [0, 1.25, -4];
|
|
85
76
|
const movedShape = await bitbybit.manifold.manifold.transforms.translate(
|
|
86
77
|
translationOptions
|
|
87
78
|
);
|
|
@@ -94,7 +85,7 @@ async function createManifoldGeometry(bitbybit: BitByBitBase, color: string) {
|
|
|
94
85
|
});
|
|
95
86
|
}
|
|
96
87
|
|
|
97
|
-
async function createJSCADGeometry(bitbybit: BitByBitBase, color: string) {
|
|
88
|
+
async function createJSCADGeometry(bitbybit: BitByBitBase, color: string): Promise<void> {
|
|
98
89
|
const geodesicSphereOptions = new Inputs.JSCAD.GeodesicSphereDto();
|
|
99
90
|
geodesicSphereOptions.radius = 1.5;
|
|
100
91
|
geodesicSphereOptions.center = [0, 1.5, 4];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BitByBitBase } from "@bitbybit-dev/babylonjs";
|
|
2
|
+
|
|
3
|
+
export type Occt = BitByBitBase["occt"];
|
|
4
|
+
|
|
5
|
+
export type Shape = Awaited<ReturnType<Occt["fillets"]["filletEdges"]>>;
|
|
6
|
+
|
|
7
|
+
export interface ModelParams {
|
|
8
|
+
size: number;
|
|
9
|
+
filletRadius: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const defaultParams: ModelParams = {
|
|
13
|
+
size: 2.5,
|
|
14
|
+
filletRadius: 0.4,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function buildModel(occt: Occt, params: ModelParams): Promise<Shape> {
|
|
18
|
+
const cube = await occt.shapes.solid.createCube({
|
|
19
|
+
size: params.size,
|
|
20
|
+
center: [0, params.size / 2, 0],
|
|
21
|
+
originOnCenter: true,
|
|
22
|
+
});
|
|
23
|
+
return occt.fillets.filletEdges({ shape: cube, radius: params.filletRadius });
|
|
24
|
+
}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"useDefineForClassFields": true,
|
|
3
|
+
"target": "ES2022",
|
|
5
4
|
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
|
|
9
|
-
/* Bundler mode */
|
|
10
5
|
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
11
8
|
"allowImportingTsExtensions": true,
|
|
12
|
-
"verbatimModuleSyntax": true,
|
|
13
9
|
"moduleDetection": "force",
|
|
14
10
|
"noEmit": true,
|
|
15
|
-
|
|
16
|
-
/* Linting */
|
|
17
11
|
"strict": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"exactOptionalPropertyTypes": true,
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noImplicitOverride": true,
|
|
16
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
18
|
"noUnusedLocals": true,
|
|
19
19
|
"noUnusedParameters": true,
|
|
20
|
+
"useUnknownInCatchVariables": true,
|
|
21
|
+
"forceConsistentCasingInFileNames": true,
|
|
22
|
+
"isolatedModules": true,
|
|
23
|
+
"verbatimModuleSyntax": true,
|
|
20
24
|
"erasableSyntaxOnly": true,
|
|
21
|
-
"
|
|
22
|
-
"
|
|
25
|
+
"noUncheckedSideEffectImports": true,
|
|
26
|
+
"skipLibCheck": true
|
|
23
27
|
},
|
|
24
|
-
"include": ["src"]
|
|
28
|
+
"include": ["src", "scripts"]
|
|
25
29
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## This template: Vite + PlayCanvas
|
|
2
|
+
|
|
3
|
+
- `src/model.ts` is the geometry. `buildModel(occt, params)` builds the OCCT shape from `ModelParams` and returns it. It knows nothing about rendering, and every kernel call is awaited, so the same function runs in the browser (through the OCCT worker, whose calls return promises) and in Node (in-process, whose calls return values). Put new geometry here, and new parameters in `ModelParams` with a default in `defaultParams`.
|
|
4
|
+
- `src/main.ts` is the wiring: it starts the PlayCanvas scene, initialises Bitbybit, calls `buildModel` and draws the result. The Manifold and JSCAD demonstrations live here as well. Keep geometry out of this file.
|
|
5
|
+
- `scripts/smoke.ts` loads the OCCT kernel in Node, runs `buildModel` with `defaultParams` and prints one JSON line with the field names `template`, `params`, `valid`, `faces`, `edges`, `volume`, `area` and `bbox`. It exits 1 when the shape is not a valid solid or has no volume. Add an assertion here when a change to the model has a fact worth pinning, such as a face count or a bounding box.
|
|
6
|
+
|
|
7
|
+
Commands:
|
|
8
|
+
|
|
9
|
+
- `npm run dev` serves the app at http://localhost:5173
|
|
10
|
+
- `npm run build` typechecks and bundles for production; `npm run typecheck` and `npm run lint` run alone as well
|
|
11
|
+
- `npm run smoke` typechecks, lints, then builds the model headlessly and prints the summary line; the kernel loads from `node_modules`, so nothing is downloaded: it is the same WebAssembly the browser runs inside a worker, loaded in-process, its content-hashed `.wasm` found beside the loader. The smoke script types the in-process kernel as the same `Occt` the browser code sees, through one `inProcess` cast, and awaits every call, so `buildModel` runs exactly as it does in the browser and `scripts/` is typechecked with the rest.
|
|
12
|
+
|
|
13
|
+
The OCCT kernel runs in a web worker in the browser, so the objects `buildModel` handles there are pointers to shapes held by the worker, not the shapes themselves. That is why geometry is built entirely inside `buildModel` and only the result is drawn.
|