Skip to content

Commit

Permalink
feat(3DTiles): add style API + C3DTFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinMachado authored and jailln committed Apr 18, 2023
1 parent f13a060 commit 864268a
Show file tree
Hide file tree
Showing 11 changed files with 541 additions and 60 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following people have contributed to iTowns.
* [Marie Lamure](https://github.com/mlamure)
* [Vincent Jaillot](https://github.com/jailln)
* [Valentin Rigolle](https://github.com/Crejak)
* [Valentin Machado](https://github.com/valentinMachado)

* [virtualcitySYSTEMS](https://www.virtualcitysystems.de/)
* [Ben Kuster](https://github.com/bkuster)
Expand Down
3 changes: 2 additions & 1 deletion docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
"C3DTBatchTable",
"C3DTBoundingVolume",
"C3DTExtensions",
"C3DTBatchTableHierarchyExtension"
"C3DTBatchTableHierarchyExtension",
"C3DTFeature"
],

"Plugins": [
Expand Down
6 changes: 3 additions & 3 deletions examples/js/3dTilesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function fillHTMLWithPickingInfo(event, pickingArg) {

// Get information from intersected objects (from the batch table and
// eventually the 3D Tiles extensions
var featureDisplayableInfo = pickingArg.layer.getInfoFromIntersectObject(intersects);
var closestC3DTileFeature = pickingArg.layer.getC3DTileFeatureFromIntersectsArray(intersects);

if (featureDisplayableInfo) {
if (closestC3DTileFeature) {
// eslint-disable-next-line
pickingArg.htmlDiv.appendChild(createHTMLListFromObject(featureDisplayableInfo));
pickingArg.htmlDiv.appendChild(createHTMLListFromObject(closestC3DTileFeature.getInfo()));
}
}
17 changes: 9 additions & 8 deletions src/Core/3DTiles/C3DTBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import C3DTilesTypes from './C3DTilesTypes';
*/
class C3DTBatchTable {
/**
* @param {ArrayBuffer} buffer - batch table buffer to parse
* @param {number} jsonLength - batch table json part length
* @param {number} binaryLength - batch table binary part length
* @param {number} batchLength - the length of the batch.
* @param {Object} registeredExtensions - extensions registered to the layer
* @param {ArrayBuffer} [buffer=new ArrayBuffer()] - batch table buffer to parse
* @param {number} [jsonLength=0] - batch table json part length
* @param {number} [binaryLength=0] - batch table binary part length
* @param {number} [batchLength=0] - the length of the batch.
* @param {Object} [registeredExtensions] - extensions registered to the layer
*/
constructor(buffer, jsonLength, binaryLength, batchLength, registeredExtensions) {
constructor(buffer = new ArrayBuffer(), jsonLength = 0, binaryLength = 0, batchLength = 0, registeredExtensions) {
if (arguments.length === 4 &&
typeof batchLength === 'object' &&
!Array.isArray(batchLength) &&
Expand All @@ -40,7 +40,8 @@ class C3DTBatchTable {
this.batchLength = batchLength;

const jsonBuffer = buffer.slice(0, jsonLength);
const jsonContent = JSON.parse(utf8Decoder.decode(new Uint8Array(jsonBuffer)));
const decodedJsonBuffer = utf8Decoder.decode(new Uint8Array(jsonBuffer));
const jsonContent = decodedJsonBuffer === '' ? null : JSON.parse(decodedJsonBuffer);

if (binaryLength > 0) {
const binaryBuffer = buffer.slice(jsonLength, jsonLength + binaryLength);
Expand Down Expand Up @@ -71,7 +72,7 @@ class C3DTBatchTable {
// returned object to batchTable.extensions
// Extensions must be registered in the layer (see an example of this in
// 3dtiles_hierarchy.html)
if (jsonContent.extensions) {
if (jsonContent && jsonContent.extensions) {
this.extensions =
registeredExtensions.parseExtensions(jsonContent.extensions, this.type);
delete jsonContent.extensions;
Expand Down
44 changes: 44 additions & 0 deletions src/Core/3DTiles/C3DTFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* C3DTFeature is a feature of a 3DTiles
*
* @class C3DTFeature
* @param {number} tileId - tile id
* @param {number} batchId - batch id
* @param {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
* @param {object} info - info in the batchTable
* @param {object} [userData={}] - some userData
* @property {number} tileId - tile id
* @property {number} batchId - batch id
* @property {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
* @property {object} info - info in the batchTable
* @property {object} [userData={}] - some userData
*/
class C3DTFeature {
#info;
constructor(tileId, batchId, groups, info, userData = {}) {
/** @type {number} */
this.tileId = tileId;

/** @type {number} */
this.batchId = batchId;

/** @type {Array<{start:number,count:number}>} */
this.groups = groups;

/** @type {object} */
this.userData = userData;

/** @type {object} */
this.#info = info;
}

/**
*
* @returns {object} - batchTable info
*/
getInfo() {
return this.#info;
}
}

export default C3DTFeature;
Loading

0 comments on commit 864268a

Please sign in to comment.