Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scale geometric error with tileset #7411

Merged
merged 10 commits into from
Sep 19, 2019
11 changes: 5 additions & 6 deletions Source/Core/Matrix3.js
Original file line number Diff line number Diff line change
@@ -1024,22 +1024,21 @@ define([
};

var UNIT = new Cartesian3(1, 1, 1);
var scaleVector = new Cartesian3();

/**
* Factors rotation matrix from arbitrary Matrix3 by dividing components by scale
* Extracts the rotation assuming the matrix is an affine transformation.
*
* @param {Matrix3} rotation-scale matrix
* @param {Matrix3} result rotation matrix with unit scale
* @returns {Matrix3} The modified result parameter.
* @param {Matrix3} matrix The matrix.
* @param {Matrix3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns {Cartesian3} The modified result parameter
* @returns {Matrix3} The modified result parameter

*/
Matrix3.getRotation = function(matrix, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('matrix', matrix);
Check.typeOf.object('result', result);
//>>includeEnd('debug');

var inverseScale = Cartesian3.divideComponents(UNIT, Matrix3.getScale(matrix, scaleVector), scaleVector);
var inverseScale = Cartesian3.divideComponents(UNIT, Matrix3.getScale(matrix, scratchScale), scratchScale);
result = Matrix3.multiplyByScale(matrix, inverseScale, result);

return result;
3 changes: 3 additions & 0 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
@@ -1265,6 +1265,7 @@ define([

var m = uniformState._normal3D;
Matrix4.getRotation(uniformState.inverseModelView3D, m);
Matrix3.getRotation(m, m);
Matrix3.transpose(m, m);
}
}
@@ -1273,13 +1274,15 @@ define([
if (uniformState._inverseNormalDirty) {
uniformState._inverseNormalDirty = false;
Matrix4.getRotation(uniformState.inverseModelView, uniformState._inverseNormal);
Matrix3.getRotation(uniformState._inverseNormal, uniformState._inverseNormal);
}
}

function cleanInverseNormal3D(uniformState) {
if (uniformState._inverseNormal3DDirty) {
uniformState._inverseNormal3DDirty = false;
Matrix4.getRotation(uniformState.inverseModelView3D, uniformState._inverseNormal3D);
Matrix3.getRotation(uniformState._inverseNormal3D, uniformState._inverseNormal3D);
}
}

1 change: 1 addition & 0 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
@@ -139,6 +139,7 @@ define([
* @type {Number}
* @readonly
*/
this.geometricError = header.geometricError;
this._geometricError = header.geometricError;

if (!defined(this._geometricError)) {
13 changes: 13 additions & 0 deletions Specs/Core/Matrix3Spec.js
Original file line number Diff line number Diff line change
@@ -642,11 +642,18 @@ defineSuite([
it('getRotation returns matrix without scale', function() {
var matrix = new Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
var result = new Matrix3();
var expected = Matrix3.fromArray([
0.12309149097933272, 0.4923659639173309, 0.8616404368553291,
0.20739033894608505, 0.5184758473652127, 0.8295613557843402,
0.26726124191242440, 0.5345224838248488, 0.8017837257372732
]);
var scale = new Cartesian3();
var expectedScale = new Cartesian3(1.0, 1.0, 1.0);
result = Matrix3.getRotation(matrix, result);
console.log(result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.log(result)

var resultScale = Matrix3.getScale(result, scale);
expect(resultScale).toEqualEpsilon(expectedScale, CesiumMath.EPSILON14);
expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON14);
});

it('getRotation does not modify rotation matrix', function() {
@@ -661,6 +668,12 @@ defineSuite([
expect(rotation).not.toBe(result);
});

it('getRotation throws without a matrix', function() {
expect(function() {
return Matrix3.getRotation();
}).toThrowDeveloperError();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a separate check for getRotation throws without a result


it('transpose works with a result parameter that is an input result parameter', function() {
var matrix = new Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
var expected = new Matrix3(1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0);