-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Don't reproject Web Mercator imagery tiles unnecessarily #4339
Changes from 22 commits
294a83f
9ab3fd1
918c59a
ca333b3
0fd3f21
bcf6f81
e2a4119
e7c65b6
3cf3faa
fb269ad
205a043
8eb8e96
0c09753
7195f28
acdf984
bd42b71
5f1888b
ce0e458
6b04032
8480d01
0534ee6
bd6a1f4
1bbe7ca
091bca3
783ea9a
5dd34a3
1f22ed7
9b79102
23dc61d
32c4117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,7 +597,11 @@ define([ | |
}; | ||
|
||
/** | ||
* Computes the intersection of two rectangles | ||
* Computes the intersection of two rectangles. This function assumes that the rectangle's coordinates are | ||
* latitude and longitude in radians and produces a correct intersection, taking into account the fact that | ||
* the same angle can be represented with multiple values as well as the wrapping of longitude at the | ||
* anti-meridian. For a simple intersection that ignores these factors and can be used with projected | ||
* coordinates, see {@link Rectangle.simpleIntersection}. | ||
* | ||
* @param {Rectangle} rectangle On rectangle to find an intersection | ||
* @param {Rectangle} otherRectangle Another rectangle to find an intersection | ||
|
@@ -656,6 +660,47 @@ define([ | |
return result; | ||
}; | ||
|
||
/** | ||
* Computes a simple intersection of two rectangles. Unlike {@link Rectangle.intersection}, this function | ||
* does not attempt to put the angular coordinates into a consistent range or to account for crossing the | ||
* anti-meridian. As such, it can be used for rectangles where the coordinates are not simply latitude | ||
* and longitude (i.e. projected coordinates). | ||
* | ||
* @param {Rectangle} rectangle On rectangle to find an intersection | ||
* @param {Rectangle} otherRectangle Another rectangle to find an intersection | ||
* @param {Rectangle} [result] The object onto which to store the result. | ||
* @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection. | ||
*/ | ||
Rectangle.simpleIntersection = function(rectangle, otherRectangle, result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add to CHANGES.md please. |
||
//>>includeStart('debug', pragmas.debug); | ||
if (!defined(rectangle)) { | ||
throw new DeveloperError('rectangle is required'); | ||
} | ||
if (!defined(otherRectangle)) { | ||
throw new DeveloperError('otherRectangle is required.'); | ||
} | ||
//>>includeEnd('debug'); | ||
|
||
var west = Math.max(rectangle.west, otherRectangle.west); | ||
var south = Math.max(rectangle.south, otherRectangle.south); | ||
var east = Math.min(rectangle.east, otherRectangle.east); | ||
var north = Math.min(rectangle.north, otherRectangle.north); | ||
|
||
if (south >= north || west >= east) { | ||
return undefined; | ||
} | ||
|
||
if (!defined(result)) { | ||
return new Rectangle(west, south, east, north); | ||
} | ||
|
||
result.west = west; | ||
result.south = south; | ||
result.east = east; | ||
result.north = north; | ||
return result; | ||
}; | ||
|
||
/** | ||
* Computes a rectangle that is the union of two rectangles. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ define([ | |
'./Cartesian2', | ||
'./Cartesian3', | ||
'./ComponentDatatype', | ||
'./defaultValue', | ||
'./defined', | ||
'./Math', | ||
'./Matrix3', | ||
|
@@ -14,6 +15,7 @@ define([ | |
Cartesian2, | ||
Cartesian3, | ||
ComponentDatatype, | ||
defaultValue, | ||
defined, | ||
CesiumMath, | ||
Matrix3, | ||
|
@@ -41,10 +43,11 @@ define([ | |
* @param {Number} maximumHeight The maximum height. | ||
* @param {Matrix4} fromENU The east-north-up to fixed frame matrix at the center of the terrain mesh. | ||
* @param {Boolean} hasVertexNormals If the mesh has vertex normals. | ||
* @param {Boolean} [hasWebMercatorT=false] true if the terrain data includes a Web Mercator texture coordinate; otherwise, false. | ||
* | ||
* @private | ||
*/ | ||
function TerrainEncoding(axisAlignedBoundingBox, minimumHeight, maximumHeight, fromENU, hasVertexNormals) { | ||
function TerrainEncoding(axisAlignedBoundingBox, minimumHeight, maximumHeight, fromENU, hasVertexNormals, hasWebMercatorT) { | ||
var quantization; | ||
var center; | ||
var toENU; | ||
|
@@ -137,9 +140,15 @@ define([ | |
* @type {Boolean} | ||
*/ | ||
this.hasVertexNormals = hasVertexNormals; | ||
|
||
/** | ||
* The terrain mesh contains a vertical texture coordinate following the Web Mercator projection. | ||
* @type {Boolean} | ||
*/ | ||
this.hasWebMercatorT = defaultValue(hasWebMercatorT, false); | ||
} | ||
|
||
TerrainEncoding.prototype.encode = function(vertexBuffer, bufferIndex, position, uv, height, normalToPack) { | ||
TerrainEncoding.prototype.encode = function(vertexBuffer, bufferIndex, position, uv, height, normalToPack, webMercatorT) { | ||
var u = uv.x; | ||
var v = uv.y; | ||
|
||
|
@@ -165,6 +174,12 @@ define([ | |
vertexBuffer[bufferIndex++] = compressed0; | ||
vertexBuffer[bufferIndex++] = compressed1; | ||
vertexBuffer[bufferIndex++] = compressed2; | ||
|
||
if (this.hasWebMercatorT) { | ||
Cartesian2.fromElements(webMercatorT, 0.0, cartesian2Scratch); | ||
var compressed3 = AttributeCompression.compressTextureCoordinates(cartesian2Scratch); | ||
vertexBuffer[bufferIndex++] = compressed3; | ||
} | ||
} else { | ||
Cartesian3.subtract(position, this.center, cartesian3Scratch); | ||
|
||
|
@@ -174,6 +189,10 @@ define([ | |
vertexBuffer[bufferIndex++] = height; | ||
vertexBuffer[bufferIndex++] = u; | ||
vertexBuffer[bufferIndex++] = v; | ||
|
||
if (this.hasWebMercatorT) { | ||
vertexBuffer[bufferIndex++] = webMercatorT; | ||
} | ||
} | ||
|
||
if (this.hasVertexNormals) { | ||
|
@@ -254,6 +273,10 @@ define([ | |
vertexStride = 6; | ||
} | ||
|
||
if (this.hasWebMercatorT) { | ||
++vertexStride; | ||
} | ||
|
||
if (this.hasVertexNormals) { | ||
++vertexStride; | ||
} | ||
|
@@ -266,17 +289,29 @@ define([ | |
textureCoordAndEncodedNormals : 1 | ||
}; | ||
var attributes = { | ||
compressed : 0 | ||
compressed0 : 0, | ||
compressed1 : 1 | ||
}; | ||
|
||
TerrainEncoding.prototype.getAttributes = function(buffer) { | ||
var datatype = ComponentDatatype.FLOAT; | ||
var sizeInBytes = ComponentDatatype.getSizeInBytes(datatype); | ||
var stride; | ||
|
||
if (this.quantization === TerrainQuantization.NONE) { | ||
var sizeInBytes = ComponentDatatype.getSizeInBytes(datatype); | ||
var position3DAndHeightLength = 4; | ||
var numTexCoordComponents = this.hasVertexNormals ? 3 : 2; | ||
var stride = (this.hasVertexNormals ? 7 : 6) * sizeInBytes; | ||
var numTexCoordComponents = 2; | ||
|
||
if (this.hasWebMercatorT) { | ||
++numTexCoordComponents; | ||
} | ||
|
||
if (this.hasVertexNormals) { | ||
++numTexCoordComponents; | ||
} | ||
|
||
stride = (position3DAndHeightLength + numTexCoordComponents) * sizeInBytes; | ||
|
||
return [{ | ||
index : attributesNone.position3DAndHeight, | ||
vertexBuffer : buffer, | ||
|
@@ -294,14 +329,44 @@ define([ | |
}]; | ||
} | ||
|
||
var numComponents = 3; | ||
numComponents += this.hasVertexNormals ? 1 : 0; | ||
return [{ | ||
index : attributes.compressed, | ||
vertexBuffer : buffer, | ||
componentDatatype : datatype, | ||
componentsPerAttribute : numComponents | ||
}]; | ||
var numCompressed0 = 3; | ||
var numCompressed1 = 0; | ||
|
||
if (this.hasWebMercatorT || this.hasVertexNormals) { | ||
++numCompressed0; | ||
} | ||
|
||
if (this.hasWebMercatorT && this.hasVertexNormals) { | ||
++numCompressed1; | ||
|
||
stride = (numCompressed0 + numCompressed1) * sizeInBytes; | ||
|
||
return [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you run this through the formatter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we're using the same editor, so running it through "the formatter" probably doesn't make sense. But I moved the open curly to the same line as the open square bracket and stuff. |
||
{ | ||
index : attributes.compressed0, | ||
vertexBuffer : buffer, | ||
componentDatatype : datatype, | ||
componentsPerAttribute : numCompressed0, | ||
offsetInBytes : 0, | ||
strideInBytes : stride | ||
}, | ||
{ | ||
index : attributes.compressed1, | ||
vertexBuffer : buffer, | ||
componentDatatype : datatype, | ||
componentsPerAttribute : numCompressed1, | ||
offsetInBytes : numCompressed0 * sizeInBytes, | ||
strideInBytes : stride | ||
} | ||
]; | ||
} else { | ||
return [{ | ||
index : attributes.compressed0, | ||
vertexBuffer : buffer, | ||
componentDatatype : datatype, | ||
componentsPerAttribute : numCompressed0 | ||
}]; | ||
} | ||
}; | ||
|
||
TerrainEncoding.prototype.getAttributeLocations = function() { | ||
|
@@ -325,6 +390,7 @@ define([ | |
result.fromScaledENU = Matrix4.clone(encoding.fromScaledENU); | ||
result.matrix = Matrix4.clone(encoding.matrix); | ||
result.hasVertexNormals = encoding.hasVertexNormals; | ||
result.hasWebMercatorT = encoding.hasWebMercatorT; | ||
return result; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we can make the performance claim in practice? In the steady state, this is probably worse.