diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 1f4524fbb8d0..c277f27bf21d 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -616,7 +616,7 @@ define([ /** * The model's bounding sphere in its local coordinate system. This does not take into - * account glTF animations and skins. + * account glTF animations and skins nor does it take into account {@link Model#minimumPixelSize}. * * @memberof Model.prototype * @@ -640,7 +640,8 @@ define([ //>>includeEnd('debug'); var nonUniformScale = Matrix4.getScale(this.modelMatrix, boundingSphereCartesian3Scratch); - Cartesian3.multiplyByScalar(nonUniformScale, this.scale, nonUniformScale); + var scale = defined(this.maximumScale) ? Math.min(this.maximumScale, this.scale) : this.scale; + Cartesian3.multiplyByScalar(nonUniformScale, scale, nonUniformScale); var scaledBoundingSphere = this._scaledBoundingSphere; scaledBoundingSphere.center = Cartesian3.multiplyComponents(this._boundingSphere.center, nonUniformScale, scaledBoundingSphere.center); @@ -3065,12 +3066,14 @@ define([ // Model's model matrix needs to be updated var modelTransformChanged = !Matrix4.equals(this._modelMatrix, this.modelMatrix) || (this._scale !== this.scale) || - (this._minimumPixelSize !== this.minimumPixelSize) || (this.minimumPixelSize !== 0.0); // Minimum pixel size changed or is enabled + (this._minimumPixelSize !== this.minimumPixelSize) || (this.minimumPixelSize !== 0.0) || // Minimum pixel size changed or is enabled + (this._maximumScale !== this.maximumScale); if (modelTransformChanged || justLoaded) { Matrix4.clone(this.modelMatrix, this._modelMatrix); this._scale = this.scale; this._minimumPixelSize = this.minimumPixelSize; + this._maximumScale = this.maximumScale; var scale = getScale(this, context, frameState); var computedModelMatrix = this._computedModelMatrix; diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index 5f41e8c82813..b9ec15dda770 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -451,6 +451,20 @@ defineSuite([ texturedBoxModel.scale = originalScale; }); + it('boundingSphere returns the bounding sphere when maximumScale is reached', function() { + var originalScale = texturedBoxModel.scale; + var originalMaximumScale = texturedBoxModel.maximumScale; + texturedBoxModel.scale = 20; + texturedBoxModel.maximumScale = 10; + + var boundingSphere = texturedBoxModel.boundingSphere; + expect(boundingSphere.center).toEqualEpsilon(new Cartesian3(0.0, -2.5, 0.0), CesiumMath.EPSILON3); + expect(boundingSphere.radius).toEqualEpsilon(7.5, CesiumMath.EPSILON3); + + texturedBoxModel.scale = originalScale; + texturedBoxModel.maximumScale = originalMaximumScale; + }); + it('boundingSphere returns the bounding sphere when modelMatrix has non-uniform scale', function() { var originalMatrix = Matrix4.clone(texturedBoxModel.modelMatrix); Matrix4.multiplyByScale(texturedBoxModel.modelMatrix, new Cartesian3(2, 5, 10), texturedBoxModel.modelMatrix);