Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/CesiumGS/cesium into worksp…
Browse files Browse the repository at this point in the history
…aces
  • Loading branch information
sanjeetsuhag committed Oct 26, 2022
2 parents dec53a3 + 9255f0d commit 1c8fe72
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 143 deletions.
59 changes: 22 additions & 37 deletions Apps/Sandcastle/gallery/I3S 3D Object Layer.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,55 +102,40 @@ <h1>Loading...</h1>
Cesium.defined(pickedFeature.content.tile.i3sNode)
) {
const i3sNode = pickedFeature.content.tile.i3sNode;
i3sNode.loadFields().then(function () {
const geometry = i3sNode.geometryData[0];
if (pickedPosition) {
const location = geometry.getClosestPointIndexOnTriangle(
pickedPosition.x,
pickedPosition.y,
pickedPosition.z
);
if (pickedPosition) {
i3sNode.loadFields().then(function () {
let description = "No attributes";
let name;
if (
location.index !== -1 &&
geometry.customAttributes.featureIndex
) {
console.log(
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
);
const featureIndex =
geometry.customAttributes.featureIndex[location.index];
if (Object.keys(i3sNode.fields).length > 0) {
description =
'<table class="cesium-infoBox-defaultTable"><tbody>';
for (const fieldName in i3sNode.fields) {
if (i3sNode.fields.hasOwnProperty(fieldName)) {
const field = i3sNode.fields[fieldName];
description += `<tr><th>${field.name}</th><td>`;
description += `${field.values[featureIndex]}</td></tr>`;
console.log(
`${field.name}: ${field.values[featureIndex]}`
);
if (
!Cesium.defined(name) &&
isNameProperty(field.name)
) {
name = field.values[featureIndex];
}
console.log(
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
);

const fields = i3sNode.getFieldsForPickedPosition(
pickedPosition
);
if (Object.keys(fields).length > 0) {
description =
'<table class="cesium-infoBox-defaultTable"><tbody>';
for (const fieldName in fields) {
if (i3sNode.fields.hasOwnProperty(fieldName)) {
description += `<tr><th>${fieldName}</th><td>`;
description += `${fields[fieldName]}</td></tr>`;
console.log(`${fieldName}: ${fields[fieldName]}`);
if (!Cesium.defined(name) && isNameProperty(fieldName)) {
name = fields[fieldName];
}
}
description += `</tbody></table>`;
}
description += `</tbody></table>`;
}
if (!Cesium.defined(name)) {
name = "unknown";
}
selectedEntity.name = name;
selectedEntity.description = description;
viewer.selectedEntity = selectedEntity;
}
});
});
}
}
},
Cesium.ScreenSpaceEventType.LEFT_CLICK);
Expand Down
59 changes: 22 additions & 37 deletions Apps/Sandcastle/gallery/I3S Feature Picking.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,55 +102,40 @@ <h1>Loading...</h1>
Cesium.defined(pickedFeature.content.tile.i3sNode)
) {
const i3sNode = pickedFeature.content.tile.i3sNode;
i3sNode.loadFields().then(function () {
const geometry = i3sNode.geometryData[0];
if (pickedPosition) {
const location = geometry.getClosestPointIndexOnTriangle(
pickedPosition.x,
pickedPosition.y,
pickedPosition.z
);
if (pickedPosition) {
i3sNode.loadFields().then(function () {
let description = "No attributes";
let name;
if (
location.index !== -1 &&
geometry.customAttributes.featureIndex
) {
console.log(
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
);
const featureIndex =
geometry.customAttributes.featureIndex[location.index];
if (Object.keys(i3sNode.fields).length > 0) {
description =
'<table class="cesium-infoBox-defaultTable"><tbody>';
for (const fieldName in i3sNode.fields) {
if (i3sNode.fields.hasOwnProperty(fieldName)) {
const field = i3sNode.fields[fieldName];
description += `<tr><th>${field.name}</th><td>`;
description += `${field.values[featureIndex]}</td></tr>`;
console.log(
`${field.name}: ${field.values[featureIndex]}`
);
if (
!Cesium.defined(name) &&
isNameProperty(field.name)
) {
name = field.values[featureIndex];
}
console.log(
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
);

const fields = i3sNode.getFieldsForPickedPosition(
pickedPosition
);
if (Object.keys(fields).length > 0) {
description =
'<table class="cesium-infoBox-defaultTable"><tbody>';
for (const fieldName in fields) {
if (i3sNode.fields.hasOwnProperty(fieldName)) {
description += `<tr><th>${fieldName}</th><td>`;
description += `${fields[fieldName]}</td></tr>`;
console.log(`${fieldName}: ${fields[fieldName]}`);
if (!Cesium.defined(name) && isNameProperty(fieldName)) {
name = fields[fieldName];
}
}
description += `</tbody></table>`;
}
description += `</tbody></table>`;
}
if (!Cesium.defined(name)) {
name = "unknown";
}
selectedEntity.name = name;
selectedEntity.description = description;
viewer.selectedEntity = selectedEntity;
}
});
});
}
}
},
Cesium.ScreenSpaceEventType.LEFT_CLICK);
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Ilya Shevelev](https://github.com/ilyaly)
- [Gabriel Aldous](https://github.com/Sn00pyW00dst0ck)
- [金俊](https://github.com/jinjun1994)
- [Oussama Bonnor](https://github.com/oussamabonnor1)
3 changes: 2 additions & 1 deletion packages/engine/Source/Scene/I3SDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ I3SDataProvider.prototype._loadGeoidData = function () {
console.log(
"No Geoid Terrain service provided - no geoid conversion will be performed."
);
return Promise.resolve();
this._geoidDataIsReadyPromise = Promise.resolve();
return this._geoidDataIsReadyPromise;
}

this._geoidDataIsReadyPromise = geoidTerrainProvider.readyPromise.then(
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/Source/Scene/I3SFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Object.defineProperties(I3SFeature.prototype, {

/**
* Loads the content.
* @returns {Promise.<Object>} A promise that is resolved when the data of the I3S feature is loaded
* @returns {Promise} A promise that is resolved when the data of the I3S feature is loaded
* @private
*/
I3SFeature.prototype.load = function () {
Expand Down
66 changes: 64 additions & 2 deletions packages/engine/Source/Scene/I3SLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function I3SLayer(dataProvider, layerData, index) {
.concat(`${layerData.href}`);
}

this._version = layerData.store.version;
const splitVersion = this._version.split(".");
this._majorVersion = parseInt(splitVersion[0]);
this._minorVersion = splitVersion.length > 1 ? parseInt(splitVersion[1]) : 0;

this._resource = new Resource({ url: tilesetUrl });
this._resource.setQueryParameters(
this._dataProvider.resource.queryParameters
Expand Down Expand Up @@ -98,11 +103,68 @@ Object.defineProperties(I3SLayer.prototype, {
return this._data;
},
},

/**
* The version string of the loaded I3S dataset
* @memberof I3SLayer.prototype
* @type {String}
* @readonly
*/
version: {
get: function () {
return this._version;
},
},

/**
* The major version number of the loaded I3S dataset
* @memberof I3SLayer.prototype
* @type {Number}
* @readonly
*/
majorVersion: {
get: function () {
return this._majorVersion;
},
},

/**
* The minor version number of the loaded I3S dataset
* @memberof I3SLayer.prototype
* @type {Number}
* @readonly
*/
minorVersion: {
get: function () {
return this._minorVersion;
},
},

/**
* When <code>true</code>, when the loaded I3S version is 1.6 or older
* @memberof I3SLayer.prototype
* @type {Boolean}
* @readonly
*/
legacyVersion16: {
get: function () {
if (!defined(this.version)) {
return undefined;
}
if (
this.majorVersion < 1 ||
(this.majorVersion === 1 && this.minorVersion <= 6)
) {
return true;
}
return false;
},
},
});

/**
* Loads the content, including the root node definition and its children
* @returns {Promise.<void>} A promise that is resolved when the layer data is loaded
* @returns {Promise} A promise that is resolved when the layer data is loaded
* @private
*/
I3SLayer.prototype.load = function () {
Expand All @@ -121,7 +183,7 @@ I3SLayer.prototype.load = function () {
return that._tileset.readyPromise.then(function () {
that._rootNode._tile = that._tileset._root;
that._tileset._root._i3sNode = that._rootNode;
if (that._data.store.version === "1.6") {
if (that.legacyVersion16) {
return that._rootNode._loadChildren();
}
});
Expand Down
56 changes: 50 additions & 6 deletions packages/engine/Source/Scene/I3SNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,52 @@ I3SNode.prototype.loadFields = function () {
return Promise.all(promises);
};

/**
* Returns the fields for a given picked position
* @param {Cartesian3} pickedPosition The picked position
* @returns {Object} Object containing field names and their values
*/
I3SNode.prototype.getFieldsForPickedPosition = function (pickedPosition) {
const geometry = this.geometryData[0];
if (!defined(geometry.customAttributes.featureIndex)) {
return {};
}

const location = geometry.getClosestPointIndexOnTriangle(
pickedPosition.x,
pickedPosition.y,
pickedPosition.z
);

if (
location.index === -1 ||
location.index > geometry.customAttributes.featureIndex.length
) {
return {};
}

const featureIndex = geometry.customAttributes.featureIndex[location.index];
return this.getFieldsForFeature(featureIndex);
};

/**
* Returns the fields for a given feature
* @param {Number} featureIndex Index of the feature whose attributes we want to get
* @returns {Object} Object containing field names and their values
*/
I3SNode.prototype.getFieldsForFeature = function (featureIndex) {
const featureFields = {};
for (const fieldName in this.fields) {
if (this.fields.hasOwnProperty(fieldName)) {
const field = this.fields[fieldName];
if (featureIndex >= 0 && featureIndex < field.values.length) {
featureFields[field.name] = field.values[featureIndex];
}
}
}
return featureFields;
};

/**
* @private
*/
Expand Down Expand Up @@ -336,11 +382,6 @@ I3SNode.prototype._loadFeatureData = function () {
this._featureData.push(newFeatureData);
featurePromises.push(newFeatureData.load());
}
} else if (defined(this._data.mesh) && defined(this._data.mesh.attribute)) {
const featureURI = `./features/0`;
const newFeatureData = new I3SFeature(this, featureURI);
this._featureData.push(newFeatureData);
featurePromises.push(newFeatureData.load());
}

return Promise.all(featurePromises);
Expand Down Expand Up @@ -661,7 +702,10 @@ I3SNode.prototype._createContentURL = function () {
};

// Load the geometry data
const dataPromises = [this._loadFeatureData(), this._loadGeometryData()];
const dataPromises = [this._loadGeometryData()];
if (this._dataProvider.legacyVersion16) {
dataPromises.push(this._loadFeatureData());
}

const that = this;
return Promise.all(dataPromises).then(function () {
Expand Down
Loading

0 comments on commit 1c8fe72

Please sign in to comment.