From ca38e70bef0d1e0ff58d71af7922bbada8873729 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Mon, 10 Dec 2018 15:01:26 +0300 Subject: [PATCH] refs #7398 moved getRotation method to Matrix3, removed geometricError recalculation on each "get" --- Source/Core/Matrix3.js | 21 +++++++++++++++++++++ Source/Core/Matrix4.js | 11 ----------- Source/Renderer/UniformState.js | 3 +-- Source/Scene/Cesium3DTile.js | 20 +++++++++++--------- Source/Scene/PointCloud.js | 8 +++----- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 23e9b6c21376..3c0f23689164 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -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) { + Matrix3.multiplyByScale( + 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) { diff --git a/Source/Core/Matrix4.js b/Source/Core/Matrix4.js index fba45a031cfe..19ed5ed1d520 100644 --- a/Source/Core/Matrix4.js +++ b/Source/Core/Matrix4.js @@ -2149,10 +2149,6 @@ define([ return result; }; - - var UNIT = new Cartesian3(1, 1, 1); - var scratchScale = new Cartesian3(); - /** * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is a affine transformation matrix. * @@ -2190,13 +2186,6 @@ define([ result[6] = matrix[8]; result[7] = matrix[9]; result[8] = matrix[10]; - Matrix3.multiplyByScale( - result, - Cartesian3.divideComponents( - UNIT, Matrix3.getScale(result, scratchScale), scratchScale - ), - result - ) return result; }; diff --git a/Source/Renderer/UniformState.js b/Source/Renderer/UniformState.js index 0097e65d3dde..35903411b737 100644 --- a/Source/Renderer/UniformState.js +++ b/Source/Renderer/UniformState.js @@ -1237,6 +1237,7 @@ define([ var m = uniformState._normal; Matrix4.getRotation(uniformState.inverseModelView, m); + Matrix3.getRotation(m, m); Matrix3.transpose(m, m); } } @@ -1254,7 +1255,6 @@ define([ function cleanInverseNormal(uniformState) { if (uniformState._inverseNormalDirty) { uniformState._inverseNormalDirty = false; - Matrix4.getRotation(uniformState.inverseModelView, uniformState._inverseNormal); } } @@ -1262,7 +1262,6 @@ define([ function cleanInverseNormal3D(uniformState) { if (uniformState._inverseNormal3DDirty) { uniformState._inverseNormal3DDirty = false; - Matrix4.getRotation(uniformState.inverseModelView3D, uniformState._inverseNormal3D); } } diff --git a/Source/Scene/Cesium3DTile.js b/Source/Scene/Cesium3DTile.js index a12824b5e890..e07cd59e9b57 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -144,6 +144,8 @@ define([ 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') { @@ -349,8 +351,6 @@ define([ // This can be overridden for testing purposes Cesium3DTile._deprecationWarning = deprecationWarning; - var scratchScale = new Cartesian3(); - defineProperties(Cesium3DTile.prototype, { /** * The tileset containing this tile. @@ -604,13 +604,7 @@ define([ get : function() { return this._commandsLength; } - }, - - geometricError : { - get : function() { - return Cartesian3.maximumComponent(Matrix4.getScale(this.computedTransform, scratchScale)) * this._geometricError; - } - } + } }); var scratchJulianDate = new JulianDate(); @@ -1056,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; diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index b2121b02b4aa..6ad8c4586295 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -116,8 +116,6 @@ define([ Check.typeOf.object('options.arrayBuffer', options.arrayBuffer); //>>includeEnd('debug'); - var that = this; - // Hold onto the payload until the render resources are created this._parsedContent = undefined; @@ -151,12 +149,12 @@ define([ // Use per-point normals to hide back-facing points. this.backFaceCulling = false; - bindProperty(this, "backFaceCulling", options.backFaceCulling); + bindProperty(this, 'backFaceCulling', options.backFaceCulling); this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading this.normalShading = true; - bindProperty(this, "normalShading", options.normalShading); + bindProperty(this, 'normalShading', options.normalShading); this._normalShading = this.normalShading; this._opaqueRenderState = undefined; @@ -1179,7 +1177,7 @@ define([ vs += ' v_color = color; \n' + ' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n'; - if (usesNormals && true) { + if (usesNormals && backFaceCulling) { vs += ' float visible = step(-normal.z, 0.0); \n' + ' gl_Position *= visible; \n' + ' gl_PointSize *= visible; \n';