Skip to content

Fix glTF voxel ordering for ellipsoid shapes #12544

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

Merged
merged 6 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"tileAvailability": {
"availableCount": 1,
"constant": 1
},
"contentAvailability": {
"availableCount": 1,
"contentAvailability": [{
"constant": 1
},
}],
"childSubtreeAvailability": {
"availableCount": 0,
"constant": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@
"asset": {
"version": "2.0"
},
"extensionsUsed": [
"EXT_primitive_voxels",
"EXT_structural_metadata"
],
"extensionsRequired": [
"EXT_primitive_voxels",
"EXT_structural_metadata"
],
"extensions": {
"EXT_structural_metadata": {
"schema": {
"classes": {
"voxel": {
"properties": {
"a": {
"type": "VEC4",
"componentType": "FLOAT32"
}
}
}
}
},
"propertyAttributes": [
{
"class": "voxel",
"properties": {
"a": {
"attribute": "_DATA"
}
}
}
]
}
},
"scene": 0,
"scenes": [
{
Expand All @@ -19,82 +53,53 @@
{
"primitives": [
{
"mode": 2147483649,
"attributes": {
"_a": 0
"_DATA": 0
},
"mode": 2147483647,
"extensions": {
"EXT_primitive_voxels": {
"shape": 0,
"dimensions": [
2,
2,
2
],
"bounds": {
"min": [
0.0,
0.0,
-1.0
],
"max": [
1.0,
1.0,
0.0
]
}
]
},
"EXT_structural_metadata": {
"propertyAttributes": [0]
}
}
}
]
}
],
"extensionsUsed": [
"EXT_primitive_voxels",
"EXT_structural_metadata"
],
"extensionsRequired": [
"EXT_primitive_voxels",
"EXT_structural_metadata"
],
"extensions": {
"EXT_structural_metadata": {
"schemaUri": "../../../../schema.json",
"propertyAttributes": [
{
"class": "voxel",
"properties": {
"a": {
"attribute": "_a"
}
}
}
]
}
},
"accessors": [
{
"bufferView": 0,
"type": "SCALAR",
"byteOffset": 0,
"componentType": 5126,
"min": [
0.0
],
"count": 8,
"max": [
1.0
1.0, 1.0, 1.0, 1.0
],
"min": [
0.0, 0.0, 0.0, 0.0
],
"count": 8
"type": "VEC4"
}
],
"bufferViews": [
{
"buffer": 0,
"byteLength": 32
"byteOffset": 0,
"byteLength": 128
}
],
"buffers": [
{
"uri": "a.bin",
"byteLength": 32
"byteLength": 128
}
]
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
"asset": {
"version": "1.1"
},
"schemaUri": "schema.json",
"schema": {
"id": "voxel",
"classes": {
"voxel": {
"properties": {
"a": {
"type": "VEC4",
"componentType": "FLOAT32"
}
}
}
}
},
"statistics": {
"classes": {
"voxel": {
Expand All @@ -28,7 +40,7 @@
500000.0
]
},
"geometricError": 0.0,
"geometricError": 16.0,
"refine": "REPLACE",
"content": {
"uri": "tiles/{level}/{x}/{y}/{z}.gltf",
Expand All @@ -45,7 +57,7 @@
},
"implicitTiling": {
"subdivisionScheme": "OCTREE",
"subtreeLevels": 3,
"subtreeLevels": 1,
"availableLevels": 1,
"subtrees": {
"uri": "subtrees/{level}/{x}/{y}/{z}.json"
Expand Down
18 changes: 5 additions & 13 deletions Apps/Sandcastle/gallery/Voxels in 3D Tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
viewer.extend(Cesium.viewerVoxelInspectorMixin);
viewer.scene.debugShowFramesPerSecond = true;

const customShaderWhite = new Cesium.CustomShader({
fragmentShaderText: `void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
{
material.diffuse = vec3(1.0);
material.alpha = 1.0;
}`,
});

const customShaderColor = new Cesium.CustomShader({
fragmentShaderText: `void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
{
Expand All @@ -60,13 +52,13 @@
}`,
});

function createPrimitive(provider, customShader) {
function createPrimitive(provider) {
viewer.scene.primitives.removeAll();

const voxelPrimitive = viewer.scene.primitives.add(
new Cesium.VoxelPrimitive({
provider: provider,
customShader: customShader,
customShader: customShaderColor,
}),
);

Expand All @@ -87,7 +79,7 @@
const provider = await Cesium.Cesium3DTilesVoxelProvider.fromUrl(
"../../SampleData/Cesium3DTiles/Voxel/VoxelBox3DTiles/tileset.json",
);
const primitive = createPrimitive(provider, customShaderColor);
const primitive = createPrimitive(provider);
},
},
{
Expand All @@ -96,7 +88,7 @@
const provider = await Cesium.Cesium3DTilesVoxelProvider.fromUrl(
"../../SampleData/Cesium3DTiles/Voxel/VoxelCylinder3DTiles/tileset.json",
);
const primitive = createPrimitive(provider, customShaderColor);
const primitive = createPrimitive(provider);
},
},
{
Expand All @@ -105,7 +97,7 @@
const provider = await Cesium.Cesium3DTilesVoxelProvider.fromUrl(
"../../SampleData/Cesium3DTiles/Voxel/VoxelEllipsoid3DTiles/tileset.json",
);
const primitive = createPrimitive(provider, customShaderWhite);
const primitive = createPrimitive(provider);
},
},
]);
Expand Down
Binary file modified Apps/Sandcastle/gallery/Voxels in 3D Tiles.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Fixed camera zooming in 3D orthographic mode when pixelRatio is not 1. [#12487](https://github.com/CesiumGS/cesium/pull/12487)
- Fixed VaryingType.MAT3: "mat2" significant typo. [#12524](https://github.com/CesiumGS/cesium/issues/12524)
- Fixed shape bounds and transforms for cylinder-shaped voxels. [#12522](https://github.com/CesiumGS/cesium/pull/12522)
- Fixed metadata ordering for ellipsoid voxel tilesets. [#12544](https://github.com/CesiumGS/cesium/pull/12544)
- Fixed an issue where clamped entities' height updates could stall when using high-resolution terrain due to a growing queue of tiles in `updateHeights` in `QuadtreePrimitive`. [#12476](https://github.com/CesiumGS/cesium/issues/12476)

## 1.127 - 2025-03-03
Expand Down
5 changes: 4 additions & 1 deletion packages/engine/Source/Scene/Cesium3DTilesVoxelProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ function Cesium3DTilesVoxelProvider(options) {
this._names = names;
this._types = types;
this._componentTypes = componentTypes;
this._metadataOrder = VoxelMetadataOrder.GLTF;
this._metadataOrder =
shape === VoxelShapeType.ELLIPSOID
? VoxelMetadataOrder.Z_UP
: VoxelMetadataOrder.Y_UP;
this._minimumValues = minimumValues;
this._maximumValues = maximumValues;
this._maximumTileCount = maximumTileCount;
Expand Down
16 changes: 14 additions & 2 deletions packages/engine/Source/Scene/VoxelMetadataOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
* In all cases, x data is contiguous in strides along the y axis,
* and each group of y strides represents a z slice.
* However, the orientation of the axes follows different conventions.
*
* @enum {number}
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*/
const VoxelMetadataOrder = {
XYZ: 0, // Default ordering following the 3D Tiles convention. Z-axis points upward.
GLTF: 1, // Ordering following the glTF convention. Y-axis points upward.
/**
* The default ordering following the 3D Tiles convention. Z-axis points upward.
* @type {number}
* @constant
*/
Z_UP: 0,
/**
* The ordering following the glTF convention. Y-axis points upward.
* @type {number}
* @constant
*/
Y_UP: 1,
};
export default Object.freeze(VoxelMetadataOrder);
2 changes: 1 addition & 1 deletion packages/engine/Source/Scene/VoxelPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ function initFromProvider(primitive, provider, context) {
primitive._paddingAfter,
primitive._inputDimensions,
);
if (provider.metadataOrder === VoxelMetadataOrder.GLTF) {
if (provider.metadataOrder === VoxelMetadataOrder.Y_UP) {
const inputDimensionsY = primitive._inputDimensions.y;
primitive._inputDimensions.y = primitive._inputDimensions.z;
primitive._inputDimensions.z = inputDimensionsY;
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/Source/Scene/VoxelProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Object.defineProperties(VoxelProvider.prototype, {
*
* @memberof VoxelProvider.prototype
* @type {VoxelMetadataOrder}
* @default VoxelMetadataOrder.XYZ
* @default VoxelMetadataOrder.Z_UP
* @readonly
*/
metadataOrder: {
Expand Down
38 changes: 17 additions & 21 deletions packages/engine/Source/Scene/VoxelRenderResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,28 @@ function VoxelRenderResources(primitive) {
// Build shader
shaderBuilder.addVertexLines([VoxelVS]);

if (primitive.provider.metadataOrder === VoxelMetadataOrder.Y_UP) {
shaderBuilder.addDefine(
"Y_UP_METADATA_ORDER",
undefined,
ShaderDestination.FRAGMENT,
);
}
const shapeType = primitive._provider.shape;
if (primitive.provider.metadataOrder === VoxelMetadataOrder.GLTF) {
if (shapeType === "BOX") {
shaderBuilder.addDefine("SHAPE_BOX", undefined, ShaderDestination.FRAGMENT);
} else if (shapeType === "CYLINDER") {
shaderBuilder.addDefine(
"GLTF_METADATA_ORDER",
"SHAPE_CYLINDER",
undefined,
ShaderDestination.FRAGMENT,
);
} else if (shapeType === "ELLIPSOID") {
shaderBuilder.addDefine(
"SHAPE_ELLIPSOID",
undefined,
ShaderDestination.FRAGMENT,
);
if (shapeType === "BOX") {
shaderBuilder.addDefine(
"SHAPE_BOX",
undefined,
ShaderDestination.FRAGMENT,
);
} else if (shapeType === "CYLINDER") {
shaderBuilder.addDefine(
"SHAPE_CYLINDER",
undefined,
ShaderDestination.FRAGMENT,
);
} else if (shapeType === "ELLIPSOID") {
shaderBuilder.addDefine(
"SHAPE_ELLIPSOID",
undefined,
ShaderDestination.FRAGMENT,
);
}
}

shaderBuilder.addFragmentLines([
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/Source/Scene/VoxelTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function VoxelTraversal(
);
Cartesian3.add(inputDimensions, paddingAfter, inputDimensions);

if (metadataOrder === VoxelMetadataOrder.GLTF) {
if (metadataOrder === VoxelMetadataOrder.Y_UP) {
const inputDimensionsY = inputDimensions.y;
inputDimensions.y = inputDimensions.z;
inputDimensions.z = inputDimensionsY;
Expand Down
Loading