cleaner constant

This commit is contained in:
Yeicor
2024-03-02 13:45:25 +01:00
parent 1e0ed4cd80
commit 50e90b0c5f
3 changed files with 7 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ import {unpartition} from "@gltf-transform/functions";
let io = new WebIO(); let io = new WebIO();
export let extrasNameKey = "__yacv_name"; export let extrasNameKey = "__yacv_name";
export let extrasNameValueHelpers = "__helpers";
/** /**
* Loads a GLB model from a URL and adds it to the document or replaces it if the names match. * Loads a GLB model from a URL and adds it to the document or replaces it if the names match.

View File

@@ -1,6 +1,6 @@
import {Ref, ShallowRef} from 'vue'; import {Ref, ShallowRef} from 'vue';
import {Document} from '@gltf-transform/core'; import {Document} from '@gltf-transform/core';
import {extrasNameKey, mergeFinalize, mergePartial, removeModel, toBuffer} from "./gltf"; import {extrasNameKey, extrasNameValueHelpers, mergeFinalize, mergePartial, removeModel, toBuffer} from "./gltf";
import {newAxes, newGridBox} from "./helpers"; import {newAxes, newGridBox} from "./helpers";
import {Box3, Matrix4, Vector3} from 'three'; import {Box3, Matrix4, Vector3} from 'three';
@@ -13,7 +13,7 @@ export class SceneMgr {
// Start merging into the current document, replacing or adding as needed // Start merging into the current document, replacing or adding as needed
document.value = await mergePartial(url, name, document.value); document.value = await mergePartial(url, name, document.value);
if (name !== "__helpers") { if (name !== extrasNameValueHelpers) {
// Reload the helpers to fit the new model // Reload the helpers to fit the new model
await this.reloadHelpers(sceneUrl, document); await this.reloadHelpers(sceneUrl, document);
} else { } else {
@@ -35,7 +35,7 @@ export class SceneMgr {
newAxes(helpersDoc, bb.getSize(new Vector3()).multiplyScalar(0.5), transform); newAxes(helpersDoc, bb.getSize(new Vector3()).multiplyScalar(0.5), transform);
newGridBox(helpersDoc, bb.getSize(new Vector3()), transform); newGridBox(helpersDoc, bb.getSize(new Vector3()), transform);
let helpersUrl = URL.createObjectURL(new Blob([await toBuffer(helpersDoc)])); let helpersUrl = URL.createObjectURL(new Blob([await toBuffer(helpersDoc)]));
await SceneMgr.loadModel(sceneUrl, document, "__helpers", helpersUrl); await SceneMgr.loadModel(sceneUrl, document, extrasNameValueHelpers, helpersUrl);
} }
static getBoundingBox(document: ShallowRef<Document>): Box3 { static getBoundingBox(document: ShallowRef<Document>): Box3 {
@@ -43,7 +43,7 @@ export class SceneMgr {
let bbMin: number[] = [1e6, 1e6, 1e6]; let bbMin: number[] = [1e6, 1e6, 1e6];
let bbMax: number[] = [-1e6, -1e6, -1e6]; let bbMax: number[] = [-1e6, -1e6, -1e6];
document.value.getRoot().listNodes().forEach(node => { document.value.getRoot().listNodes().forEach(node => {
if ((node.getExtras()[extrasNameKey] ?? "__helpers") === "__helpers") return; if ((node.getExtras()[extrasNameKey] ?? extrasNameValueHelpers) === extrasNameValueHelpers) return;
let transform = new Matrix4(...node.getWorldMatrix()); let transform = new Matrix4(...node.getWorldMatrix());
for (let prim of node.getMesh()?.listPrimitives() ?? []) { for (let prim of node.getMesh()?.listPrimitives() ?? []) {
let accessor = prim.getAttribute('POSITION'); let accessor = prim.getAttribute('POSITION');

View File

@@ -11,7 +11,7 @@ import {
VSpacer, VSpacer,
VTooltip, VTooltip,
} from "vuetify/lib/components"; } from "vuetify/lib/components";
import {extrasNameKey} from "../misc/gltf"; import {extrasNameKey, extrasNameValueHelpers} from "../misc/gltf";
import {Document, Mesh} from "@gltf-transform/core"; import {Document, Mesh} from "@gltf-transform/core";
import {inject, ref, ShallowRef, watch} from "vue"; import {inject, ref, ShallowRef, watch} from "vue";
import type ModelViewerWrapper from "../viewer/ModelViewerWrapper.vue"; import type ModelViewerWrapper from "../viewer/ModelViewerWrapper.vue";
@@ -181,7 +181,7 @@ function onModelLoad() {
// back faces with a different material. // back faces with a different material.
child.material.side = FrontSide; child.material.side = FrontSide;
if (modelName !== "__helpers") { if (modelName !== extrasNameValueHelpers) {
// The back of the material only writes to the stencil buffer the areas // The back of the material only writes to the stencil buffer the areas
// that should be covered by the plane, but does not render anything // that should be covered by the plane, but does not render anything
let backChild = child.clone(); let backChild = child.clone();