Code Monkey home page Code Monkey logo

pg2b3dm's Introduction

pg2b3dm

Build statusNuget [NuGet]Join the chat at https://discord.gg/gGCka4Nd

Tool for converting 3D geometries from PostGIS to 3D Tiles. The generated 3D Tiles can be visualized in Cesium JS, Cesium for Unreal, Cesium for Unity3D, Cesium for Omniverse, QGIS, ArcGIS Pro, ArcGIS Maps SDK for JavaScript, Mapbox GL JS v3 (experimental) or other 3D Tiles client viewers.

image

Features:

  • 3D Tiles 1.1 Implicit tiling;

  • 3D Tiles extensions EXT_Mesh_Features and EXT_Structural_Metadata;

  • Valid glTF 2.0 files;

  • Shading PbrMetallicRoughness and PbrSpecularGlossiness;

  • Query parameter support;

  • Cesium: LOD support and Outlines support (using CESIUM_primitive_outline);

  • Triangulation of input geometries LineStrings/Polygon/MultiPolygon/PolyhedralSurface with Z values;

  • Docker support.

Resulting tilesets can be validated against 3D Tiles Validator (https://github.com/CesiumGS/3d-tiles-validator).

Tileset.json and glb/b3dm tiles are by default created in the 'output/content' subdirectory (or specify output directory with -o, --output).

Getting started

Convert 3D Data (Multipolygon Z) to 3D Tiles

Result: 7-688-32.gpkg (34 MB)

  • Import in PostGIS database, convert to EPSG:4979 (WGS84 ellipsoidal heights). Note: in the Cesium client viewer the terrain should be added to see the buildings on the correct height.
$ ogr2ogr -f PostgreSQL pg:"host=localhost user=postgres password=postgres" -t_srs epsg:4979 7-688-32.gpkg lod22_3d -nln sibbe

When the terrain is not used, omit the -t_srs parameter (in this case the Dutch EPSG code EPSG:7415 of the input data will be used).

  • Optional: Add spatial index
postgresql> CREATE INDEX ON sibbe USING gist(st_centroid(st_envelope(geom)))
  • Convert to 3D Tiles using pg2b3dm
$ pg2b3dm -h localhost -U postgres -c geom -d postgres -t sibbe -a identificatie

Output should be as follows:

https://gist.github.com/bertt/fa084f55217dded35c6fb1607e81a9f3

  • The resulting tileset can be added to CesiumJS using:
   const tileset = await Cesium.Cesium3DTileset.fromUrl(
      "./1.1/tileset.json"
    );  
    viewer.scene.primitives.add(tileset);
  • The Dutch terrain can be added in CesiumJS using:
var terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl('https://api.pdok.nl/kadaster/3d-basisvoorziening/ogc/v1_0/collections/digitaalterreinmodel/quantized-mesh');
viewer.scene.terrainProvider = terrainProvider;
viewer.scene.globe.depthTestAgainstTerrain=true;

Older getting started documents:

1] See getting started for a tutorial how to convert a 2D shapefile of buildings with height attribute to 3D Tiles and visualize in CesiumJS/Cesium for Unreal/Unity3D.

2] For a dataprocessing workflow from CityGML to 3D Tiles using GDAL, PostGIS and FME see dataprocessing/dataprocessing_citygml.

Demo

Alt Text

Live Sample viewers

image

  • FOSS4G presentations

Presentation at FOSS4G 2021: A fast web 3D viewer for 11 million buildings https://www.youtube.com/watch?v=1_JM2Xf5mDk

Presentation at FOSS4G 2019: 3D geodata in the MapBox GL JS viewer with 3D Tiles https://www.youtube.com/watch?v=HXQJbyEnC9w

texel

Command line options

All parameters are optional, except the -t --table option.

