diff --git a/src/tools/contentProcessing/GltfUtilities.ts b/src/tools/contentProcessing/GltfUtilities.ts index 131601a..750c091 100644 --- a/src/tools/contentProcessing/GltfUtilities.ts +++ b/src/tools/contentProcessing/GltfUtilities.ts @@ -8,6 +8,9 @@ import { Extensions } from "../../tilesets"; import { GltfPipelineLegacy } from "./GltfPipelineLegacy"; import { GltfWeb3dQuantizedAttributes } from "./GltfWeb3dQuantizedAttributes"; +import { Loggers } from "../../base"; +const logger = Loggers.get("contentProcessing"); + /** * Internal utility methods related to glTF/GLB data. * @@ -293,11 +296,13 @@ export class GltfUtilities { if (!rtcExtension) { return; } - // Compute the translation, taking the y-up-vs-z-up transform into account + + // Compute the translation + logger.info("Applying RTC for gltfUpAxis=Z"); const rtcTranslation = [ rtcExtension.center[0], + rtcExtension.center[1], rtcExtension.center[2], - -rtcExtension.center[1], ]; const scenes = gltf.scenes; if (!scenes) { diff --git a/src/tools/migration/TileFormatsMigration.ts b/src/tools/migration/TileFormatsMigration.ts index f18e717..6203f2e 100644 --- a/src/tools/migration/TileFormatsMigration.ts +++ b/src/tools/migration/TileFormatsMigration.ts @@ -1,4 +1,4 @@ -import { Document } from "@gltf-transform/core"; +import { Document, mat4 } from "@gltf-transform/core"; import { TileFormatsMigrationPnts } from "./TileFormatsMigrationPnts"; import { TileFormatsMigrationB3dm } from "./TileFormatsMigrationB3dm"; @@ -78,6 +78,31 @@ export class TileFormatsMigration { ); } + /** + * Apply the given transform to a new root in the given glTF-Transform + * document. + * + * The given transform is assumed to be a 16-element array that + * describes the 4x4 transform matrix, in column major order. + * + * @param document - The glTF-Transform document + * @param transform - The transform + */ + static applyTransform(document: Document, transform: number[]) { + const root = document.getRoot(); + const scenes = root.listScenes(); + for (const scene of scenes) { + const oldChildren = scene.listChildren(); + for (const oldChild of oldChildren) { + const newRoot = document.createNode(); + newRoot.setMatrix(transform as mat4); + scene.removeChild(oldChild); + newRoot.addChild(oldChild); + scene.addChild(newRoot); + } + } + } + /** * Apply the given RTC_CENTER to the given glTF-Transform document, * by inserting a new root node that carries the given RTC_CENTER diff --git a/src/tools/migration/TileFormatsMigrationB3dm.ts b/src/tools/migration/TileFormatsMigrationB3dm.ts index 2126b68..595c63e 100644 --- a/src/tools/migration/TileFormatsMigrationB3dm.ts +++ b/src/tools/migration/TileFormatsMigrationB3dm.ts @@ -56,6 +56,7 @@ export class TileFormatsMigrationB3dm { // a new root node above each scene node, that carries the // RTC_CENTER as its translation if (featureTable.RTC_CENTER) { + logger.info("Applying RTC center"); const rtcCenter = TileTableData.obtainRtcCenter( featureTable.RTC_CENTER, featureTableBinary @@ -63,6 +64,10 @@ export class TileFormatsMigrationB3dm { TileFormatsMigration.applyRtcCenter(document, rtcCenter); } + logger.info("Applying axis conversions"); + const axisConversion = [1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]; + TileFormatsMigration.applyTransform(document, axisConversion); + // If there are batches, then convert the batch table into // an `EXT_structural_metadata` property table, and convert // the `_BATCHID` attributes of the primitives into diff --git a/src/tools/tilesetProcessing/upgrade/TilesetObjectUpgrader.ts b/src/tools/tilesetProcessing/upgrade/TilesetObjectUpgrader.ts index 36c1aa2..63f380f 100644 --- a/src/tools/tilesetProcessing/upgrade/TilesetObjectUpgrader.ts +++ b/src/tools/tilesetProcessing/upgrade/TilesetObjectUpgrader.ts @@ -61,6 +61,12 @@ export class TilesetObjectUpgrader { logger.debug(`Upgrading extension declarations`); Extensions.removeExtensionUsed(tileset, "3DTILES_content_gltf"); } + + const asset = tileset.asset as any; + if (asset.gltfUpAxis !== undefined) { + logger.info(`Removing glTFUpAxis declaration`); + delete asset.gltfUpAxis; + } } /**