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

Adds ModelExperimental3DTileContent, B3dmLoader, removes Cesium3DTileContentFeatureTable #9873

Merged
merged 32 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a88c178
Adds ModelExperimental3DTileContent
sanjeetsuhag Oct 11, 2021
94ff88d
Removes dependency on content's feature table
sanjeetsuhag Oct 13, 2021
7adc4a4
Adds generation of empty feature table in B3dmLoader
Oct 13, 2021
075a43d
Doc fix [skip-ci]
Oct 13, 2021
55d74d7
Reverts B3DM and Gltf Cesium3DTileContent classes to old versions wit…
Oct 13, 2021
853a5e4
doc fix [skip-ci]
sanjeetsuhag Oct 14, 2021
c9492b6
Removes Cesium3DTileContentFeatureTable
sanjeetsuhag Oct 14, 2021
d606b7a
Removes unused tests from specs
sanjeetsuhag Oct 14, 2021
580d883
Adds B3dmLoaderSpec
sanjeetsuhag Oct 14, 2021
1b5f695
Fixes pipeline specs
sanjeetsuhag Oct 14, 2021
f5552fc
Fixes ModelFeatureTable specs
sanjeetsuhag Oct 14, 2021
e90073e
Adds specs to check if the right type of features are created in Mode…
sanjeetsuhag Oct 14, 2021
b2d2065
Spec fix
sanjeetsuhag Oct 14, 2021
bd66720
Adds more coverage
sanjeetsuhag Oct 15, 2021
38c3b14
More specs
sanjeetsuhag Oct 15, 2021
2bc4586
Adds more spec for the right type of picking in all cases
sanjeetsuhag Oct 15, 2021
5404f84
Adds RTC Transform object to loader
sanjeetsuhag Oct 19, 2021
1d51698
Adds B3dmParser
sanjeetsuhag Oct 19, 2021
bd63137
Feedback pass
sanjeetsuhag Oct 19, 2021
16a1eab
Adds back B3dmParserSpec functions, some more checks
sanjeetsuhag Oct 19, 2021
4710c2b
Fixes the error check
Oct 19, 2021
a537696
Add WebGL to B3dmParserSpec
Oct 19, 2021
a52b683
Adds more checks
sanjeetsuhag Oct 20, 2021
c4eda3a
more spec fixes
sanjeetsuhag Oct 20, 2021
bbf93c2
Removes broken spec
sanjeetsuhag Oct 20, 2021
25708b4
more updates
sanjeetsuhag Oct 21, 2021
dbe47e7
Addresses feedback
sanjeetsuhag Oct 21, 2021
326319a
Eslint fixes
sanjeetsuhag Oct 21, 2021
6181220
Merge branch 'main' of https://github.com/CesiumGS/cesium into model-…
sanjeetsuhag Oct 21, 2021
b6f6a7c
Merge fixes
sanjeetsuhag Oct 21, 2021
00c4c71
Eslint fixes
sanjeetsuhag Oct 21, 2021
f692e9e
Adds back name
sanjeetsuhag Oct 21, 2021
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
174 changes: 45 additions & 129 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import Cartesian3 from "../Core/Cartesian3.js";
import Color from "../Core/Color.js";
import combine from "../Core/combine.js";
import ComponentDatatype from "../Core/ComponentDatatype.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import deprecationWarning from "../Core/deprecationWarning.js";
import destroyObject from "../Core/destroyObject.js";
import DeveloperError from "../Core/DeveloperError.js";
import ExperimentalFeatures from "../Core/ExperimentalFeatures.js";
import getJsonFromTypedArray from "../Core/getJsonFromTypedArray.js";
import Matrix4 from "../Core/Matrix4.js";
import RequestType from "../Core/RequestType.js";
Expand All @@ -20,9 +18,7 @@ import Cesium3DTileFeatureTable from "./Cesium3DTileFeatureTable.js";
import ClassificationModel from "./ClassificationModel.js";
import Model from "./Model.js";
import ModelAnimationLoop from "./ModelAnimationLoop.js";
import ModelExperimental from "./ModelExperimental/ModelExperimental.js";
import ModelUtility from "./ModelUtility.js";
import parseBatchTable from "./parseBatchTable.js";

