@@ -8,11 +8,14 @@ define([
8
8
'../Core/defineProperties' ,
9
9
'../Core/deprecationWarning' ,
10
10
'../Core/destroyObject' ,
11
+ '../Core/Ellipsoid' ,
11
12
'../Core/getMagic' ,
12
13
'../Core/Intersect' ,
13
14
'../Core/JulianDate' ,
15
+ '../Core/Math' ,
14
16
'../Core/Matrix3' ,
15
17
'../Core/Matrix4' ,
18
+ '../Core/OrientedBoundingBox' ,
16
19
'../Core/Rectangle' ,
17
20
'../Core/Request' ,
18
21
'../Core/RequestScheduler' ,
@@ -41,11 +44,14 @@ define([
41
44
defineProperties ,
42
45
deprecationWarning ,
43
46
destroyObject ,
47
+ Ellipsoid ,
44
48
getMagic ,
45
49
Intersect ,
46
50
JulianDate ,
51
+ CesiumMath ,
47
52
Matrix3 ,
48
53
Matrix4 ,
54
+ OrientedBoundingBox ,
49
55
Rectangle ,
50
56
Request ,
51
57
RequestScheduler ,
@@ -90,6 +96,9 @@ define([
90
96
var parentTransform = defined ( parent ) ? parent . computedTransform : tileset . modelMatrix ;
91
97
var computedTransform = Matrix4 . multiply ( parentTransform , this . transform , new Matrix4 ( ) ) ;
92
98
99
+ var parentInitialTransform = defined ( parent ) ? parent . _initialTransform : Matrix4 . IDENTITY ;
100
+ this . _initialTransform = Matrix4 . multiply ( parentInitialTransform , this . transform , new Matrix4 ( ) ) ;
101
+
93
102
/**
94
103
* The final computed transform of this tile
95
104
* @type {Matrix4 }
@@ -882,6 +891,8 @@ define([
882
891
var scratchHalfAxes = new Matrix3 ( ) ;
883
892
var scratchCenter = new Cartesian3 ( ) ;
884
893
var scratchRectangle = new Rectangle ( ) ;
894
+ var scratchOrientedBoundingBox = new OrientedBoundingBox ( ) ;
895
+ var scratchTransform = new Matrix4 ( ) ;
885
896
886
897
function createBox ( box , transform , result ) {
887
898
var center = Cartesian3 . fromElements ( box [ 0 ] , box [ 1 ] , box [ 2 ] , scratchCenter ) ;
@@ -899,13 +910,42 @@ define([
899
910
return new TileOrientedBoundingBox ( center , halfAxes ) ;
900
911
}
901
912
902
- function createRegion ( region , result ) {
903
- var rectangleRegion = Rectangle . unpack ( region , 0 , scratchRectangle ) ;
913
+ function createBoxFromTransformedRegion ( region , transform , initialTransform , result ) {
914
+ var rectangle = Rectangle . unpack ( region , 0 , scratchRectangle ) ;
915
+ var minimumHeight = region [ 4 ] ;
916
+ var maximumHeight = region [ 5 ] ;
917
+
918
+ var orientedBoundingBox = OrientedBoundingBox . fromRectangle ( rectangle , minimumHeight , maximumHeight , Ellipsoid . WGS84 , scratchOrientedBoundingBox ) ;
919
+ var center = orientedBoundingBox . center ;
920
+ var halfAxes = orientedBoundingBox . halfAxes ;
921
+
922
+ // A region bounding volume is not transformed by the transform in the tileset JSON,
923
+ // but may be transformed by additional transforms applied in Cesium.
924
+ // This is why the transform is calculated as the difference between the initial transform and the current transform.
925
+ transform = Matrix4 . multiplyTransformation ( transform , Matrix4 . inverseTransformation ( initialTransform , scratchTransform ) , scratchTransform ) ;
926
+ center = Matrix4 . multiplyByPoint ( transform , center , center ) ;
927
+ var rotationScale = Matrix4 . getRotation ( transform , scratchMatrix ) ;
928
+ halfAxes = Matrix3 . multiply ( rotationScale , halfAxes , halfAxes ) ;
929
+
930
+ if ( defined ( result ) && ( result instanceof TileOrientedBoundingBox ) ) {
931
+ result . update ( center , halfAxes ) ;
932
+ return result ;
933
+ }
934
+
935
+ return new TileOrientedBoundingBox ( center , halfAxes ) ;
936
+ }
937
+
938
+ function createRegion ( region , transform , initialTransform , result ) {
939
+ if ( ! Matrix4 . equalsEpsilon ( transform , initialTransform , CesiumMath . EPSILON8 ) ) {
940
+ return createBoxFromTransformedRegion ( region , transform , initialTransform , result ) ;
941
+ }
904
942
905
943
if ( defined ( result ) ) {
906
- // Don't update regions when the transform changes
907
944
return result ;
908
945
}
946
+
947
+ var rectangleRegion = Rectangle . unpack ( region , 0 , scratchRectangle ) ;
948
+
909
949
return new TileBoundingRegion ( {
910
950
rectangle : rectangleRegion ,
911
951
minimumHeight : region [ 4 ] ,
@@ -949,16 +989,14 @@ define([
949
989
return createBox ( boundingVolumeHeader . box , transform , result ) ;
950
990
}
951
991
if ( defined ( boundingVolumeHeader . region ) ) {
952
- return createRegion ( boundingVolumeHeader . region , result ) ;
992
+ return createRegion ( boundingVolumeHeader . region , transform , this . _initialTransform , result ) ;
953
993
}
954
994
if ( defined ( boundingVolumeHeader . sphere ) ) {
955
995
return createSphere ( boundingVolumeHeader . sphere , transform , result ) ;
956
996
}
957
997
throw new RuntimeError ( 'boundingVolume must contain a sphere, region, or box' ) ;
958
998
} ;
959
999
960
- var scratchTransform = new Matrix4 ( ) ;
961
-
962
1000
/**
963
1001
* Update the tile's transform. The transform is applied to the tile's bounding volumes.
964
1002
*
@@ -978,12 +1016,12 @@ define([
978
1016
// Update the bounding volumes
979
1017
var header = this . _header ;
980
1018
var content = this . _header . content ;
981
- this . _boundingVolume = this . createBoundingVolume ( header . boundingVolume , computedTransform , this . _boundingVolume ) ;
1019
+ this . _boundingVolume = this . createBoundingVolume ( header . boundingVolume , this . computedTransform , this . _boundingVolume ) ;
982
1020
if ( defined ( this . _contentBoundingVolume ) ) {
983
- this . _contentBoundingVolume = this . createBoundingVolume ( content . boundingVolume , computedTransform , this . _contentBoundingVolume ) ;
1021
+ this . _contentBoundingVolume = this . createBoundingVolume ( content . boundingVolume , this . computedTransform , this . _contentBoundingVolume ) ;
984
1022
}
985
1023
if ( defined ( this . _viewerRequestVolume ) ) {
986
- this . _viewerRequestVolume = this . createBoundingVolume ( header . viewerRequestVolume , computedTransform , this . _viewerRequestVolume ) ;
1024
+ this . _viewerRequestVolume = this . createBoundingVolume ( header . viewerRequestVolume , this . computedTransform , this . _viewerRequestVolume ) ;
987
1025
}
988
1026
989
1027
// Destroy the debug bounding volumes. They will be generated fresh.
0 commit comments