If --username and/or --dbname are not specified the current username is used as default.

  -U, --username                  Database user

  -h, --host                      (Default: localhost) Database host

  -d, --dbname                    Database name

  -c, --column                    (Default: geom) Geometry column

  -t, --table                     Required. Database table, include database schema if needed

  -p, --port                      (Default: 5432) Database port

  -o, --output                    (Default: output) Output path

  -a, --attributecolumns          (Default: '') Attribute columns

  -q, --query                     (Default: '') Query parameter

  --copyright                     (Default: '') glTF asset copyright

  --default_color                 (Default: #FFFFFF) Default color

  --default_metallic_roughness    (Default: #008000) Default metallic roughness

  --double_sided                  (Default: true) Default double sided

  --create_gltf                   (Default: true) Create glTF files

  --radiuscolumn                  (Default: '') Column with radius values for lines

  --format                        (Default: Cesium) Application mode (Cesium/Mapbox)

  --max_features_per_tile         (Default: 1000) maximum features per tile (Cesium)

  -l, --lodcolumn                 (Default: '') LOD column (Cesium)

  -g, --geometricerrors           (Default: 2000,0) Geometric errors (Cesium)

  --shaderscolumn                 (Default: '') shaders column (Cesium)

  --use_implicit_tiling           (Default: true) use 1.1 implicit tiling (Cesium)

  --add_outlines                  (Default: false) Add outlines (Cesium)

  -r, --refinement                (Default: REPLACE) Refinement ADD/REPLACE (Cesium)

  --zoom                          (Default: 15) Zoom level (Mapbox)

  --help                          Display this help screen.

  --version                       Display version information.

Sample command for running pg2b3dm:

-h localhost -U postgres -c geom_triangle --shaderscolumn shaders -t delaware_buildings -d postgres -g 100,0 

Installation

Prerequisite: .NET 6.0 SDK is installed https://dotnet.microsoft.com/download/dotnet/6.0

$ dotnet tool install -g pg2b3dm

Or update

$ dotnet tool update -g pg2b3dm

To run:

$ pg2b3dm

Benchmarking

Source Table Size Features Time Tiles Tiles/Minute Tile uncompressed Tile compressed
Dutch 3d BAG buildings lod12_3d 12 GB 9.712.728 1h 54m 23s 29098 255
French IGN buildings batiment_construction 142 GB 46.286.334 3h 21m 33s 117745 585 92GB 11GB

Styling

For styling see styling 3D Tiles

Geometries

Input geometries must be of type LineString/MultilineString/Polygon/MultiPolygon/PolyhedralSurface (with z values). When the geometry is not triangulated, pg2b3dm will perform triangulation. Geometries with interior rings are supported.

For large datasets create a spatial index on the geometry column:

psql> CREATE INDEX ON the_table USING gist(st_centroid(st_envelope(geom_triangle)));

When there the spatial index is not present the following warning is shown.

image

For line geometries a 3D tube is created with a radius of 1 meter. When a radius column is specified (option --radiuscolumn), the radius from that columns is used for the tube. The radius column must be of type 'real', sample for random radius between 0.5 and 1.5:

postgresql> alter table delaware_buildings add column radius real;
postgresql> update delaware_buildings set radius = 0.5 + random() * (1.5 - 0.5);

Sample with pipes (green = data, blue = water, purple = sewage, yellow = gas, red = electricity):

image

Query parameter

The -q --query will be added to the 'where' part of all queries.

Samples:

Attribute query:

-q "ogc_fid=118768"

Spatial query:

-q "ST_Intersects(wkb_geometry, 'SRID=4326;POLYGON((-75.56996406 39.207228824,-75.56996406 39.2074420320001,-75.5696300339999 39.2074420320001,-75.5696300339999 39.207228824,-75.56996406 39.207228824))'::geometry)"

Make sure to check the indexes when using large tables.

Attributes

With the -a attributecolumns parameter multiple columns with attributes can be specified. The attribute information is stored in the b3dm batch table or in the glTF (using EXT_Structural_Metadata extension).

Multiple columns must be comma separated (without spaces):

Sample: --attributescolumns col1,col2

When using 3D TIles 1.1 and EXT_Structural_Metadata, the following mapping between PostgreSQL data types and 3D Tiles data types is used:

PostgreSQL data type 3D Tiles data type (type / componenttype)
boolean boolean / -
smallint scalar / int16
integer scalar / int32
bigint scalar / int64
real scalar / float32
numeric scalar / float32
double precision scalar / float64
numeric[] all of length 3 vec3 / float32
numeric[] all of length 16 mat4 / float32
numeric[] scalar / float32
varchar string

When one of the above types (except boolean and array types) is set to NULL in the database, the null values are converted to a nodata value to be used in the 3D Tiles batch table.

Also arrays of the above types are supported, like:

bool[], smallint[], int[], bigint[], real[], numeric[][], double precision[] and varchar[]

Arrays can be of fixed length or not.

When the type is numeric[]/numeric[][], it is checked if all the items contain 3 (vector3) or 16 values (mat4) . If so, the vec3 or mat4 type is used.

Null values are not supported in arrays (including vector3 and matrix types).

When other types are used, there will be a exception.

Example creating string values in a column:

postgresql> alter table delaware_buildings add column random_string varchar not null default 'standaard waarde'

and for an array of strings:

postgresql> ALTER TABLE delaware_buildings  ADD COLUMN random_strings VARCHAR[] DEFAULT '{waarde1, waarde2}'

In the options you can now specify the column name 'random_string' and/or 'random_strings' to add the values.

Cesium support

For Cesium support (tiling schema, LODS, outlines) see Cesium notes

Mapbox support

MapBox GL JS v3 (experimental) support is available in this version.

Use parameter "-f Mapbox" to create tiles for Mapbox.

Tiles are written in format {z}-{x}-{y}.b3dm or {z}-{x}-{y}.glb in the content directory.

The tiles should be Draco compressed, for example use gltf-pipeline (https://github.com/CesiumGS/gltf-pipeline)

To load the tiles in Mapbox GL JS v3 (v3.2.0) use the following code:

ap.on('style.load', () => {

map.addSource('bag-3d', {
        "type": "batched-model",
        "maxzoom": 15,
        "minzoom": 15,
        "tiles": [
          "{url_to_tiles}/content/{z}-{x}-{y}.glb"
        ]
      }
)});

// add the custom style layer to the map
map.on('style.load', () => {
  map.addLayer({
    id: 'bag-layer',
    type: 'model',
    source: 'bag-3d',          
  });
});


For previous Mapbox support notes see Mapbox notes

ArcGIS Pro support

In ArcGIS Pro 3.2 support for 3D Tiles is added (https://pro.arcgis.com/en/pro-app/latest/help/mapping/layer-properties/work-with-3d-tiles-layers.htm)

Sample: Use option 'Data from path' with https://geodan.github.io/pg2b3dm/sample_data/3dbag/sibbe/1.0/tileset.json

image

image

QGIS support

In QGIS 3.34 support for 3D Tiles is added see https://cesium.com/blog/2023/11/07/qgis-now-supports-3d-tiles/

To create 3D Tiles for QGIS use parameters '--create_gltf false --use_implicit_tiling false' as 3D Tiles 1.1 features are not supported yet.

Sample dataset Sibbe https://geodan.github.io/pg2b3dm/sample_data/3dbag/sibbe/1.0/tileset.json

image

Game engines Unity3D / Unreal / Omniverse support

To create 3D Tiles for game engines use parameters '--create_gltf false --use_implicit_tiling false' as 3D Tiles 1.1 features are not supported yet.

Sample dataset Sibbe: https://geodan.github.io/pg2b3dm/sample_data/3dbag/sibbe/1.0/tileset.json

Run from Docker

Docker image: https://hub.docker.com/repository/docker/geodan/pg2b3dm

Tags used (https://hub.docker.com/repository/docker/geodan/pg2b3dm/tags):

  • {version}: specific version

  • latest: is build automatically after push to master

Building Dockers

$ git clone https://github.com/Geodan/pg2b3dm.git
$ cd pg2b3dm/src
$ docker build -t geodan/pg2b3dm .

Test feature branch:

$ git clone https://github.com/Geodan/pg2b3dm.git
$ git checkout {name_of_feature_branch}
$ cd pg2b3dm/src
$ docker build -t geodan/pg2b3dm:{name_of_feature_branch} .

Running

Sample on Linux:

$ docker run -v $(pwd)/output:/app/output -it geodan/pg2b3dm -h my_host -U my_user -d my_database -t my_schema.my_table

Run from source

Requirement: Install .NET 6.0 SDK

https://dotnet.microsoft.com/download/dotnet/6.0

Installation guide see https://docs.microsoft.com/en-us/dotnet/core/install/

To run the app:

$ git clone https://github.com/Geodan/pg2b3dm.git
$ cd pg2b3dm/src/pg2b3dm
$ dotnet run -- -h my_host -U my_user -d my_database -t my_schema.my_table

To create an self-contained executable '~/bin/pg2b3dm' for Linux:

$ git clone https://github.com/Geodan/pg2b3dm.git
$ cd pg2b3dm/src/pg2b3dm
$ dotnet publish -c Release -r linux-x64 /p:PublishSingleFile=true
$ cp ./bin/Release/net6.0/linux-x64/publish/pg2b3dm ~/bin
$ ~/bin/pg2b3dm

Alternative options for parameter -r in dotnet publish: 'osx-x64' (Mac), 'win-x64' (Windows)

Debugging in Visual Studio Code

$ git clone https://github.com/Geodan/pg2b3dm.git

$ cd src

$ code .

In Visual Studio Code, open .vscode/launch.json and adjust the 'args' parameter to your environment

"args": ["-h" ,"my_host", "-U" ,"my_user", "-d", "my_database", "-t", "my_table"],            

Press F5 to start debugging.

Dependencies

History

2024-04-09: release 2.8.1: no rounding of bounding volume values

2024-04-09: release 2.8.0, improve bounding volume z values when using explicit tiling

2024-04-03: release 2.7.0, create more tileset.json files with explicit tiling + change spatial index check + performance improvement count features

2024-03-20: release 2.6.1, fix z of boundingvolumes

2024-03-06: release 2.6.0, add support for Mapbox v3 (experimental), added parameter --format (default Cesium) Cesium/Mapbox

2024-02-20: release 2.5.1, add support for multiline strings

2024-02-15: release 2.5.0

  • add support for single shaders per geometry #147

  • add lines support, added option --radiuscolumn #146

  • update triangulator for higher precision normals calculation

2024-02-08: release 2.4.0, add support for polygons with interior rings

2024-01-26: release 2.3.0, add support for null values in attribute columns (except array types)

2024-01-26: release 2.2.1, fix for degenerated triangles

2024-01-25: release 2.2.0, add support for 3D Tiles 1.1 all EXT_Structural_Metadata types + create tileset.json file with version 1.0 when create_gltf is false and use_implicit_tiling is false

2024-01-23: release 2.1.0, fix of offsets + add polygonZ support

2024-01-10: release 2.0.1, fix for triangulator + add check on interrior rings (not supported)

2024-01-03: release 2.0.0,

  • Breaking change: removed input coordinate system requirement (EPSG:4978), use EPSG:4326/EPSG:4979 or local coordinate system instead.

  • glTF transformation is defined in tileset.json (instead of in glTF asset). As a result, the glTF assets are no longer 'skewed' when visualized in a glTF viewer.

  • removed parameter 'boundingvolume_heights', heights are calculated from the input data

2023-11-13: release 1.8.5, fix for dataset with geometries on 1 location

2023-10-25: release 1.8.4, add -r --refinement option

2023-10-17: release 1.8.3, tileset.json asset version from 1.0 to 1.1, database connection timeout removed

2023-10-04: release 1.8.2, use humanizer with resources

2023-09-26: release 1.8.1, updating triangulator

2023-09-22: release 1.8, adding 3D Tiles 1.1 Metadata support (EXT_Mesh_Features / EXT_Structural_Metadata). Options added: create_gltf (default true), double_sided (default true)

2023-08-29: release 1.7.1, improve spatial index check

2023-08-29: release 1.7.0, add triangulator - runs only when geometry is not triangulated

2023-08-29: release 1.6.3, add support for MultiPolygonZ

2023-08-17: release 1.6.2, add check for spatial index

2023-08-16: release 1.6.1, translate b3dm's to center of tile for Mapbox GL JS v3

2023-08-16: release 1.6.0, add experimental support for Mapbox GL JS v3

2023-06-20: release 1.5.5, fix issue when only 1 level is generated

2023-04-06: release 1.5.3, fix disappearing features

2023-04-04: release 1.5.2, fix query parameter

2023-03-27: release 1.5.1, add outlines support for multiple shaders

2023-03-15: release 1.5.0, adding options 'add_outlines' (default false) and 'default_color' (#FFFFFF)

2023-02-16: release 1.4.3, fix for implicit tiling - missing b3dm's on high z-levels

2023-02-02: release 1.4.2, fix subtree files generation

2023-02-01: release 1.4.1, fix global tool

2023-02-01: release 1.4, adding tree of subtree files support

2023-01-10: release 1.3, adding LOD support

2022-12-13: release 1.2.3, fixing parameter use_implicit_tiling

2022-08-30: release 1.2.2, fixing initial boundingbox issue

2022-08-29: release 1.2.1

  • Fixing debug boundingVolumes and query parameter;

  • Option 'use_implicit_tiling' default value changed from False to True;

2022-08-24: release 1.1: adding parameters sql_command_timeout (default: 30 seconds) and boundingvolume_heights (default: 0,100)

2022-08-23: release 1.0

Use a quadtree tiling method by default, fix skewed bounding volumes in Cesium.

MapBox GL JS support is discontinued at the moment.

Breaking changes:

  • removed: parameter -i, --idcolumn

  • removed: parameter -e, --extenttile

  • renamed: parameter implicit_tiling_max_features to max_features_per_tile

2022-08-09: release 0.16, fixing materials (MetallicRoughness and SpecularGlossiness)

2022-08-09: release 0.15, use 1 geometric error for implicit tiling

2022-07-20: release 0.14, adding 3D Tiles 1.1 implicit tiling option

2022-07-05: release 0.13, adding glTF asset copyright

2022-01-24: release 0.12, to .NET 6, fixing decimal symbols regional settings on Windows

2021-10-27: release 0.11.2, fixing non latin characters issue in batch table

2021-09-30: release 0.11, adding multiple attribute columns support. 0.11.1 contains bug fix for batch table length

2020-11-17: release 0.10, adding shader support PbrMetallicRoughness and PbrSpecularGlossiness + to .NET 5.0

2020-06-18: release 0.9.4, adding query parameter support (-q --query)

2020-05-07: release 0.9.3, rewriting tiling method

2019-11-18: release 0.8 adding -f, --featurespertile and -e, --extenttile options

2019-10-02: release 0.7 adding id column option (default 'id')

2019-09-02: release 0.6 adding batching option on single column (-a option)

2019-08-21: release 0.5.1 with fix for non trusted Postgres connection

2019-08-20: release 0.5 adds support for multiple colors

2019-08-15: release 0.4.4 improving roof colors

2019-08-15: release 0.4.3 change degenerated triangles detection + removal

2019-08-14: release 0.4.2 fixing roof colors + filter very small triangles (<0.01)

2019-08-13: release 0.4.1 with fix for roof colors (option -r)

2019-08-12: release 0.4 adding roof color column option (-r)

2019-08-01: release 0.3.3 with 2 colors

2019-07-09: release 0.3 using library SharpGLTF

2019-06-01: release 0.2.1 with some small fixes

2019-06-01: initial release 0.2

2019-05-01: initial release 0.1

pg2b3dm's People

Contributors

b-de-v avatar bertt avatar d1kkop avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pg2b3dm's Issues

Optimize queries/database connection

Currently the speed of pg2b3dm seems to be depending on the queries to the database. It seems some queries may be optimized or may benifit from indexes.

Performance retrieving geometry for b3dm

check performance retrieiving geometry per tile:

Currently:

select row_number, ST_AsBinary(geom1) from(SELECT row_number() over(), geom1 FROM(select ST_RotateX(ST_Translate(geom, 3887644.96479532*-1,332065.652563738*-1 , 5028604.16646635*-1), -pi() / 2) as geom1, ST_Area(ST_Force2D(geom)) AS weight FROM roofs_3d.roofs_extruded where ST_GeometryType(geom) =  'ST_PolyhedralSurface' ORDER BY weight DESC) as t) as p where row_number in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

Reduce b3dm tile size

In tool 3DBuilder (https://www.microsoft.com/en-us/p/3d-builder), it's possible to load a GLB file and repair/save it. When performing this repair on file 1.b3dm the GLB reduces in size from 473KB to 111KB (4 time smaller).

Q: is it possible to perform this repair also from code?

Alternative: run some kind of compression tool (using draco?) after generating tiles.

lod seems to assume to have 0

Is see this query passing by on a dataset that has lod levels 1 and 2 but not 0:

select exists(
	select geom 
	from results.extruded_3857_dst 
	where ST_Intersects(ST_Centroid(ST_Envelope(geom)), ST_MakeEnvelope(467395.56335918076, 6765013.961907677, 467895.56335918076, 6765513.961907677, 3857)) 
	and ST_GeometryType(geom) =  'ST_PolyhedralSurface' 
	and lod=0
)

The result is that no features are being exported since obviously no feature has lod=0

Is this seems to by not intentional since pg2b3dm first correctly finds the lod levels present as:
Detected 2 lod levels: [1,2]

Enable specular and emissive color as well

Currently only diffusecolor is set for the materials.
Having the option to add specular and emissive color on top of diffuse color would greatly enhance the visuals. Most BIM models do have a combination of the three.

Default extent maybe too large

Turns out that the tiles with a default extent of 2000 meters will grow up to 20 MB in size.
When setting it to 250 meters tiles tend not to exceed 2mb and mostly stick to around 700 k

support b3dm batching in MapBox GL JS

In release 0.6 the b3dm batching option is added, its working in Cesium (right click on building in https://geodan.github.io/pg2b3dm/sample_data/amsterdam/cesium/ and inspect the developer console) .

Work: add support for b3dm batching in MapBox GL JS viewer (https://geodan.github.io/pg2b3dm/sample_data/amsterdam/mapbox/.

The MapBox tiles at https://geodan.github.io/pg2b3dm/sample_data/amsterdam/mapbox/tiles already contain the batch information.

Batch order number is stored in the triangle vertices, see _BATCHID custom vertex attribute. The batch table is stored in the b3dm header, it looks like {"blockid":["0363100012181805","0363100012165029","0363100012171317","0363100012181781","0363100012175342","0363100012179660","0363100012180279","0363100012171641","0363100012182712","0363100012171855","0363100012179576","0363100012178404","0363100012171077","0363100012175828"]}

Add error handling

Add error handling for:

  • Invalid geometries;
  • Geometries that are not trianguled.

Q: should process completely stop when detecting invalid/not triangulated geometries or just ignore them and continue?

Proposal: Just stop the process when detecting invalid/not triangulated geometries with correct error message.

Crash halfway on itemCount 0 must be greater than or equal to 1

Command:

docker run \
	-v $(pwd)/data/tiles:/app/output \
	-it geodan/pg2b3dm \
	-h metis -U tomt -d maquette_nl -p 5433 \
	-t tmp.betterroofs_extruded 

output:

tool: pg2b3dm 0.3.1.0
Start processing....
Calculating bounding boxes...
Writing tileset.json...
Writing 24 tiles...
Progress: tile 7 - 29.17%
Unhandled Exception: System.ArgumentOutOfRangeException: itemCount 0 must be greater than or equal to 1.
Parameter name: itemCount
   at SharpGLTF.Guard.MustBeGreaterThanOrEqualTo[TValue](TValue value, TValue min, String parameterName)
   at SharpGLTF.Schema2.Accessor.SetData(BufferView buffer, Int32 bufferByteOffset, Int32 itemCount, DimensionType dimensions, EncodingType encoding, Boolean normalized)
   at SharpGLTF.Schema2.Accessor.SetVertexData(BufferView buffer, Int32 bufferByteOffset, Int32 itemCount, DimensionType dimensions, EncodingType encoding, Boolean normalized)
   at SharpGLTF.Schema2.Accessor.SetVertexData(MemoryAccessor src)
   at SharpGLTF.Schema2.Schema2Toolkit.CreateVertexAccessor(ModelRoot root, MemoryAccessor memAccessor)
   at SharpGLTF.Schema2.Schema2Toolkit.WithVertexAccessor(MeshPrimitive primitive, MemoryAccessor memAccessor)
   at SharpGLTF.Schema2.Schema2Toolkit.WithVertexAccessors(MeshPrimitive primitive, IEnumerable`1 memAccessors)
   at SharpGLTF.Geometry.PackedPrimitiveBuilder`1.CopyToMesh(Mesh dstMesh, Func`2 materialEvaluator)
   at SharpGLTF.Geometry.PackedMeshBuilder`1.CreateSchema2Mesh(ModelRoot root, Func`2 materialEvaluator)
   at SharpGLTF.Schema2.Schema2Toolkit.CreateMeshes[TMaterial,TvP,TvM,TvS](ModelRoot root, Func`2 materialEvaluator, MeshBuilder`4[] meshBuilders)
   at pg2b3dm.Program.WriteB3dm(List`1 geomrecords, Int32 tile_id) in /src/pg2b3dm/Program.cs:line 171
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Crash when not using attributes -a

Sample without -a option: -h localhost -U postgres -c geom_triangle -t delaware_buildings_3857_no_lod -d postgres -i id -e 2000 -r colors -o tiles

Program is crashing:

%Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at pg2b3dm.Program.GetAttributes(List`1 geometries) in D:\dev\github.com\geodan\pg2b3dm\src\pg2b3dm\Program.cs:line 162
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, String idcolumn, Double[] translation, List`1 tiles, Int32 epsg, String outputPath, Int32 counter, Int32 maxcount, String colorColumn, String attributesColumn, String lodColumn) in D:\dev\github.com\geodan\pg2b3dm\src\pg2b3dm\Program.cs:line 143
   at pg2b3dm.Program.<>c.<Main>b__1_0(Options o) in D:\dev\github.com\geodan\pg2b3dm\src\pg2b3dm\Program.cs:line 101
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at pg2b3dm.Program.Main(String[] args) in D:\dev\github.com\geodan\pg2b3dm\src\pg2b3dm\Program.cs:line 24

D:\dev\github.com\geodan\pg2b3dm\src\pg2b3dm\bin\Debug\netcoreapp3.1\pg2b3dm.exe (process 26104) exited with code 0.

B3dms not rendered in Cesium when using SharpGLTF

B3dms are not rendered when using SharpGLTF library.

Error in Cesium:

"[.WebGL-0000024C2480EB90]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0"

When loading in Cesium the GLTF created with SharpGLTF (so without b3dm tile), rendering goes well.

Crash on timeout

encountered a stalling process on a pgsql timeout:
Coincidentally the swap space of the machine ran full but not sure if this is related.

Writing 1421 tiles...
Progress: tile 253 - 17.80%
Unhandled Exception: Npgsql.NpgsqlException: Exception while reading from stream ---> System.IO.IOException: Unable to read data from the transport connection: Connection timed out. ---> System.Net.Sockets.SocketException: Connection timed out
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass31_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
   --- End of inner exception stack trace ---
   at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass31_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at pg2b3dm.BoundingBoxRepository.GetGeometrySubset(NpgsqlConnection conn, String geometry_table, String geometry_column, Double[] translation, Int32[] row_numbers, String colorColumn) in /src/pg2b3dm/BoundingBoxRepository.cs:line 80
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, Double[] translation, Node node, String outputPath, String colorColumn) in /src/pg2b3dm/Program.cs:line 85
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, Double[] translation, Node node, String outputPath, String colorColumn) in /src/pg2b3dm/Program.cs:line 98
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, Double[] translation, Node node, String outputPath, String colorColumn) in /src/pg2b3dm/Program.cs:line 98
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, Double[] translation, Node node, String outputPath, String colorColumn) in /src/pg2b3dm/Program.cs:line 98
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, Double[] translation, Node node, String outputPath, String colorColumn) in /src/pg2b3dm/Program.cs:line 98
   at pg2b3dm.Program.WriteTiles(NpgsqlConnection conn, String geometryTable, String geometryColumn, Double[] translation, Node node, String outputPath, String colorColumn) in /src/pg2b3dm/Program.cs:line 98
   at pg2b3dm.Program.<>c.<Main>b__2_0(Options o) in /src/pg2b3dm/Program.cs:line 73
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at pg2b3dm.Program.Main(String[] args) in /src/pg2b3dm/Program.cs:line 79

Rotated tiles

At the moment the tiles are rotated:

cesium_rotated

Q: Is it possible to generate and visualize tiles without the rotation, like:

cesium_not_rotated

gltf warnings

when validating the gltf ((https://github.khronos.org/glTF-Validator/)) there are lots of warnings,
for example 1.b3dm :

{
    "uri": "1.glb",
    "mimeType": "model/gltf-binary",
    "validatorVersion": "2.0.0-dev.2.7",
    "validatedAt": "2019-06-19T12:35:53.273Z",
    "issues": {
        "numErrors": 16384,
        "numWarnings": 0,
        "numInfos": 0,
        "numHints": 0,
        "messages": [
            {
                "code": "ACCESSOR_INVALID_FLOAT",
                "message": "Accessor element at index 198 is NaN or Infinity.",
                "severity": 0,
                "pointer": "/accessors/1"
            },
            {
                "code": "ACCESSOR_INVALID_FLOAT",
                "message": "Accessor element at index 199 is NaN or Infinity.",
                "severity": 0,
                "pointer": "/accessors/1"
            },
            {
                "code": "ACCESSOR_INVALID_FLOAT",
                "message": "Accessor element at index 200 is NaN or Infinity.",
                "severity": 0,
                "pointer": "/accessors/1"
            },

question

image
Follow your documentation step by step, but hint at the problem.How can I solve this problem?The data was downloaded from the link you provided.

Add getting started manual

Add getting started manual:

  • Get buildings data from OpenstreetMap;
  • Import buildings in PostGIS;
  • Process buildings (triangulate, project);
  • Run tiling pg2b3dm;
  • View results in Cesium.

Add colors

Add colors to buildings.

Options:

  • add r,g,b color values to parts of glb
  • drape image (aerial picture) over buildings

Tileset.json: round boundingvolume values

remove exponential values for boundingvolume

sample:

 "boundingVolume": {
      "box": [
        9.3132257461547852E-10,
        15.165075950091705,
        -4.6566128730773926E-10,
        1130.6094067522015,
        0.0,
        0.0,
        0.0,
        2168.6548668255564,
        0.0,
        0.0,
        0.0,
        1272.8861378305592
      ]
    }

Missing tiles?

When running pg2b3dm and py3dtiles on table tmptom.betterroofs_extruded (containing 4212 geometries) fewer tiles are generated then expected.

pg2b3dm: generates 56 tiles
py3dtiles: generates 49 tiles

With max 20 geometries per tiles, we expect at least 4212/20 = 210 tiles

Visual inspection result:

pg2b3dm:

pg2b3dm

py3dtiles:

py3dtiles

Adding textures

Experiment with adding textures to tiles (like air or building pictures)

Commandline parameters renaming

Commandline parameters renaming proposal:

1] Geometry column
From:
-c, --column (Default: geom) Geometry column name
To:
-g -geometrycolumn (Default: geom) Geometry column name

2] Color column
From:
-r , --roofcolorcolumn (default: '') color column name
To:
-c , -colorcolumn (default: '') color column name

generate tileset from shapefile failed

i follow this guide https://github.com/Geodan/pg2b3dm/blob/master/getting_started.md#reproject-geometry-to-3857 to generate tileset

when i run docker run -it --network mynetwork bertt/tesselate_building -h some-postgis -U postgres -d postgres -t delaware_buildings -i geom_3857 -o geom_triangle_3857 --idcolumn ogc_fid --stylecolumn style --colorscolumn colors,i got such error

Unhandled exception. Npgsql.PostgresException (0x80004005): XX000: transform: couldn't project point (-8.40839e+06 4.74422e+06 0): latitude or longitude exceeded limits (-14)
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2797
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 568
   at tesselate_building_sample_console.Program.<>c__DisplayClass1_0.<Main>b__0(Options o) in /src/tesselate_building_sample_console/Program.cs:line 65
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at tesselate_building_sample_console.Program.Main(String[] args) in /src/tesselate_building_sample_console/Program.cs:line 78
  Exception data:
    Severity: ERROR
    SqlState: XX000
    MessageText: transform: couldn't project point (-8.40839e+06 4.74422e+06 0): latitude or longitude exceeded limits (-14)
    File: lwgeom_pg.c
    Line: 128
    Routine: pg_error

plz help

Tiles generated but not in correct location

Hi, I followed the "Getting started" section and used Delaware data to start with.
No problems occurred during conversion and I can get tileset.json and list of b3dm files.

After that, I modified the sample_data/index_cesium.html file to use the above tileset but the buildings were floating in space.

I noticed that the projection need to be 4978 as mentioned in #35. I recreated database table by using 4978 projection but I still cannot get the building displayed in Delaware.
Here is a screenshot during loading the Cesium viewer, I can see some buildings there but they are in somewhere around South America.
cesium

This is the tileset json in Chrome development tool.
tileset

And here are some details of my development machine:
Windows 10 Pro
Docker Desktop 2.2.0.3
GDAL 2.4.3 (for ogr2ogr)

Can anyone give me some advice? Thank you!

Colors on wall instead of roof

Since version 0.4.4.0 it seems that the roofcolor is assigned to SE facing walls only.

image
(color shows almost black on picture)

Don't pause after finishing

Currently the program requests a user to 'press a key' after finishing. This is blocking it from being used in scripting.

Max-Z of every tile seems to be set to max-Z of whole dataset

This causes all tiles to be very large, especially when there's an error in the data, and consequently this gives unexpected results when taking the geometricError into account.
Didn't check but Min-Z has likely the same behaviour but less important.

tileset.json: small difference with py3dtiles

difference in values for boundingvolume.x: 1695.914 versus 1130.6094067522015,

pg2b3dm:

 "boundingVolume": {
      "box": [
        9.3132257461547852E-10,
        15.165075950091705,
        -4.6566128730773926E-10,
        1130.6094067522015,
        0.0,
        0.0,
        0.0,
        2168.6548668255564,
        0.0,
        0.0,
        0.0,
        1272.8861378305592
      ]
    }

py3dtiles:

    "boundingVolume": {
      "box": [
        0,
        15.165,
        0,
        1695.914,
        0,
        0,
        0,
        2168.655,
        0,
        0,
        0,
        1272.886
      ]

Missing tiles #2?

table tmptom.betterroofs_extruded, 4304 polysurfacehedrals

py3dtiles generates 411 tiles
pg2b3dm generates 59 tiles

visual inspection:

py3dtiles:

py3dtiles

pg2b3dm:

pg2b3dm

Batch table binary

Currently the batch information is written in clear json in the b3dm header.

Improvement: write binary batch table field instead of json text and test if all still works.

Expected result: smaller tiles

Alpha channel and colors

Hi all,
i am having some trouble trying to get working b3dm tiles along with alpha channel.

Following the docs alpha channel is meant to be working.
if i set the style column as

'{ "walls": "#A6D92400", "roof":"#A67D2900", "floor":"#A6D75200"}'

i am expecting to have those colors 60% transparent.

Any clue to what am i doing wrong?

Thanks,
A.

Refine: replace

At the moment, refine=add is used in tileset.json. Can we switch to refine=replace instead ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.