Commit 4a40a34b authored by Matthias Betz's avatar Matthias Betz
Browse files

add scaling

fix issue with loading positioning with no removed buildings
fix issue with loading animated gltf
parent ef677e29
Showing with 175 additions and 20 deletions
+175 -20
import { ToolboxType, WindowSlot, NotificationType } from '@vcmap/ui'; import { ToolboxType, WindowSlot, NotificationType } from '@vcmap/ui';
import { Cesium3DTileStyle, Math as CMath, ConstantProperty, Transforms, HeadingPitchRoll, Cesium3DTileset } from '@vcmap-cesium/engine'; import { Cesium3DTileStyle, Math as CMath, Cartesian3, ConstantProperty, Transforms, HeadingPitchRoll, Cesium3DTileset, Matrix4 } from '@vcmap-cesium/engine';
import { AbstractInteraction, EventType } from '@vcmap/core'; import { AbstractInteraction, createTransformationHandler, EventType, ScaleInteraction, TransformationHandler, TransformationMode } from '@vcmap/core';
import { name, version, mapVersion } from '../package.json'; import { name, version, mapVersion } from '../package.json';
import BIMOptions, { windowId } from './upload.vue'; import BIMOptions, { bimOptionsId } from './upload.vue';
import objectList, {} from './objectList.vue'; import objectList, { objectListId } from './objectList.vue';
import scaleControl, { scaleControlId } from './scaleControl.vue';
let url;
let model; let model;
let conditions = [[true, true]]; let conditions = [[true, true]];
let activeMouseEvent; let activeMouseEvent;
...@@ -16,6 +16,7 @@ const hpRollMap = new Map(); ...@@ -16,6 +16,7 @@ const hpRollMap = new Map();
let placedModels = []; let placedModels = [];
let hpRoll; let hpRoll;
let app; let app;
let currentlyScaledModel;
const hidingFeatures = []; const hidingFeatures = [];
const hidingListener = function(tile) { const hidingListener = function(tile) {
let allHidden = true; let allHidden = true;
...@@ -34,7 +35,7 @@ const hidingListener = function(tile) { ...@@ -34,7 +35,7 @@ const hidingListener = function(tile) {
const primitives = app.maps.activeMap.getScene().primitives; const primitives = app.maps.activeMap.getScene().primitives;
for (let i = 0; i < primitives.length; i++) { for (let i = 0; i < primitives.length; i++) {
const tileSet = primitives.get(i); const tileSet = primitives.get(i);
if (!tileSet instanceof Cesium3DTileset) { if (!(tileSet instanceof Cesium3DTileset)) {
continue; continue;
} }
tileSet.tileVisible.removeEventListener(hidingListener); tileSet.tileVisible.removeEventListener(hidingListener);
...@@ -46,6 +47,40 @@ function updateHideCondition(gmlId) { ...@@ -46,6 +47,40 @@ function updateHideCondition(gmlId) {
conditions.unshift(['${gml_id} === "' + gmlId + '"', false]); conditions.unshift(['${gml_id} === "' + gmlId + '"', false]);
} }
function setScale(scaleValue) {
const vcMap = app.maps.activeMap;
const name = currentlyScaledModel.name;
const position = currentlyScaledModel.position.getValue();
const orientation = currentlyScaledModel.orientation;
const uri = currentlyScaledModel.model.uri;
vcMap.getEntities().remove(currentlyScaledModel);
removePlacedModel(currentlyScaledModel);
// Add the new model to the viewer
const newModel = vcMap.getEntities().add({
name: name,
position: position,
orientation: orientation,
model: {
uri: uri,
scale: scaleValue,
show: true,
},
});
placedModels.push({
model: newModel,
name: name,
});
const oldHpRoll = hpRollMap.get(currentlyScaledModel);
if (oldHpRoll !== undefined) {
hpRollMap.set(newModel, oldHpRoll);
}
currentlyScaledModel = newModel;
}
function saveObjects() { function saveObjects() {
const outputObject = {}; const outputObject = {};
const outputArray = []; const outputArray = [];
...@@ -59,6 +94,7 @@ function saveObjects() { ...@@ -59,6 +94,7 @@ function saveObjects() {
name: m.name, name: m.name,
position: m.model.position.getValue(), position: m.model.position.getValue(),
heading: heading, heading: heading,
scale: m.model.model.scale.getValue(),
}); });
} }
outputObject.placedObjects = outputArray; outputObject.placedObjects = outputArray;
...@@ -69,7 +105,7 @@ function saveObjects() { ...@@ -69,7 +105,7 @@ function saveObjects() {
outputObject.hiddenObjects = hiddenObjects; outputObject.hiddenObjects = hiddenObjects;
let textData = JSON.stringify(outputObject); let textData = JSON.stringify(outputObject);
let blobData = new Blob([textData], {type: "application/json"}); let blobData = new Blob([textData], {type: "application/json"});
saveFile('ObjektPlatzierung.json', window.URL.createObjectURL(blobData)); saveFile('ObjektPositionierung.json', window.URL.createObjectURL(blobData));
} }
function saveFile(fileName, urlFile){ function saveFile(fileName, urlFile){
...@@ -89,7 +125,6 @@ function setupModel(vcsApp, windowPos, url, name) { ...@@ -89,7 +125,6 @@ function setupModel(vcsApp, windowPos, url, name) {
const scene = vcMap.getScene(); const scene = vcMap.getScene();
const ray = scene.camera.getPickRay(windowPos); const ray = scene.camera.getPickRay(windowPos);
const center = scene.globe.pick(ray, scene); const center = scene.globe.pick(ray, scene);
heightDif = 0;
// Add the model to the viewer // Add the model to the viewer
model = vcMap.getEntities().add({ model = vcMap.getEntities().add({
name: name, name: name,
...@@ -239,6 +274,7 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -239,6 +274,7 @@ export default function smartVillagesPlugin(config, baseUrl) {
}, },
pluginState, pluginState,
setupModel, setupModel,
setScale,
saveObjects, saveObjects,
loadObjects(app) { loadObjects(app) {
// Create an input element // Create an input element
...@@ -283,6 +319,7 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -283,6 +319,7 @@ export default function smartVillagesPlugin(config, baseUrl) {
position: loadingObject.position, position: loadingObject.position,
model: { model: {
uri: objectUrl, uri: objectUrl,
scale: loadingObject.scale,
show: true, show: true,
}, },
}); });
...@@ -304,15 +341,17 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -304,15 +341,17 @@ export default function smartVillagesPlugin(config, baseUrl) {
loops: 0, loops: 0,
}); });
} }
const primitives = vcMap.getScene().primitives; if (objects.hiddenObjects.length > 0) {
for (let i = 0; i < primitives.length; i++) { const primitives = vcMap.getScene().primitives;
const tileSet = primitives.get(i); for (let i = 0; i < primitives.length; i++) {
if (!tileSet instanceof Cesium3DTileset) { const tileSet = primitives.get(i);
continue; if (!(tileSet instanceof Cesium3DTileset)) {
continue;
}
tileSet.tileVisible.addEventListener(hidingListener);
} }
tileSet.tileVisible.addEventListener(hidingListener);
} }
} }
reader.readAsText(file); reader.readAsText(file);
}); });
...@@ -326,7 +365,8 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -326,7 +365,8 @@ export default function smartVillagesPlugin(config, baseUrl) {
}, },
initialize(vcsApp) { initialize(vcsApp) {
app = vcsApp; app = vcsApp;
vcsApp.contextMenuManager.addEventHandler(async (event) => {
vcsApp.contextMenuManager.addEventHandler(async (event) => {
const actions = []; const actions = [];
const pick = vcsApp.maps.activeMap.getScene().pick(event.windowPosition); const pick = vcsApp.maps.activeMap.getScene().pick(event.windowPosition);
if (pick !== undefined && pick.primitive !== undefined && pick.primitive.id !== undefined) { if (pick !== undefined && pick.primitive !== undefined && pick.primitive.id !== undefined) {
...@@ -364,13 +404,31 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -364,13 +404,31 @@ export default function smartVillagesPlugin(config, baseUrl) {
}, },
}); });
actions.push({
id: 'scale',
name: 'Objekt skalieren',
callback() {
currentlyScaledModel = model;
vcsApp.windowManager.add(
{
id: scaleControlId,
component: scaleControl,
slot: WindowSlot.DYNAMIC_LEFT,
state: {
headerTitle: "Skalierung",
},
},
name,
);
}
});
actions.push({ actions.push({
id: 'delete', id: 'delete',
name: 'Objekt entfernen', name: 'Objekt entfernen',
callback() { callback() {
vcsApp.maps.activeMap.getEntities().remove(model); vcsApp.maps.activeMap.getEntities().remove(model);
removePlacedModel(model); removePlacedModel(model);
console.log(placedModels);
}, },
}); });
...@@ -435,7 +493,7 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -435,7 +493,7 @@ export default function smartVillagesPlugin(config, baseUrl) {
callback() { callback() {
vcsApp.windowManager.add( vcsApp.windowManager.add(
{ {
id: windowId, id: bimOptionsId,
component: BIMOptions, component: BIMOptions,
slot: WindowSlot.DETACHED, slot: WindowSlot.DETACHED,
position: { position: {
...@@ -460,7 +518,7 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -460,7 +518,7 @@ export default function smartVillagesPlugin(config, baseUrl) {
callback() { callback() {
vcsApp.windowManager.add( vcsApp.windowManager.add(
{ {
id: windowId, id: objectListId,
component: objectList, component: objectList,
slot: WindowSlot.DYNAMIC_LEFT, slot: WindowSlot.DYNAMIC_LEFT,
state: { state: {
......
...@@ -133,6 +133,7 @@ function uploadModel() { ...@@ -133,6 +133,7 @@ function uploadModel() {
const exporter = new GLTFExporter(); const exporter = new GLTFExporter();
const options = { const options = {
binary: true, binary: true,
animations: gltf.animations,
}; };
exporter.parse(gltf.scene, exporter.parse(gltf.scene,
// called when the gltf has been generated // called when the gltf has been generated
...@@ -189,6 +190,8 @@ function uploadModel() { ...@@ -189,6 +190,8 @@ function uploadModel() {
return `$${keys[index]}`; return `$${keys[index]}`;
} }
export const objectListId = "object_list_id";
export default { export default {
name: 'objectList', name: 'objectList',
components: { components: {
......
<template>
<v-sheet>
<VcsFormSection heading="Skalierung">
<template #default>
<v-container class="py-0 px-1">
<v-row no-gutters>
<v-col>
<VcsLabel html-for="numberInput" :dense="dense">
Skalierungsfaktor:
</VcsLabel>
</v-col>
<v-col>
<VcsTextField id="numberInput" :dense="dense" type="number" step="0.1" unit="" v-model.number="scale"
show-spin-buttons />
</v-col>
</v-row>
<v-row no-gutters justify="center">
<v-col>
<VcsFormButton id="loadBtn" @click="scaleModel()"> Skalieren </VcsFormButton>
</v-col>
</v-row>
</v-container>
</template>
</VcsFormSection>
</v-sheet>
</template>
<script setup>
import { inject, ref, watch } from 'vue';
let app = undefined;
const scale = ref(1.0);
app = inject('vcsApp');
const { setScale } = app.plugins.getByKey(name);
function scaleModel() {
setScale(scale.value);
}
</script>
<script>
import {
VcsList,
VcsFormButton,
VcsTextField,
Icons,
VcsFormSection,
createListItemRenameAction,
NotificationType,
} from '@vcmap/ui';
import {
VSwitch,
VSheet,
VDialog,
VCard,
VForm,
VContainer,
VRow,
VCol,
} from 'vuetify/lib';
import { inject, watch } from 'vue';
import { name } from '../package.json';
export const scaleControlId = "scale_control_id";
export default {
name: 'scaleControl',
components: {
VcsFormButton,
VcsTextField,
VcsFormSection,
VSwitch,
VSheet,
VDialog,
VCard,
VForm,
VContainer,
VRow,
VCol,
},
setup() {
},
};
</script>
<style lang="scss" scoped>
.d-grid {
display: grid;
grid-template-columns: 1fr 1fr;
}
</style>
...@@ -40,7 +40,7 @@ import { ...@@ -40,7 +40,7 @@ import {
import { VContainer, VRow, VForm, VCol } from 'vuetify/lib'; import { VContainer, VRow, VForm, VCol } from 'vuetify/lib';
import { name } from '../package.json'; import { name } from '../package.json';
export const windowId = 'upload_ifc_id'; export const bimOptionsId = 'upload_ifc_id';
export default { export default {
name: 'IFC Konvertierung', name: 'IFC Konvertierung',
......
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