Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#### Fixes :wrench:

- Removes the minimum tile threshold of four for WMTS. [#4372](https://github.com/CesiumGS/cesium/issues/4372)
- Fixed a crash that could happen when loading PNTS (point cloud) data that contained a batch table without a binary part [#11166](https://github.com/CesiumGS/cesium/issues/11166)
- Fixes issue where multiple instances of a Gaussian splat tileset would transform tile positions incorrectly and render out of position. [12795](https://github.com/CesiumGS/cesium/issues/12795)
- Fixed a crash that could happen when loading PNTS (point cloud) data that contained a batch table without a binary part. [#11166](https://github.com/CesiumGS/cesium/issues/11166)

#### Additions :tada:

Expand Down
35 changes: 26 additions & 9 deletions packages/engine/Source/Scene/GaussianSplat3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ function GaussianSplat3DTileContent(loader, tileset, tile, resource) {
}

/**
* Original position, scale and rotation values for splats. Used to maintain
* consistency when multiple transforms may occur. Downstream consumers otherwise may not know
* the underlying data was modified.
* Local copies of attribute buffers with transformed values. Originals are kept in the gltf loader.
* These are the buffers that are used for rendering.
* @type {undefined|Float32Array}
* @private
*/
this._originalPositions = undefined;
this._originalRotations = undefined;
this._originalScales = undefined;
this._positions = undefined;
this._rotations = undefined;
this._scales = undefined;

/**
* glTF primitive data that contains the Gaussian splat data needed for rendering.
Expand Down Expand Up @@ -347,6 +346,24 @@ Object.defineProperties(GaussianSplat3DTileContent.prototype, {
this._group = value;
},
},

positions: {
get: function () {
return this._positions;
},
},

rotations: {
get: function () {
return this._rotations;
},
},

scales: {
get: function () {
return this._scales;
},
},
Comment on lines +350 to +366
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline docs?

});

/**
Expand Down Expand Up @@ -429,21 +446,21 @@ GaussianSplat3DTileContent.prototype.update = function (primitive, frameState) {
this.worldTransform = loader.components.scene.nodes[0].matrix;
this._ready = true;

this._originalPositions = new Float32Array(
this._positions = new Float32Array(
ModelUtility.getAttributeBySemantic(
this.splatPrimitive,
VertexAttributeSemantic.POSITION,
).typedArray,
);

this._originalRotations = new Float32Array(
this._rotations = new Float32Array(
ModelUtility.getAttributeBySemantic(
this.splatPrimitive,
VertexAttributeSemantic.ROTATION,
).typedArray,
);

this._originalScales = new Float32Array(
this._scales = new Float32Array(
ModelUtility.getAttributeBySemantic(
this.splatPrimitive,
VertexAttributeSemantic.SCALE,
Expand Down
91 changes: 44 additions & 47 deletions packages/engine/Source/Scene/GaussianSplatPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ GaussianSplatPrimitive.transformTile = function (tile) {
computedModelMatrix,
scratchMatrix4A,
);
const positions = tile.content._originalPositions;
const rotations = tile.content._originalRotations;
const scales = tile.content._originalScales;
const positions = tile.content.positions;
const rotations = tile.content.rotations;
const scales = tile.content.scales;
const attributePositions = ModelUtility.getAttributeBySemantic(
splatPrimitive,
VertexAttributeSemantic.POSITION,
Expand All @@ -442,19 +442,19 @@ GaussianSplatPrimitive.transformTile = function (tile) {
const position = new Cartesian3();
const rotation = new Quaternion();
const scale = new Cartesian3();
for (let i = 0; i < positions.length / 3; ++i) {
position.x = positions[i * 3];
position.y = positions[i * 3 + 1];
position.z = positions[i * 3 + 2];
for (let i = 0; i < attributePositions.length / 3; ++i) {
position.x = attributePositions[i * 3];
position.y = attributePositions[i * 3 + 1];
position.z = attributePositions[i * 3 + 2];

rotation.x = rotations[i * 4];
rotation.y = rotations[i * 4 + 1];
rotation.z = rotations[i * 4 + 2];
rotation.w = rotations[i * 4 + 3];
rotation.x = attributeRotations[i * 4];
rotation.y = attributeRotations[i * 4 + 1];
rotation.z = attributeRotations[i * 4 + 2];
rotation.w = attributeRotations[i * 4 + 3];

scale.x = scales[i * 3];
scale.y = scales[i * 3 + 1];
scale.z = scales[i * 3 + 2];
scale.x = attributeScales[i * 3];
scale.y = attributeScales[i * 3 + 1];
scale.z = attributeScales[i * 3 + 2];

Matrix4.fromTranslationQuaternionRotationScale(
position,
Expand All @@ -469,18 +469,18 @@ GaussianSplatPrimitive.transformTile = function (tile) {
Matrix4.getRotation(scratchMatrix4C, rotation);
Matrix4.getScale(scratchMatrix4C, scale);

attributePositions[i * 3] = position.x;
attributePositions[i * 3 + 1] = position.y;
attributePositions[i * 3 + 2] = position.z;
positions[i * 3] = position.x;
positions[i * 3 + 1] = position.y;
positions[i * 3 + 2] = position.z;

attributeRotations[i * 4] = rotation.x;
attributeRotations[i * 4 + 1] = rotation.y;
attributeRotations[i * 4 + 2] = rotation.z;
attributeRotations[i * 4 + 3] = rotation.w;
rotations[i * 4] = rotation.x;
rotations[i * 4 + 1] = rotation.y;
rotations[i * 4 + 2] = rotation.z;
rotations[i * 4 + 3] = rotation.w;

attributeScales[i * 3] = scale.x;
attributeScales[i * 3 + 1] = scale.y;
attributeScales[i * 3 + 2] = scale.z;
scales[i * 3] = scale.x;
scales[i * 3 + 1] = scale.y;
scales[i * 3 + 2] = scale.z;
}
};

Expand Down Expand Up @@ -767,57 +767,54 @@ GaussianSplatPrimitive.prototype.update = function (frameState) {
const aggregateAttributeValues = (
componentDatatype,
getAttributeCallback,
numberOfComponents,
) => {
let aggregate;
let offset = 0;
for (const tile of tiles) {
const primitive = tile.content.splatPrimitive;
const attribute = getAttributeCallback(primitive);
const content = tile.content;
const attribute = getAttributeCallback(content);
const componentsPerAttribute = defined(numberOfComponents)
? numberOfComponents
: AttributeType.getNumberOfComponents(attribute.type);
const buffer = defined(attribute.typedArray)
? attribute.typedArray
: attribute;
if (!defined(aggregate)) {
aggregate = ComponentDatatype.createTypedArray(
componentDatatype,
totalElements *
AttributeType.getNumberOfComponents(attribute.type),
totalElements * componentsPerAttribute,
);
}
aggregate.set(attribute.typedArray, offset);
offset += attribute.typedArray.length;
aggregate.set(buffer, offset);
offset += buffer.length;
}
return aggregate;
};

this._positions = aggregateAttributeValues(
ComponentDatatype.FLOAT,
(splatPrimitive) =>
ModelUtility.getAttributeBySemantic(
splatPrimitive,
VertexAttributeSemantic.POSITION,
),
(content) => content.positions,
3,
);

this._scales = aggregateAttributeValues(
ComponentDatatype.FLOAT,
(splatPrimitive) =>
ModelUtility.getAttributeBySemantic(
splatPrimitive,
VertexAttributeSemantic.SCALE,
),
(content) => content.scales,
3,
);

this._rotations = aggregateAttributeValues(
ComponentDatatype.FLOAT,
(splatPrimitive) =>
ModelUtility.getAttributeBySemantic(
splatPrimitive,
VertexAttributeSemantic.ROTATION,
),
(content) => content.rotations,
4,
);

this._colors = aggregateAttributeValues(
ComponentDatatype.UNSIGNED_BYTE,
(splatPrimitive) =>
(content) =>
ModelUtility.getAttributeBySemantic(
splatPrimitive,
content.splatPrimitive,
VertexAttributeSemantic.COLOR,
),
);
Expand Down