|
1 | 1 | define([
|
2 | 2 | '../Core/arraySlice',
|
| 3 | + '../Core/BoundingSphere', |
3 | 4 | '../Core/Cartesian3',
|
4 | 5 | '../Core/Cartesian4',
|
5 | 6 | '../Core/Check',
|
@@ -39,6 +40,7 @@ define([
|
39 | 40 | './ShadowMode'
|
40 | 41 | ], function(
|
41 | 42 | arraySlice,
|
| 43 | + BoundingSphere, |
42 | 44 | Cartesian3,
|
43 | 45 | Cartesian4,
|
44 | 46 | Check,
|
@@ -171,7 +173,8 @@ define([
|
171 | 173 |
|
172 | 174 | this.time = 0.0; // For styling
|
173 | 175 | this.shadows = ShadowMode.ENABLED;
|
174 |
| - this.boundingVolume = undefined; |
| 176 | + this.boundingSphere = undefined; |
| 177 | + this._computeBoundingSphere = defaultValue(options.computeBoundingSphere, true); |
175 | 178 |
|
176 | 179 | this.clippingPlanes = undefined;
|
177 | 180 | this.isClipped = false;
|
@@ -602,6 +605,16 @@ define([
|
602 | 605 | strideInBytes : 0
|
603 | 606 | });
|
604 | 607 |
|
| 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 | + |
605 | 618 | if (hasColors) {
|
606 | 619 | if (isRGB565) {
|
607 | 620 | attributes.push({
|
@@ -1148,10 +1161,6 @@ define([
|
1148 | 1161 | }
|
1149 | 1162 | }
|
1150 | 1163 |
|
1151 |
| - var scratchComputedTranslation = new Cartesian4(); |
1152 |
| - var scratchComputedMatrixIn2D = new Matrix4(); |
1153 |
| - var scratchModelMatrix = new Matrix4(); |
1154 |
| - |
1155 | 1164 | function decodeDraco(pointCloud, context) {
|
1156 | 1165 | if (pointCloud._decodingState === DecodingState.READY) {
|
1157 | 1166 | return false;
|
@@ -1207,6 +1216,10 @@ define([
|
1207 | 1216 | return true;
|
1208 | 1217 | }
|
1209 | 1218 |
|
| 1219 | + var scratchComputedTranslation = new Cartesian4(); |
| 1220 | + var scratchModelMatrix = new Matrix4(); |
| 1221 | + var scratchScale = new Cartesian3(); |
| 1222 | + |
1210 | 1223 | PointCloud.prototype.update = function(frameState) {
|
1211 | 1224 | var context = frameState.context;
|
1212 | 1225 | var decoding = decodeDraco(this, context);
|
@@ -1247,16 +1260,24 @@ define([
|
1247 | 1260 | var translation = Matrix4.getColumn(modelMatrix, 3, scratchComputedTranslation);
|
1248 | 1261 | if (!Cartesian4.equals(translation, Cartesian4.UNIT_W)) {
|
1249 | 1262 | 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); |
1254 | 1263 | }
|
1255 | 1264 | }
|
1256 | 1265 |
|
1257 | 1266 | Matrix4.clone(modelMatrix, this._drawCommand.modelMatrix);
|
1258 | 1267 |
|
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 | + } |
1260 | 1281 | }
|
1261 | 1282 |
|
1262 | 1283 | if (this.clippingPlanesDirty) {
|
|
0 commit comments