mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-20 22:47:04 +01:00
slightly faster initial load
This commit is contained in:
@@ -4,7 +4,7 @@ import {Ref, ref} from 'vue';
|
||||
import {Document} from '@gltf-transform/core';
|
||||
import {ModelViewerInfo} from "./viewer/ModelViewerWrapper.vue";
|
||||
import {splitGlbs} from "../models/glb/glbs";
|
||||
import {merge, toBuffer} from "../models/glb/merge";
|
||||
import {mergeFinalize, mergePartial, toBuffer} from "../models/glb/merge";
|
||||
import {settings} from "./settings";
|
||||
|
||||
export type SceneMgrRefData = {
|
||||
@@ -28,7 +28,7 @@ export class SceneMgr {
|
||||
}
|
||||
|
||||
/** Creates a new SceneManagerData object */
|
||||
static newData(): [Ref<SceneMgrRefData>, SceneMgrData] {
|
||||
static newData(): [Ref<SceneMgrRefData>, SceneMgrData] {
|
||||
let refData: any = ref({
|
||||
viewerSrc: null,
|
||||
viewer: null,
|
||||
@@ -54,17 +54,11 @@ export class SceneMgr {
|
||||
console.log("Loading", name, "which has", numChunks, "GLB chunks");
|
||||
|
||||
// Start merging each chunk into the current document, replacing or adding as needed
|
||||
let lastShow = performance.now();
|
||||
while (true) {
|
||||
let {value: glbData, done} = await glbsSplitter.next();
|
||||
if (done) break;
|
||||
data.document = await merge(glbData, name, data.document);
|
||||
|
||||
// Show the partial model while loading every once in a while
|
||||
if (performance.now() - lastShow > settings.displayLoadingEveryMs) {
|
||||
await this.showCurrentDoc(refData, data);
|
||||
lastShow = performance.now();
|
||||
}
|
||||
data.document = await mergePartial(glbData, name, data.document);
|
||||
// TODO: Report load progress
|
||||
}
|
||||
|
||||
// Display the final fully loaded model
|
||||
@@ -73,6 +67,7 @@ export class SceneMgr {
|
||||
|
||||
/** Serializes the current document into a GLB and updates the viewerSrc */
|
||||
private static async showCurrentDoc(refData: Ref<SceneMgrRefData>, data: SceneMgrData) {
|
||||
data.document = await mergeFinalize(data.document);
|
||||
let buffer = await toBuffer(data.document);
|
||||
let blob = new Blob([buffer], {type: 'model/gltf-binary'});
|
||||
console.log("Showing current doc", data.document, "as", Array.from(buffer));
|
||||
|
||||
@@ -7,8 +7,10 @@ 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 merge(glb: Uint8Array, name: string, document: Document): Promise<Document> {
|
||||
export async function mergePartial(glb: Uint8Array, name: string, document: Document): Promise<Document> {
|
||||
|
||||
let newDoc = await io.readBinary(glb);
|
||||
|
||||
@@ -18,12 +20,14 @@ export async function merge(glb: Uint8Array, name: string, document: Document):
|
||||
let merged = document.merge(newDoc);
|
||||
|
||||
// noinspection TypeScriptValidateJSTypes
|
||||
return await merged.transform(mergeScenes(), unpartition()); // Single scene & buffer required!
|
||||
return await merged.transform(mergeScenes()); // Single scene & buffer required!
|
||||
}
|
||||
|
||||
export async function mergeFinalize(document: Document): Promise<Document> {
|
||||
return await document.transform(unpartition());
|
||||
}
|
||||
|
||||
export async function toBuffer(doc: Document): Promise<Uint8Array> {
|
||||
|
||||
return io.writeBinary(doc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user