Skip to content

Commit f79ff9a

Browse files
committed
Initial work for computing bounding sphere
1 parent 178003f commit f79ff9a

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

Source/Scene/PointCloud.js

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define([
22
'../Core/arraySlice',
3+
'../Core/BoundingSphere',
34
'../Core/Cartesian3',
45
'../Core/Cartesian4',
56
'../Core/Check',
@@ -39,6 +40,7 @@ define([
3940
'./ShadowMode'
4041
], function(
4142
arraySlice,
43+
BoundingSphere,
4244
Cartesian3,
4345
Cartesian4,
4446
Check,
@@ -171,7 +173,8 @@ define([
171173

172174
this.time = 0.0; // For styling
173175
this.shadows = ShadowMode.ENABLED;
174-
this.boundingVolume = undefined;
176+
this.boundingSphere = undefined;
177+
this._computeBoundingSphere = defaultValue(options.computeBoundingSphere, true);
175178

176179
this.clippingPlanes = undefined;
177180
this.isClipped = false;
@@ -602,6 +605,16 @@ define([
602605
strideInBytes : 0
603606
});
604607

608+
if (isQuantized || isQuantizedDraco) {
609+
if (pointCloud._computeBoundingSphere) {
610+
// Quantized volume offset is applied later to the model matrix
611+
var scale = pointCloud._quantizedVolumeScale;
612+
var center = Cartesian3.multiplyByScalar(scale, 0.5, new Cartesian3());
613+
var radius = Cartesian3.maximumComponent(scale) * 0.5;
614+
pointCloud.boundingSphere = new BoundingSphere(center, radius);
615+
}
616+
}
617+
605618
if (hasColors) {
606619
if (isRGB565) {
607620
attributes.push({
@@ -1148,10 +1161,6 @@ define([
11481161
}
11491162
}
11501163

1151-
var scratchComputedTranslation = new Cartesian4();
1152-
var scratchComputedMatrixIn2D = new Matrix4();
1153-
var scratchModelMatrix = new Matrix4();
1154-
11551164
function decodeDraco(pointCloud, context) {
11561165
if (pointCloud._decodingState === DecodingState.READY) {
11571166
return false;
@@ -1207,6 +1216,10 @@ define([
12071216
return true;
12081217
}
12091218

1219+
var scratchComputedTranslation = new Cartesian4();
1220+
var scratchModelMatrix = new Matrix4();
1221+
var scratchScale = new Cartesian3();
1222+
12101223
PointCloud.prototype.update = function(frameState) {
12111224
var context = frameState.context;
12121225
var decoding = decodeDraco(this, context);
@@ -1247,16 +1260,24 @@ define([
12471260
var translation = Matrix4.getColumn(modelMatrix, 3, scratchComputedTranslation);
12481261
if (!Cartesian4.equals(translation, Cartesian4.UNIT_W)) {
12491262
Transforms.basisTo2D(projection, modelMatrix, modelMatrix);
1250-
} else {
1251-
var center = this.boundingVolume.center;
1252-
var to2D = Transforms.wgs84To2DModelMatrix(projection, center, scratchComputedMatrixIn2D);
1253-
Matrix4.multiply(to2D, modelMatrix, modelMatrix);
12541263
}
12551264
}
12561265

12571266
Matrix4.clone(modelMatrix, this._drawCommand.modelMatrix);
12581267

1259-
this._drawCommand.boundingVolume = this.boundingVolume;
1268+
if (this._computeBoundingSphere) {
1269+
var boundingSphere = this._drawCommand.boundingVolume;
1270+
if (!defined(boundingSphere)) {
1271+
boundingSphere = this.boundingSphere.clone();
1272+
this._drawCommand.boundingVolume = boundingSphere;
1273+
}
1274+
var center = boundingSphere.center;
1275+
Matrix4.multiplyByPoint(modelMatrix, center, center);
1276+
var scale = Matrix4.getScale(modelMatrix, scratchScale);
1277+
boundingSphere.radius *= Cartesian3.maximumComponent(scale);
1278+
} else {
1279+
this._drawCommand.boundingVolume = this.boundingSphere;
1280+
}
12601281
}
12611282

12621283
if (this.clippingPlanesDirty) {

Source/Scene/PointCloud3DTileContent.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ define([
6262
this._pointCloud = new PointCloud({
6363
arrayBuffer : arrayBuffer,
6464
byteOffset : byteOffset,
65+
computeBoundingSphere : false,
6566
opaquePass : Pass.CESIUM_3D_TILE,
6667
vertexShaderLoaded : getVertexShaderLoaded(this),
6768
fragmentShaderLoaded : getFragmentShaderLoaded(this),
@@ -286,11 +287,11 @@ define([
286287
batchTable.update(tileset, frameState);
287288
}
288289

289-
var boundingVolume;
290+
var boundingSphere;
290291
if (defined(tile._contentBoundingVolume)) {
291-
boundingVolume = mode === SceneMode.SCENE3D ? tile._contentBoundingVolume.boundingSphere : tile._contentBoundingVolume2D.boundingSphere;
292+
boundingSphere = mode === SceneMode.SCENE3D ? tile._contentBoundingVolume.boundingSphere : tile._contentBoundingVolume2D.boundingSphere;
292293
} else {
293-
boundingVolume = mode === SceneMode.SCENE3D ? tile._boundingVolume.boundingSphere : tile._boundingVolume2D.boundingSphere;
294+
boundingSphere = mode === SceneMode.SCENE3D ? tile._boundingVolume.boundingSphere : tile._boundingVolume2D.boundingSphere;
294295
}
295296

296297
var styleDirty = this._styleDirty;
@@ -301,7 +302,7 @@ define([
301302
pointCloud.modelMatrix = tile.computedTransform;
302303
pointCloud.time = tileset.timeSinceLoad;
303304
pointCloud.shadows = tileset.shadows;
304-
pointCloud.boundingVolume = boundingVolume;
305+
pointCloud.boundingSphere = boundingSphere;
305306
pointCloud.clippingPlanes = clippingPlanes;
306307
pointCloud.isClipped = defined(clippingPlanes) && clippingPlanes.enabled && tile._isClipped;
307308
pointCloud.clippingPlanesDirty = tile.clippingPlanesDirty;

Source/Scene/TimeDynamicPointCloud.js

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ define([
323323
}).then(function(arrayBuffer) {
324324
frame.pointCloud = new PointCloud({
325325
arrayBuffer : arrayBuffer,
326+
computeBoundingSphere : true,
326327
fragmentShaderLoaded : getFragmentShaderLoaded,
327328
uniformMapLoaded : getUniformMapLoaded(that),
328329
pickIdLoaded : getPickIdLoaded

0 commit comments

Comments
 (0)