Skip to content

Commit 7d5d0e2

Browse files
committed
updated to reflect my PR to cesium CesiumGS/cesium#13077
1 parent ffb0dc6 commit 7d5d0e2

File tree

7 files changed

+4106
-127
lines changed

7 files changed

+4106
-127
lines changed

src/DebugVisualization.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Scene, MeshBuilder, StandardMaterial, Color3, Vector3 } from '@babylonjs/core';
2+
import { Ellipsoid } from 'cesium';
23

34
export class DebugVisualization {
45
private babylonScene: Scene;
@@ -7,6 +8,7 @@ export class DebugVisualization {
78
private cameraUpdatePaused = false;
89
private boundingVolumesVisible = false;
910
private frustumVisible = false;
11+
private referenceObjectsVisible = false;
1012

1113
private frustumVisualization: any = null;
1214
private boundingVolumeWireframes: any[] = [];
@@ -17,6 +19,7 @@ export class DebugVisualization {
1719
this.babylonScene = babylonScene;
1820
this.cesiumTileset = cesiumTileset;
1921
this.setupKeyboardControls();
22+
this.createReferenceObjects();
2023
}
2124

2225
private setupKeyboardControls(): void {
@@ -34,6 +37,10 @@ export class DebugVisualization {
3437
event.preventDefault();
3538
this.toggleFrustumVisibility();
3639
break;
40+
case 't':
41+
event.preventDefault();
42+
this.toggleReferenceObjectsVisibility();
43+
break;
3744
}
3845
});
3946
}
@@ -69,6 +76,81 @@ export class DebugVisualization {
6976
}
7077
}
7178

