Skip to content

Commit

Permalink
DRAFT for handling gltfUpAxis in upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Dec 27, 2024
1 parent 0af80b9 commit b5dab25
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/tools/contentProcessing/GltfUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 26 additions & 1 deletion src/tools/migration/TileFormatsMigration.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/tools/migration/TileFormatsMigrationB3dm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ 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
);
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
Expand Down
6 changes: 6 additions & 0 deletions src/tools/tilesetProcessing/upgrade/TilesetObjectUpgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit b5dab25

Please sign in to comment.