@@ -96,6 +96,9 @@ define([
96
96
var parentTransform = defined ( parent ) ? parent . computedTransform : tileset . modelMatrix ;
97
97
var computedTransform = Matrix4 . multiply ( parentTransform , this . transform , new Matrix4 ( ) ) ;
98
98
99
+ var parentInitialTransform = defined ( parent ) ? parent . _initialTransform : Matrix4 . IDENTITY ;
100
+ this . _initialTransform = Matrix4 . multiply ( parentInitialTransform , this . transform , new Matrix4 ( ) ) ;
101
+
99
102
/**
100
103
* The final computed transform of this tile
101
104
* @type {Matrix4 }
@@ -884,6 +887,7 @@ define([
884
887
var scratchCenter = new Cartesian3 ( ) ;
885
888
var scratchRectangle = new Rectangle ( ) ;
886
889
var scratchOrientedBoundingBox = new OrientedBoundingBox ( ) ;
890
+ var scratchTransform = new Matrix4 ( ) ;
887
891
888
892
function createBox ( box , transform , result ) {
889
893
var center = Cartesian3 . fromElements ( box [ 0 ] , box [ 1 ] , box [ 2 ] , scratchCenter ) ;
@@ -901,7 +905,7 @@ define([
901
905
return new TileOrientedBoundingBox ( center , halfAxes ) ;
902
906
}
903
907
904
- function createBoxFromTransformedRegion ( region , transform , result ) {
908
+ function createBoxFromTransformedRegion ( region , transform , initialTransform , result ) {
905
909
var rectangle = Rectangle . unpack ( region , 0 , scratchRectangle ) ;
906
910
var minimumHeight = region [ 4 ] ;
907
911
var maximumHeight = region [ 5 ] ;
@@ -910,7 +914,10 @@ define([
910
914
var center = orientedBoundingBox . center ;
911
915
var halfAxes = orientedBoundingBox . halfAxes ;
912
916
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 ) ;
914
921
center = Matrix4 . multiplyByPoint ( transform , center , center ) ;
915
922
var rotationScale = Matrix4 . getRotation ( transform , scratchMatrix ) ;
916
923
halfAxes = Matrix3 . multiply ( rotationScale , halfAxes , halfAxes ) ;
@@ -923,9 +930,9 @@ define([
923
930
return new TileOrientedBoundingBox ( center , halfAxes ) ;
924
931
}
925
932
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 ) ;
929
936
}
930
937
931
938
if ( defined ( result ) ) {
@@ -978,16 +985,14 @@ define([
978
985
return createBox ( boundingVolumeHeader . box , transform , result ) ;
979
986
}
980
987
if ( defined ( boundingVolumeHeader . region ) ) {
981
- return createRegion ( boundingVolumeHeader . region , transform , result ) ;
988
+ return createRegion ( boundingVolumeHeader . region , transform , this . _initialTransform , result ) ;
982
989
}
983
990
if ( defined ( boundingVolumeHeader . sphere ) ) {
984
991
return createSphere ( boundingVolumeHeader . sphere , transform , result ) ;
985
992
}
986
993
throw new RuntimeError ( 'boundingVolume must contain a sphere, region, or box' ) ;
987
994
} ;
988
995
989
- var scratchTransform = new Matrix4 ( ) ;
990
-
991
996
/**
992
997
* Update the tile's transform. The transform is applied to the tile's bounding volumes.
993
998
*
@@ -1007,12 +1012,12 @@ define([
1007
1012
// Update the bounding volumes
1008
1013
var header = this . _header ;
1009
1014
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 ) ;
1011
1016
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 ) ;
1013
1018
}
1014
1019
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 ) ;
1016
1021
}
1017
1022
1018
1023
// Destroy the debug bounding volumes. They will be generated fresh.
0 commit comments