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
22 changes: 22 additions & 0 deletions Source/Core/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,28 @@ define([
return result;
};

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

/**
* Factors rotation matrix from arbitrary Matrix3 by dividing components by scale
*
* @param {Matrix3} rotation-scale matrix
* @param {Matrix3} result rotation matrix with unit scale
* @returns {Matrix3} The modified result parameter.
*/
Matrix3.getRotation = function(matrix, result) {
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
//>>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);
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
result = Matrix3.multiplyByScale(matrix, inverseScale, result);

return result;
};

function computeFrobeniusNorm(matrix) {
var norm = 0.0;
for (var i = 0; i < 9; ++i) {
Expand Down
3 changes: 1 addition & 2 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,7 @@ define([

var m = uniformState._normal;
Matrix4.getRotation(uniformState.inverseModelView, m);
Matrix3.getRotation(m, m);
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
Matrix3.transpose(m, m);
}
}
Expand All @@ -1271,15 +1272,13 @@ define([
function cleanInverseNormal(uniformState) {
if (uniformState._inverseNormalDirty) {
uniformState._inverseNormalDirty = false;

Matrix4.getRotation(uniformState.inverseModelView, uniformState._inverseNormal);
}
}

function cleanInverseNormal3D(uniformState) {
if (uniformState._inverseNormal3DDirty) {
uniformState._inverseNormal3DDirty = false;

Matrix4.getRotation(uniformState.inverseModelView3D, uniformState._inverseNormal3D);
}
}
Expand Down
16 changes: 13 additions & 3 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ define([
* @type {Number}
* @readonly
*/
this.geometricError = header.geometricError;
this._geometricError = header.geometricError;
lilleyse marked this conversation as resolved.
Show resolved Hide resolved

if (!defined(this.geometricError)) {
this.geometricError = defined(parent) ? parent.geometricError : tileset._geometricError;
if (!defined(this._geometricError)) {
this._geometricError = defined(parent) ? parent.geometricError : tileset._geometricError;
Cesium3DTile._deprecationWarning('geometricErrorUndefined', 'Required property geometricError is undefined for this tile. Using parent\'s geometric error instead.');
}

this.updateGeometricErrorScale();

var refine;
if (defined(header.refine)) {
if (header.refine === 'replace' || header.refine === 'add') {
Expand Down Expand Up @@ -1114,12 +1116,20 @@ define([
this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume);
}

this.updateGeometricErrorScale();

// Destroy the debug bounding volumes. They will be generated fresh.
this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
};

Cesium3DTile.prototype.updateGeometricErrorScale = function() {
var scale = Matrix4.getScale(this.computedTransform, scratchScale);
var uniformScale = Cartesian3.maximumComponent(scale);
this.geometricError = this._geometricError * uniformScale;
};

function applyDebugSettings(tile, tileset, frameState) {
if (!frameState.passes.render) {
return;
Expand Down
22 changes: 22 additions & 0 deletions Specs/Core/Matrix3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,28 @@ defineSuite([
expect(result).toEqual(expected);
});

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 scale = new Cartesian3();
var expectedScale = new Cartesian3(1.0, 1.0, 1.0);
result = Matrix3.getRotation(matrix, result);
var resultScale = Matrix3.getScale(result, scale);
expect(resultScale).toEqualEpsilon(expectedScale, CesiumMath.EPSILON14);
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
});

it('getRotation does not modify rotation matrix', function() {
var tmp = new Matrix3();
var result = new Matrix3();
var rotation = Matrix3.clone(Matrix3.IDENTITY, new Matrix3());
Matrix3.multiply(rotation, Matrix3.fromRotationX(1.0, tmp), rotation);
Matrix3.multiply(rotation, Matrix3.fromRotationY(2.0, tmp), rotation);
Matrix3.multiply(rotation, Matrix3.fromRotationZ(3.0, tmp), rotation);
result = Matrix3.getRotation(rotation, result);
expect(rotation).toEqualEpsilon(result, CesiumMath.EPSILON14);
expect(rotation).not.toBe(result);
});

it('transpose works with a result parameter that is an input result parameter', function() {
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down