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

.pnts loader for ModelExperimental #9978

Merged
merged 50 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9649ca5
WIP: set up scaffolding for transcoding PNTS
ptrgags Dec 8, 2021
8e9d72d
WIP continue working on parser and loader
ptrgags Dec 8, 2021
b01f0ab
WIP build attribute components
ptrgags Dec 9, 2021
7eee81f
WIP - Handle the decoded draco attributes
ptrgags Dec 9, 2021
79b3c57
Get something rendering on the screen
ptrgags Dec 9, 2021
a5052f1
Get point cloud rendering on the screen
ptrgags Dec 10, 2021
c65c0f7
Add more details to parsed attributes
ptrgags Dec 10, 2021
f0cd412
Refactor parsedContent object
ptrgags Dec 10, 2021
398b677
Start working on unit tests
ptrgags Dec 13, 2021
d09f367
Start adding tests for PntsLoader
ptrgags Dec 13, 2021
8281e65
Add RGB565 decoding function
ptrgags Dec 14, 2021
b09142d
Parse RGB565 on the CPU
ptrgags Dec 14, 2021
ca1e80e
Handle oct-encoded normals
ptrgags Dec 14, 2021
22582e9
Fix batch table unit tests
ptrgags Dec 14, 2021
4697576
Fix oct encoded normal tests
ptrgags Dec 15, 2021
b6322a1
Add more tests to PntsLoader and PntsParser
ptrgags Dec 15, 2021
d2f62b9
b3dm is lowercase
ptrgags Dec 15, 2021
4310f5a
Update B3dm tests to use B3dmLoader & B3dmParser more directly
ptrgags Dec 15, 2021
d048bc9
Use separate MersenneTwister RNG for pnts
ptrgags Dec 15, 2021
8c3172d
Fix bounding spheres for quantized positions
ptrgags Dec 15, 2021
8bcfd85
Clean up buffers on unload
ptrgags Dec 15, 2021
a15cef5
Pass isTranslucent flag through
ptrgags Dec 16, 2021
cba1cb1
Fix bounding volume calculation
ptrgags Dec 16, 2021
3b597e3
Update documentation
ptrgags Dec 17, 2021
bb24378
Don't hold on to typed array
ptrgags Dec 17, 2021
b3f5264
Free memory from parsedContent when done
ptrgags Dec 17, 2021
1b7df45
Move MersenneTwister into function
ptrgags Dec 17, 2021
6a11330
Used quantized volume to compute min/max
ptrgags Dec 17, 2021
c5c9c8a
Merge branch 'main' into pnts-loader
ptrgags Dec 17, 2021
2b0e870
Update to use tileset.enableModelExperimental
ptrgags Dec 17, 2021
86e7409
Fix constant color
ptrgags Dec 17, 2021
9c87758
BATCH_LENGTH not BATCHES_LENGTH
ptrgags Dec 17, 2021
aca0b0b
add missing set index for batch ID
ptrgags Dec 17, 2021
518d834
Merge branch 'main' into pnts-loader
ptrgags Jan 4, 2022
54bd8d1
Tag .pnts models as TILE_PNTS
ptrgags Jan 4, 2022
251eddc
Update to use components.transform
ptrgags Jan 4, 2022
a34e169
Move sRGB conversion functions to builtins
ptrgags Jan 4, 2022
c7cc4a5
Handle sRGB colors from .pnts files
ptrgags Jan 4, 2022
19f72ec
Update sRgb conversion code
ptrgags Jan 4, 2022
9553044
Update unit tests
ptrgags Jan 5, 2022
41a1005
Add define for HAS_SRGB_COLOR
ptrgags Jan 5, 2022
9ac5fc2
Default to dark grey
ptrgags Jan 5, 2022
fb67acb
Fix translucency
ptrgags Jan 5, 2022
e5a3d08
Render as unlit unless normals are present
ptrgags Jan 5, 2022
0941231
Fix oct-encoded normals
ptrgags Jan 5, 2022
bfc91ea
Move quantized offset to model matrix
ptrgags Jan 5, 2022
a3748b3
Handle component data type of batch ID
ptrgags Jan 5, 2022
3595ab6
Fix compilation error
ptrgags Jan 6, 2022
7ca7747
Fix unit tests
ptrgags Jan 6, 2022
907caff
Don't destroy attribute buffers when styling is applied
ptrgags Jan 6, 2022
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
46 changes: 46 additions & 0 deletions Source/Core/AttributeCompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,50 @@ AttributeCompression.dequantize = function (
return dequantizedTypedArray;
};

