Skip to content

Commit

Permalink
Remove empty 'children' arrays during upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Oct 16, 2023
1 parent 03b8663 commit b5f77f3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

### 0.?.? - 2023-mm-dd

- The `upgrade` command is now removing empty `tile.children` arrays, setting the `children` to be `undefined` instead.

### 0.3.1 - 2023-10-10
- Integrated a dedicated logging library (via [#61](https://github.com/CesiumGS/3d-tiles-tools/pull/61))
- By default, only few, informative messages are logged to the console
Expand Down
20 changes: 20 additions & 0 deletions specs/tilesetProcessing/TilesetUpgraderSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const unitBoundingBox = {
// (checked for both `content` and `contents`)
// - The `extensionsUsed` and `extensionsRequired` should no
// longer contain `3DTILES_content_gltf`
// - One tile has an empty 'children' array that should
// be removed
const inputTilesetJsonRaw: unknown = {
asset: {
version: "0.0",
Expand Down Expand Up @@ -55,6 +57,11 @@ const inputTilesetJsonRaw: unknown = {
boundingVolume: unitBoundingBox,
geometricError: 1.0,
},
{
boundingVolume: unitBoundingBox,
geometricError: 1.0,
children: [],
},
],
},
};
Expand Down Expand Up @@ -116,4 +123,17 @@ describe("TilesetUpgrader", function () {
expect(tileset.extensionsUsed).not.toContain("3DTILES_content_gltf");
expect(tileset.extensionsRequired).not.toContain("3DTILES_content_gltf");
});

it("removes an empty 'children' array", async function () {
const targetVersion = "1.1";
const tilesetUpgrader = new TilesetUpgrader(
targetVersion,
gltfUpgradeOptions
);

const tileset = JSON.parse(inputTilesetJsonString) as Tileset;
await tilesetUpgrader.upgradeTileset(tileset);

expect(tileset.root.children![2].children).toBeUndefined();
});
});
3 changes: 3 additions & 0 deletions src/tilesetProcessing/TilesetUpgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class TilesetUpgrader {
upgradedAssetVersionNumber: "1.0",
upgradeRefineCase: true,
upgradeContentUrlToUri: true,
upgradeEmptyChildrenToUndefined: true,

upgradeContentGltfExtensionDeclarations: false,

Expand All @@ -92,6 +93,8 @@ export class TilesetUpgrader {
upgradedAssetVersionNumber: "1.1",
upgradeRefineCase: true,
upgradeContentUrlToUri: true,
upgradeEmptyChildrenToUndefined: true,

upgradeContentGltfExtensionDeclarations: true,

upgradeB3dmGltf1ToGltf2: false,
Expand Down
21 changes: 21 additions & 0 deletions src/tilesetProcessing/upgrade/TilesetObjectUpgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class TilesetObjectUpgrader {
logger.debug(`Upgrading content.url to content.uri`);
await this.upgradeEachContentUrlToUri(tileset);
}
if (this.upgradeOptions.upgradeEmptyChildrenToUndefined) {
logger.debug(`Upgrading empty children arrays to be 'undefined'`);
await this.upgradeEmptyChildrenToUndefined(tileset);
}
if (this.upgradeOptions.upgradeContentGltfExtensionDeclarations) {
logger.debug(`Upgrading extension declarations`);
Extensions.removeExtensionUsed(tileset, "3DTILES_content_gltf");
Expand Down Expand Up @@ -127,6 +131,23 @@ export class TilesetObjectUpgrader {
);
}

/**
* Upgrade each empty 'children' in any tile by deleting them and
* causing the children to become 'undefined'
*
* @param tileset - The tileset
*/
private async upgradeEmptyChildrenToUndefined(tileset: Tileset) {
const root = tileset.root;
await Tiles.traverseExplicit(root, async (tilePath: Tile[]) => {
const tile = tilePath[tilePath.length - 1];
if (tile.children !== undefined && tile.children.length === 0) {
delete tile.children;
}
return true;
});
}

/**
* Upgrade the `refine` property of each tile to be written in
* uppercase letters.
Expand Down
4 changes: 4 additions & 0 deletions src/tilesetProcessing/upgrade/TilesetUpgradeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export type TilesetUpgradeOptions = {
// to `content.uri`
upgradeContentUrlToUri: boolean;

// Whether empty `tile.children` arrays should
// be removed and become `undefined`
upgradeEmptyChildrenToUndefined: true;

// Indicates whether the `3DTILES_content_gltf` extension
// declaration should be removed, as part of an upgrade
// to 1.1, where glTF is supported without an extension
Expand Down

0 comments on commit b5f77f3

Please sign in to comment.