GithubHelp home page GithubHelp logo

geodan / mapbox-3dtiles Goto Github PK

View Code? Open in Web Editor NEW
277.0 277.0 63.0 42.82 MB

3D Tiles implementation using Mapbox GL JS custom layers

License: BSD 3-Clause "New" or "Revised" License

JavaScript 95.67% HTML 4.33%

mapbox-3dtiles's Introduction

mapbox-3dtiles

3D Tiles implementation using Mapbox GL JS custom layers

See https://geodan.github.io/mapbox-3dtiles/ for a working demo.

Screenshot

This is a proof-of-concept implementation of a 3D Tiles viewer as a Mapbox GL JS custom layer. WebGL rendering is implemented using three.js. Only Web Mercator (EPSG:3857) tilesets are supported, as this is the projection mapbox uses. Earth-centered earth-fixed tilesets are explicitly not supported. Tilesets used for testing were generated using pg2b3dm, using a PostGIS database with EPSG:3857 geometries.

This is by no means a complete implementation of the 3D Tile specification. Currently the following features are supported:

  • Geometric error based tile loading
  • Replacement and additive refinement
  • Only Box bounding volumes are supported
  • Tile transforms
  • External tilesets
  • Tile types:
    • Batched 3D Model (b3dm)
    • Point Cloud (pnts): basic implementation

The following features are not supported at this time:

  • Any coordinate system other than EPSG:3857
  • Region and sphere bounding volumes
  • Viewer request volumes
  • Instanced 3D Model (i3dm) tiles
  • Composite (cmpt) tiles
  • 3D Tile Styles

Instructions

In a directory on your webserver run the folowing commands:

git clone https://github.com/Geodan/mapbox-3dtiles.git
cd mapbox-3dtiles
npm install
cd ./ahn
tar xvf ahn_points.tar.gz
cd ../rotterdam
tar xvf rotterdam_3dtiles_small.tar.gz

Next, copy file "apikeys.js.example" to "apikeys.js" and add your mapbox token. Point your browser to the directory in question and you should see a basic viewer with 3d tiles content.

Creating tilesets

Tilesets can be created using pg2b3dm, using a PostGIS database table as source. The PostGIS table should contain 3D geometries in EPSG:3857 projection.

Example query creating extruded 3D buildings in EPSG:3857:

DROP TABLE IF EXISTS <schema>.<output_table>;
CREATE TABLE <schema>.<output_table> AS (
	WITH extent AS (
		SELECT ST_MakeEnvelope(<minx>, <miny>, <maxx>, <maxy>, <input_srid>) geom
	),
	footprints AS (
		SELECT a.id AS id, a.height, a.geom
		FROM <schema>.<input_table> a, extent b
		WHERE ST_Intersects(a.geom, b.geom)
	)
	SELECT id, ST_Force3D(ST_Extrude(ST_Transform(ST_MakeValid(geom), 3857), 0, 0, height)) AS geom
	FROM footprints
);
DELETE FROM <schema>.<output_table> WHERE geom IS NULL; -- cleanup
DELETE FROM <schema>.<output_table> WHERE ST_GeometryType(geom) NOT LIKE 'ST_PolyhedralSurface'; -- cleanup

Creating tileset using pg2b3dm:

pg2b3dm -h <my_host> -U <my_user> -d <my_database> -p <my_port> -c <geom_column> -t <my_schema.my_table>

For more information, see the pg2b3dm documentation.

Creating tileset from point cloud:

Pointcloud data is not yet supported by pg2b3dm and needs to be exporterd with an earlier tool called py3dtiles

py3dtiles convert --srs_in <srs_in> --srs_out 3857 --out <tileset_name> pointcloud.las

For more information, see the py3dtiles documentation.

mapbox-3dtiles's People

Contributors

anneb avatar dependabot[bot] avatar kanviner avatar tomvantilburg 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-3dtiles's Issues

Collaboration opportunity?

Hi, very nice demo, thanks for sharing.

We are also developing a framework-independent 3d tile loader (part of our loaders.gl effort), you can see results developing at:

