Skip to content
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

3D Tiles - Load tiles without extensions #5206

Merged
merged 4 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 31 additions & 115 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ define([
'../Core/DeveloperError',
'../Core/getAbsoluteUri',
'../Core/getBaseUri',
'../Core/getMagic',
'../Core/getStringFromTypedArray',
'../Core/loadArrayBuffer',
'../Core/Request',
'../Core/RequestScheduler',
'../Core/RequestType',
'../ThirdParty/when',
'./Cesium3DTileBatchTable',
'./Cesium3DTileContentState',
'./Cesium3DTileFeature',
'./Cesium3DTileFeatureTable',
'./getAttributeOrUniformBySemantic',
Expand All @@ -34,15 +29,10 @@ define([
DeveloperError,
getAbsoluteUri,
getBaseUri,
getMagic,
getStringFromTypedArray,
loadArrayBuffer,
Request,
RequestScheduler,
RequestType,
when,
Cesium3DTileBatchTable,
Cesium3DTileContentState,
Cesium3DTileFeature,
Cesium3DTileFeatureTable,
getAttributeOrUniformBySemantic,
Expand All @@ -59,7 +49,7 @@ define([
*
* @private
*/
function Batched3DModel3DTileContent(tileset, tile, url) {
function Batched3DModel3DTileContent(tileset, tile, url, arrayBuffer, byteOffset) {
this._model = undefined;
this._url = url;
this._tileset = tileset;
Expand All @@ -68,14 +58,12 @@ define([
/**
* The following properties are part of the {@link Cesium3DTileContent} interface.
*/
this.state = Cesium3DTileContentState.UNLOADED;
this.batchTable = undefined;
this.featurePropertiesDirty = false;

this._contentReadyToProcessPromise = when.defer();
this._readyPromise = when.defer();
this._featuresLength = 0;
this._features = undefined;

initialize(this, arrayBuffer, byteOffset);
}

// This can be overridden for testing purposes
Expand All @@ -87,7 +75,7 @@ define([
*/
featuresLength : {
get : function() {
return this._featuresLength;
return this.batchTable.featuresLength;
}
},

Expand All @@ -105,10 +93,7 @@ define([
*/
trianglesLength : {
get : function() {
if (defined(this._model)) {
return this._model.trianglesLength;
}
return 0;
return this._model.trianglesLength;
}
},

Expand All @@ -117,10 +102,7 @@ define([
*/
vertexMemorySizeInBytes : {
get : function() {
if (defined(this._model)) {
return this._model.vertexMemorySizeInBytes;
}
return 0;
return this._model.vertexMemorySizeInBytes;
}
},

Expand All @@ -129,10 +111,7 @@ define([
*/
textureMemorySizeInBytes : {
get : function() {
if (defined(this._model)) {
return this._model.textureMemorySizeInBytes;
}
return 0;
return this._model.textureMemorySizeInBytes;
}
},

Expand All @@ -141,10 +120,7 @@ define([
*/
batchTableMemorySizeInBytes : {
get : function() {
if (defined(this.batchTable)) {
return this.batchTable.memorySizeInBytes;
}
return 0;
return this.batchTable.memorySizeInBytes;
}
},

Expand All @@ -157,28 +133,19 @@ define([
}
},

/**
* Part of the {@link Cesium3DTileContent} interface.
*/
contentReadyToProcessPromise : {
get : function() {
return this._contentReadyToProcessPromise.promise;
}
},

/**
* Part of the {@link Cesium3DTileContent} interface.
*/
readyPromise : {
get : function() {
return this._readyPromise.promise;
return this._model.readyPromise;
}
}
});

function createFeatures(content) {
var tileset = content._tileset;
var featuresLength = content._featuresLength;
var featuresLength = content.featuresLength;
if (!defined(content._features) && (featuresLength > 0)) {
var features = new Array(featuresLength);
for (var i = 0; i < featuresLength; ++i) {
Expand All @@ -199,7 +166,7 @@ define([
* Part of the {@link Cesium3DTileContent} interface.
*/
Batched3DModel3DTileContent.prototype.getFeature = function(batchId) {
var featuresLength = this._featuresLength;
var featuresLength = this.featuresLength;
//>>includeStart('debug', pragmas.debug);
if (!defined(batchId) || (batchId < 0) || (batchId >= featuresLength)) {
throw new DeveloperError('batchId is required and between zero and featuresLength - 1 (' + (featuresLength - 1) + ').');
Expand All @@ -212,38 +179,6 @@ define([

var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;

/**
* Part of the {@link Cesium3DTileContent} interface.
*/
Batched3DModel3DTileContent.prototype.request = function() {
var that = this;

var distance = this._tile.distanceToCamera;
var promise = RequestScheduler.schedule(new Request({
url : this._url,
server : this._tile.requestServer,
requestFunction : loadArrayBuffer,
type : RequestType.TILES3D,
distance : distance
}));

if (!defined(promise)) {
return false;
}

this.state = Cesium3DTileContentState.LOADING;
promise.then(function(arrayBuffer) {
if (that.isDestroyed()) {
return when.reject('tileset is destroyed');
}
that.initialize(arrayBuffer);
}).otherwise(function(error) {
that.state = Cesium3DTileContentState.FAILED;
that._readyPromise.reject(error);
});
return true;
};

function getBatchIdAttributeName(gltf) {
var batchIdAttributeName = getAttributeOrUniformBySemantic(gltf, '_BATCHID');
if (!defined(batchIdAttributeName)) {
Expand Down Expand Up @@ -285,21 +220,17 @@ define([
};
}

/**
* Part of the {@link Cesium3DTileContent} interface.
*/
Batched3DModel3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) {
function initialize(content, arrayBuffer, byteOffset) {
var tileset = content._tileset;
var tile = content._tile;
var basePath = getAbsoluteUri(getBaseUri(content._url, true));

var byteStart = defaultValue(byteOffset, 0);
byteOffset = byteStart;

var uint8Array = new Uint8Array(arrayBuffer);
var magic = getMagic(uint8Array, byteOffset);
if (magic !== 'b3dm') {
throw new DeveloperError('Invalid Batched 3D Model. Expected magic=b3dm. Read magic=' + magic);
}

var view = new DataView(arrayBuffer);
byteOffset += sizeOfUint32; // Skip magic number
byteOffset += sizeOfUint32; // Skip magic

//>>includeStart('debug', pragmas.debug);
var version = view.getUint32(byteOffset, true);
Expand Down Expand Up @@ -371,7 +302,6 @@ define([

batchLength = featureTable.getGlobalProperty('BATCH_LENGTH', ComponentDatatype.UNSIGNED_INT);
featureTable.featuresLength = batchLength;
this._featuresLength = batchLength;

var batchTableJson;
var batchTableBinary;
Expand All @@ -394,48 +324,35 @@ define([
}
}

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

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

// PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes.
// The pick shader still needs to be patched.
var model = new Model({
content._model = new Model({
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
basePath : getAbsoluteUri(getBaseUri(this._url, true)),
modelMatrix : this._tile.computedTransform,
upAxis : this._tileset._gltfUpAxis,
shadows: this._tileset.shadows,
debugWireframe: this._tileset.debugWireframe,
basePath : basePath,
requestType : RequestType.TILES3D,
modelMatrix : tile.computedTransform,
upAxis : tileset._gltfUpAxis,
shadows: tileset.shadows,
debugWireframe: tileset.debugWireframe,
incrementallyLoadTextures : false,
pickPrimitive : this._tileset,
vertexShaderLoaded : getVertexShaderCallback(this),
fragmentShaderLoaded : getFragmentShaderCallback(this),
pickPrimitive : tileset,
vertexShaderLoaded : getVertexShaderCallback(content),
fragmentShaderLoaded : getFragmentShaderCallback(content),
uniformMapLoaded : batchTable.getUniformMapCallback(),
pickVertexShaderLoaded : getPickVertexShaderCallback(this),
pickVertexShaderLoaded : getPickVertexShaderCallback(content),
pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTable.getPickUniformMapCallback(),
addBatchIdToGeneratedShaders : (batchLength > 0) // If the batch table has values in it, generated shaders will need a batchId attribute
});

this._model = model;
this.state = Cesium3DTileContentState.PROCESSING;
this._contentReadyToProcessPromise.resolve(this);

var that = this;

model.readyPromise.then(function(model) {
that.state = Cesium3DTileContentState.READY;
that._readyPromise.resolve(that);
}).otherwise(function(error) {
that.state = Cesium3DTileContentState.FAILED;
that._readyPromise.reject(error);
});
};
}

/**
* Part of the {@link Cesium3DTileContent} interface.
Expand Down Expand Up @@ -469,7 +386,6 @@ define([
this._model.shadows = this._tileset.shadows;
this._model.debugWireframe = this._tileset.debugWireframe;
this._model.update(frameState);

frameState.addCommand = oldAddCommand;
};

Expand Down
Loading