Skip to content

Commit

Permalink
Merge pull request #1543 from xeokit/fix-split-properties-decompress
Browse files Browse the repository at this point in the history
[FIX] Fix decompression of properties in split metadata files
  • Loading branch information
xeolabs authored Jun 18, 2024
2 parents e8daec6 + 50fe9b0 commit bca8dff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 27 additions & 4 deletions src/viewer/metadata/MetaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class MetaModel {

this.metaScene.metaModels[this.id] = this;

this._propertyLookup = [];

/**
* True when this MetaModel has been finalized.
* @type {boolean}
Expand All @@ -152,7 +154,7 @@ class MetaModel {
* @type {MetaObject|null}
*/
get rootMetaObject() {
if (this.rootMetaObjects.length == 1) {
if (this.rootMetaObjects.length === 1) {
return this.rootMetaObjects[0];
}
return null;
Expand All @@ -173,6 +175,12 @@ class MetaModel {
const metaScene = this.metaScene;
const propertyLookup = metaModelData.properties;

if (propertyLookup) {
for (let i = 0, len = propertyLookup.length; i < len; i++) {
this._propertyLookup.push(propertyLookup[i]);
}
}

// Create global Property Sets

if (metaModelData.propertySets) {
Expand All @@ -183,9 +191,6 @@ class MetaModel {
}
let propertySet = metaScene.propertySets[propertySetData.id];
if (!propertySet) {
if (propertyLookup) {
this._decompressProperties(propertyLookup, propertySetData.properties);
}
propertySet = new PropertySet({
id: propertySetData.id,
originalSystemId: propertySetData.originalSystemId || propertySetData.id,
Expand Down Expand Up @@ -232,15 +237,21 @@ class MetaModel {
}

_decompressProperties(propertyLookup, properties) {
const propsNotFound = [];
for (let i = 0, len = properties.length; i < len; i++) {
const property = properties[i];
if (Number.isInteger(property)) {
const lookupProperty = propertyLookup[property];
if (lookupProperty) {
properties[i] = lookupProperty;
} else {
propsNotFound.push(property);
}
}
}
if (propsNotFound.length > 0) {
console.error(`[MetaModel._decompressProperties] Properties not found: ${propsNotFound}`);
}
}

finalize() {
Expand Down Expand Up @@ -308,6 +319,18 @@ class MetaModel {
(metaScene.metaObjectsByType[type] || (metaScene.metaObjectsByType[type] = {}))[objectId] = metaObject;
}

// Decompress properties

if (this.propertySets) {
for (let i = 0, len = this.propertySets.length; i < len; i++) {
const propertySet = this.propertySets[i];
this._decompressProperties(this._propertyLookup, propertySet.properties);
}
}


this._propertyLookup = [];

this.finalized = true;

this.metaScene.fire("metaModelCreated", this.id);
Expand Down
6 changes: 5 additions & 1 deletion src/viewer/metadata/PropertySet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class PropertySet {
const properties = params.properties;
for (let i = 0, len = properties.length; i < len; i++) {
const property = properties[i];
this.properties.push(new Property(property.name, property.value, property.type, property.valueType, property.description));
if (Number.isInteger(property)) { // Will decompress in MetaModel.finalize();
this.properties.push(property);
} else {
this.properties.push(new Property(property.name, property.value, property.type, property.valueType, property.description));
}
}
}
}
Expand Down

0 comments on commit bca8dff

Please sign in to comment.