vvoovv / blosm

Blosm addon for Blender. A few clicks import of Google 3D cities, OpenStreetMap, terrain. Global coverage. Source code is in the branch 'release'.
1.5k stars 182 forks source link

OGC 3D Tiles support #497

Open vvoovv opened 1 month ago

vvoovv commented 1 month ago

This issue is used to track everything related to OGC 3D Tiles support in Blender.

A table with existing OGC 3D Tiles data sets is maintained at #498.

vvoovv commented 1 month ago

The first task is to load files with the extension b3dm into Blender. There is no built-in importer for them in Blender.

Google 3D Tiles use files with the externsion glb which can be loaded by Blender's built-in glTF importer.

An example b3dm file from the Aarhus data set: Tile_69_L18_00110.zip. Unzip it first.

jo-chemla commented 1 month ago

Quick comment, b3dm is the ancestor version of OGC/Cesium 3D-tiles spec (the tiled mesh pendant of 3d-tiles, similar to pnts for tiled pointclouds, i3dm for instances and cmpt for composite) - see the release post introducing 3d-tiles next now 3d-tiles 1.1 spec - also see version history. So if you can read Google Photorealistic Cities, you already read OGC/3D-tiles 1.1 format.

CesiumGS/3d-tiles-tools and donmccurdy/glTF-Transform are useful tooling to convert and upgrade tilesets from the 1.0 version to the newest 1.1 version - but it usually requires processing the whole tileset, not meant for on-the-fly conversion. Although these are js packages, so you could use some of the underlying methods rather than using the CLI.

A long discussion here discusses whether the portion to merge tiles of a tileset to a single mesh should be part of 3d-tiles-tools or belong somewhere else. Also, donmccurdy was thinking about integrating 3d-tiles IO tooling to gltf-transform, see discussion here. Hope this is useful!

vvoovv commented 1 month ago

Batched 3D Model (b3dm) was deprecated in 3D Tiles 1.1. See b3dm migration guide. From here.

image

vvoovv commented 1 month ago

An example b3dm file from the Aarhus data set: Tile_69_L18_00110.zip. Unzip it first.

The following code does convert the attached file Tile_69_L18_00110.b3dm to the glb format which Blender's glTF built-in addon can import.

The package py3dtiles is required:

pip install py3dtiles
from pathlib import Path

from py3dtiles.tileset.content import read_binary_tile_content

# input file
b3dmFile = "Tile_69_L18_00110.b3dm"
# output file
glbFile = "Tile_69_L18_00110.glb"

b3dm = read_binary_tile_content(Path(b3dmFile))
gltf = b3dm.body.gltf
with Path(glbFile).open('wb') as f:
    f.write(gltf.to_array())
vvoovv commented 1 month ago

Neither py3dtiles nor the online viewer https://www.3dpea.com/en/view-B3DM-online can process b3dm files from the Helsinki data set.

vvoovv commented 1 month ago

The following code does convert the attached file Tile_69_L18_00110.b3dm to the glb format which Blender's glTF built-in addon can import.

That code generates a glb file positioned at the origin. However it must be positioned somewhere on the Earth surface as it is the case with the Google 3D Tiles in the glb format.

I've found how to achieve that, so 3D tiles in both glb and b3dm formats can be processed in the same way by the Blosm addon.

from pathlib import Path

from py3dtiles.tileset.content import read_binary_tile_content

# input file
b3dmFile = Tile_69_L18_00110.b3dm"
# output file
glbFile = b3dmFile[:-4] + "glb"

b3dm = read_binary_tile_content(Path(b3dmFile))
gltf = b3dm.body.gltf
rtc_center = b3dm.body.feature_table.header.data.get("RTC_CENTER")
if rtc_center:
    gltf.header["nodes"] = [
        {'mesh': 0, 'translation': [rtc_center[0], rtc_center[2], -rtc_center[1]]}
    ]
with Path(glbFile).open('wb') as f:
    f.write(gltf.to_array())
vvoovv commented 2 weeks ago

A new GUI:

image

vvoovv commented 2 weeks ago

I added a stripped off package py3dtiles to blosm/threed_tiles. The package py3dtiles is required to read a b3dm file and save it as a glb file.

Below is the description of what was modified in the package py3dtiles (version 7.0.0 downloaded from here).

jo-chemla commented 2 weeks ago

Nice to see that custom tileset url within the UI! Will this work - in the end - only with version 1.0 3D-tiles tilesets (with tiles stored as b3dm) or also with 1.1 3D-Tiles (where tiles are actually glb)?

vvoovv commented 2 weeks ago

@jo-chemla

Both glb and b3dm tiles will be supported, as long as the resulting glb files can be imported by Blender's glTF importer.

vvoovv commented 1 week ago

I was able to import some data sets:

image

image

I've been relying on the parameter geometricError to import a specific Level of Details. However the scales of this parameter are different in Google 3D Tiles and the above data sets. This has to be reconsidered.

The bounding volume is defined by a box in the Google 3D Tiles, while it's defined by a sphere in the above data sets. The intersection test of a box and a sphere also needs more attention.