lots of improvements

This commit is contained in:
Yeicor
2024-02-17 17:37:15 +01:00
parent 52f6349c34
commit a0b8cfe2a8
8 changed files with 154 additions and 39 deletions

41
src/misc/scene.ts Normal file
View File

@@ -0,0 +1,41 @@
import type {ModelViewerElement} from '@google/model-viewer';
import type {ModelScene} from "@google/model-viewer/lib/three-components/ModelScene";
import {ref, Ref} from 'vue';
import {Document} from '@gltf-transform/core';
import {ModelViewerInfo} from "./viewer/ModelViewerWrapper.vue";
type SceneManagerData = {
/** When updated, forces the viewer to load a new model replacing the current one */
viewerSrc: string | null
/** The model viewer HTML element with all APIs */
viewer: ModelViewerElement | null
/** The (hidden) scene of the model viewer */
viewerScene: ModelScene | null
/** The currently shown document, which must match the viewerSrc. */
document: Document | null
}
/** This class helps manage SceneManagerData. All methods are static to support reactivity... */
export class SceneMgr {
private constructor() {
}
/** Creates a new SceneManagerData object */
static newData(): Ref<SceneManagerData> {
return ref({
viewerSrc: null,
viewer: null,
viewerScene: null,
document: null,
});
}
/** Should be called any model finishes loading successfully (after a viewerSrc update) */
static onload(data: SceneManagerData, info: typeof ModelViewerInfo) {
console.log("ModelViewer loaded", info);
data.viewer = info.viewer;
data.viewerScene = info.scene;
}
}