Skip to content

Commit 466f780

Browse files
authored
Merge pull request #12522 from CesiumGS/voxel-cylinder-fix
Fix shape bounds and transforms for VoxelCylinderShape
2 parents 88bfd95 + e6a6af5 commit 466f780

File tree

13 files changed

+157
-107
lines changed

13 files changed

+157
-107
lines changed

Apps/SampleData/Cesium3DTiles/Voxel/VoxelBox3DTiles/tileset.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,25 @@
6868
"subtrees": {
6969
"uri": "subtrees/{level}/{x}/{y}/{z}.json"
7070
}
71-
}
71+
},
72+
"transform": [
73+
6378137.0,
74+
0.0,
75+
0.0,
76+
0.0,
77+
0.0,
78+
6378137.0,
79+
0.0,
80+
0.0,
81+
0.0,
82+
0.0,
83+
6378137.0,
84+
0.0,
85+
0.0,
86+
0.0,
87+
0.0,
88+
1.0
89+
]
7290
},
7391
"extensionsUsed": [
7492
"3DTILES_content_voxels"

Apps/SampleData/Cesium3DTiles/Voxel/VoxelCylinder3DTiles/tileset.json

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,9 @@
3333
"boundingVolume": {
3434
"extensions": {
3535
"3DTILES_bounding_volume_cylinder": {
36-
"cylinder": [
37-
0.0,
38-
0.0,
39-
0.0,
40-
1.0,
41-
0.0,
42-
0.0,
43-
0.0,
44-
1.0,
45-
0.0,
46-
0.0,
47-
0.0,
48-
1.0
49-
]
36+
"height": 2.0,
37+
"minRadius": 0.0,
38+
"maxRadius": 1.0
5039
}
5140
}
5241
},
@@ -72,7 +61,25 @@
7261
"subtrees": {
7362
"uri": "subtrees/{level}/{x}/{y}/{z}.json"
7463
}
75-
}
64+
},
65+
"transform": [
66+
6378137.0,
67+
0.0,
68+
0.0,
69+
0.0,
70+
0.0,
71+
6378137.0,
72+
0.0,
73+
0.0,
74+
0.0,
75+
0.0,
76+
6378137.0,
77+
0.0,
78+
0.0,
79+
0.0,
80+
0.0,
81+
1.0
82+
]
7683
},
7784
"extensionsUsed": [
7885
"3DTILES_bounding_volume_cylinder",

Apps/Sandcastle/gallery/Voxel Picking.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,22 @@
6464

6565
const scratchColor = new Cesium.Color();
6666

67+
const globalTransform = Cesium.Matrix4.fromScale(
68+
Cesium.Cartesian3.fromElements(
69+
Cesium.Ellipsoid.WGS84.maximumRadius,
70+
Cesium.Ellipsoid.WGS84.maximumRadius,
71+
Cesium.Ellipsoid.WGS84.maximumRadius,
72+
),
73+
);
74+
6775
function ProceduralMultiTileVoxelProvider(shape) {
6876
this.shape = shape;
6977
this.dimensions = new Cesium.Cartesian3(4, 4, 4);
7078
this.names = ["color"];
7179
this.types = [Cesium.MetadataType.VEC4];
7280
this.componentTypes = [Cesium.MetadataComponentType.FLOAT32];
7381
this._levelCount = 3;
82+
this.globalTransform = globalTransform;
7483
}
7584

7685
ProceduralMultiTileVoxelProvider.prototype.requestData = function (options) {
@@ -157,19 +166,10 @@
157166
},
158167
});
159168

160-
const modelMatrix = Cesium.Matrix4.fromScale(
161-
Cesium.Cartesian3.fromElements(
162-
Cesium.Ellipsoid.WGS84.maximumRadius,
163-
Cesium.Ellipsoid.WGS84.maximumRadius,
164-
Cesium.Ellipsoid.WGS84.maximumRadius,
165-
),
166-
);
167-
168169
const voxelPrimitive = scene.primitives.add(
169170
new Cesium.VoxelPrimitive({
170171
provider: provider,
171172
customShader: customShader,
172-
modelMatrix: modelMatrix,
173173
}),
174174
);
175175

