mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-19 22:24:17 +01:00
add support for programmatically and efficiently removing objects, better API and more CI automation
This commit is contained in:
@@ -32,11 +32,13 @@ const disableTap = ref(false);
|
||||
const setDisableTap = (val: boolean) => disableTap.value = val;
|
||||
provide('disableTap', {disableTap, setDisableTap});
|
||||
|
||||
async function onModelLoadRequest(event: NetworkUpdateEvent) {
|
||||
// Load a new batch of models to optimize rendering time
|
||||
async function onModelUpdateRequest(event: NetworkUpdateEvent) {
|
||||
// Load/unload a new batch of models to optimize rendering time
|
||||
console.log("Received model update request", event.models);
|
||||
let doc = sceneDocument.value;
|
||||
for (let model of event.models) {
|
||||
let isLast = event.models[event.models.length - 1].url == model.url;
|
||||
for (let modelIndex in event.models) {
|
||||
let isLast = parseInt(modelIndex) === event.models.length - 1;
|
||||
let model = event.models[modelIndex];
|
||||
if (!model.isRemove) {
|
||||
doc = await SceneMgr.loadModel(sceneUrl, doc, model.name, model.url, isLast, isLast);
|
||||
} else {
|
||||
@@ -54,7 +56,7 @@ async function onModelRemoveRequest(name: string) {
|
||||
|
||||
// Set up the load model event listener
|
||||
let networkMgr = new NetworkManager();
|
||||
networkMgr.addEventListener('update', (e) => onModelLoadRequest(e as NetworkUpdateEvent));
|
||||
networkMgr.addEventListener('update', (e) => onModelUpdateRequest(e as NetworkUpdateEvent));
|
||||
// Start loading all configured models ASAP
|
||||
for (let model of settings.preload) {
|
||||
networkMgr.load(model);
|
||||
|
||||
@@ -5,6 +5,12 @@ import {createVuetify} from 'vuetify';
|
||||
import * as directives from 'vuetify/lib/directives/index.mjs';
|
||||
import 'vuetify/dist/vuetify.css';
|
||||
|
||||
// @ts-ignore
|
||||
if (__APP_NAME__) {
|
||||
// @ts-ignore
|
||||
console.log(`Starting ${__APP_NAME__} v${__APP_VERSION__} (${__APP_GIT_SHA__}${__APP_GIT_DIRTY__ ? "+dirty" : ""})...`);
|
||||
}
|
||||
|
||||
const vuetify = createVuetify({
|
||||
directives,
|
||||
theme: {
|
||||
|
||||
@@ -82,10 +82,13 @@ export class NetworkManager extends EventTarget {
|
||||
|
||||
private foundModel(name: string, hash: string | null, url: string, isRemove: boolean) {
|
||||
let prevHash = this.knownObjectHashes[name];
|
||||
let hashToCheck = hash + (isRemove ? "-remove" : "");
|
||||
// console.debug("Found model", name, "with hash", hash, "and previous hash", prevHash);
|
||||
if (!hash || hashToCheck !== prevHash) {
|
||||
this.knownObjectHashes[name] = hash;
|
||||
if (!hash || hash !== prevHash || isRemove) {
|
||||
if (!isRemove) {
|
||||
this.knownObjectHashes[name] = hash;
|
||||
} else {
|
||||
delete this.knownObjectHashes[name];
|
||||
}
|
||||
let newModel = new NetworkUpdateEventModel(name, url, hash, isRemove);
|
||||
this.bufferedUpdates.push(newModel);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ export class SceneMgr {
|
||||
|
||||
private static async reloadHelpers(sceneUrl: Ref<string>, document: Document, reloadScene: boolean): Promise<Document> {
|
||||
let bb = SceneMgr.getBoundingBox(document);
|
||||
if (!bb) return document;
|
||||
|
||||
// Create the helper axes and grid box
|
||||
let helpersDoc = new Document();
|
||||
@@ -45,7 +46,8 @@ export class SceneMgr {
|
||||
return await SceneMgr.loadModel(sceneUrl, document, extrasNameValueHelpers, helpersUrl, false, reloadScene);
|
||||
}
|
||||
|
||||
static getBoundingBox(document: Document): Box3 {
|
||||
static getBoundingBox(document: Document): Box3 | null {
|
||||
if (document.getRoot().listNodes().length === 0) return null;
|
||||
// Get bounding box of the model and use it to set the size of the helpers
|
||||
let bbMin: number[] = [1e6, 1e6, 1e6];
|
||||
let bbMax: number[] = [-1e6, -1e6, -1e6];
|
||||
|
||||
Reference in New Issue
Block a user