@bitbybit-dev/create-app 1.3.2-rc.1 → 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,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useRef, type ReactElement } from "react";
|
|
2
2
|
import * as THREE from "three";
|
|
3
3
|
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
|
|
4
4
|
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
@@ -8,15 +8,18 @@ interface ViewerProps {
|
|
|
8
8
|
urls: string[] | null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface ViewerScene {
|
|
12
|
+
scene: THREE.Scene;
|
|
13
|
+
camera: THREE.PerspectiveCamera;
|
|
14
|
+
renderer: THREE.WebGLRenderer;
|
|
15
|
+
controls: OrbitControls;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const MODEL_SPACING = 15;
|
|
19
|
+
|
|
20
|
+
export function Viewer({ url, urls }: ViewerProps): ReactElement {
|
|
12
21
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
13
|
-
const sceneRef = useRef<
|
|
14
|
-
scene: THREE.Scene;
|
|
15
|
-
camera: THREE.PerspectiveCamera;
|
|
16
|
-
renderer: THREE.WebGLRenderer;
|
|
17
|
-
controls: OrbitControls;
|
|
18
|
-
animationId: number;
|
|
19
|
-
} | null>(null);
|
|
22
|
+
const sceneRef = useRef<ViewerScene | null>(null);
|
|
20
23
|
|
|
21
24
|
useEffect(() => {
|
|
22
25
|
const container = containerRef.current;
|
|
@@ -38,7 +41,6 @@ export function Viewer({ url, urls }: ViewerProps) {
|
|
|
38
41
|
controls.enableDamping = true;
|
|
39
42
|
controls.dampingFactor = 0.05;
|
|
40
43
|
|
|
41
|
-
// Lighting — matches old working frontend
|
|
42
44
|
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8);
|
|
43
45
|
scene.add(ambientLight);
|
|
44
46
|
|
|
@@ -50,20 +52,20 @@ export function Viewer({ url, urls }: ViewerProps) {
|
|
|
50
52
|
fillLight.position.set(-10, 5, -10);
|
|
51
53
|
scene.add(fillLight);
|
|
52
54
|
|
|
53
|
-
// Grid
|
|
54
55
|
const grid = new THREE.GridHelper(30, 30, 0x2e3136, 0x24272c);
|
|
55
56
|
scene.add(grid);
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
let animationId = 0;
|
|
59
|
+
const animate = (): void => {
|
|
60
|
+
animationId = requestAnimationFrame(animate);
|
|
59
61
|
controls.update();
|
|
60
62
|
renderer.render(scene, camera);
|
|
61
63
|
};
|
|
62
64
|
|
|
63
|
-
sceneRef.current = { scene, camera, renderer, controls
|
|
65
|
+
sceneRef.current = { scene, camera, renderer, controls };
|
|
64
66
|
animate();
|
|
65
67
|
|
|
66
|
-
const handleResize = () => {
|
|
68
|
+
const handleResize = (): void => {
|
|
67
69
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
68
70
|
camera.updateProjectionMatrix();
|
|
69
71
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
@@ -72,7 +74,7 @@ export function Viewer({ url, urls }: ViewerProps) {
|
|
|
72
74
|
|
|
73
75
|
return () => {
|
|
74
76
|
window.removeEventListener("resize", handleResize);
|
|
75
|
-
cancelAnimationFrame(
|
|
77
|
+
cancelAnimationFrame(animationId);
|
|
76
78
|
renderer.dispose();
|
|
77
79
|
container.removeChild(renderer.domElement);
|
|
78
80
|
sceneRef.current = null;
|
|
@@ -83,72 +85,50 @@ export function Viewer({ url, urls }: ViewerProps) {
|
|
|
83
85
|
if (!sceneRef.current) return;
|
|
84
86
|
const { scene, camera, controls } = sceneRef.current;
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
const toRemove = scene.children.filter((c) => c.type === "Group");
|
|
88
|
-
toRemove.forEach((c) => scene.remove(c));
|
|
88
|
+
for (const group of scene.children.filter((child) => child.type === "Group")) scene.remove(group);
|
|
89
89
|
|
|
90
90
|
const allUrls = urls ?? (url ? [url] : []);
|
|
91
91
|
if (allUrls.length === 0) return;
|
|
92
|
+
const startX = -MODEL_SPACING * (allUrls.length - 1) / 2;
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.error("[Viewer] proxy fetch failed:", res.status);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const buffer = await res.arrayBuffer();
|
|
102
|
-
|
|
103
|
-
const loader = new GLTFLoader();
|
|
104
|
-
loader.parse(
|
|
105
|
-
buffer,
|
|
106
|
-
"",
|
|
107
|
-
(gltf) => {
|
|
108
|
-
// Offset models side-by-side when loading multiple
|
|
109
|
-
if (allUrls.length > 1) {
|
|
110
|
-
const spacing = 15;
|
|
111
|
-
const startX = -spacing * (allUrls.length - 1) / 2;
|
|
112
|
-
gltf.scene.position.x += startX + i * spacing;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Apply porcelain material
|
|
116
|
-
gltf.scene.traverse((child) => {
|
|
117
|
-
if ((child as THREE.Mesh).isMesh) {
|
|
118
|
-
(child as THREE.Mesh).material = new THREE.MeshPhysicalMaterial({
|
|
119
|
-
color: 0xffffff,
|
|
120
|
-
metalness: 0.0,
|
|
121
|
-
roughness: 0.15,
|
|
122
|
-
clearcoat: 0.8,
|
|
123
|
-
clearcoatRoughness: 0.1,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
scene.add(gltf.scene);
|
|
129
|
-
|
|
130
|
-
// Fit camera to model
|
|
131
|
-
const box = new THREE.Box3().setFromObject(gltf.scene);
|
|
132
|
-
const center = box.getCenter(new THREE.Vector3());
|
|
133
|
-
const size = box.getSize(new THREE.Vector3());
|
|
134
|
-
const maxDim = Math.max(size.x, size.y, size.z);
|
|
135
|
-
|
|
136
|
-
controls.target.copy(center);
|
|
137
|
-
camera.position.set(
|
|
138
|
-
center.x + maxDim * 1.5,
|
|
139
|
-
center.y + maxDim,
|
|
140
|
-
center.z + maxDim * 1.5,
|
|
141
|
-
);
|
|
142
|
-
controls.update();
|
|
143
|
-
},
|
|
144
|
-
(err) => {
|
|
145
|
-
console.error("[Viewer] GLTFLoader.parse error:", err);
|
|
146
|
-
},
|
|
147
|
-
);
|
|
148
|
-
} catch (err) {
|
|
149
|
-
console.error("[Viewer] fetch error for:", modelUrl, err);
|
|
94
|
+
const show = async (modelUrl: string, index: number): Promise<void> => {
|
|
95
|
+
const response = await fetch(`/api/proxy-download?url=${encodeURIComponent(modelUrl)}`);
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
console.error("[Viewer] proxy fetch failed:", response.status);
|
|
98
|
+
return;
|
|
150
99
|
}
|
|
151
|
-
|
|
100
|
+
const gltf = await new GLTFLoader().parseAsync(await response.arrayBuffer(), "");
|
|
101
|
+
if (allUrls.length > 1) gltf.scene.position.x += startX + index * MODEL_SPACING;
|
|
102
|
+
|
|
103
|
+
gltf.scene.traverse((child) => {
|
|
104
|
+
if (child instanceof THREE.Mesh) {
|
|
105
|
+
child.material = new THREE.MeshPhysicalMaterial({
|
|
106
|
+
color: 0xffffff,
|
|
107
|
+
metalness: 0.0,
|
|
108
|
+
roughness: 0.15,
|
|
109
|
+
clearcoat: 0.8,
|
|
110
|
+
clearcoatRoughness: 0.1,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
scene.add(gltf.scene);
|
|
116
|
+
|
|
117
|
+
const box = new THREE.Box3().setFromObject(gltf.scene);
|
|
118
|
+
const center = box.getCenter(new THREE.Vector3());
|
|
119
|
+
const size = box.getSize(new THREE.Vector3());
|
|
120
|
+
const maxDim = Math.max(size.x, size.y, size.z);
|
|
121
|
+
|
|
122
|
+
controls.target.copy(center);
|
|
123
|
+
camera.position.set(center.x + maxDim * 1.5, center.y + maxDim, center.z + maxDim * 1.5);
|
|
124
|
+
controls.update();
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
for (const [index, modelUrl] of allUrls.entries()) {
|
|
128
|
+
show(modelUrl, index).catch((error: unknown) => {
|
|
129
|
+
console.error("[Viewer] could not show", modelUrl, error);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
152
132
|
}, [url, urls]);
|
|
153
133
|
|
|
154
134
|
return <div ref={containerRef} style={{ position: "fixed", top: 0, left: 0, width: "100vw", height: "100vh", zIndex: 1 }} />;
|
|
@@ -3,7 +3,12 @@ import { createRoot } from "react-dom/client";
|
|
|
3
3
|
import { App } from "./App";
|
|
4
4
|
import "./styles.css";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const root = document.getElementById("root");
|
|
7
|
+
if (!root) {
|
|
8
|
+
throw new Error("index.html has no #root element to mount the app in");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
createRoot(root).render(
|
|
7
12
|
<StrictMode>
|
|
8
13
|
<App />
|
|
9
14
|
</StrictMode>,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { useEffect, useState, type ReactElement } from "react";
|
|
2
|
+
import { downloadsOf, glbUrlOf, readJson, stringOf } from "../api";
|
|
2
3
|
|
|
3
4
|
interface ModelsPanelProps {
|
|
4
5
|
active: boolean;
|
|
@@ -7,111 +8,102 @@ interface ModelsPanelProps {
|
|
|
7
8
|
onLoadModels: (urls: string[]) => void;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// REST backend: { downloadUrl: "..." }
|
|
13
|
-
if (typeof data.downloadUrl === "string") return data.downloadUrl;
|
|
14
|
-
// SDK backend: { downloads: [{ format, downloadUrl, filename }] }
|
|
15
|
-
const downloads = data.downloads as { format: string; downloadUrl: string }[] | undefined;
|
|
16
|
-
if (Array.isArray(downloads)) {
|
|
17
|
-
const glb = downloads.find((d) => d.format === "glb") ?? downloads[0];
|
|
18
|
-
return glb?.downloadUrl;
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
11
|
+
function glbUrlIn(data: Record<string, unknown>): string | undefined {
|
|
12
|
+
return stringOf(data, "downloadUrl") ?? glbUrlOf(downloadsOf(data["downloads"]));
|
|
21
13
|
}
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return [];
|
|
15
|
+
function batchGlbUrlsIn(data: Record<string, unknown>): string[] {
|
|
16
|
+
const listed = data["downloadUrls"];
|
|
17
|
+
if (Array.isArray(listed)) return listed.filter((entry: unknown): entry is string => typeof entry === "string");
|
|
18
|
+
const subTasks = data["subTasks"];
|
|
19
|
+
if (!Array.isArray(subTasks)) return [];
|
|
20
|
+
return subTasks.flatMap((task: unknown) => {
|
|
21
|
+
const downloads = task !== null && typeof task === "object" && "downloads" in task ? downloadsOf(task.downloads) : [];
|
|
22
|
+
const glbUrl = glbUrlOf(downloads);
|
|
23
|
+
return glbUrl ? [glbUrl] : [];
|
|
24
|
+
});
|
|
36
25
|
}
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
const
|
|
27
|
+
function rememberTask(taskId: string): void {
|
|
28
|
+
const url = new URL(window.location.href);
|
|
29
|
+
url.searchParams.set("task", taskId);
|
|
30
|
+
window.history.replaceState({}, "", url.toString());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const taskFromUrl = (): string | null => new URLSearchParams(window.location.search).get("task");
|
|
34
|
+
|
|
35
|
+
export function ModelsPanel({ active, modelLoaded, onLoadModel, onLoadModels }: ModelsPanelProps): ReactElement {
|
|
36
|
+
const [existingTaskId] = useState(taskFromUrl);
|
|
37
|
+
const [status, setStatus] = useState(existingTaskId ? "Fetching the existing task result..." : "");
|
|
40
38
|
const [error, setError] = useState(false);
|
|
41
|
-
const [loading, setLoading] = useState(
|
|
39
|
+
const [loading, setLoading] = useState(existingTaskId !== null);
|
|
42
40
|
|
|
43
|
-
// On mount, check for ?task= query param and fetch existing result
|
|
44
41
|
useEffect(() => {
|
|
45
|
-
const params = new URLSearchParams(window.location.search);
|
|
46
|
-
const existingTaskId = params.get("task");
|
|
47
42
|
if (!existingTaskId) return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
43
|
+
let cancelled = false;
|
|
44
|
+
const load = async (): Promise<void> => {
|
|
45
|
+
try {
|
|
46
|
+
const data = await readJson(await fetch(`/api/task/${encodeURIComponent(existingTaskId)}`));
|
|
47
|
+
if (cancelled) return;
|
|
48
|
+
const downloadUrl = glbUrlIn(data);
|
|
49
|
+
const taskStatus = stringOf(data, "status");
|
|
55
50
|
if (downloadUrl) {
|
|
56
51
|
setStatus("Model loaded!");
|
|
57
52
|
onLoadModel(downloadUrl);
|
|
58
|
-
} else if (
|
|
59
|
-
setStatus(`Task still ${
|
|
53
|
+
} else if (taskStatus !== undefined && taskStatus !== "completed") {
|
|
54
|
+
setStatus(`Task still ${taskStatus} - click to regenerate.`);
|
|
60
55
|
} else {
|
|
61
|
-
throw new Error(data
|
|
56
|
+
throw new Error(stringOf(data, "error") ?? "Could not fetch the result");
|
|
62
57
|
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
setStatus(
|
|
58
|
+
} catch (caught: unknown) {
|
|
59
|
+
if (cancelled) return;
|
|
60
|
+
setStatus(caught instanceof Error ? caught.message : "Could not fetch the result");
|
|
66
61
|
setError(true);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
} finally {
|
|
63
|
+
if (!cancelled) setLoading(false);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
void load();
|
|
67
|
+
return () => { cancelled = true; };
|
|
68
|
+
}, [existingTaskId, onLoadModel]);
|
|
70
69
|
|
|
71
|
-
const generate = async () => {
|
|
70
|
+
const generate = async (): Promise<void> => {
|
|
72
71
|
setLoading(true);
|
|
73
72
|
setError(false);
|
|
74
|
-
setStatus("Generating
|
|
73
|
+
setStatus("Generating the dragon cup...");
|
|
75
74
|
try {
|
|
76
|
-
const
|
|
77
|
-
if (!
|
|
78
|
-
const data = await
|
|
79
|
-
const downloadUrl =
|
|
75
|
+
const response = await fetch("/api/generate", { method: "POST" });
|
|
76
|
+
if (!response.ok) throw new Error(`Server error: ${response.status}`);
|
|
77
|
+
const data = await readJson(response);
|
|
78
|
+
const downloadUrl = glbUrlIn(data);
|
|
80
79
|
if (!downloadUrl) throw new Error("No GLB download URL returned");
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
const url = new URL(window.location.href);
|
|
85
|
-
url.searchParams.set("task", data.taskId);
|
|
86
|
-
window.history.replaceState({}, "", url.toString());
|
|
87
|
-
}
|
|
81
|
+
const taskId = stringOf(data, "taskId");
|
|
82
|
+
if (taskId) rememberTask(taskId);
|
|
88
83
|
|
|
89
84
|
setStatus("Model loaded!");
|
|
90
85
|
onLoadModel(downloadUrl);
|
|
91
|
-
} catch (
|
|
92
|
-
|
|
93
|
-
setStatus(msg);
|
|
86
|
+
} catch (caught: unknown) {
|
|
87
|
+
setStatus(caught instanceof Error ? caught.message : "Unknown error");
|
|
94
88
|
setError(true);
|
|
95
89
|
} finally {
|
|
96
90
|
setLoading(false);
|
|
97
91
|
}
|
|
98
92
|
};
|
|
99
93
|
|
|
100
|
-
const generateBatch = async () => {
|
|
94
|
+
const generateBatch = async (): Promise<void> => {
|
|
101
95
|
setLoading(true);
|
|
102
96
|
setError(false);
|
|
103
|
-
setStatus("Generating batch
|
|
97
|
+
setStatus("Generating a batch of three variations...");
|
|
104
98
|
try {
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
const
|
|
108
|
-
const urls = extractBatchGlbUrls(data);
|
|
99
|
+
const response = await fetch("/api/generate-batch", { method: "POST" });
|
|
100
|
+
if (!response.ok) throw new Error(`Server error: ${response.status}`);
|
|
101
|
+
const urls = batchGlbUrlsIn(await readJson(response));
|
|
109
102
|
if (urls.length === 0) throw new Error("No GLB downloads returned");
|
|
110
103
|
setStatus(`Loaded ${urls.length} models!`);
|
|
111
104
|
onLoadModels(urls);
|
|
112
|
-
} catch (
|
|
113
|
-
|
|
114
|
-
setStatus(msg);
|
|
105
|
+
} catch (caught: unknown) {
|
|
106
|
+
setStatus(caught instanceof Error ? caught.message : "Unknown error");
|
|
115
107
|
setError(true);
|
|
116
108
|
} finally {
|
|
117
109
|
setLoading(false);
|
|
@@ -121,10 +113,10 @@ export function ModelsPanel({ active, modelLoaded, onLoadModel, onLoadModels }:
|
|
|
121
113
|
return (
|
|
122
114
|
<div className={`panel ${active ? "" : "hidden"} ${modelLoaded ? "minimized" : ""}`}>
|
|
123
115
|
<div className="actions">
|
|
124
|
-
<button className="btn" disabled={loading} onClick={generate}>
|
|
116
|
+
<button className="btn" disabled={loading} onClick={() => { void generate(); }}>
|
|
125
117
|
Generate Dragon Cup
|
|
126
118
|
</button>
|
|
127
|
-
<button className="btn btn-outline" disabled={loading} onClick={generateBatch}>
|
|
119
|
+
<button className="btn btn-outline" disabled={loading} onClick={() => { void generateBatch(); }}>
|
|
128
120
|
Generate Batch (3 Cups)
|
|
129
121
|
</button>
|
|
130
122
|
</div>
|