-
Notifications
You must be signed in to change notification settings - Fork 365
Add support for Babylon tiles renderer #1389
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
Open
gkjohnson
wants to merge
22
commits into
master
Choose a base branch
from
babylon-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a610c63
Add babylon renderer
gkjohnson ddf0843
Add a README
gkjohnson a332c82
Adjust aliases
gkjohnson 12dd922
Move comment
gkjohnson a2b7190
Add demos
gkjohnson b9f1737
Fixups
gkjohnson c1faf47
Remove log
gkjohnson 70b9573
Clean up demos
gkjohnson 4a1a2e9
Add minimum types
gkjohnson 536b571
Add new demos
gkjohnson eff8588
Reduce scratch math object creation
gkjohnson bd781de
Reduce scratch variable creation
gkjohnson d584309
Use specific imports
gkjohnson 01bae72
Fixes
gkjohnson cbf7554
Fix frustums
gkjohnson 1d6cfb8
Fix import usage
gkjohnson 0d40047
Merge remote-tracking branch 'origin/master' into babylon-support
gkjohnson 2739f5a
Add attributions to the index js example
gkjohnson 7c1f8a9
Add initial work for babylon google attributions
gkjohnson 78431dd
Merge branch 'master' into babylon-support
gkjohnson 0ee8a73
simplify styles
gkjohnson 7bfdcb7
Fix lint issue
gkjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
| } ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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", | ||
| "cesium": "^1.132.0", | ||
| "concurrently": "^6.2.1", | ||
| "eslint": "^9.0.0", | ||
|
|
@@ -95,6 +101,7 @@ | |
| "eslint-plugin-react-hooks": "^5.0.0", | ||
| "globals": "^16.5.0", | ||
| "leva": "^0.10.0", | ||
| "lil-gui": "^0.21.0", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
|
@@ -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" | ||
|
|
@@ -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 | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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! )