Skip to content

Commit ce97f10

Browse files
committed
fix tiles orientation
1 parent 415ab46 commit ce97f10

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

apps/api/src/services/mesh.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ export function mapCoordinates(
9696

9797
vMap.set(i / 2, next);
9898

99-
// NATURAL COORDINATE MAPPING:
99+
// Z-UP COORDINATE MAPPING (3D Tiles standard):
100100
// Grid coordinates → Web Mercator → Centered Three.js coordinates
101101
const rasterX = tileBounds.minX + (gx / tileSize) * tileWidth; // Web Mercator X (easting)
102102
const rasterY = tileBounds.maxY - (gy / tileSize) * tileHeight; // Web Mercator Y (northing) - Y-FLIPPED
103103

104-
// Three.js coordinates (centered at origin)
104+
// Three.js coordinates (centered at origin) - Z-UP SYSTEM
105105
const threejsX = rasterX - tilesetCenter[0]; // X = easting (centered)
106-
const threejsY = elevation; // Y = elevation (up)
107-
const threejsZ = rasterY - tilesetCenter[1]; // Z = northing (centered)
106+
const threejsY = rasterY - tilesetCenter[1]; // Y = northing (centered)
107+
const threejsZ = elevation; // Z = elevation (up)
108108

109109
pos.push(threejsX, threejsY, threejsZ);
110110
uvs.push(gx / tileSize, 1.0 - gy / tileSize);

apps/api/src/services/tiles.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ export function createTileChildren(
7272
for (const q of quads) {
7373
const geometricError = Math.max(50, 2000 / Math.pow(2, childLevel));
7474

75-
// Natural bounding box calculation - no rotation
75+
// Z-UP COORDINATE SYSTEM (3D Tiles standard):
76+
// X = easting, Y = northing, Z = elevation (up)
7677
const boxCenterX = (q.minX + q.maxX) / 2 - centerX; // X = easting (centered)
77-
const boxCenterY = (minHeight + maxHeight) / 2; // Y = elevation
78-
const boxCenterZ = (q.minY + q.maxY) / 2 - centerY; // Z = northing (centered)
78+
const boxCenterY = (q.minY + q.maxY) / 2 - centerY; // Y = northing (centered)
79+
const boxCenterZ = (minHeight + maxHeight) / 2; // Z = elevation (up)
7980

8081
const boxWidth = q.maxX - q.minX; // X extent (easting)
81-
const boxHeight = maxHeight - minHeight; // Y extent (elevation)
82-
const boxDepth = q.maxY - q.minY; // Z extent (northing)
82+
const boxHeight = q.maxY - q.minY; // Y extent (northing)
83+
const boxDepth = maxHeight - minHeight; // Z extent (elevation)
8384

8485
children.push({
8586
boundingVolume: {
@@ -92,10 +93,10 @@ export function createTileChildren(
9293
0, // X axis half-extents (easting)
9394
0,
9495
boxHeight / 2,
95-
0, // Y axis half-extents (elevation)
96+
0, // Y axis half-extents (northing)
9697
0,
9798
0,
98-
boxDepth / 2, // Z axis half-extents (northing)
99+
boxDepth / 2, // Z axis half-extents (elevation)
99100
],
100101
},
101102
refine: 'REPLACE',
@@ -131,14 +132,15 @@ export function createRootTile(
131132
maxH: number,
132133
maxLevel: number,
133134
) {
134-
// Natural root bounding box calculation
135+
// Z-UP COORDINATE SYSTEM (3D Tiles standard):
136+
// X = easting, Y = northing, Z = elevation (up)
135137
const rootBoxCenterX = 0; // X = easting (centered at origin)
136-
const rootBoxCenterY = (minH + maxH) / 2; // Y = elevation center
137-
const rootBoxCenterZ = 0; // Z = northing (centered at origin)
138+
const rootBoxCenterY = 0; // Y = northing (centered at origin)
139+
const rootBoxCenterZ = (minH + maxH) / 2; // Z = elevation center
138140

139141
const rootBoxWidth = square[2] - square[0]; // X extent (easting)
140-
const rootBoxHeight = maxH - minH; // Y extent (elevation)
141-
const rootBoxDepth = square[3] - square[1]; // Z extent (northing)
142+
const rootBoxHeight = square[3] - square[1]; // Y extent (northing)
143+
const rootBoxDepth = maxH - minH; // Z extent (elevation)
142144

143145
return {
144146
boundingVolume: {
@@ -151,10 +153,10 @@ export function createRootTile(
151153
0, // X axis half-extents (easting)
152154
0,
153155
rootBoxHeight / 2,
154-
0, // Y axis half-extents (elevation)
156+
0, // Y axis half-extents (northing)
155157
0,
156158
0,
157-
rootBoxDepth / 2, // Z axis half-extents (northing)
159+
rootBoxDepth / 2, // Z axis half-extents (elevation)
158160
],
159161
},
160162
refine: 'REPLACE',

apps/web/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function addCoordinateAxes() {
7575
const axesHelper = new THREE.AxesHelper(50000);
7676
scene.add(axesHelper);
7777
console.log(
78-
'📐 World axes visible. Red: X (East), Green: Y (Up/Elevation), Blue: Z (North).',
78+
'📐 World axes visible. Red: X (East), Green: Y (North), Blue: Z (Up/Elevation).',
7979
);
8080
}
8181

@@ -481,7 +481,7 @@ window.addEventListener('keydown', (event) => {
481481
✅ Ground grid aligned to tileset
482482
✅ Tile bounding boxes (green)
483483
✅ Tile center points (red spheres)
484-
✅ Coordinate axes (R=East, G=Up, B=North)
484+
✅ Coordinate axes (R=East, G=North, B=Up/Elevation)
485485
✅ Frustum visibility checking
486486
`);
487487
break;

0 commit comments

Comments
 (0)