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 all 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
176 changes: 176 additions & 0 deletions Source/Scene/B3dmParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import Check from "../Core/Check.js";
import defaultValue from "../Core/defaultValue.js";
import deprecationWarning from "../Core/deprecationWarning.js";
import getJsonFromTypedArray from "../Core/getJsonFromTypedArray.js";
import RuntimeError from "../Core/RuntimeError.js";

/**
* Handles parsing of a Batched 3D Model.
*
* @namespace B3dmParser
* @private
*/
var B3dmParser = {};
B3dmParser._deprecationWarning = deprecationWarning;

var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;

/**
* Parses the contents of a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel|Batched 3D Model}.
*
* @private
*
* @param {ArrayBuffer} arrayBuffer The array buffer containing the B3DM.
* @param {Number} [byteOffset=0] The byte offset of the beginning of the B3DM in the array buffer.
* @returns {Object} Returns an object with the batch length, feature table (binary and json), batch table (binary and json) and glTF parts of the B3DM.
*/
B3dmParser.parse = function (arrayBuffer, byteOffset) {
var byteStart = defaultValue(byteOffset, 0);
//>>includeStart('debug', pragmas.debug);
Check.defined("arrayBuffer", arrayBuffer);
//>>includeEnd('debug');

byteOffset = byteStart;

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

var version = view.getUint32(byteOffset, true);
if (version !== 1) {
throw new RuntimeError(
"Only Batched 3D Model version 1 is supported. Version " +
version +
" is not."
);
}
byteOffset += sizeOfUint32;

var byteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

var featureTableJsonByteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

var featureTableBinaryByteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

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

var batchTableBinaryByteLength = view.getUint32(byteOffset, true);
byteOffset += sizeOfUint32;

var batchLength;

// Legacy header #1: [batchLength] [batchTableByteLength]
// Legacy header #2: [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]
// Current header: [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength]
// If the header is in the first legacy format 'batchTableJsonByteLength' will be the start of the JSON string (a quotation mark) or the glTF magic.
// Accordingly its first byte will be either 0x22 or 0x67, and so the minimum uint32 expected is 0x22000000 = 570425344 = 570MB. It is unlikely that the feature table JSON will exceed this length.
// The check for the second legacy format is similar, except it checks 'batchTableBinaryByteLength' instead
if (batchTableJsonByteLength >= 570425344) {
// First legacy check
byteOffset -= sizeOfUint32 * 2;
batchLength = featureTableJsonByteLength;
batchTableJsonByteLength = featureTableBinaryByteLength;
batchTableBinaryByteLength = 0;
featureTableJsonByteLength = 0;
featureTableBinaryByteLength = 0;
B3dmParser._deprecationWarning(
"b3dm-legacy-header",
"This b3dm header is using the legacy format [batchLength] [batchTableByteLength]. The new format is [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength] from https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel."
);
} else if (batchTableBinaryByteLength >= 570425344) {
// Second legacy check
byteOffset -= sizeOfUint32;
batchLength = batchTableJsonByteLength;
batchTableJsonByteLength = featureTableJsonByteLength;
batchTableBinaryByteLength = featureTableBinaryByteLength;
featureTableJsonByteLength = 0;
featureTableBinaryByteLength = 0;
B3dmParser._deprecationWarning(
"b3dm-legacy-header",
"This b3dm header is using the legacy format [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]. The new format is [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength] from https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel."
);
}

var featureTableJson;
if (featureTableJsonByteLength === 0) {
featureTableJson = {
BATCH_LENGTH: defaultValue(batchLength, 0),
};
} else {
featureTableJson = getJsonFromTypedArray(
uint8Array,
byteOffset,
featureTableJsonByteLength
);
byteOffset += featureTableJsonByteLength;
}

var featureTableBinary = new Uint8Array(
arrayBuffer,
byteOffset,
featureTableBinaryByteLength
);
byteOffset += featureTableBinaryByteLength;

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.
batchTableJson = getJsonFromTypedArray(
uint8Array,
byteOffset,
batchTableJsonByteLength
);
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 gltfByteLength = byteStart + byteLength - byteOffset;
if (gltfByteLength === 0) {
throw new RuntimeError("glTF byte length must be greater than 0.");
}

var gltfView;
if (byteOffset % 4 === 0) {
gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength);
} else {
// Create a copy of the glb so that it is 4-byte aligned
B3dmParser._deprecationWarning(
"b3dm-glb-unaligned",
"The embedded glb is not aligned to a 4-byte boundary."
);
gltfView = new Uint8Array(
uint8Array.subarray(byteOffset, byteOffset + gltfByteLength)
);
}

return {
batchLength: batchLength,
featureTableJson: featureTableJson,
featureTableBinary: featureTableBinary,
batchTableJson: batchTableJson,
batchTableBinary: batchTableBinary,
gltf: gltfView,
};
};

export default B3dmParser;
Loading