OmarShehata / google-earth-as-gltf

MIT License
343 stars 14 forks source link

Georeferenced glTF tiles? #4

Open haharooted opened 9 months ago

haharooted commented 9 months ago

Hey Omar

This is some really neat work! I've been having a lot of fun trying out renders using these gltf 3d tiles. I have been trying hard to figure out a way to "place" this gltf in the correct place. In the software i use right now i load a normal XYZ layer as basemap and then manually place the glTF model on top, then adjust it manually one by one to try and make it fit - however this takes a long time to do, and never really fits perfectly, see pic.

image

Do you have any clues as to how i could solve this? I see that we send the viewport as a request to the google 3d tiles, but after they are loaded with loaders.gl and then exported i guess we "lose" the coordinates?

Is this what you mean on this line about normalizing it?

https://github.com/OmarShehata/google-earth-as-gltf/blob/765470cf359dce680ccc6b7e58f3c958cd4be755/simple-node-example/fetch-tiles.js#L64C1-L65C1

As you can probably hear, i'm not really sharp on 3d tiles and these kinds of formats - but i feel like what im trying to do should be possible in an easier way lol. Basically just to load the gltf model and get it correctly placed!

OmarShehata commented 9 months ago

Thank you for the kind words @haharooted! Glad you've found this project useful

Do you have any clues as to how i could solve this? I see that we send the viewport as a request to the google 3d tiles, but after they are loaded with loaders.gl and then exported i guess we "lose" the coordinates?

Yes! My main motivation with this repo is to load the glTF tiles in a standard engine that does NOT support geographic coordinates, and that does require stripping/extracting the geometry and normalizing it around an origin of 0/0/0. Right now this is happening here: https://github.com/OmarShehata/google-earth-as-gltf/blob/765470cf359dce680ccc6b7e58f3c958cd4be755/src/Viewer.js#L73-L102

In your case, you actually want the geographic coordinates, so you have two options:

The first option is easier, relying on the engine. The second option requires more upfront work but can be easier to port over to any engine (so if we get an example of that, it'd be helpful for the community)

OmarShehata commented 9 months ago

What engine/renderer are you using?

haharooted commented 9 months ago

What engine/renderer are you using?

I have been trying get it working in a completely normal Mapbox Gl / Maplibre Gl setup with Deck.gl or Three.js (using loaders.gl for the gltf loading). Obviously it works just adding the google tiles as a Tile3DLayer, but sadly this is not a possibility in this case - it has to be a simple local .gltf/.glb that gets loaded/rendered on top of the map for a really small area.

In your case, you actually want the geographic coordinates, so you have two options:

  • If your engine just supports ECEF coordinates, you should be able to load the glTF tiles directly "as is" and it would "just work" (but maybe there's some finagling needed there)

As mentioned, i can't add the tiles in my situation, but can only add one(or multiple) gltf tiles for a small area. I will be reading the 3d-tiles spec to try and figure out how the format works, i just don't get it right now haha. I see that for each specific tile they have "position" field with something that looks like coordinates, but i guess thats their position relative to something else.

  • You use the normalized geometry, but calculate the lat/lng/orientation that the tile is supposed to be at, and placed it there. The first option is easier, relying on the engine. The second option requires more upfront work but can be easier to port over to any engine (so if we get an example of that, it'd be helpful for the community)

I'd love to figure out a way to programatically figure out where the stitched together gltf "fits" in the real world. I guess in a way we already know where we're interested in since we're making a request from a specific viewport. I will be reading the 3d-tiles spec to try and understand where the coordinates for the gltf object actually are.

haharooted commented 9 months ago

I found a pretty good resource: https://github.com/CesiumGS/3d-tiles/blob/main/3d-tiles-reference-card.pdf

image

Aha! Bounding volume. Maybe this is it!

haharooted commented 9 months ago
image

Some funny things happening ...