Skip to content
Open
Show file tree
Hide file tree
Changes from 17 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
32 changes: 32 additions & 0 deletions example/babylonjs/googleMapsAerial.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>

<head>
<title>Google Maps Aerial - Babylon.js 3D Tiles</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<style type="text/css">
html,
body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}

#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
display: block;
}
</style>
</head>

<body>
<canvas id="renderCanvas"></canvas>
<script type="module" src="./googleMapsAerial.js"></script>
</body>

</html>
81 changes: 81 additions & 0 deletions example/babylonjs/googleMapsAerial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as BABYLON from 'babylonjs';
import { TilesRenderer } from '3d-tiles-renderer/babylonjs';
import { CesiumIonAuthPlugin } from '3d-tiles-renderer/core/plugins';
import GUI from 'lil-gui';

const GOOGLE_TILES_ASSET_ID = 2275207;

// gui
const params = {
enabled: true,
visibleTiles: 0,
errorTarget: 20,
};

const gui = new GUI();
gui.add( params, 'enabled' );
gui.add( params, 'visibleTiles' ).name( 'Visible Tiles' ).listen().disable();
gui.add( params, 'errorTarget', 1, 100 );

// engine
const canvas = document.getElementById( 'renderCanvas' );
const engine = new BABYLON.Engine( canvas, true );
engine.setHardwareScalingLevel( 1 / window.devicePixelRatio );

// scene
const scene = new BABYLON.Scene( engine );
scene.useRightHandedSystem = true;

// camera
const camera = new BABYLON.ArcRotateCamera(
'camera',
- Math.PI / 2,
Math.PI / 3,
100000,
new BABYLON.Vector3( 0, 0, 0 ),
scene,
);
camera.attachControl( canvas, true );
camera.minZ = 1;
camera.maxZ = 1e7;
camera.wheelPrecision = 0.25;
camera.setPosition( new BABYLON.Vector3( 500, 300, - 500 ) );

// tiles
const tiles = new TilesRenderer( null, scene );
tiles.registerPlugin( new CesiumIonAuthPlugin( {
apiToken: import.meta.env.VITE_ION_KEY,
assetId: GOOGLE_TILES_ASSET_ID,
autoRefreshToken: true,
} ) );
tiles.errorTarget = params.errorTarget;

// position so Tokyo Tower is visible
tiles.group.rotation.set( - 0.6223599766516501, 8.326672684688674e-17, - 0.8682210177215869 );
tiles.group.position.set( 0, - 6370877.772522855 - 150, 20246.934953993885 );

// Babylon render loop
scene.onBeforeRenderObservable.add( () => {

if ( params.enabled ) {

tiles.errorTarget = params.errorTarget;
tiles.update();
params.visibleTiles = tiles.visibleTiles.size;

}

} );

engine.runRenderLoop( () => {

scene.render();

} );

// Handle window resize
window.addEventListener( 'resize', () => {

engine.resize();

} );
31 changes: 31 additions & 0 deletions example/babylonjs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>

<head>
<title>Babylon.js 3D Tiles Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<style type="text/css">
html,
body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}

#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
}
</style>
</head>

<body>
<canvas id="renderCanvas"></canvas>
<script type="module" src="./index.js"></script>
</body>

</html>
68 changes: 68 additions & 0 deletions example/babylonjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as BABYLON from 'babylonjs';
import { TilesRenderer } from '3d-tiles-renderer/babylonjs';
import GUI from 'lil-gui';

const TILESET_URL = 'https://raw.githubusercontent.com/NASA-AMMOS/3DTilesSampleData/master/msl-dingo-gap/0528_0260184_to_s64o256_colorize/0528_0260184_to_s64o256_colorize/0528_0260184_to_s64o256_colorize_tileset.json';

// gui
const params = {
enabled: true,
visibleTiles: 0,
};

const gui = new GUI();
gui.add( params, 'enabled' );
gui.add( params, 'visibleTiles' ).listen().disable();

// init engine
const canvas = document.getElementById( 'renderCanvas' );
const engine = new BABYLON.Engine( canvas, true );
engine.setHardwareScalingLevel( 1 / window.devicePixelRatio );

// TODO: Babylon uses left handed coordinate system but our data is in a right handed one.
// The coordinate system flag may need to be accounted for when parsing the data
const scene = new BABYLON.Scene( engine );
scene.useRightHandedSystem = true;

// Camera controls
const camera = new BABYLON.ArcRotateCamera(
'camera',
- Math.PI / 2,
Math.PI / 2.5,
50,
new BABYLON.Vector3( 0, 0, 0 ),
scene,
);
camera.attachControl( canvas, true );
camera.minZ = 0.1;
camera.maxZ = 1000;

// instantiate tiles renderer and orient the group so it's Z+ down
const tiles = new TilesRenderer( TILESET_URL, scene );
tiles.group.rotation.x = Math.PI / 2;

// render
scene.onBeforeRenderObservable.add( () => {

if ( params.enabled ) {

tiles.update();

}

params.visibleTiles = tiles.visibleTiles.size;

} );

engine.runRenderLoop( () => {

scene.render();

} );

// resize
window.addEventListener( 'resize', () => {

engine.resize();

} );
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"types": "./src/r3f/index.d.ts",
"import": "./build/index.r3f.js"
},
"./babylonjs": {
"types": "./src/babylonjs/index.d.ts",
"import": "./build/index.babylonjs.js"
},
"./core/plugins": {
"types": "./src/core/plugins/index.d.ts",
"import": "./build/index.core-plugins.js"
Expand Down Expand Up @@ -87,6 +91,8 @@
"@types/three": "^0.170.0",
"@vitejs/plugin-react": "^4.3.2",
"@vitest/eslint-plugin": "^1.5.1",
"babylonjs": "^7.0.0",
"babylonjs-loaders": "^7.0.0",
Copy link

@georginahalpern georginahalpern Dec 8, 2025

Choose a reason for hiding this comment

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

recommend using @babylonjs/core and @babylonjs/loaders. that will also allow us to move over to the es6 ImportMeshAsync in gltfloader (though im happy to submit a PR after this checkin though! )

"cesium": "^1.132.0",
"concurrently": "^6.2.1",
"eslint": "^9.0.0",
Expand All @@ -95,6 +101,7 @@
"eslint-plugin-react-hooks": "^5.0.0",
"globals": "^16.5.0",
"leva": "^0.10.0",
"lil-gui": "^0.21.0",

Choose a reason for hiding this comment

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

could perhaps use the bayblon GUI system here

"postprocessing": "^6.36.4",
"three": "^0.170.0",
"typescript": "^5.6.0",
Expand All @@ -104,6 +111,8 @@
},
"peerDependencies": {
"@react-three/fiber": "^8.17.9 || ^9.0.0",
"babylonjs": "^7.0.0",
"babylonjs-loaders": "^7.0.0",
"react": "^18.3.1 || ^19.0.0",
"react-dom": "^18.3.1 || ^19.0.0",
"three": ">=0.167.0"
Expand All @@ -112,11 +121,20 @@
"@react-three/fiber": {
"optional": true
},
"babylonjs": {
"optional": true
},
"babylonjs-loaders": {
"optional": true
},
"react": {
"optional": true
},
"react-dom": {
"optional": true
},
"three": {
"optional": true
}
}
}
Loading
Loading