Skip to content

Commit

Permalink
Subtle interaction of Model.scale and maximumScale
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Nov 4, 2015
1 parent bdcf991 commit c9e402b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions Specs/Scene/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c9e402b

Please sign in to comment.