refactor most of the frontend and add permissive cors to backend

This commit is contained in:
Yeicor
2024-02-24 17:22:58 +01:00
parent 7dfdbdd34c
commit a72cc8dd09
13 changed files with 149 additions and 148 deletions

View File

@@ -1,9 +1,14 @@
<script setup lang="ts">
import {VExpansionPanel, VExpansionPanels, VExpansionPanelText, VExpansionPanelTitle} from "vuetify/lib/components";
import type ModelViewerWrapper from "../viewer/ModelViewerWrapper.vue";
import Loading from "../misc/Loading.vue";
let props = defineProps<{ viewer: typeof ModelViewerWrapper | null }>();
</script>
<template>
<v-expansion-panels>
<Loading v-if="!props.viewer"/>
<v-expansion-panels v-else>
<v-expansion-panel key="model-id">
<v-expansion-panel-title>? F ? E ? V | Model Name</v-expansion-panel-title>
<v-expansion-panel-text>Content</v-expansion-panel-text>

View File

@@ -1,81 +0,0 @@
import {Document, Scene, Transform, WebIO} from "@gltf-transform/core";
import {unpartition} from "@gltf-transform/functions";
let io = new WebIO();
/**
* Given the bytes of a GLB file and a parsed GLTF document, it parses and merges the GLB into the document.
*
* It can replace previous models in the document if the provided name matches the name of a previous model.
*
* Remember to call mergeFinalize after all models have been merged (slower required operations).
*/
export async function mergePartial(glb: Uint8Array, name: string, document: Document): Promise<Document> {
// Load the new document
let newDoc = await io.readBinary(glb);
// Remove any previous model with the same name and ensure consistent names
// noinspection TypeScriptValidateJSTypes
await newDoc.transform(dropByName(name), setNames(name));
// Merge the new document into the current one
return document.merge(newDoc);
}
export async function mergeFinalize(document: Document): Promise<Document> {
// Single scene & buffer required before loading & rendering
return await document.transform(mergeScenes(), unpartition());
}
export async function toBuffer(doc: Document): Promise<Uint8Array> {
return io.writeBinary(doc);
}
/** Given a parsed GLTF document and a name, it forces the names of all elements to be identified by the name (or derivatives) */
function setNames(name: string): Transform {
return (doc: Document, _: any) => {
// Do this automatically for all elements changing any name
for (let elem of doc.getGraph().listEdges().map(e => e.getChild())) {
// If setName is available, use it (preserving original names)
elem.setName(name + "/" + elem.getName());
}
// Special cases, specify the kind and number ID of primitives
let i = 0;
for (let mesh of doc.getRoot().listMeshes()) {
for (let prim of mesh.listPrimitives()) {
let kind = (prim.getMode() === WebGL2RenderingContext.POINTS ? "vertex" :
(prim.getMode() === WebGL2RenderingContext.LINES ? "edge" : "face"));
prim.setName(name + "/" + kind + "/" + (i++));
}
}
}
}
/** Ensures that all elements with the given name are removed from the document */
function dropByName(name: string): Transform {
return (doc: Document, _: any) => {
for (let elem of doc.getGraph().listEdges().map(e => e.getChild())) {
if (elem.getName().startsWith(name + "/") && !(elem instanceof Scene)) {
elem.dispose();
}
}
return doc;
};
}
/** Merges all scenes in the document into a single default scene */
function mergeScenes(): Transform {
return (doc: Document) => {
let root = doc.getRoot();
let scene = root.getDefaultScene() ?? root.listScenes()[0];
for (let dropScene of root.listScenes()) {
if (dropScene === scene) continue;
for (let node of dropScene.listChildren()) {
scene.addChild(node);
}
dropScene.dispose();
}
}
}