/**
* Decode RGB565-encoded colors into a floating point typed array containing
* normalized RGB values.
*
* @param {Uint16Array} typedArray Array of RGB565 values
* @param {Float32Array} [result] Array to store the normalized VEC3 result
*/
AttributeCompression.decodeRGB565 = function (typedArray, result) {
//>>includeStart('debug', pragmas.debug);
Check.defined("typedArray", typedArray);

var expectedLength = typedArray.length * 3;
if (defined(result)) {
Check.typeOf.number.equals(
"result.length",
"typedArray.length * 3",
result.length,
expectedLength
);
}
//>>includeEnd('debug');

var count = typedArray.length;
if (!defined(result)) {
result = new Float32Array(count * 3);
}

var mask5 = (1 << 5) - 1;
var mask6 = (1 << 6) - 1;
var normalize5 = 1.0 / 31.0;
var normalize6 = 1.0 / 63.0;
for (var i = 0; i < count; i++) {
var value = typedArray[i];
var red = value >> 11;
var green = (value >> 5) & mask6;
var blue = value & mask5;

var offset = 3 * i;
result[offset] = red * normalize5;
result[offset + 1] = green * normalize6;
result[offset + 2] = blue * normalize5;
}

return result;
};

export default AttributeCompression;
6 changes: 3 additions & 3 deletions Source/Scene/B3dmParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;
*
* @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.
* @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);
Expand Down
9 changes: 9 additions & 0 deletions Source/Scene/Cesium3DTileContentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ var Cesium3DTileContentFactory = {
);
},
pnts: function (tileset, tile, resource, arrayBuffer, byteOffset) {
if (ExperimentalFeatures.enableModelExperimental) {
return ModelExperimental3DTileContent.fromPnts(
tileset,
tile,
resource,
arrayBuffer,
byteOffset
);
}
return new PointCloud3DTileContent(
tileset,
tile,
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/ModelComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Quantization() {

/**
* The step size of the quantization volume, equal to
* quantizedVolumeDimensions / quantizedVolumeOffset (component-wise).
* quantizedVolumeDimensions / normalizationRange (component-wise).
* Not applicable for oct encoded attributes.
* The type should match the attribute type - e.g. if the attribute type
* is AttributeType.VEC4 the dimensions should be a Cartesian4.
Expand Down
8 changes: 4 additions & 4 deletions Source/Scene/ModelExperimental/B3dmLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ var FeatureIdAttribute = ModelComponents.FeatureIdAttribute;
* @private
*
* @param {Object} options Object with the following properties:
* @param {Resource} options.b3dmResource The {@link Resource} containing the B3DM.
* @param {ArrayBuffer} options.arrayBuffer The array buffer of the B3DM contents.
* @param {Number} [options.byteOffset] The byte offset to the beginning of the B3DM contents in the array buffer.
* @param {Resource} options.b3dmResource The {@link Resource} containing the b3dm.
* @param {ArrayBuffer} options.arrayBuffer The array buffer of the b3dm contents.
* @param {Number} [options.byteOffset] The byte offset to the beginning of the b3dm contents in the array buffer.
* @param {Resource} [options.baseResource] The {@link Resource} that paths in the glTF JSON are relative to.
* @param {Boolean} [options.releaseGltfJson=false] When true, the glTF JSON is released once the glTF is loaded. This is is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.
* @param {Boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.
Expand Down Expand Up @@ -262,7 +262,7 @@ B3dmLoader.prototype.load = function () {
function handleError(b3dmLoader, error) {
b3dmLoader.unload();
b3dmLoader._state = B3dmLoaderState.FAILED;
var errorMessage = "Failed to load B3DM";
var errorMessage = "Failed to load b3dm";
error = b3dmLoader.getError(errorMessage, error);
b3dmLoader._promise.reject(error);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/ModelExperimental/CustomShaderGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var model = Cesium.ModelExperimental.fromGltf({,

**Note**: As of this writing, only tilesets that use the `3DTILES_content_gltf`
extension will support `CustomShaders`. Future releases will add support for
other formats such as B3DM.
other formats such as b3dm.

## Uniforms

Expand Down
39 changes: 38 additions & 1 deletion Source/Scene/ModelExperimental/ModelExperimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import destroyObject from "../../Core/destroyObject.js";
import Matrix4 from "../../Core/Matrix4.js";
import ModelFeatureTable from "./ModelFeatureTable.js";
import B3dmLoader from "./B3dmLoader.js";
import PntsLoader from "./PntsLoader.js";
import Color from "../../Core/Color.js";

/**
Expand Down Expand Up @@ -205,7 +206,12 @@ function initialize(model) {
ModelExperimentalUtility.getFailedLoadFunction(model, "model", resource)
);

loader.texturesLoadedPromise
// Transcoded .pnts models do not have textures
var texturesLoadedPromise = defaultValue(
loader.texturesLoadedPromise,
when.resolve()
);
texturesLoadedPromise
.then(function () {
model._texturesLoaded = true;
})
Expand Down Expand Up @@ -818,6 +824,37 @@ ModelExperimental.fromB3dm = function (options) {
featureIdAttributeIndex: options.featureIdAttributeIndex,
featureIdTextureIndex: options.featureIdTextureIndex,
};

var model = new ModelExperimental(modelOptions);
return model;
};

ModelExperimental.fromPnts = function (options) {
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
var loaderOptions = {
arrayBuffer: options.arrayBuffer,
byteOffset: options.byteOffset,
releaseGltfJson: options.releaseGltfJson,
incrementallyLoadTextures: options.incrementallyLoadTextures,
upAxis: options.upAxis,
forwardAxis: options.forwardAxis,
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
};
var loader = new PntsLoader(loaderOptions);

var modelOptions = {
loader: loader,
resource: options.resource,
modelMatrix: options.modelMatrix,
debugShowBoundingVolume: options.debugShowBoundingVolume,
cull: options.cull,
opaquePass: options.opaquePass,
allowPicking: options.allowPicking,
customShader: options.customShader,
content: options.content,
show: options.show,
featureIdAttributeIndex: options.featureIdAttributeIndex,
featureIdTextureIndex: options.featureIdTextureIndex,
};
ptrgags marked this conversation as resolved.
Show resolved Hide resolved

var model = new ModelExperimental(modelOptions);
return model;
};
Expand Down
29 changes: 29 additions & 0 deletions Source/Scene/ModelExperimental/ModelExperimental3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,32 @@ ModelExperimental3DTileContent.fromB3dm = function (
content._model = ModelExperimental.fromB3dm(modelOptions);
return content;
};

ModelExperimental3DTileContent.fromPnts = function (
tileset,
tile,
resource,
arrayBuffer,
byteOffset
) {
var content = new ModelExperimental3DTileContent(tileset, tile, resource);

var modelOptions = {
arrayBuffer: arrayBuffer,
byteOffset: byteOffset,
resource: resource,
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
modelMatrix: tile.computedTransform,
upAxis: tileset._gltfUpAxis,
forwardAxis: Axis.X,
incrementallyLoadTextures: false,
customShader: tileset.customShader,
content: content,
colorBlendMode: tileset.colorBlendMode,
colorBlendAmount: tileset.colorBlendAmount,
};
content._model = ModelExperimental.fromPnts(modelOptions);
return content;
};
Loading