Apps/Sandcastle/gallery/Voxels in 3D Tiles.html

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,13 @@
6060
}`,
6161
});
6262

63-
const modelMatrix = Cesium.Matrix4.fromScale(
64-
Cesium.Cartesian3.fromElements(
65-
Cesium.Ellipsoid.WGS84.maximumRadius,
66-
Cesium.Ellipsoid.WGS84.maximumRadius,
67-
Cesium.Ellipsoid.WGS84.maximumRadius,
68-
),
69-
);
70-
71-
function createPrimitive(provider, customShader, modelMatrix) {
63+
function createPrimitive(provider, customShader) {
7264
viewer.scene.primitives.removeAll();
7365

7466
const voxelPrimitive = viewer.scene.primitives.add(
7567
new Cesium.VoxelPrimitive({
7668
provider: provider,
7769
customShader: customShader,
78-
modelMatrix: modelMatrix,
7970
}),
8071
);
8172

@@ -96,7 +87,7 @@
9687
const provider = await Cesium.Cesium3DTilesVoxelProvider.fromUrl(
9788
"../../SampleData/Cesium3DTiles/Voxel/VoxelBox3DTiles/tileset.json",
9889
);
99-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
90+
const primitive = createPrimitive(provider, customShaderColor);
10091
},
10192
},
10293
{
@@ -105,7 +96,7 @@
10596
const provider = await Cesium.Cesium3DTilesVoxelProvider.fromUrl(
10697
"../../SampleData/Cesium3DTiles/Voxel/VoxelCylinder3DTiles/tileset.json",
10798
);
108-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
99+
const primitive = createPrimitive(provider, customShaderColor);
109100
},
110101
},
111102
{
@@ -114,11 +105,7 @@
114105
const provider = await Cesium.Cesium3DTilesVoxelProvider.fromUrl(
115106
"../../SampleData/Cesium3DTiles/Voxel/VoxelEllipsoid3DTiles/tileset.json",
116107
);
117-
const primitive = createPrimitive(
118-
provider,
119-
customShaderWhite,
120-
Cesium.Matrix4.IDENTITY,
121-
);
108+
const primitive = createPrimitive(provider, customShaderWhite);
122109
},
123110
},
124111
]);

Apps/Sandcastle/gallery/Voxels.html

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
viewer.extend(Cesium.viewerVoxelInspectorMixin);
4848
viewer.scene.debugShowFramesPerSecond = true;
4949

50+
const globalTransform = Cesium.Matrix4.fromScale(
51+
Cesium.Cartesian3.fromElements(
52+
Cesium.Ellipsoid.WGS84.maximumRadius,
53+
Cesium.Ellipsoid.WGS84.maximumRadius,
54+
Cesium.Ellipsoid.WGS84.maximumRadius,
55+
),
56+
);
57+
5058
function ProceduralSingleTileVoxelProvider(shape) {
5159
this.shape = shape;
5260
this.minBounds = Cesium.VoxelShapeType.getMinBounds(shape).clone();
@@ -55,6 +63,7 @@
5563
this.names = ["color"];
5664
this.types = [Cesium.MetadataType.VEC4];
5765
this.componentTypes = [Cesium.MetadataComponentType.FLOAT32];
66+
this.globalTransform = globalTransform;
5867
}
5968

6069
const scratchColor = new Cesium.Color();
@@ -110,6 +119,7 @@
110119
this.names = ["color"];
111120
this.types = [Cesium.MetadataType.VEC4];
112121
this.componentTypes = [Cesium.MetadataComponentType.FLOAT32];
122+
this.globalTransform = globalTransform;
113123

114124
this._levelCount = 2;
115125
this._allVoxelData = new Array(this._levelCount);
@@ -214,14 +224,13 @@
214224
return Promise.resolve(content);
215225
};
216226

217-
function createPrimitive(provider, customShader, modelMatrix) {
227+
function createPrimitive(provider, customShader) {
218228
viewer.scene.primitives.removeAll();
219229

220230
const voxelPrimitive = viewer.scene.primitives.add(
221231
new Cesium.VoxelPrimitive({
222232
provider: provider,
223233
customShader: customShader,
224-
modelMatrix: modelMatrix,
225234
}),
226235
);
227236

@@ -245,14 +254,6 @@
245254
}`,
246255
});
247256

