This commit is contained in:
ggetz 2024-08-26 09:39:17 -04:00
parent 8ad5fd9c32
commit e1be5f9c3f
3 changed files with 56 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import TerrainMesh from "./TerrainMesh.js";
* Terrain data for a single tile where the terrain data is represented as a glb (binary glTF).
*
* @alias Cesium3DTilesTerrainData
* @experimental
* @constructor
*
* @param {Object} options Object with the following properties:
@ -33,6 +34,7 @@ import TerrainMesh from "./TerrainMesh.js";
* The point is expressed in ellipsoid-scaled coordinates.
* @param {Number} options.skirtHeight The height of the skirt to add on the edges of the tile.
* @param {Boolean} [options.requestVertexNormals=false] Indicates whether normals should be loaded.
* @param {Boolean} [options.requestWaterMask=false] Indicates whether water mask data should be loaded.
* @param {Credit[]} [options.credits] Array of credits for this tile.
* @param {Number} [options.childTileMask=15] A bit mask indicating which of this tile's four children exist.
* If a child's bit is set, geometry will be requested for that tile as well when it
@ -100,6 +102,9 @@ function Cesium3DTilesTerrainData(options) {
/** @type {Boolean} */
this._hasVertexNormals = defaultValue(options.requestVertexNormals, false);
/** @type {Boolean} */
this._hasWaterMask = defaultValue(options.requestWaterMask, false);
/** @type {Boolean} */
this._hasWebMercatorT = true;
@ -120,6 +125,8 @@ function Cesium3DTilesTerrainData(options) {
* @type {TerrainMesh|undefined}
*/
this._mesh = undefined;
this._waterMask = undefined;
}
Object.defineProperties(Cesium3DTilesTerrainData.prototype, {
@ -146,8 +153,7 @@ Object.defineProperties(Cesium3DTilesTerrainData.prototype, {
waterMask: {
// @ts-ignore
get: function () {
// Not supported currently
return undefined;
return this._waterMask;
},
},
});
@ -273,6 +279,7 @@ Cesium3DTilesTerrainData.prototype.createMesh = function (options) {
ellipsoid: ellipsoid,
rectangle: rectangle,
hasVertexNormals: this._hasVertexNormals,
hasWaterMask: this._hasWaterMask,
hasWebMercatorT: this._hasWebMercatorT,
gltf: this._gltf,
minimumHeight: this._minimumHeight,
@ -295,7 +302,7 @@ Cesium3DTilesTerrainData.prototype.createMesh = function (options) {
return Promise.resolve(verticesPromise).then(function (result) {
const taskResult = result;
// Need to re-clone and re-wrap all buffers and complex ojects to put them back into their normal state
// Need to re-clone and re-wrap all buffers and complex objects to put them back into their normal state
const encoding = TerrainEncoding.clone(
taskResult.encoding,
new TerrainEncoding()
@ -347,6 +354,8 @@ Cesium3DTilesTerrainData.prototype.createMesh = function (options) {
);
that._mesh = mesh;
that._waterMask = new Uint8Array(taskResult.waterMaskBuffer);
return Promise.resolve(mesh);
});
};

View File

@ -170,14 +170,14 @@ function decodeNormals(gltf) {
bufferViewMeshOpt.byteLength
);
const normalByteLengh = bufferViewMeshOpt.byteStride;
const normalsResult = new Int8Array(normalCount * normalByteLengh);
const normalByteLength = bufferViewMeshOpt.byteStride;
const normalsResult = new Int8Array(normalCount * normalByteLength);
// @ts-ignore
MeshoptDecoder.decodeVertexBuffer(
new Uint8Array(normalsResult.buffer),
normalCount,
normalByteLengh,
normalByteLength,
compressedBuffer
);
@ -339,6 +339,28 @@ function decodeEdgeIndices(gltf, name) {
return indices;
}
/**
* @private
* @param {Object.<string,*>} gltf
* @param {String} propertyId
* @returns {Uint8Array}
*/
function decodeWaterMask(gltf, propertyId) {
const loader = new GltfStructuralMetadataLoader({
gltf: gltf,
extension:
})
const propertyTexture;
const property = propertyTexture.getProperty(propertyId);
property.textureReader
const propertyTable = structuralMetadata.getPropertyTable(propertyTableId)
return propertyTable.getPropertyTypedArray(propertyId);
}
/**
* @private
* @typedef GltfInfo

View File

@ -186,7 +186,8 @@ function isChildAvailable(implicitTileset, subtree, coord, x, y) {
* Initialization options for the Cesium3DTilesTerrainProvider constructor
*
* @property {boolean} [requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server, in the form of per vertex normals if available.
* @property {Ellipsoid} [ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
* @property {boolean} [requestWaterMask=false] Flag that indicates if the client should request per tile water masks from the server, if available.
* @property {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
* @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.
*/
@ -194,6 +195,7 @@ function isChildAvailable(implicitTileset, subtree, coord, x, y) {
* A {@link TerrainProvider} that accesses terrain data in a 3D Tiles format.
*
* @alias Cesium3DTilesTerrainProvider
* @experimental
* @constructor
*
* @param {Cesium3DTilesTerrainProvider.ConstructorOptions}[options] An object describing initialization options
@ -240,10 +242,25 @@ function Cesium3DTilesTerrainProvider(options) {
// @ts-ignore
this._resource = undefined;
/**
* Boolean flag that indicates if the client should request vertex normals from the server.
* @type {boolean}
* @default false
* @private
*/
this._requestVertexNormals = defaultValue(
options.requestVertexNormals,
false
);
/**
* Boolean flag that indicates if the client should request tile watermasks from the server.
* @type {boolean}
* @default false
* @private
*/
this._requestWaterMask = defaultValue(options.requestWaterMask, false);
this._hasWaterMask = false;
}
/**
@ -694,7 +711,7 @@ Object.defineProperties(Cesium3DTilesTerrainProvider.prototype, {
// @ts-ignore
hasWaterMask: {
get: function () {
return false;
return this._hasWaterMask && this._requestWaterMask;
},
},