Skip to content

Commit

Permalink
Merge pull request #4183 from AnalyticalGraphicsInc/pnts-updates
Browse files Browse the repository at this point in the history
3D Tiles Points updates - quantization and oct-encoding
  • Loading branch information
pjcozzi authored Sep 2, 2016
2 parents 415891e + 4344f74 commit e077f89
Show file tree
Hide file tree
Showing 142 changed files with 3,710 additions and 1,619 deletions.
8 changes: 7 additions & 1 deletion Apps/Sandcastle/gallery/3D Tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@
}, {
name : 'Composite', url : '../../../Specs/Data/Cesium3DTiles/Composite/Composite/'
}, {
name : 'Points', url : '../../../Specs/Data/Cesium3DTiles/Points/PointsRGB/'
name : 'PointCloud', url : '../../../Specs/Data/Cesium3DTiles/PointCloud/PointCloudRGB/'
}, {
name : 'PointCloudConstantColor', url : '../../../Specs/Data/Cesium3DTiles/PointCloud/PointCloudConstantColor/'
}, {
name : 'PointCloudNormals', url : '../../../Specs/Data/Cesium3DTiles/PointCloud/PointCloudQuantizedOctEncoded/'
}, {
name : 'PointCloudBatched', url : '../../../Specs/Data/Cesium3DTiles/PointCloud/PointCloudBatched/'
}];