248-
const modelMatrix = Cesium.Matrix4.fromScale(
249-
Cesium.Cartesian3.fromElements(
250-
Cesium.Ellipsoid.WGS84.maximumRadius,
251-
Cesium.Ellipsoid.WGS84.maximumRadius,
252-
Cesium.Ellipsoid.WGS84.maximumRadius,
253-
),
254-
);
255-
256257
Sandcastle.addToolbarMenu([
257258
{
258259
text: "Ellipsoid - Procedural Tile",
@@ -262,7 +263,7 @@
262263
);
263264
provider.minBounds.z = 0.0;
264265
provider.maxBounds.z = 1000000.0;
265-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
266+
const primitive = createPrimitive(provider, customShaderColor);
266267
},
267268
},
268269
{
@@ -271,7 +272,7 @@
271272
const provider = new ProceduralSingleTileVoxelProvider(
272273
Cesium.VoxelShapeType.CYLINDER,
273274
);
274-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
275+
const primitive = createPrimitive(provider, customShaderColor);
275276
},
276277
},
277278
{
@@ -280,7 +281,7 @@
280281
const provider = new ProceduralSingleTileVoxelProvider(
281282
Cesium.VoxelShapeType.BOX,
282283
);
283-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
284+
const primitive = createPrimitive(provider, customShaderColor);
284285
},
285286
},
286287
{
@@ -289,7 +290,7 @@
289290
const provider = new ProceduralMultiTileVoxelProvider(
290291
Cesium.VoxelShapeType.BOX,
291292
);
292-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
293+
const primitive = createPrimitive(provider, customShaderColor);
293294
},
294295
},
295296
{
@@ -300,7 +301,7 @@
300301
);
301302
provider.minBounds.z = 0.0;
302303
provider.maxBounds.z = 1000000.0;
303-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
304+
const primitive = createPrimitive(provider, customShaderColor);
304305
},
305306
},
306307
{
@@ -309,7 +310,7 @@
309310
const provider = new ProceduralMultiTileVoxelProvider(
310311
Cesium.VoxelShapeType.CYLINDER,
311312
);
312-
const primitive = createPrimitive(provider, customShaderColor, modelMatrix);
313+
const primitive = createPrimitive(provider, customShaderColor);
313314
},
314315
},
315316
]);

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Fixed broken Entity Tracking [sandcastle](https://sandcastle.cesium.com/?src=Entity%20tracking.html). [#12467](https://github.com/CesiumGS/cesium/pull/12467)
1818
- `Camera.getPickRay` now correctly returns a ray with origin in world coordinates in orthographic mode. [#12500](https://github.com/CesiumGS/cesium/pull/12500)
1919
- Fixed camera zooming in 3D orthographic mode when pixelRatio is not 1. [#12487](https://github.com/CesiumGS/cesium/pull/12487)
20+
- Fixed shape bounds and transforms for cylinder-shaped voxels. [#12522](https://github.com/CesiumGS/cesium/pull/12522)
2021

2122
## 1.127 - 2025-03-03
2223

Specs/Data/Cesium3DTiles/Voxel/VoxelCylinder3DTiles/tileset.json

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,9 @@
2121
"boundingVolume": {
2222
"extensions": {
2323
"3DTILES_bounding_volume_cylinder": {
24-
"cylinder": [
25-
0.0,
26-
0.0,
27-
0.0,
28-
1.0,
29-
0.0,
30-
0.0,
31-
0.0,
32-
1.0,
33-
0.0,
34-
0.0,
35-
0.0,
36-
1.0
37-
]
24+
"height": 2.0,
25+
"minRadius": 0.0,
26+
"maxRadius": 1.0
3827
}
3928
}
4029
},

packages/engine/Source/Scene/Cesium3DTilesVoxelProvider.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import ResourceCache from "./ResourceCache.js";
1919
import RuntimeError from "../Core/RuntimeError.js";
2020
import VoxelBoxShape from "./VoxelBoxShape.js";
2121
import VoxelContent from "./VoxelContent.js";
22-
import VoxelCylinderShape from "./VoxelCylinderShape.js";
2322
import VoxelMetadataOrder from "./VoxelMetadataOrder.js";
2423
import VoxelShapeType from "./VoxelShapeType.js";
24+
import CesiumMath from "../Core/Math.js";
25+
import Quaternion from "../Core/Quaternion.js";
2526

2627
/**
2728
* @typedef {Object} Cesium3DTilesVoxelProvider.ConstructorOptions
@@ -485,7 +486,7 @@ function getShape(tile) {
485486
return getEllipsoidShape(boundingVolume.region);
486487
} else if (hasExtension(boundingVolume, "3DTILES_bounding_volume_cylinder")) {
487488
return getCylinderShape(
488-
boundingVolume.extensions["3DTILES_bounding_volume_cylinder"].cylinder,
489+
boundingVolume.extensions["3DTILES_bounding_volume_cylinder"],
489490
tileTransform,
490491
);
491492
}
@@ -534,16 +535,39 @@ function getBoxShape(box, tileTransform) {
534535
}
535536

536537
function getCylinderShape(cylinder, tileTransform) {
537-
const obb = OrientedBoundingBox.unpack(cylinder);
538-
const shapeTransform = Matrix4.fromRotationTranslation(
539-
obb.halfAxes,
540-
obb.center,
538+
const {
539+
minRadius,
540+
maxRadius,
541+
height,
542+
minAngle = -CesiumMath.PI,
543+
maxAngle = CesiumMath.PI,
544+
translation = [0, 0, 0],
545+
rotation = [0, 0, 0, 1],
546+
} = cylinder;
547+
548+
//>>includeStart('debug', pragmas.debug);
549+
Check.typeOf.number("minRadius", minRadius);
550+
Check.typeOf.number("maxRadius", maxRadius);
551+
Check.typeOf.number("height", height);
552+
Check.typeOf.number("minAngle", minAngle);
553+
Check.typeOf.number("maxAngle", maxAngle);
554+
Check.typeOf.object("translation", translation);
555+
Check.typeOf.object("rotation", rotation);
556+
//>>includeEnd('debug');
557+
558+
const minHeight = -0.5 * height + translation[2];
559+
const maxHeight = 0.5 * height + translation[2];
560+
561+
const shapeTransform = Matrix4.fromTranslationQuaternionRotationScale(
562+
Cartesian3.unpack(translation),
563+
Quaternion.unpack(rotation),
564+
new Cartesian3(maxRadius, maxRadius, 0.5 * height),
541565
);
542566

543567
return {
544568
shape: VoxelShapeType.CYLINDER,
545-
minBounds: Cartesian3.clone(VoxelCylinderShape.DefaultMinBounds),
546-
maxBounds: Cartesian3.clone(VoxelCylinderShape.DefaultMaxBounds),
569+
minBounds: Cartesian3.fromElements(minRadius, minAngle, minHeight),
570+
maxBounds: Cartesian3.fromElements(maxRadius, maxAngle, maxHeight),
547571
shapeTransform: shapeTransform,
548572
globalTransform: tileTransform,
549573
};

0 commit comments

Comments
 (0)