/**
* Represents the contents of a
Expand Down Expand Up @@ -65,11 +61,6 @@ function Batched3DModel3DTileContent(
this.featurePropertiesDirty = false;
this._groupMetadata = undefined;

this._featureMetadata = undefined;
this._featureTables = [];
this._featureTableId = undefined;
this._featureTable = undefined;

initialize(this, arrayBuffer, byteOffset);
}

Expand All @@ -79,7 +70,7 @@ Batched3DModel3DTileContent._deprecationWarning = deprecationWarning;
Object.defineProperties(Batched3DModel3DTileContent.prototype, {
featuresLength: {
get: function () {
return defined(this.batchTable) ? this.batchTable.featuresLength : 0;
return this.batchTable.featuresLength;
},
},

Expand Down Expand Up @@ -109,7 +100,7 @@ Object.defineProperties(Batched3DModel3DTileContent.prototype, {

batchTableByteLength: {
get: function () {
return defined(this.batchTable) ? this.batchTable.memorySizeInBytes : 0;
return this.batchTable.memorySizeInBytes;
},
},

Expand Down Expand Up @@ -145,43 +136,7 @@ Object.defineProperties(Batched3DModel3DTileContent.prototype, {

batchTable: {
get: function () {
return ExperimentalFeatures.enableModelExperimental
? this._featureTable
: this._batchTable;
},
},

/**
* @private
*/
featureMetadata: {
get: function () {
return this._featureMetadata;
},
},

/**
* @private
*/
featureTables: {
get: function () {
return this._featureTables;
},
set: function (value) {
this._featureTables = value;
},
},

/**
* @private
*/
featureTableId: {
get: function () {
return this._featureTableId;
},
set: function (value) {
this._featureTableId = value;
this._featureTable = this._featureTables[value];
return this._batchTable;
},
},

Expand Down Expand Up @@ -412,28 +367,14 @@ function initialize(content, arrayBuffer, byteOffset) {
colorChangedCallback = createColorChangedCallback(content);
}

var batchTable;
if (
ExperimentalFeatures.enableModelExperimental &&
batchLength > 0 &&
defined(batchTableJson)
) {
var featureMetadata = parseBatchTable({
count: batchLength,
batchTable: batchTableJson,
binaryBody: batchTableBinary,
});
content._featureMetadata = featureMetadata;
} else {
batchTable = new Cesium3DTileBatchTable(
content,
batchLength,
batchTableJson,
batchTableBinary,
colorChangedCallback
);
content._batchTable = batchTable;
}
var batchTable = new Cesium3DTileBatchTable(
content,
batchLength,
batchTableJson,
batchTableBinary,
colorChangedCallback
);
content._batchTable = batchTable;