79+
private toggleReferenceObjectsVisibility(): void {
80+
this.referenceObjectsVisible = !this.referenceObjectsVisible;
81+
console.log(this.referenceObjectsVisible ? '🌍 Reference objects visible' : '🌍 Reference objects hidden');
82+
83+
// Find and toggle all reference objects
84+
const referenceObjectNames = ['earthSphere', 'skyBarrier', 'centerSphere', 'northPole', 'southPole'];
85+
86+
referenceObjectNames.forEach(name => {
87+
const mesh = this.babylonScene.getMeshByName(name);
88+
if (mesh) {
89+
mesh.setEnabled(this.referenceObjectsVisible);
90+
}
91+
});
92+
}
93+
94+
private createReferenceObjects(): void {
95+
const marsRadius = Ellipsoid.MARS.maximumRadius; // Official Cesium Mars ellipsoid radius
96+
97+
// Mars sphere (hidden wireframe)
98+
const marsSphere = MeshBuilder.CreateSphere(
99+
'earthSphere',
100+
{ diameter: marsRadius * 2, segments: 64 },
101+
this.babylonScene
102+
);
103+
marsSphere.position = Vector3.Zero();
104+
marsSphere.setEnabled(false);
105+
const marsMaterial = new StandardMaterial('earthMaterial', this.babylonScene);
106+
marsMaterial.diffuseColor = new Color3(0.8, 0.4, 0.2); // Mars reddish color
107+
marsMaterial.emissiveColor = new Color3(0.2, 0.1, 0.05);
108+
marsMaterial.wireframe = true;
109+
marsSphere.material = marsMaterial;
110+
111+
// Sky barrier (hidden) - scaled by 2x
112+
const skyBarrierRadius = marsRadius * 2;
113+
const skyBarrier = MeshBuilder.CreateSphere(
114+
'skyBarrier',
115+
{ diameter: skyBarrierRadius * 2, segments: 32 },
116+
this.babylonScene
117+
);
118+
skyBarrier.position = Vector3.Zero();
119+
skyBarrier.setEnabled(false);
120+
const skyMaterial = new StandardMaterial('skyMaterial', this.babylonScene);
121+
skyMaterial.diffuseColor = new Color3(0.8, 0.2, 0.2);
122+
skyMaterial.emissiveColor = new Color3(0.1, 0.05, 0.05);
123+
skyMaterial.wireframe = true;
124+
skyMaterial.alpha = 0.3;
125+
skyBarrier.material = skyMaterial;
126+
127+
// Center reference sphere (green wireframe)
128+
const centerSphere = MeshBuilder.CreateSphere('centerSphere', { diameter: 100000 }, this.babylonScene);
129+
centerSphere.position = Vector3.Zero();
130+
const centerMaterial = new StandardMaterial('centerMaterial', this.babylonScene);
131+
centerMaterial.diffuseColor = new Color3(0, 1, 0);
132+
centerMaterial.emissiveColor = new Color3(0, 0.5, 0);
133+
centerMaterial.wireframe = true;
134+
centerMaterial.backFaceCulling = false;
135+
centerSphere.material = centerMaterial;
136+
137+
// North pole marker (white box)
138+
const northPole = MeshBuilder.CreateBox('northPole', { size: 5000000 }, this.babylonScene);
139+
northPole.position = new Vector3(0, 10000000, 0);
140+
const northMaterial = new StandardMaterial('northMaterial', this.babylonScene);
141+
northMaterial.diffuseColor = new Color3(1, 1, 1);
142+
northMaterial.emissiveColor = new Color3(0.5, 0.5, 0.5);
143+
northPole.material = northMaterial;
144+
145+
// South pole marker (blue box)
146+
const southPole = MeshBuilder.CreateBox('southPole', { size: 5000000 }, this.babylonScene);
147+
southPole.position = new Vector3(0, -10000000, 0);
148+
const southMaterial = new StandardMaterial('southMaterial', this.babylonScene);
149+
southMaterial.diffuseColor = new Color3(0, 0, 1);
150+
southMaterial.emissiveColor = new Color3(0, 0, 0.5);
151+
southPole.material = southMaterial;
152+
}
153+
72154
updateVisualizations(camera: any, frameNumber: number): void {
73155
if (this.frustumVisible) {
74156
this.updateFrustumVisualization(camera, frameNumber);

src/SimpleBabylonTileContent.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ export class SimpleBabylonTileContent {
3333

3434
result.meshes.forEach((mesh) => {
3535
mesh.setEnabled(false);
36+
37+
// Ensure all materials are fully opaque
38+
if (mesh.material) {
39+
if (mesh.material.alpha !== undefined) {
40+
mesh.material.alpha = 1.0;
41+
}
42+
if (mesh.material.transparencyMode !== undefined) {
43+
mesh.material.transparencyMode = 0; // OPAQUE mode
44+
}
45+
// For PBR materials
46+
if (mesh.material.baseColor && mesh.material.baseColor.a !== undefined) {
47+
mesh.material.baseColor.a = 1.0;
48+
}
49+
if (mesh.material.albedoColor && mesh.material.albedoColor.a !== undefined) {
50+
mesh.material.albedoColor.a = 1.0;
51+
}
52+
}
3653
});
3754

3855
this._meshes = result.meshes;

src/SimpleIntegration.ts

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import { Camera, Engine, Vector3, Matrix } from '@babylonjs/core';
2-
import * as Cesium from 'cesium';
2+
import {
3+
Ion,
4+
IonResource,
5+
Cartesian3,
6+
Cartographic,
7+
Ellipsoid,
8+
PerspectiveFrustum,
9+
SceneMode,
10+
JulianDate,
11+
GeographicProjection
12+
} from 'cesium';
13+
14+
// Import internal Cesium classes that may not be publicly exported
15+
import * as CesiumInternal from 'cesium';
316

417
import { SimpleBabylonTileContent } from './SimpleBabylonTileContent';
518

619
//This can go away after PR to cesium is accepted
7-
import CesiumTilesetDerived from './cesium_derived/CesiumTilesetDerived.js';
20+
//import CesiumTilesetDerived from './cesium_derived/CesiumTilesetDerived.js';
21+
import CesiumTilesetDerived from './cesium_derived/Cesium3DTileset';
822

923
import { DebugVisualization } from './DebugVisualization';
1024

@@ -38,8 +52,8 @@ export class SimpleIntegration {
3852

3953
// Set up Cesium Ion authentication using native Cesium
4054
// TODO: Update with your new Cesium Ion token from https://cesium.com/ion/tokens
41-
Cesium.Ion.defaultAccessToken =
42-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZWNjOTdkOS03ODQ2LTRiYzAtOGNiZC0yMmUwY2ZiOTM2M2MiLCJpZCI6MjIwODczLCJpYXQiOjE3NjQ2OTMxODh9.QlACQnWP4oWZCFQKuR2FXWw_KiLJwm9wsg6U6ynqIw4';
55+
Ion.defaultAccessToken =
56+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4OWQ5MDg2Mi02MDRmLTRhMWItYjZjZS1mMGE3YWI1MDAyOWYiLCJpZCI6MjIwODczLCJpYXQiOjE3NjQ4NjgxNDh9.Grk7U6JuiU7YNrP5bjCAsrifDqBJIxtQZF4Lf52ocMo';
4357

4458
// BABYLON.JS: Set up proper Cesium content factory registration
4559
this.setupBabylonContentFactory();
@@ -49,8 +63,8 @@ export class SimpleIntegration {
4963

5064
// Create reusable pass state exactly like Cesium Scene does
5165
// Access internal classes through Cesium namespace
52-
const Cesium3DTilePassState = (Cesium as any).Cesium3DTilePassState;
53-
const Cesium3DTilePass = (Cesium as any).Cesium3DTilePass;
66+
const Cesium3DTilePassState = (CesiumInternal as any).Cesium3DTilePassState;
67+
const Cesium3DTilePass = (CesiumInternal as any).Cesium3DTilePass;
5468

5569
this.renderTilesetPassState = new Cesium3DTilePassState({
5670
pass: Cesium3DTilePass.RENDER,
@@ -72,36 +86,36 @@ export class SimpleIntegration {
7286
const babylonUp = this.camera.upVector || Vector3.Up();
7387

7488
// Simple coordinate transformation: Babylon → Cesium ECEF
75-
const position = new Cesium.Cartesian3(babylonPos.x, -babylonPos.z, babylonPos.y);
89+
const position = new Cartesian3(babylonPos.x, -babylonPos.z, babylonPos.y);
7690

7791
// Transform direction vector (from camera toward target)
78-
const direction = new Cesium.Cartesian3(babylonDir.x, -babylonDir.z, babylonDir.y);
79-
Cesium.Cartesian3.normalize(direction, direction);
92+
const direction = new Cartesian3(babylonDir.x, -babylonDir.z, babylonDir.y);
93+
Cartesian3.normalize(direction, direction);
8094

81-
const up = new Cesium.Cartesian3(babylonUp.x, -babylonUp.z, babylonUp.y);
82-
Cesium.Cartesian3.normalize(up, up);
95+
const up = new Cartesian3(babylonUp.x, -babylonUp.z, babylonUp.y);
96+
Cartesian3.normalize(up, up);
8397

8498
// Calculate right vector
85-
const right = new Cesium.Cartesian3();
86-
Cesium.Cartesian3.cross(direction, up, right);
87-
Cesium.Cartesian3.normalize(right, right);
99+
const right = new Cartesian3();
100+
Cartesian3.cross(direction, up, right);
101+
Cartesian3.normalize(right, right);
88102

89103
// Recalculate up to ensure orthogonality
90-
Cesium.Cartesian3.cross(right, direction, up);
91-
Cesium.Cartesian3.normalize(up, up);
104+
Cartesian3.cross(right, direction, up);
105+
Cartesian3.normalize(up, up);
92106

93107
// Create frustum
94-
const frustum = new Cesium.PerspectiveFrustum({
108+
const frustum = new PerspectiveFrustum({
95109
fov: this.camera.fov,
96110
aspectRatio: this.engine.getRenderWidth() / this.engine.getRenderHeight(),
97111
near: this.camera.minZ, // Now consistent: both use 0.1
98112
far: this.camera.maxZ,
99113
});
100114

101115
// Calculate cartographic position for geographic reference
102-
const positionCartographic = Cesium.Cartographic.fromCartesian(
116+
const positionCartographic = Cartographic.fromCartesian(
103117
position,
104-
Cesium.Ellipsoid.WGS84
118+
Ellipsoid.WGS84
105119
);
106120

107121
return {
@@ -134,11 +148,12 @@ export class SimpleIntegration {
134148
): Promise<void> {
135149
try {
136150
// Use standard Cesium Ion asset loading
137-
const resource = await Cesium.IonResource.fromAssetId(assetId);
151+
const resource = await IonResource.fromAssetId(assetId);
138152

139153
this.cesiumTileset = (await CesiumTilesetDerived.fromUrl(resource, {
140154
show: true,
141155
shadows: 1,
156+
disableDynamicMapManager: true
142157
})) as CesiumTilesetDerived;
143158

144159
await this.cesiumTileset.readyPromise;
@@ -201,14 +216,14 @@ export class SimpleIntegration {
201216
drawingBufferHeight: this.engine.getRenderHeight(),
202217
},
203218
cullingVolume: cullingVolume,
204-
mode: Cesium.SceneMode.SCENE3D,
219+
mode: SceneMode.SCENE3D,
205220
frameNumber: ++this.frameCount,
206221
// CRITICAL: Add JulianDate time for BaseTraversal tile prioritization
207-
time: Cesium.JulianDate.now(),
222+
time: JulianDate.now(),
208223
// CESIUM EXACT: newFrame flag - true only for actual new frames
209224
newFrame: this.frameCount !== this.lastFrameNumber,
210225
// CRITICAL: Add pass information that SkipTraversal needs
211-
pass: (Cesium as any).Pass ? (Cesium as any).Pass.RENDER : 0,
226+
pass: (CesiumInternal as any).Pass ? (CesiumInternal as any).Pass.RENDER : 0,
212227
// Let Cesium use its default maximumScreenSpaceError for Google tiles
213228
tilesetPassState: this.renderTilesetPassState, // Required by CesiumTilesetDerived
214229
// CREDIT DISPLAY: Add credits as HTML comments once
@@ -219,7 +234,7 @@ export class SimpleIntegration {
219234
},
220235
// Additional properties from working commit 72dfb2e:
221236
pixelRatio: 1.0,
222-
mapProjection: new Cesium.GeographicProjection(),
237+
mapProjection: new GeographicProjection(),
223238
verticalExaggeration: 1.0,
224239
verticalExaggerationRelativeHeight: 0.0,
225240
commandList: [],
@@ -233,12 +248,12 @@ export class SimpleIntegration {
233248
try {
234249
// Set up load timestamp if needed (from prePassesUpdate)
235250
if (!(this.cesiumTileset as any)._loadTimestamp) {
236-
(this.cesiumTileset as any)._loadTimestamp = Cesium.JulianDate.clone(frameState.time);
251+
(this.cesiumTileset as any)._loadTimestamp = JulianDate.clone(frameState.time);
237252
}
238253

239254
// Calculate time since load (from prePassesUpdate)
240255
const timeSinceLoad = Math.max(
241-
Cesium.JulianDate.secondsDifference(
256+
JulianDate.secondsDifference(
242257
frameState.time,
243258
(this.cesiumTileset as any)._loadTimestamp
244259
) * 1000,
@@ -279,7 +294,7 @@ export class SimpleIntegration {
279294
* BABYLON.JS: Set up proper Cesium content factory to create BabylonTileContent
280295
*/
281296
private setupBabylonContentFactory(): void {
282-
const Cesium3DTileContentFactory = (Cesium as any).Cesium3DTileContentFactory;
297+
const Cesium3DTileContentFactory = (CesiumInternal as any).Cesium3DTileContentFactory;
283298
const babylonScene = this.camera.getScene();
284299

285300
Cesium3DTileContentFactory.b3dm = function (
@@ -315,7 +330,7 @@ export class SimpleIntegration {
315330
* CRITICAL FIX: Optimize RequestScheduler for Google 3D Tiles massive tile hierarchy
316331
*/
317332
private optimizeRequestSchedulerForGoogle3DTiles(): void {
318-
const RequestScheduler = (Cesium as any).RequestScheduler;
333+
const RequestScheduler = (CesiumInternal as any).RequestScheduler;
319334
if (!RequestScheduler) return;
320335

321336
RequestScheduler.maximumRequests = 100;

0 commit comments

Comments
 (0)