A few remarks:

  • We created loaders.gl to enable collaboration/interoperability with others developers, such as yourselves.
  • As you have probably discovered, implementing the full 3d tiles standard is a big effort and as such, best shared.
  • If collaboration sounds interesting, happy to connect.

Also:

  • Could you clarify the licenses on your open source code, ideally by adding a LICENSE file to your repo? As it stands, it is not clear whether we can use/copy/fork your code
  • One idea would be to port your mapbox/THREE.js sample to use the loaders.gl/3d-tiles loader and include as a demo on loaders.gl website (with attribution to yourselves of course!)
  • If we can't use your implementation as a base due to licensing issues that is OK, we'd likely roll our own, but why reinvent the wheel when working with open source?

npm install failed

npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR! network request to https://repo.geodan.io/repository/npm/mapbox-gl failed, reason: socket hang up
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\wbz\AppData\Roaming\npm-cache_logs\2020-06-27T14_17_15_655Z-debug.log

How to load cesium 3dtile

I am using Metashape for modeling, but the exported 3D tiles cannot be loaded directly. May I know how to handle this? Thank you very much

External tilesets?

I did an experiment with external tilesets see https://bertt.github.io/mapbox_3dtiles_samples/external.html

In this sample parent file external.json (https://bertt.github.io/mapbox_3dtiles_samples/external.json) is loaded, after that I can see child
tileset.json (https://bertt.github.io/mapbox_3dtiles_samples/tileset.json) is also loaded. But nothing is drawn on the map :-(

The same trick works in Cesium viewer.

When directly using child tileset https://bertt.github.io/mapbox_3dtiles_samples/tileset.json it works as expected (see https://bertt.github.io/mapbox_3dtiles_samples/index.html)

Add debugging functionality

Add debugging functions, something like in Cesium: debugShowBoundingVolume, debugColorizeTiles, debugShowGeometricError, debugShowRenderingStatistics

Load textured 3d models

Hi Tom,

Would this implementation work with a textured 3d model that has been presented as a 3D tile service?

External tileset broken?

I'm using latest version of develop branch, testing external tileset.json function. I encounter the following error when using external.json (which references tileset.json):

Mapbox3DTiles.js:53981 ReferenceError: TileSet is not defined
    at ThreeDeeTile.load (Mapbox3DTiles.js:53964)
    at ThreeDeeTile.checkLoad (Mapbox3DTiles.js:54186)
    at ThreeDeeTile.checkLoad (Mapbox3DTiles.js:54192)
    at Mapbox3DTilesLayer.loadVisibleTiles (Mapbox3DTiles.js:59708)
    at Mapbox3DTiles.js:59799

Working site (references tileset.json):
https://bertt.github.io/mapbox_3dtiles_samples/samples/external/index_working.html#15.62/39.160792/-75.52649/0/45

Not working site (references external.json which references tileset.json):
https://bertt.github.io/mapbox_3dtiles_samples/samples/external/index_not_working.html#15.62/39.160792/-75.52649/0/45

The sample was working before upgrading to the latest commit in develop branch (old version was using mapbox-gl 1.9)

Error after removing layer

All Mapbox3DTiles layers are broken after removing a Mapbox3DTiles layer from the map, this has probably something to do with: https://github.com/Geodan/mapbox-3dtiles/blob/master/Mapbox3DTiles.mjs#L691

Uncaught TypeError: this.cameraSync is null
    loadVisibleTiles Mapbox3DTiles.mjs:72
    updateCallback Mapbox3DTiles.mjs:117
    updateCamera CameraSync.mjs:120
    CameraSync CameraSync.mjs:38
    fire mapbox-gl.js:31
    _fireEvent mapbox-gl.js:35
    _fireEvents mapbox-gl.js:35
    _updateMapTransform mapbox-gl.js:35
    _applyChanges mapbox-gl.js:35
    _requestFrame mapbox-gl.js:35
    run mapbox-gl.js:35
    _render mapbox-gl.js:35
    _frame mapbox-gl.js:35
    frame mapbox-gl.js:31
    triggerRepaint mapbox-gl.js:35
    _render mapbox-gl.js:35
    _frame mapbox-gl.js:35
    frame mapbox-gl.js:31
    triggerRepaint mapbox-gl.js:35
    _update mapbox-gl.js:35
    _updateMapTransform mapbox-gl.js:35
    _applyChanges mapbox-gl.js:35
    _requestFrame mapbox-gl.js:35
    run mapbox-gl.js:35
    _render mapbox-gl.js:35
    _frame mapbox-gl.js:35
    frame mapbox-gl.js:31

Instanced 3D Tiles (i3dm)

Add support for instanced 3D Tiles (i3dm).

Specs: https://github.com/CesiumGS/3d-tiles/tree/master/specification/TileFormats/Instanced3DModel

Working sample in Cesium:

see https://bertt.github.io/cesium_3dtiles_samples/samples/instanced/

Contains 1 tile (tree.i3dm) with tree.glb and two instances defined. Right clicking displays batch information in console (Height: Height: 101 or 102)

Not working sample in MapBox:

see https://bertt.github.io/mapbox_3dtiles_samples/samples/instanced/

Content tree.i3dm:

i3dm file: tree.i3dm
i3dm header version: 1
i3dm GltfFormat: 1
i3dm header magic: i3dm
i3dm featuretable json: {"INSTANCES_LENGTH":2,"POSITION":{"byteOffset":0},"EAST_NORTH_UP":true}
i3dm instances length: 2
i3dm batch table json: {"Height":[100,101]}
positions: <-8407347, 4743739.5, 38.29>,<-8406181, 4744924, 38.29>
normal ups: : -
normal rights: : -
Scale non-uniform: : -
Scales: -
Batch ids: : -

Question about intersectsBox and crs transform.

Hi, I'm new to 3d tiles and trying to use this lib to display my cesium asset tiles, and found during the checkLoad, there is no boundingvolume intersets with the camera frustum. Below are my understanding toward this issue and how this lib works, and I wish you can help me to clarify some of the doubts and point a direction. Thank you so much.

To my understanding, this is how 3d tile works: The vertex info in b3dm/pnts are merely forming meshes in a non-georeferenced Cartesian coordinate system. It is the boundingvolume that defines its geo location and bounding. And the bounding volume can be in any crs or even non georeferenced(in 3d scene Cartesian coordinate system). The transform is applied to project children's crs to the parent's crs, or from root crs to base map crs(in this case, web mercator EPSG:3857 for mapbox).

So I assume the problem with my case lies in the crs. The cesium ion assets are not in EPSG3857(There is no crs info in the tileset.json, I assume it is in EPSG: 4979 since it is recommended in the 3d tile standard), and the transform provided is not from 4979 to 3857.

So there can be two approaches:

  1. Transform the boundingvolume into 3857 to make it consistent with mapbox crs, and remove the transform info(or use default identity matrix).
  2. Leave the boundingvolume as it is, and change the transform info to the transform needed from the boundingvolume's crs to 3857.

I've tried gdal and epsg.io to transform 4979 to 3857, but failed. And I don't really have a clue about how to form the transform matrix needed from 4979 to 3857.

Could you please help to clarify the doubt and shed some light upon this issue?
Thank you.

Some Questions

Hey,
really cool work!

i have some basic questions:

  • is this a fork of a mapbox version, or like a plugin?
  • Could i use it with any mapbox version, also like the new v2? If so, would it also working with the new elevation model?
  • are the 3D models click, hover able?
  • are maybe also styleexpression possible? or some way to color the buildings by some function in different way?

Draco

When using glTF's with Draco compression there is an error:

THREE.GLTFLoader: No DRACOLoader instance provided.
at new GLTFDracoMeshCompressionExtension (GLTFLoader.js:556)
at GLTFLoader.parse (GLTFLoader.js:184)
at ThreeDeeTile.load (Mapbox3DTiles.js:295)

Sample:

https://bertt.github.io/mapbox_3dtiles_samples/draco.html

Prepare presentation FOSS4G 2019

  • Add packages with yarn (threejs, mapboxgs)
  • Build new data with pg2b3dm (Amsterdam)
  • Change readme (packages, pg2b3dm etc)
  • Upgrade to newest threejs and mapbox versions
  • Add workaround for z-scaling (x1.5?) in documentation

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.