var gltfByteLength = byteStart + byteLength - byteOffset;
if (gltfByteLength === 0) {
Expand Down Expand Up @@ -478,53 +419,39 @@ function initialize(content, arrayBuffer, byteOffset) {
);

if (!defined(content._classificationType)) {
var modelOptions = {
// PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes.
// The pick shader still needs to be patched.
content._model = new Model({
gltf: gltfView,
cull: false, // The model is already culled by 3D Tiles
releaseGltfJson: true, // Models are unique and will not benefit from caching so save memory
opaquePass: Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass
basePath: resource,
requestType: RequestType.TILES3D,
modelMatrix: content._contentModelMatrix,
upAxis: tileset._gltfUpAxis,
forwardAxis: Axis.X,
shadows: tileset.shadows,
debugWireframe: tileset.debugWireframe,
incrementallyLoadTextures: false,
};

if (ExperimentalFeatures.enableModelExperimental) {
modelOptions.content = content;
modelOptions.customShader = tileset.customShader;
modelOptions.content = content;
content._model = ModelExperimental.fromGltf(modelOptions);
} else {
modelOptions = combine(modelOptions, {
requestType: RequestType.TILES3D,
shadows: tileset.shadows,
debugWireframe: tileset.debugWireframe,
vertexShaderLoaded: getVertexShaderCallback(content),
fragmentShaderLoaded: getFragmentShaderCallback(content),
uniformMapLoaded: batchTable.getUniformMapCallback(),
pickIdLoaded: getPickIdCallback(content),
addBatchIdToGeneratedShaders: batchLength > 0, // If the batch table has values in it, generated shaders will need a batchId attribute
pickObject: pickObject,
imageBasedLightingFactor: tileset.imageBasedLightingFactor,
lightColor: tileset.lightColor,
luminanceAtZenith: tileset.luminanceAtZenith,
sphericalHarmonicCoefficients: tileset.sphericalHarmonicCoefficients,
specularEnvironmentMaps: tileset.specularEnvironmentMaps,
backFaceCulling: tileset.backFaceCulling,
showOutline: tileset.showOutline,
});
// PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes.
// The pick shader still needs to be patched.
content._model = new Model(modelOptions);
}

vertexShaderLoaded: getVertexShaderCallback(content),
fragmentShaderLoaded: getFragmentShaderCallback(content),
uniformMapLoaded: batchTable.getUniformMapCallback(),
pickIdLoaded: getPickIdCallback(content),
addBatchIdToGeneratedShaders: batchLength > 0, // If the batch table has values in it, generated shaders will need a batchId attribute
pickObject: pickObject,
imageBasedLightingFactor: tileset.imageBasedLightingFactor,
lightColor: tileset.lightColor,
luminanceAtZenith: tileset.luminanceAtZenith,
sphericalHarmonicCoefficients: tileset.sphericalHarmonicCoefficients,
specularEnvironmentMaps: tileset.specularEnvironmentMaps,
backFaceCulling: tileset.backFaceCulling,
showOutline: tileset.showOutline,
});
content._model.readyPromise.then(function (model) {
if (defined(model.activeAnimations)) {
model.activeAnimations.addAll({
loop: ModelAnimationLoop.REPEAT,
});
}
model.activeAnimations.addAll({
loop: ModelAnimationLoop.REPEAT,
});
});
} else {
// This transcodes glTF to an internal representation for geometry so we can take advantage of the re-batching of vector data.
Expand Down Expand Up @@ -562,17 +489,10 @@ function createFeatures(content) {
}

Batched3DModel3DTileContent.prototype.hasProperty = function (batchId, name) {
return this.batchTable.hasProperty(batchId, name);
return this._batchTable.hasProperty(batchId, name);
};

Batched3DModel3DTileContent.prototype.getFeature = function (batchId) {
if (
ExperimentalFeatures.enableModelExperimental &&
defined(this.batchTable)
) {
return this.batchTable.getFeature(batchId);
}

//>>includeStart('debug', pragmas.debug);
var featuresLength = this.featuresLength;
if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {
Expand Down Expand Up @@ -618,14 +538,12 @@ Batched3DModel3DTileContent.prototype.update = function (tileset, frameState) {

var model = this._model;
var tile = this._tile;
var batchTable = this.batchTable;
var batchTable = this._batchTable;

// 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.
if (defined(batchTable)) {
batchTable.update(tileset, frameState);
}
batchTable.update(tileset, frameState);

this._contentModelMatrix = Matrix4.multiply(
tile.computedTransform,
Expand Down Expand Up @@ -668,16 +586,14 @@ Batched3DModel3DTileContent.prototype.update = function (tileset, frameState) {

model.update(frameState);

if (!ExperimentalFeatures.enableModelExperimental) {
// If any commands were pushed, add derived commands
var commandEnd = frameState.commandList.length;
if (
commandStart < commandEnd &&
(frameState.passes.render || frameState.passes.pick) &&
!defined(this._classificationType)
) {
batchTable.addDerivedCommands(frameState, commandStart);
}
// If any commands were pushed, add derived commands
var commandEnd = frameState.commandList.length;
if (
commandStart < commandEnd &&
(frameState.passes.render || frameState.passes.pick) &&
!defined(this._classificationType)
) {
batchTable.addDerivedCommands(frameState, commandStart);
}
};

Expand Down
28 changes: 27 additions & 1 deletion Source/Scene/Cesium3DTileContentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import PointCloud3DTileContent from "./PointCloud3DTileContent.js";
import Tileset3DTileContent from "./Tileset3DTileContent.js";
import Vector3DTileContent from "./Vector3DTileContent.js";
import RuntimeError from "../Core/RuntimeError.js";
import ExperimentalFeatures from "../Core/ExperimentalFeatures.js";
import ModelExperimental3DTileContent from "./ModelExperimental/ModelExperimental3DTileContent.js";

/**
* Maps a tile's magic field in its header to a new content object for the tile's payload.
Expand All @@ -16,6 +18,15 @@ import RuntimeError from "../Core/RuntimeError.js";
*/
var Cesium3DTileContentFactory = {
b3dm: function (tileset, tile, resource, arrayBuffer, byteOffset) {
if (ExperimentalFeatures.enableModelExperimental) {
return ModelExperimental3DTileContent.fromB3dm(
tileset,
tile,
resource,
arrayBuffer,
byteOffset
);
}
return new Batched3DModel3DTileContent(
tileset,
tile,
Expand Down Expand Up @@ -91,10 +102,25 @@ var Cesium3DTileContentFactory = {
var dataView = new DataView(arrayBuffer, byteOffset);
var byteLength = dataView.getUint32(8, true);
var glb = new Uint8Array(arrayBuffer, byteOffset, byteLength);

if (ExperimentalFeatures.enableModelExperimental) {
return ModelExperimental3DTileContent.fromGltf(
tileset,
tile,
resource,
glb
);
}
return new Gltf3DTileContent(tileset, tile, resource, glb);
},
gltf: function (tileset, tile, resource, json) {
if (ExperimentalFeatures.enableModelExperimental) {
return ModelExperimental3DTileContent.fromGltf(
tileset,
tile,
resource,
json
);
}
return new Gltf3DTileContent(tileset, tile, resource, json);
},
};
Expand Down
Loading