mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-20 06:27:04 +01:00
better glbs model loading
This commit is contained in:
@@ -9,7 +9,7 @@ import Models from "./models/Models.vue";
|
|||||||
import {VLayout, VMain, VToolbarTitle} from "vuetify/lib/components";
|
import {VLayout, VMain, VToolbarTitle} from "vuetify/lib/components";
|
||||||
import {settings} from "./misc/settings";
|
import {settings} from "./misc/settings";
|
||||||
import {NetworkManager, NetworkUpdateEvent} from "./misc/network";
|
import {NetworkManager, NetworkUpdateEvent} from "./misc/network";
|
||||||
import {newSceneMgrData, SceneMgr, SceneManagerData} from "./misc/scene";
|
import {SceneManagerData, SceneMgr} from "./misc/scene";
|
||||||
|
|
||||||
// NOTE: The ModelViewer library is big (THREE.js), so we split it and import it asynchronously
|
// NOTE: The ModelViewer library is big (THREE.js), so we split it and import it asynchronously
|
||||||
const ModelViewerWrapper = defineAsyncComponent({
|
const ModelViewerWrapper = defineAsyncComponent({
|
||||||
@@ -51,7 +51,7 @@ for (let model of settings.preloadModels) {
|
|||||||
</sidebar>
|
</sidebar>
|
||||||
|
|
||||||
<!-- The right collapsible sidebar has the list of tools -->
|
<!-- The right collapsible sidebar has the list of tools -->
|
||||||
<sidebar :opened-init="openSidebarsByDefault" side="right" :width="120">
|
<sidebar :opened-init="openSidebarsByDefault" side="right" :width="48 * 3 /* buttons */ + 1">
|
||||||
<template #toolbar>
|
<template #toolbar>
|
||||||
<v-toolbar-title>Tools</v-toolbar-title>
|
<v-toolbar-title>Tools</v-toolbar-title>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
export const settings = {
|
export const settings = {
|
||||||
preloadModels: [
|
preloadModels: [
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
new URL('../../assets/fox.glb', import.meta.url).href,
|
// new URL('../../assets/fox.glb', import.meta.url).href,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// new URL('../../assets/logo.glbs', import.meta.url).href,
|
new URL('../../assets/logo.glbs', import.meta.url).href,
|
||||||
// Websocket URLs automatically listen for new models from the python backend
|
// Websocket URLs automatically listen for new models from the python backend
|
||||||
//"ws://localhost:8080/"
|
//"ws://localhost:8080/"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export async function* splitGlbs(readerSrc: ReadableStream<Uint8Array>): AsyncGe
|
|||||||
finalBuffer.set(buffer4Bytes);
|
finalBuffer.set(buffer4Bytes);
|
||||||
finalBuffer.set(remaining, buffer4Bytes.length);
|
finalBuffer.set(remaining, buffer4Bytes.length);
|
||||||
yield finalBuffer
|
yield finalBuffer
|
||||||
} else if (magic !== "GLBS") {
|
} else if (magic === "GLBS") {
|
||||||
// First, we read the number of chunks (can be 0xFFFFFFFF if the number of chunks is unknown).
|
// First, we read the number of chunks (can be 0xFFFFFFFF if the number of chunks is unknown).
|
||||||
[buffer4Bytes, buffered] = await readN(reader, buffered, 4);
|
[buffer4Bytes, buffered] = await readN(reader, buffered, 4);
|
||||||
let numChunks = new DataView(buffer4Bytes.buffer).getUint32(0, true);
|
let numChunks = new DataView(buffer4Bytes.buffer).getUint32(0, true);
|
||||||
@@ -28,7 +28,8 @@ export async function* splitGlbs(readerSrc: ReadableStream<Uint8Array>): AsyncGe
|
|||||||
// - Read length
|
// - Read length
|
||||||
[buffer4Bytes, buffered] = await readN(reader, buffered, 4);
|
[buffer4Bytes, buffered] = await readN(reader, buffered, 4);
|
||||||
if (buffer4Bytes.length === 0) {
|
if (buffer4Bytes.length === 0) {
|
||||||
if (numChunks != 0xFFFFFFFF) throw new Error('Unexpected end of stream while reading chunk length');
|
if (numChunks != 0xFFFFFFFF) throw new Error('Unexpected end of stream while reading chunk length:'+
|
||||||
|
' expected ' + (numChunks - i) + ' more chunks');
|
||||||
else break // We reached the end of the stream of unknown length, so we stop reading chunks.
|
else break // We reached the end of the stream of unknown length, so we stop reading chunks.
|
||||||
}
|
}
|
||||||
let length = new DataView(buffer4Bytes.buffer).getUint32(0, true);
|
let length = new DataView(buffer4Bytes.buffer).getUint32(0, true);
|
||||||
@@ -41,7 +42,8 @@ export async function* splitGlbs(readerSrc: ReadableStream<Uint8Array>): AsyncGe
|
|||||||
reader.releaseLock()
|
reader.releaseLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reads exactly `n` bytes from the reader and returns them as a Uint8Array.
|
/**
|
||||||
|
* Reads up to `n` bytes from the reader and returns them as a Uint8Array.
|
||||||
* An over-read is possible, in which case the returned array will still have `n` bytes and the over-read bytes will be
|
* An over-read is possible, in which case the returned array will still have `n` bytes and the over-read bytes will be
|
||||||
* returned. They should be provided to the next call to `readN` to avoid losing data.
|
* returned. They should be provided to the next call to `readN` to avoid losing data.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -59,6 +59,18 @@ function centerCamera() {
|
|||||||
<v-btn icon="" @click="centerCamera">
|
<v-btn icon="" @click="centerCamera">
|
||||||
<svg-icon type="mdi" :path="mdiCrosshairsGps"/>
|
<svg-icon type="mdi" :path="mdiCrosshairsGps"/>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
<v-btn icon="" @click="centerCamera">
|
||||||
|
<svg-icon type="mdi" :path="mdiCrosshairsGps"/>
|
||||||
|
</v-btn>
|
||||||
|
<v-btn icon="" @click="centerCamera">
|
||||||
|
<svg-icon type="mdi" :path="mdiCrosshairsGps"/>
|
||||||
|
</v-btn>
|
||||||
|
<v-btn icon="" @click="centerCamera">
|
||||||
|
<svg-icon type="mdi" :path="mdiCrosshairsGps"/>
|
||||||
|
</v-btn>
|
||||||
|
<v-btn icon="" @click="centerCamera">
|
||||||
|
<svg-icon type="mdi" :path="mdiCrosshairsGps"/>
|
||||||
|
</v-btn>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!--suppress CssUnusedSymbol -->
|
<!--suppress CssUnusedSymbol -->
|
||||||
|
|||||||
Reference in New Issue
Block a user