Refactoring

This commit is contained in:
2024-03-25 21:22:53 +01:00
parent 6e6eb5069f
commit 073d474bc3
17 changed files with 66 additions and 36 deletions

View File

@@ -22,8 +22,9 @@
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import {onDestroy, onMount} from "svelte";
import { CollectionEntry } from "astro:content";
export let file: string;
export let pub: CollectionEntry<"publics">;
export let fov: number = 60;
export let near: number = 1
export let far: number = 1000;
@@ -40,6 +41,10 @@
let observer: ResizeObserver;
onMount(() => {
if (!pub.data["3d"]) {
return;
}
scene = new THREE.Scene();
scene.background = new THREE.Color(0x171717);
camera = new THREE.PerspectiveCamera(fov, 1, near, far);
@@ -52,8 +57,8 @@
const loader = new GLTFLoader();
loader.load(`/3d/${file}.glb`, (gltf) => {
let s = scene.add(gltf.scene);
loader.load(`/3d/${pub.id}.glb`, (gltf) => {
scene.add(gltf.scene);
let cube_bbox = new THREE.Box3();
cube_bbox.setFromObject(gltf.scene);
@@ -64,7 +69,9 @@
camera.position.set(0, center.y, distance);
controls.update();
}, undefined, console.log);
}, undefined, (e) => {
console.error(e);
});
div.append(renderer.domElement);