Commit 5a38e4d7 authored by Luna Riegel's avatar Luna Riegel
Browse files

Rework Catalog model loading

parent 1573e335
...@@ -6,7 +6,7 @@ import BIMOptions, { bimOptionsId } from './upload.vue'; ...@@ -6,7 +6,7 @@ import BIMOptions, { bimOptionsId } from './upload.vue';
import objectList, { objectListId } from './objectList.vue'; import objectList, { objectListId } from './objectList.vue';
import scaleControl, { scaleControlId } from './scaleControl.vue'; import scaleControl, { scaleControlId } from './scaleControl.vue';
import * as Cesium from "@vcmap-cesium/engine"; import * as Cesium from "@vcmap-cesium/engine";
import {loadCatalogModel} from "./objectList.vue";
let model; let model;
let conditions = [[true, true]]; let conditions = [[true, true]];
...@@ -56,6 +56,7 @@ function setScale(scaleValue) { ...@@ -56,6 +56,7 @@ function setScale(scaleValue) {
const position = currentlyScaledModel.position.getValue(); const position = currentlyScaledModel.position.getValue();
const orientation = currentlyScaledModel.orientation; const orientation = currentlyScaledModel.orientation;
const uri = currentlyScaledModel.model.uri; const uri = currentlyScaledModel.model.uri;
const fromCatalog = currentlyScaledModel.fromCatalog;
vcMap.getEntities().remove(currentlyScaledModel); vcMap.getEntities().remove(currentlyScaledModel);
removePlacedModel(currentlyScaledModel); removePlacedModel(currentlyScaledModel);
...@@ -70,6 +71,7 @@ function setScale(scaleValue) { ...@@ -70,6 +71,7 @@ function setScale(scaleValue) {
scale: scaleValue, scale: scaleValue,
show: true, show: true,
}, },
fromCatalog: fromCatalog,
}); });
placedModels.push({ placedModels.push({
model: newModel, model: newModel,
...@@ -102,6 +104,7 @@ function saveObjects() { ...@@ -102,6 +104,7 @@ function saveObjects() {
position: [wgs84X, wgs84Y, height], position: [wgs84X, wgs84Y, height],
heading: heading, heading: heading,
scale: m.model.model.scale.getValue(), scale: m.model.model.scale.getValue(),
fromCatalog: m.fromCatalog,
}); });
} }
outputObject.placedObjects = outputArray; outputObject.placedObjects = outputArray;
...@@ -127,7 +130,7 @@ function saveFile(fileName, urlFile){ ...@@ -127,7 +130,7 @@ function saveFile(fileName, urlFile){
} }
function setupModel(vcsApp, windowPos, url, name) { function setupModel(vcsApp, windowPos, url, name, fromCatalog) {
const vcMap = vcsApp.maps.activeMap; const vcMap = vcsApp.maps.activeMap;
const scene = vcMap.getScene(); const scene = vcMap.getScene();
const ray = scene.camera.getPickRay(windowPos); const ray = scene.camera.getPickRay(windowPos);
...@@ -141,6 +144,7 @@ function setupModel(vcsApp, windowPos, url, name) { ...@@ -141,6 +144,7 @@ function setupModel(vcsApp, windowPos, url, name) {
show: true, show: true,
scale: 1, scale: 1,
}, },
fromCatalog: fromCatalog,
}); });
placedModels.push({ placedModels.push({
model: model, model: model,
...@@ -351,12 +355,27 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -351,12 +355,27 @@ export default function smartVillagesPlugin(config, baseUrl) {
} }
} }
if (objectUrl === undefined) { if (objectUrl === undefined) {
app.notifier.add({ console.log("From Catalog:" + loadingObject.fromCatalog);
type: NotificationType.ERROR, if (loadingObject.fromCatalog === true){
message: "Objekt mit dem namen: " + loadingObject.name + " konnte nicht in den geladenen Objekten gefunden werden. Konfiguration konnte nicht vollständig geladen werden.", // TODO: Fetch from catalog
}); objectUrl = loadingObject.uri;
// abort // Load the model into memory
return; loadCatalogModel(objectUrl).catch(e => {
console.error(e);
app.notifier.add({
type: NotificationType.ERROR,
message: "Katalogobject: " + loadingObject.name + " konnte nicht geladenen werden. Konfiguration konnte nicht vollständig geladen werden.",
});
});
return;
}else {
app.notifier.add({
type: NotificationType.ERROR,
message: "Objekt mit dem namen: " + loadingObject.name + " konnte nicht in den geladenen Objekten gefunden werden. Konfiguration konnte nicht vollständig geladen werden.",
});
// abort
return;
}
} }
const cartPos = Cartesian3.fromDegrees(loadingObject.position[0], loadingObject.position[1], loadingObject.position[2]); const cartPos = Cartesian3.fromDegrees(loadingObject.position[0], loadingObject.position[1], loadingObject.position[2]);
// Add the model to the viewer // Add the model to the viewer
...@@ -368,6 +387,7 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -368,6 +387,7 @@ export default function smartVillagesPlugin(config, baseUrl) {
scale: loadingObject.scale, scale: loadingObject.scale,
show: true, show: true,
}, },
fromCatalog: loadingObject.fromCatalog,
}); });
const roll = new HeadingPitchRoll(); const roll = new HeadingPitchRoll();
hpRollMap.set(model, roll); hpRollMap.set(model, roll);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</template> </template>
<template #default> <template #default>
<v-expansion-panels multiple> <v-expansion-panels multiple>
<VcsExpansionPanel v-for = "(subcats, categoryName) in objLib" :key="categoryName" :heading="categoryName" value="opened"> <VcsExpansionPanel v-for = "(subcats, categoryName) in objLib" :key="categoryName" :heading="categoryName">
<v-container v-for="(entries, subCategory) in subcats" :key = "subCategory" class=" py-1 px-1 border-b-md"> <v-container v-for="(entries, subCategory) in subcats" :key = "subCategory" class=" py-1 px-1 border-b-md">
<v-col> <v-col>
<VcsLabel class="mb-4 text-h2">{{subCategory}}</VcsLabel> <VcsLabel class="mb-4 text-h2">{{subCategory}}</VcsLabel>
...@@ -210,71 +210,74 @@ function getCatalogueEntries(json, linkPrefix) { ...@@ -210,71 +210,74 @@ function getCatalogueEntries(json, linkPrefix) {
} }
async function retrieveCatalogModel(modelLink){ async function retrieveCatalogModel(modelLink){
if(preloadedModels.value[modelLink] != null){ loadCatalogModel(modelLink).then(model => {
const catModel = preloadedModels.value[modelLink]; const catModel = model;
const x = window.innerWidth / 2; const x = window.innerWidth / 2;
const y = window.innerHeight / 2; const y = window.innerHeight / 2;
const cart = new Cartesian2(x, y); const cart = new Cartesian2(x, y);
setupModelFunction(app, cart, catModel.url, catModel.modelLink); setupModelFunction(app, cart, catModel.url, catModel.modelLink, true);
} else { }).catch(error => {
const loader = new GLTFLoader(); console.error(error);
loader.load( app.notifier.add({
modelLink, type: NotificationType.ERROR,
function (gltf) { message:
const bounds = new THREE.Box3().setFromObject(gltf.scene); 'Ein Fehler ist beim Laden des Katalogobjektes aufgetreten.',
const x = bounds.min.x + (bounds.max.x - bounds.min.x) / 2; timeout: 20000,
const z = bounds.min.z + (bounds.max.z - bounds.min.z) / 2; });
const m = new THREE.Matrix4().makeTranslation(-x, -bounds.min.y, -z); });
gltf.scene.applyMatrix4(m); }
const exporter = new GLTFExporter();
const options = {
binary: true,
animations: gltf.animations,
};
exporter.parse( export async function loadCatalogModel(modelLink){
gltf.scene, return new Promise( (resolve, reject) => {
function (output) { if(preloadedModels.value[modelLink] != null){
const blob = new Blob([output], { type: 'application/octet-stream' }); resolve(preloadedModels.value[modelLink]);
const url = URL.createObjectURL(blob); } else{
//Todo: parse model from catalog
projectStateObject.objects.push({ const loader = new GLTFLoader();
name: modelLink, loader.load(
url: url, modelLink,
}); function (gltf) {
const x = window.innerWidth / 2; const bounds = new THREE.Box3().setFromObject(gltf.scene);
const y = window.innerHeight / 2; const x = bounds.min.x + (bounds.max.x - bounds.min.x) / 2;
const cart = new Cartesian2(x, y); const z = bounds.min.z + (bounds.max.z - bounds.min.z) / 2;
setupModelFunction(app, cart, url, modelLink); const m = new THREE.Matrix4().makeTranslation(-x, -bounds.min.y, -z);
preloadedModels.value[modelLink] = { gltf.scene.applyMatrix4(m);
url: url,
modelLink: modelLink, const exporter = new GLTFExporter();
}; const options = {
}, binary: true,
function (error) { animations: gltf.animations,
app.notifier.add({ };
type: NotificationType.ERROR,
message: exporter.parse(
'Ein Fehler ist beim Laden der glTF Datei aufgetreten. Bitte vergewissern Sie sich, dass es sich um eine gültige glTF2.0 Datei handelt.', gltf.scene,
timeout: 20000, function (output) {
}); const blob = new Blob([output], { type: 'application/octet-stream' });
}, const url = URL.createObjectURL(blob);
options
); projectStateObject.objects.push({
}, name: modelLink,
undefined, url: url,
function (error) { });
app.notifier.add({ preloadedModels.value[modelLink] = {
type: NotificationType.ERROR, url: url,
message: modelLink: modelLink,
'Ein Fehler ist beim Laden der glTF Datei aufgetreten. Bitte vergewissern Sie sich, dass es sich um eine gültige glTF2.0 Datei handelt.' + };
' Fehlermeldung: ' + error.message, resolve(preloadedModels.value[modelLink]);
timeout: 20000, },
}); function (error) {
} reject(error);
); },
} options
);
},
undefined,
function (error) {
reject(error);
}
);
}
})
} }
function uploadModel() { function uploadModel() {
...@@ -336,7 +339,7 @@ function uploadModel() { ...@@ -336,7 +339,7 @@ function uploadModel() {
const x = window.innerWidth / 2; const x = window.innerWidth / 2;
const y = window.innerHeight / 2; const y = window.innerHeight / 2;
const cart = new Cartesian2(x, y); const cart = new Cartesian2(x, y);
setupModelFunction(app, cart, url, name); setupModelFunction(app, cart, url, name, false);
}, },
} }
] ]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment