Skip to content

Commit f717788

Browse files
committed
Apply transform diff rather than full transform
1 parent 28b1c4b commit f717788

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Source/Scene/Cesium3DTile.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ define([
9696
var parentTransform = defined(parent) ? parent.computedTransform : tileset.modelMatrix;
9797
var computedTransform = Matrix4.multiply(parentTransform, this.transform, new Matrix4());
9898

99+
var parentInitialTransform = defined(parent) ? parent._initialTransform : Matrix4.IDENTITY;
100+
this._initialTransform = Matrix4.multiply(parentInitialTransform, this.transform, new Matrix4());
101+
99102
/**
100103
* The final computed transform of this tile
101104
* @type {Matrix4}
@@ -884,6 +887,7 @@ define([
884887
var scratchCenter = new Cartesian3();
885888
var scratchRectangle = new Rectangle();
886889
var scratchOrientedBoundingBox = new OrientedBoundingBox();
890+
var scratchTransform = new Matrix4();
887891

888892
function createBox(box, transform, result) {
889893
var center = Cartesian3.fromElements(box[0], box[1], box[2], scratchCenter);
@@ -901,7 +905,7 @@ define([
901905
return new TileOrientedBoundingBox(center, halfAxes);
902906
}
903907

904-
function createBoxFromTransformedRegion(region, transform, result) {
908+
function createBoxFromTransformedRegion(region, transform, initialTransform, result) {
905909
var rectangle = Rectangle.unpack(region, 0, scratchRectangle);
906910
var minimumHeight = region[4];
907911
var maximumHeight = region[5];
@@ -910,7 +914,10 @@ define([
910914
var center = orientedBoundingBox.center;
911915
var halfAxes = orientedBoundingBox.halfAxes;
912916

913-
// Find the transformed center and halfAxes
917+
// A region bounding volume is not transformed by the transform in the tileset JSON,
918+
// but may be transformed by additional transforms applied in Cesium.
919+
// This is why the transform is calculated as the difference between the initial transform and the current transform.
920+
transform = Matrix4.multiplyTransformation(transform, Matrix4.inverseTransformation(initialTransform, scratchTransform), scratchTransform);
914921
center = Matrix4.multiplyByPoint(transform, center, center);
915922
var rotationScale = Matrix4.getRotation(transform, scratchMatrix);
916923
halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
@@ -923,9 +930,9 @@ define([
923930
return new TileOrientedBoundingBox(center, halfAxes);
924931
}
925932

926-
function createRegion(region, transform, result) {
927-
if (!Matrix4.equalsEpsilon(transform, Matrix4.IDENTITY, CesiumMath.EPSILON6)) {
928-
return createBoxFromTransformedRegion(region, transform, result);
933+
function createRegion(region, transform, initialTransform, result) {
934+
if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {
935+
return createBoxFromTransformedRegion(region, transform, initialTransform, result);
929936
}
930937

931938
if (defined(result)) {
@@ -978,16 +985,14 @@ define([
978985
return createBox(boundingVolumeHeader.box, transform, result);
979986
}
980987
if (defined(boundingVolumeHeader.region)) {
981-
return createRegion(boundingVolumeHeader.region, transform, result);
988+
return createRegion(boundingVolumeHeader.region, transform, this._initialTransform, result);
982989
}
983990
if (defined(boundingVolumeHeader.sphere)) {
984991
return createSphere(boundingVolumeHeader.sphere, transform, result);
985992
}
986993
throw new RuntimeError('boundingVolume must contain a sphere, region, or box');
987994
};
988995

989-
var scratchTransform = new Matrix4();
990-
991996
/**
992997
* Update the tile's transform. The transform is applied to the tile's bounding volumes.
993998
*
@@ -1007,12 +1012,12 @@ define([
10071012
// Update the bounding volumes
10081013
var header = this._header;
10091014
var content = this._header.content;
1010-
this._boundingVolume = this.createBoundingVolume(header.boundingVolume, computedTransform, this._boundingVolume);
1015+
this._boundingVolume = this.createBoundingVolume(header.boundingVolume, this.computedTransform, this._boundingVolume);
10111016
if (defined(this._contentBoundingVolume)) {
1012-
this._contentBoundingVolume = this.createBoundingVolume(content.boundingVolume, computedTransform, this._contentBoundingVolume);
1017+
this._contentBoundingVolume = this.createBoundingVolume(content.boundingVolume, this.computedTransform, this._contentBoundingVolume);
10131018
}
10141019
if (defined(this._viewerRequestVolume)) {
1015-
this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, computedTransform, this._viewerRequestVolume);
1020+
this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume);
10161021
}
10171022

10181023
// Destroy the debug bounding volumes. They will be generated fresh.

Specs/Scene/Batched3DModel3DTileContentSpec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ defineSuite([
199199
});
200200

201201
it('renders with a tile transform and region bounding volume', function() {
202-
return Cesium3DTilesTester.loadTileset(scene, withTransformRegionUrl).then(function(tileset) {
203-
Cesium3DTilesTester.expectRenderTileset(scene, tileset);
204-
});
202+
return expectRenderWithTransform(withTransformRegionUrl);
205203
});
206204

207205
it('picks with batch table', function() {

0 commit comments

Comments
 (0)