var tileset;
Expand Down
21 changes: 9 additions & 12 deletions Source/Core/PointGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ define([
if (!defined(options.positionsTypedArray)) {
throw new DeveloperError('options.positionsTypedArray is required.');
}
if (!defined(options.colorsTypedArray)) {
throw new DeveloperError('options.colorsTypedArray is required');
}
//>>includeEnd('debug');

this._positionsTypedArray = options.positionsTypedArray;
Expand Down Expand Up @@ -77,18 +80,12 @@ define([
values : positions
});

var colors = pointGeometry._colorsTypedArray;
if (defined(colors)) {
// Check if the colors are provided as rgb or rgba
var colorComponentsPerAttribute = (colors.length === positions.length) ? 3 : 4;

attributes.color = new GeometryAttribute({
componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
componentsPerAttribute : colorComponentsPerAttribute,
values : colors,
normalize : true
});
}
attributes.color = new GeometryAttribute({
componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
componentsPerAttribute : 3,
values : pointGeometry._colorsTypedArray,
normalize : true
});

// User provided bounding sphere to save computation time.
var boundingSphere = pointGeometry._boundingSphere;
Expand Down
77 changes: 53 additions & 24 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define([
'../Core/RequestType',
'../ThirdParty/when',
'./Cesium3DTileFeature',
'./Cesium3DTileBatchTableResources',
'./Cesium3DTileBatchTable',
'./Cesium3DTileContentState',
'./Model'
], function(
Expand All @@ -32,7 +32,7 @@ define([
RequestType,
when,
Cesium3DTileFeature,
Cesium3DTileBatchTableResources,
Cesium3DTileBatchTable,
Cesium3DTileContentState,
Model) {
'use strict';
Expand All @@ -57,7 +57,7 @@ define([
* The following properties are part of the {@link Cesium3DTileContent} interface.
*/
this.state = Cesium3DTileContentState.UNLOADED;
this.batchTableResources = undefined;
this.batchTable = undefined;
this.featurePropertiesDirty = false;

this._contentReadyToProcessPromise = when.defer();
Expand Down Expand Up @@ -120,7 +120,7 @@ define([
* Part of the {@link Cesium3DTileContent} interface.
*/
Batched3DModel3DTileContent.prototype.hasProperty = function(name) {
return this.batchTableResources.hasProperty(name);
return this.batchTable.hasProperty(name);
};

/**
Expand Down Expand Up @@ -199,27 +199,54 @@ define([
var byteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

var batchLength = view.getUint32(byteOffset, true);
this._featuresLength = batchLength;
var batchTableJsonByteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

var batchTableResources = new Cesium3DTileBatchTableResources(this, batchLength);
this.batchTableResources = batchTableResources;
var batchTableBinaryByteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

var batchTableByteLength = view.getUint32(byteOffset, true);
var batchLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;
if (batchTableByteLength > 0) {
var batchTableString = getStringFromTypedArray(uint8Array, byteOffset, batchTableByteLength);
byteOffset += batchTableByteLength;

// TODO : remove this legacy check before merging into master
// Legacy header: [batchLength] [batchTableByteLength]
// Current header: [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]
// If the header is in the legacy format 'batchLength' will be the start of the JSON string (a quotation mark) or the glTF magic.
// Accordingly the first byte of uint32 will be either 0x22 or 0x67 and so the uint32 will exceed any reasonable 'batchLength'.
if (batchLength > 10000000) {
byteOffset -= sizeOfUint32;
batchLength = batchTableJsonByteLength;
batchTableJsonByteLength = batchTableBinaryByteLength;
batchTableBinaryByteLength = 0;
console.log('Warning: b3dm header is using the legacy format [batchLength] [batchTableByteLength]. The new format is [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength] from https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/TileFormats/Batched3DModel/README.md.');
}

this._featuresLength = batchLength;

var batchTableJson;
var batchTableBinary;
if (batchTableJsonByteLength > 0) {
// PERFORMANCE_IDEA: is it possible to allocate this on-demand? Perhaps keep the
// arraybuffer/string compressed in memory and then decompress it when it is first accessed.
//
// We could also make another request for it, but that would make the property set/get
// API async, and would double the number of numbers in some cases.
batchTableResources.batchTable = JSON.parse(batchTableString);
var batchTableString = getStringFromTypedArray(uint8Array, byteOffset, batchTableJsonByteLength);
batchTableJson = JSON.parse(batchTableString);
byteOffset += batchTableJsonByteLength;

if (batchTableBinaryByteLength > 0) {
// Has a batch table binary
batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength);
// Copy the batchTableBinary section and let the underlying ArrayBuffer be freed
batchTableBinary = new Uint8Array(batchTableBinary);
byteOffset += batchTableBinaryByteLength;
}
}

var batchTable = new Cesium3DTileBatchTable(this, batchLength, batchTableJson, batchTableBinary);
this.batchTable = batchTable;

var gltfByteLength = byteStart + byteLength - byteOffset;
var gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength);

Expand All @@ -229,13 +256,14 @@ define([
gltf : gltfView,
cull : false, // The model is already culled by the 3D tiles
releaseGltfJson : true, // Models are unique and will not benefit from caching so save memory
vertexShaderLoaded : batchTableResources.getVertexShaderCallback(),
fragmentShaderLoaded : batchTableResources.getFragmentShaderCallback(),
uniformMapLoaded : batchTableResources.getUniformMapCallback(),
pickVertexShaderLoaded : batchTableResources.getPickVertexShaderCallback(),
pickFragmentShaderLoaded : batchTableResources.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTableResources.getPickUniformMapCallback(),
basePath : this._url
basePath : this._url,
modelMatrix : this._tile.computedTransform,
vertexShaderLoaded : batchTable.getVertexShaderCallback(),
fragmentShaderLoaded : batchTable.getFragmentShaderCallback(),
uniformMapLoaded : batchTable.getUniformMapCallback(),
pickVertexShaderLoaded : batchTable.getPickVertexShaderCallback(),
pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTable.getPickUniformMapCallback()
});

this._model = model;
Expand All @@ -258,7 +286,7 @@ define([
*/
Batched3DModel3DTileContent.prototype.applyDebugSettings = function(enabled, color) {
color = enabled ? color : Color.WHITE;
this.batchTableResources.setAllColor(color);
this.batchTable.setAllColor(color);
};

/**
Expand All @@ -267,13 +295,14 @@ define([
Batched3DModel3DTileContent.prototype.update = function(tileset, frameState) {
var oldAddCommand = frameState.addCommand;
if (frameState.passes.render) {
frameState.addCommand = this.batchTableResources.getAddCommand();
frameState.addCommand = this.batchTable.getAddCommand();
}

// In the PROCESSING state we may be calling update() to move forward
// the content's resource loading. In the READY state, it will
// actually generate commands.
this.batchTableResources.update(tileset, frameState);
this.batchTable.update(tileset, frameState);
this._model.modelMatrix = this._tile.computedTransform;
this._model.update(frameState);

frameState.addCommand = oldAddCommand;
Expand All @@ -291,7 +320,7 @@ define([
*/
Batched3DModel3DTileContent.prototype.destroy = function() {
this._model = this._model && this._model.destroy();
this.batchTableResources = this.batchTableResources && this.batchTableResources.destroy();
this.batchTable = this.batchTable && this.batchTable.destroy();

return destroyObject(this);
};
Expand Down
Loading

0 comments on commit e077f89

Please sign in to comment.