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
21 changes: 21 additions & 0 deletions Source/Core/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,27 @@ 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
Matrix3.multiplyByScale(
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
matrix,
Cartesian3.divideComponents(
UNIT, Matrix3.getScale(matrix, scaleVector), scaleVector
),
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 @@ -1237,6 +1237,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 @@ -1254,15 +1255,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 @@ -137,13 +137,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 @@ -1048,12 +1050,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) {
var hasContentBoundingVolume = defined(tile._header.content) && defined(tile._header.content.boundingVolume);
var empty = tile.hasEmptyContent || tile.hasTilesetContent;
Expand Down