Upload folder using huggingface_hub
Browse files
6.3.0/model3D/Index.svelte
CHANGED
|
@@ -157,15 +157,15 @@
|
|
| 157 |
root={gradio.shared.root}
|
| 158 |
display_mode={gradio.props.display_mode}
|
| 159 |
clear_color={gradio.props.clear_color}
|
| 160 |
-
value={gradio.props.value}
|
| 161 |
camera_position={gradio.props.camera_position}
|
| 162 |
zoom_speed={gradio.props.zoom_speed}
|
| 163 |
bind:uploading
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
i18n={gradio.i18n}
|
| 170 |
max_file_size={gradio.shared.max_file_size}
|
| 171 |
upload={(...args) => gradio.shared.client.upload(...args)}
|
|
|
|
| 157 |
root={gradio.shared.root}
|
| 158 |
display_mode={gradio.props.display_mode}
|
| 159 |
clear_color={gradio.props.clear_color}
|
| 160 |
+
bind:value={gradio.props.value}
|
| 161 |
camera_position={gradio.props.camera_position}
|
| 162 |
zoom_speed={gradio.props.zoom_speed}
|
| 163 |
bind:uploading
|
| 164 |
+
onchange={handle_change}
|
| 165 |
+
ondrag={handle_drag}
|
| 166 |
+
onclear={handle_clear}
|
| 167 |
+
onload={handle_load}
|
| 168 |
+
onerror={handle_error}
|
| 169 |
i18n={gradio.i18n}
|
| 170 |
max_file_size={gradio.shared.max_file_size}
|
| 171 |
upload={(...args) => gradio.shared.client.upload(...args)}
|
6.3.0/model3D/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/model3d",
|
| 3 |
-
"version": "0.16.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/model3d",
|
| 3 |
+
"version": "0.16.1",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
6.3.0/model3D/shared/Canvas3D.svelte
CHANGED
|
@@ -5,19 +5,28 @@
|
|
| 5 |
|
| 6 |
let BABYLON_VIEWER: typeof import("@babylonjs/viewer");
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
let canvas: HTMLCanvasElement;
|
| 18 |
-
let viewer
|
| 19 |
-
let viewerDetails
|
| 20 |
-
let mounted = false;
|
| 21 |
|
| 22 |
onMount(() => {
|
| 23 |
const initViewer = async (): Promise<void> => {
|
|
@@ -43,9 +52,14 @@
|
|
| 43 |
};
|
| 44 |
});
|
| 45 |
|
| 46 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
function setRenderingMode(pointsCloud: boolean, wireframe: boolean): void {
|
|
|
|
| 49 |
viewerDetails.scene.forcePointsCloud = pointsCloud;
|
| 50 |
viewerDetails.scene.forceWireframe = wireframe;
|
| 51 |
}
|
|
@@ -81,6 +95,7 @@
|
|
| 81 |
zoom_speed: number,
|
| 82 |
pan_speed: number
|
| 83 |
): void {
|
|
|
|
| 84 |
const camera = viewerDetails.camera;
|
| 85 |
if (camera_position[0] !== null) {
|
| 86 |
camera.alpha = (camera_position[0] * Math.PI) / 180;
|
|
@@ -101,7 +116,7 @@
|
|
| 101 |
}
|
| 102 |
|
| 103 |
export function reset_camera_position(): void {
|
| 104 |
-
if (viewerDetails) {
|
| 105 |
viewer.resetCamera();
|
| 106 |
}
|
| 107 |
}
|
|
|
|
| 5 |
|
| 6 |
let BABYLON_VIEWER: typeof import("@babylonjs/viewer");
|
| 7 |
|
| 8 |
+
let {
|
| 9 |
+
value,
|
| 10 |
+
display_mode,
|
| 11 |
+
clear_color,
|
| 12 |
+
camera_position,
|
| 13 |
+
zoom_speed,
|
| 14 |
+
pan_speed
|
| 15 |
+
}: {
|
| 16 |
+
value: FileData;
|
| 17 |
+
display_mode: "solid" | "point_cloud" | "wireframe";
|
| 18 |
+
clear_color: [number, number, number, number];
|
| 19 |
+
camera_position: [number | null, number | null, number | null];
|
| 20 |
+
zoom_speed: number;
|
| 21 |
+
pan_speed: number;
|
| 22 |
+
} = $props();
|
| 23 |
|
| 24 |
+
let url = $derived(value.url);
|
| 25 |
|
| 26 |
let canvas: HTMLCanvasElement;
|
| 27 |
+
let viewer = $state<Viewer>();
|
| 28 |
+
let viewerDetails = $state<Readonly<ViewerDetails>>();
|
| 29 |
+
let mounted = $state(false);
|
| 30 |
|
| 31 |
onMount(() => {
|
| 32 |
const initViewer = async (): Promise<void> => {
|
|
|
|
| 52 |
};
|
| 53 |
});
|
| 54 |
|
| 55 |
+
$effect(() => {
|
| 56 |
+
if (mounted) {
|
| 57 |
+
load_model(url);
|
| 58 |
+
}
|
| 59 |
+
});
|
| 60 |
|
| 61 |
function setRenderingMode(pointsCloud: boolean, wireframe: boolean): void {
|
| 62 |
+
if (!viewerDetails) return;
|
| 63 |
viewerDetails.scene.forcePointsCloud = pointsCloud;
|
| 64 |
viewerDetails.scene.forceWireframe = wireframe;
|
| 65 |
}
|
|
|
|
| 95 |
zoom_speed: number,
|
| 96 |
pan_speed: number
|
| 97 |
): void {
|
| 98 |
+
if (!viewerDetails) return;
|
| 99 |
const camera = viewerDetails.camera;
|
| 100 |
if (camera_position[0] !== null) {
|
| 101 |
camera.alpha = (camera_position[0] * Math.PI) / 180;
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
export function reset_camera_position(): void {
|
| 119 |
+
if (viewerDetails && viewer) {
|
| 120 |
viewer.resetCamera();
|
| 121 |
}
|
| 122 |
}
|
6.3.0/model3D/shared/Canvas3DGS.svelte
CHANGED
|
@@ -3,19 +3,25 @@
|
|
| 3 |
import * as SPLAT from "gsplat";
|
| 4 |
import type { FileData } from "@gradio/client";
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
let canvas: HTMLCanvasElement;
|
| 13 |
let scene: SPLAT.Scene;
|
| 14 |
let camera: SPLAT.Camera;
|
| 15 |
-
let renderer
|
| 16 |
let controls: SPLAT.OrbitControls;
|
| 17 |
-
let mounted = false;
|
| 18 |
-
let frameId
|
| 19 |
|
| 20 |
function reset_scene(): void {
|
| 21 |
if (frameId !== null) {
|
|
@@ -92,11 +98,13 @@
|
|
| 92 |
};
|
| 93 |
});
|
| 94 |
|
| 95 |
-
|
| 96 |
-
path: undefined
|
| 97 |
-
});
|
| 98 |
|
| 99 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
</script>
|
| 101 |
|
| 102 |
<canvas bind:this={canvas}></canvas>
|
|
|
|
| 3 |
import * as SPLAT from "gsplat";
|
| 4 |
import type { FileData } from "@gradio/client";
|
| 5 |
|
| 6 |
+
let {
|
| 7 |
+
value,
|
| 8 |
+
zoom_speed,
|
| 9 |
+
pan_speed
|
| 10 |
+
}: {
|
| 11 |
+
value: FileData;
|
| 12 |
+
zoom_speed: number;
|
| 13 |
+
pan_speed: number;
|
| 14 |
+
} = $props();
|
| 15 |
+
|
| 16 |
+
let url = $derived(value.url);
|
| 17 |
|
| 18 |
let canvas: HTMLCanvasElement;
|
| 19 |
let scene: SPLAT.Scene;
|
| 20 |
let camera: SPLAT.Camera;
|
| 21 |
+
let renderer = $state<SPLAT.WebGLRenderer | null>(null);
|
| 22 |
let controls: SPLAT.OrbitControls;
|
| 23 |
+
let mounted = $state(false);
|
| 24 |
+
let frameId = $state<number | null>(null);
|
| 25 |
|
| 26 |
function reset_scene(): void {
|
| 27 |
if (frameId !== null) {
|
|
|
|
| 98 |
};
|
| 99 |
});
|
| 100 |
|
| 101 |
+
let path = $derived(value?.path);
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
$effect(() => {
|
| 104 |
+
if (canvas && mounted && path) {
|
| 105 |
+
reset_scene();
|
| 106 |
+
}
|
| 107 |
+
});
|
| 108 |
</script>
|
| 109 |
|
| 110 |
<canvas bind:this={canvas}></canvas>
|
6.3.0/model3D/shared/Model3D.svelte
CHANGED
|
@@ -7,27 +7,36 @@
|
|
| 7 |
import type Canvas3DGS from "./Canvas3DGS.svelte";
|
| 8 |
import type Canvas3D from "./Canvas3D.svelte";
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
null
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
let current_settings = { camera_position, zoom_speed, pan_speed };
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
let use_3dgs = false;
|
| 29 |
-
let Canvas3DGSComponent: typeof Canvas3DGS;
|
| 30 |
-
let Canvas3DComponent: typeof Canvas3D;
|
| 31 |
async function loadCanvas3D(): Promise<typeof Canvas3D> {
|
| 32 |
const module = await import("./Canvas3D.svelte");
|
| 33 |
return module.default;
|
|
@@ -36,25 +45,27 @@
|
|
| 36 |
const module = await import("./Canvas3DGS.svelte");
|
| 37 |
return module.default;
|
| 38 |
}
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
if (
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
-
}
|
| 51 |
|
| 52 |
-
let canvas3d: Canvas3D | undefined;
|
| 53 |
function handle_undo(): void {
|
| 54 |
canvas3d?.reset_camera_position();
|
| 55 |
}
|
| 56 |
|
| 57 |
-
$
|
| 58 |
if (
|
| 59 |
!dequal(current_settings.camera_position, camera_position) ||
|
| 60 |
current_settings.zoom_speed !== zoom_speed ||
|
|
@@ -63,7 +74,7 @@
|
|
| 63 |
canvas3d?.update_camera(camera_position, zoom_speed, pan_speed);
|
| 64 |
current_settings = { camera_position, zoom_speed, pan_speed };
|
| 65 |
}
|
| 66 |
-
}
|
| 67 |
</script>
|
| 68 |
|
| 69 |
<BlockLabel
|
|
@@ -79,7 +90,7 @@
|
|
| 79 |
<IconButton
|
| 80 |
Icon={Undo}
|
| 81 |
label="Undo"
|
| 82 |
-
|
| 83 |
disabled={!has_change_history}
|
| 84 |
/>
|
| 85 |
{/if}
|
|
|
|
| 7 |
import type Canvas3DGS from "./Canvas3DGS.svelte";
|
| 8 |
import type Canvas3D from "./Canvas3D.svelte";
|
| 9 |
|
| 10 |
+
let {
|
| 11 |
+
value,
|
| 12 |
+
display_mode = "solid",
|
| 13 |
+
clear_color = [0, 0, 0, 0],
|
| 14 |
+
label = "",
|
| 15 |
+
show_label,
|
| 16 |
+
i18n,
|
| 17 |
+
zoom_speed = 1,
|
| 18 |
+
pan_speed = 1,
|
| 19 |
+
camera_position = [null, null, null],
|
| 20 |
+
has_change_history = false
|
| 21 |
+
}: {
|
| 22 |
+
value: FileData | null;
|
| 23 |
+
display_mode?: "solid" | "point_cloud" | "wireframe";
|
| 24 |
+
clear_color?: [number, number, number, number];
|
| 25 |
+
label?: string;
|
| 26 |
+
show_label: boolean;
|
| 27 |
+
i18n: I18nFormatter;
|
| 28 |
+
zoom_speed?: number;
|
| 29 |
+
pan_speed?: number;
|
| 30 |
+
camera_position?: [number | null, number | null, number | null];
|
| 31 |
+
has_change_history?: boolean;
|
| 32 |
+
} = $props();
|
| 33 |
|
| 34 |
+
let current_settings = $state({ camera_position, zoom_speed, pan_speed });
|
| 35 |
+
let use_3dgs = $state(false);
|
| 36 |
+
let Canvas3DGSComponent = $state<typeof Canvas3DGS>();
|
| 37 |
+
let Canvas3DComponent = $state<typeof Canvas3D>();
|
| 38 |
+
let canvas3d = $state<Canvas3D | undefined>();
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
async function loadCanvas3D(): Promise<typeof Canvas3D> {
|
| 41 |
const module = await import("./Canvas3D.svelte");
|
| 42 |
return module.default;
|
|
|
|
| 45 |
const module = await import("./Canvas3DGS.svelte");
|
| 46 |
return module.default;
|
| 47 |
}
|
| 48 |
+
|
| 49 |
+
$effect(() => {
|
| 50 |
+
if (value) {
|
| 51 |
+
use_3dgs = value.path.endsWith(".splat") || value.path.endsWith(".ply");
|
| 52 |
+
if (use_3dgs) {
|
| 53 |
+
loadCanvas3DGS().then((component) => {
|
| 54 |
+
Canvas3DGSComponent = component;
|
| 55 |
+
});
|
| 56 |
+
} else {
|
| 57 |
+
loadCanvas3D().then((component) => {
|
| 58 |
+
Canvas3DComponent = component;
|
| 59 |
+
});
|
| 60 |
+
}
|
| 61 |
}
|
| 62 |
+
});
|
| 63 |
|
|
|
|
| 64 |
function handle_undo(): void {
|
| 65 |
canvas3d?.reset_camera_position();
|
| 66 |
}
|
| 67 |
|
| 68 |
+
$effect(() => {
|
| 69 |
if (
|
| 70 |
!dequal(current_settings.camera_position, camera_position) ||
|
| 71 |
current_settings.zoom_speed !== zoom_speed ||
|
|
|
|
| 74 |
canvas3d?.update_camera(camera_position, zoom_speed, pan_speed);
|
| 75 |
current_settings = { camera_position, zoom_speed, pan_speed };
|
| 76 |
}
|
| 77 |
+
});
|
| 78 |
</script>
|
| 79 |
|
| 80 |
<BlockLabel
|
|
|
|
| 90 |
<IconButton
|
| 91 |
Icon={Undo}
|
| 92 |
label="Undo"
|
| 93 |
+
onclick={() => handle_undo()}
|
| 94 |
disabled={!has_change_history}
|
| 95 |
/>
|
| 96 |
{/if}
|
6.3.0/model3D/shared/Model3DUpload.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import {
|
| 3 |
import { Upload, ModifyUpload } from "@gradio/upload";
|
| 4 |
import type { FileData, Client } from "@gradio/client";
|
| 5 |
import { BlockLabel } from "@gradio/atoms";
|
|
@@ -8,83 +8,107 @@
|
|
| 8 |
import type Canvas3DGS from "./Canvas3DGS.svelte";
|
| 9 |
import type Canvas3D from "./Canvas3D.svelte";
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
async function handle_upload({
|
| 34 |
detail
|
| 35 |
}: CustomEvent<FileData>): Promise<void> {
|
| 36 |
value = detail;
|
| 37 |
await tick();
|
| 38 |
-
|
| 39 |
-
|
| 40 |
}
|
| 41 |
|
| 42 |
async function handle_clear(): Promise<void> {
|
| 43 |
value = null;
|
| 44 |
await tick();
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
let use_3dgs = false;
|
| 50 |
-
let Canvas3DGSComponent: typeof Canvas3DGS;
|
| 51 |
-
let Canvas3DComponent: typeof Canvas3D;
|
| 52 |
-
async function loadCanvas3D(): Promise<typeof Canvas3D> {
|
| 53 |
-
const module = await import("./Canvas3D.svelte");
|
| 54 |
-
return module.default;
|
| 55 |
-
}
|
| 56 |
-
async function loadCanvas3DGS(): Promise<typeof Canvas3DGS> {
|
| 57 |
-
const module = await import("./Canvas3DGS.svelte");
|
| 58 |
-
return module.default;
|
| 59 |
-
}
|
| 60 |
-
$: if (value) {
|
| 61 |
-
use_3dgs = value.path.endsWith(".splat") || value.path.endsWith(".ply");
|
| 62 |
-
if (use_3dgs) {
|
| 63 |
-
loadCanvas3DGS().then((component) => {
|
| 64 |
-
Canvas3DGSComponent = component;
|
| 65 |
-
});
|
| 66 |
-
} else {
|
| 67 |
-
loadCanvas3D().then((component) => {
|
| 68 |
-
Canvas3DComponent = component;
|
| 69 |
-
});
|
| 70 |
-
}
|
| 71 |
}
|
| 72 |
|
| 73 |
-
let canvas3d: Canvas3D | undefined;
|
| 74 |
async function handle_undo(): Promise<void> {
|
| 75 |
canvas3d?.reset_camera_position();
|
| 76 |
}
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
drag: boolean;
|
| 82 |
-
load: FileData;
|
| 83 |
-
}>();
|
| 84 |
-
|
| 85 |
-
let dragging = false;
|
| 86 |
-
|
| 87 |
-
$: dispatch("drag", dragging);
|
| 88 |
</script>
|
| 89 |
|
| 90 |
<BlockLabel {show_label} Icon={File} label={label || "3D Model"} />
|
|
@@ -100,7 +124,7 @@
|
|
| 100 |
filetype={[".stl", ".obj", ".gltf", ".glb", "model/obj", ".splat", ".ply"]}
|
| 101 |
bind:dragging
|
| 102 |
bind:uploading
|
| 103 |
-
on:error
|
| 104 |
aria_label={i18n("model3d.drop_to_upload")}
|
| 105 |
>
|
| 106 |
<slot />
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { tick } from "svelte";
|
| 3 |
import { Upload, ModifyUpload } from "@gradio/upload";
|
| 4 |
import type { FileData, Client } from "@gradio/client";
|
| 5 |
import { BlockLabel } from "@gradio/atoms";
|
|
|
|
| 8 |
import type Canvas3DGS from "./Canvas3DGS.svelte";
|
| 9 |
import type Canvas3D from "./Canvas3D.svelte";
|
| 10 |
|
| 11 |
+
let {
|
| 12 |
+
value = $bindable(),
|
| 13 |
+
display_mode = "solid",
|
| 14 |
+
clear_color = [0, 0, 0, 0],
|
| 15 |
+
label = "",
|
| 16 |
+
show_label,
|
| 17 |
+
root,
|
| 18 |
+
i18n,
|
| 19 |
+
zoom_speed = 1,
|
| 20 |
+
pan_speed = 1,
|
| 21 |
+
max_file_size = null,
|
| 22 |
+
uploading = $bindable(),
|
| 23 |
+
upload_promise = $bindable(),
|
| 24 |
+
camera_position = [null, null, null],
|
| 25 |
+
upload,
|
| 26 |
+
stream_handler,
|
| 27 |
+
onchange,
|
| 28 |
+
onclear,
|
| 29 |
+
ondrag,
|
| 30 |
+
onload,
|
| 31 |
+
onerror
|
| 32 |
+
}: {
|
| 33 |
+
value?: FileData | null;
|
| 34 |
+
display_mode?: "solid" | "point_cloud" | "wireframe";
|
| 35 |
+
clear_color?: [number, number, number, number];
|
| 36 |
+
label?: string;
|
| 37 |
+
show_label: boolean;
|
| 38 |
+
root: string;
|
| 39 |
+
i18n: I18nFormatter;
|
| 40 |
+
zoom_speed?: number;
|
| 41 |
+
pan_speed?: number;
|
| 42 |
+
max_file_size?: number | null;
|
| 43 |
+
uploading?: boolean;
|
| 44 |
+
upload_promise?: Promise<(FileData | null)[]> | null;
|
| 45 |
+
camera_position?: [number | null, number | null, number | null];
|
| 46 |
+
upload: Client["upload"];
|
| 47 |
+
stream_handler: Client["stream"];
|
| 48 |
+
onchange?: (value: FileData | null) => void;
|
| 49 |
+
onclear?: () => void;
|
| 50 |
+
ondrag?: (dragging: boolean) => void;
|
| 51 |
+
onload?: (value: FileData) => void;
|
| 52 |
+
onerror?: (error: string) => void;
|
| 53 |
+
} = $props();
|
| 54 |
|
| 55 |
+
let use_3dgs = $state(false);
|
| 56 |
+
let Canvas3DGSComponent = $state<typeof Canvas3DGS>();
|
| 57 |
+
let Canvas3DComponent = $state<typeof Canvas3D>();
|
| 58 |
+
let canvas3d = $state<Canvas3D | undefined>();
|
| 59 |
+
let dragging = $state(false);
|
| 60 |
+
|
| 61 |
+
async function loadCanvas3D(): Promise<typeof Canvas3D> {
|
| 62 |
+
const module = await import("./Canvas3D.svelte");
|
| 63 |
+
return module.default;
|
| 64 |
+
}
|
| 65 |
+
async function loadCanvas3DGS(): Promise<typeof Canvas3DGS> {
|
| 66 |
+
const module = await import("./Canvas3DGS.svelte");
|
| 67 |
+
return module.default;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
$effect(() => {
|
| 71 |
+
if (value) {
|
| 72 |
+
use_3dgs = value.path.endsWith(".splat") || value.path.endsWith(".ply");
|
| 73 |
+
if (use_3dgs) {
|
| 74 |
+
loadCanvas3DGS().then((component) => {
|
| 75 |
+
Canvas3DGSComponent = component;
|
| 76 |
+
});
|
| 77 |
+
} else {
|
| 78 |
+
loadCanvas3D().then((component) => {
|
| 79 |
+
Canvas3DComponent = component;
|
| 80 |
+
});
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
$effect(() => {
|
| 86 |
+
ondrag?.(dragging);
|
| 87 |
+
});
|
| 88 |
|
| 89 |
async function handle_upload({
|
| 90 |
detail
|
| 91 |
}: CustomEvent<FileData>): Promise<void> {
|
| 92 |
value = detail;
|
| 93 |
await tick();
|
| 94 |
+
onchange?.(value);
|
| 95 |
+
onload?.(value as FileData);
|
| 96 |
}
|
| 97 |
|
| 98 |
async function handle_clear(): Promise<void> {
|
| 99 |
value = null;
|
| 100 |
await tick();
|
| 101 |
+
onclear?.();
|
| 102 |
+
onchange?.(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
}
|
| 104 |
|
|
|
|
| 105 |
async function handle_undo(): Promise<void> {
|
| 106 |
canvas3d?.reset_camera_position();
|
| 107 |
}
|
| 108 |
|
| 109 |
+
function handle_error({ detail }: CustomEvent<string>): void {
|
| 110 |
+
onerror?.(detail);
|
| 111 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
</script>
|
| 113 |
|
| 114 |
<BlockLabel {show_label} Icon={File} label={label || "3D Model"} />
|
|
|
|
| 124 |
filetype={[".stl", ".obj", ".gltf", ".glb", "model/obj", ".splat", ".ply"]}
|
| 125 |
bind:dragging
|
| 126 |
bind:uploading
|
| 127 |
+
on:error={handle_error}
|
| 128 |
aria_label={i18n("model3d.drop_to_upload")}
|
| 129 |
>
|
| 130 |
<slot />
|