diff --git a/CHANGES.md b/CHANGES.md index 5716bbe50b1..46c4f9d6909 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Change Log * Fixed `PolygonGeometry` when using `VertexFormat.POSITION_ONLY`, `perPositionHeight` and `extrudedHeight` [#6790](expect(https://github.com/AnalyticalGraphicsInc/cesium/pull/6790) * Fixed a bug that was preventing 3D Tilesets on the opposite side of the globe from being occluded [#6714](https://github.com/AnalyticalGraphicsInc/cesium/issues/6714) * Fixed a bug where 3D Tilesets using the `region` bounding volume don't get transformed when the tileset's `modelMatrix` changes. [6755](https://github.com/AnalyticalGraphicsInc/cesium/pull/6755) +* Fixed `PolygonGeometry` and `EllipseGeometry` tangent and bitangent attributes when a texture rotation is used [#6788](https://github.com/AnalyticalGraphicsInc/cesium/pull/6788) ### 1.47 - 2018-07-02 diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 9c855da8566..aaa0e3a630c 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -62,6 +62,7 @@ define([ var scratchCartesian4 = new Cartesian3(); var texCoordScratch = new Cartesian2(); var textureMatrixScratch = new Matrix3(); + var tangentMatrixScratch = new Matrix3(); var quaternionScratch = new Quaternion(); var scratchNormal = new Cartesian3(); @@ -104,8 +105,19 @@ define([ var geodeticNormal = ellipsoid.scaleToGeodeticSurface(center, scratchCartesian1); ellipsoid.geodeticSurfaceNormal(geodeticNormal, geodeticNormal); - var rotation = Quaternion.fromAxisAngle(geodeticNormal, stRotation, quaternionScratch); - var textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrixScratch); + + var textureMatrix = textureMatrixScratch; + var tangentMatrix = tangentMatrixScratch; + if (stRotation !== 0) { + var rotation = Quaternion.fromAxisAngle(geodeticNormal, stRotation, quaternionScratch); + textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrix); + + rotation = Quaternion.fromAxisAngle(geodeticNormal, -stRotation, quaternionScratch); + tangentMatrix = Matrix3.fromQuaternion(rotation, tangentMatrix); + } else { + textureMatrix = Matrix3.clone(Matrix3.IDENTITY, textureMatrix); + tangentMatrix = Matrix3.clone(Matrix3.IDENTITY, tangentMatrix); + } var minTexCoord = Cartesian2.fromElements(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, scratchMinTexCoord); var maxTexCoord = Cartesian2.fromElements(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, scratchMaxTexCoord); @@ -152,7 +164,7 @@ define([ if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) { if (vertexFormat.tangent || vertexFormat.bitangent) { tangent = Cartesian3.normalize(Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent), tangent); - Matrix3.multiplyByVector(textureMatrix, tangent, tangent); + Matrix3.multiplyByVector(tangentMatrix, tangent, tangent); } if (vertexFormat.normal) { normals[i] = normal.x; diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index 785448ef724..c91026befa5 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -90,6 +90,7 @@ define([ var appendTextureCoordinatesCartesian3 = new Cartesian3(); var appendTextureCoordinatesQuaternion = new Quaternion(); var appendTextureCoordinatesMatrix3 = new Matrix3(); + var tangentMatrixScratch = new Matrix3(); function computeAttributes(options) { var vertexFormat = options.vertexFormat; @@ -134,8 +135,18 @@ define([ var bitangent = scratchBitangent; var recomputeNormal = true; - var rotation = Quaternion.fromAxisAngle(tangentPlane._plane.normal, stRotation, appendTextureCoordinatesQuaternion); - var textureMatrix = Matrix3.fromQuaternion(rotation, appendTextureCoordinatesMatrix3); + var textureMatrix = appendTextureCoordinatesMatrix3; + var tangentRotationMatrix = tangentMatrixScratch; + if (stRotation !== 0.0) { + var rotation = Quaternion.fromAxisAngle(tangentPlane._plane.normal, stRotation, appendTextureCoordinatesQuaternion); + textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrix); + + rotation = Quaternion.fromAxisAngle(tangentPlane._plane.normal, -stRotation, appendTextureCoordinatesQuaternion); + tangentRotationMatrix = Matrix3.fromQuaternion(rotation, tangentRotationMatrix); + } else { + textureMatrix = Matrix3.clone(Matrix3.IDENTITY, textureMatrix); + tangentRotationMatrix = Matrix3.clone(Matrix3.IDENTITY, tangentRotationMatrix); + } var bottomOffset = 0; var bottomOffset2 = 0; @@ -206,14 +217,14 @@ define([ if (perPositionHeight) { scratchPerPosNormal = Cartesian3.fromArray(normals, attrIndex, scratchPerPosNormal); scratchPerPosTangent = Cartesian3.cross(Cartesian3.UNIT_Z, scratchPerPosNormal, scratchPerPosTangent); - scratchPerPosTangent = Cartesian3.normalize(Matrix3.multiplyByVector(textureMatrix, scratchPerPosTangent, scratchPerPosTangent), scratchPerPosTangent); + scratchPerPosTangent = Cartesian3.normalize(Matrix3.multiplyByVector(tangentRotationMatrix, scratchPerPosTangent, scratchPerPosTangent), scratchPerPosTangent); if (vertexFormat.bitangent) { scratchPerPosBitangent = Cartesian3.normalize(Cartesian3.cross(scratchPerPosNormal, scratchPerPosTangent, scratchPerPosBitangent), scratchPerPosBitangent); } } tangent = Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent); - tangent = Cartesian3.normalize(Matrix3.multiplyByVector(textureMatrix, tangent, tangent), tangent); + tangent = Cartesian3.normalize(Matrix3.multiplyByVector(tangentRotationMatrix, tangent, tangent), tangent); if (vertexFormat.bitangent) { bitangent = Cartesian3.normalize(Cartesian3.cross(normal, tangent, bitangent), bitangent); }