Geodan / i3dm.export

Export 3D Instanced Tiles from PostGIS table
MIT License
42 stars 22 forks source link

i3dm tiles cannot be loaded into Cesium #15

Closed fnicollet closed 3 years ago

fnicollet commented 3 years ago

Hello,

I am trying to use the tiles generated by i3dm in Cesium JS, but it seems that the tileset.json pyramid is not correct, it is somewhere in the ocean around india while my dataset is in France. Here is a test in the Cesium Sandcastle:

var viewer = new Cesium.Viewer("cesiumContainer");
var tileset = new Cesium.Cesium3DTileset ({
    url: "https://dev.business-geografic.com/bdx-3d-data/i3dm/arbres/tileset.json",
});
viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset);

tileset.readyPromise.then (function (tileset) {
    console.log("DATASET i3DM loaded");

});

Link for live demo: https://sandcastle.cesium.com/#c=bZHBTgIxEIZfpdnTmkAbww0XIgFvGk3YeOql2w7LaLfddLqLYHx3y4IJKr20M/N/07/TXgXWI+wgsBlzsGNLIOwa/jrkcpnpIV56FxU6CDK7uZOuT1RECwTxN3baJqvyXMw/pZOxC3bKZLaNsaWpEAZ6XnWU2hGNa/B1UBvUXPtGVOZjPDFjo6ISODGNUKEKQOJ8GX8j72Q2ku5rsDGY5KTBAW8DNhixB+LKmPxMXMgO3jelvyxI99M3gDL7l+AbJOBxC47lm87piD6dfgg2PEZ7R94Ct75O41ktysX6oWQ4WT0x65UBcxqRjGeT2SgrKO4tzKVjw7rHpvUhsjSWnHMRoWmtiumVVaffkxlNdASP0kJcooXBnqGZXfkVpq0iSpVNZ+0aDyCzeSGS/h96NImufu4hWLU/yra388dTknNeiBReJ6P3tlLhT+dv

When i generated the tiles, I only had this log:

Exporting i3dm's from public.arbres_instances...
Tile extent: 1000
Set extent: 10000
Potential tiles: 4000 in 40 sets.

The postgis dataset is projected in 4326:

                 st_astext
-------------------------------------------
 POINT(-0.580255753718069 44.8414808634925)
 POINT(-0.58024728846137 44.8413548361828)
 POINT(-0.580249814770417 44.8412793588877)
 POINT(-0.580250249559187 44.8412109737063)
...

Do you know what could be the issue here ?

Thanks! Fabien

fnicollet commented 3 years ago

If I compare your sample: https://bertt.github.io/mapbox_3dtiles_samples/samples/instanced/tileset.json and what i generated: https://dev.business-geografic.com/bdx-3d-data/i3dm/arbres/tileset.json

it seems that I don't have a "transform" node in the root node, while you have:

"transform": [
      1.0,
      -0.0,
      0.0,
      0.0,
      0.0,
      1.0,
      0.0,
      0.0,
      0.0,
      0.0,
      1.0,
      0.0,
      518020.625,
      6881447.0,
      0.0,
      1.0
    ]

And 518020.625, 6881447.0 are the EPSG:3857 coordinates for north of Harlem, which is the correct location for your dataset

fnicollet commented 3 years ago

Tried it in mapbox-gl-js with your sample page, I get an error:

Mapbox3DTiles.js:53932 ReferenceError: TileSet is not defined
    at ThreeDeeTile.load (Mapbox3DTiles.js:53915)
    at ThreeDeeTile.checkLoad (Mapbox3DTiles.js:54138)

It seems to crash while trying to load a "tileset json child" (Class "TileSet" does not exist which might be another issue)

Thanks,

bertt commented 3 years ago

Note: cesium as client is not supported

jailln commented 3 years ago

I think this tool could be of great interest for the geospatial community since to my knowledge there is currently no open tool available to create 3D Tiles tilesets with i3dm tiles. However, 3D Tiles is a standard format that is client-agnostic, therefore could you elaborate on why the produced tilesets are constrained to mapbox-gl-js ?
In addition, the tileset generated by Fabien cannot be loaded in mapbox-gl-js. Do you have any idea why ?

Thanks.

bertt commented 3 years ago

We have build this tool specifically for using i3dm tiles in MapBox GL JS. Technically it should be possible to add Cesium support, but it's not trivial because of mathematics involved.

bertt commented 3 years ago

Did you follow the getting started guide? https://github.com/Geodan/i3dm.export/blob/main/docs/getting_started.md Roughly the same procedure should be needed for your table public.arbres_instances

fnicollet commented 3 years ago

Yes, I followed the getting started step-by-step to generate public.arbres_instance. The only difference was that I didn't use this line:

delete from traffic_signs_instances where st_x(geom) < 4.5 or st_x(geom)>5.0;

Which must be only for your dataset I guess? And i serve the file with a simple Apache Web server, not a python server, but that shouldn't change anything, it is just serving static files

Fabien

bertt commented 3 years ago

yes that line is to delete some outliers in the sample data. Is the generated mapbox tileset available online somewhere?

fnicollet commented 3 years ago

You can load the data via this URL, if that's what you mean: https://dev.business-geografic.com/bdx-3d-data/i3dm/arbres/tileset.json The URL and the files are all on a public server, so you can test locally

bertt commented 3 years ago

ok, and the mapbox viewer (with the error) is there as well?

fnicollet commented 3 years ago

ah no, sorry, i'll upload it if that helps you, just a minute

fnicollet commented 3 years ago

Here is the page with the mapbox-gl viewer and your Mapbox3DTiles.js file from the demo page, to reproduce the issue: http://dev.business-geografic.com/github-i3dm/index-i3dm.html

bertt commented 3 years ago

what happens if you change the reference to tileset.json to relative url (like url: 'tileset.json')

fnicollet commented 3 years ago

moved the files next to tileset.json and changed to a relative URL, no change: https://dev.business-geografic.com/bdx-3d-data/i3dm/arbres/index-i3dm.html

bertt commented 3 years ago

looks like the client code is a bit older to support the sub tileset.json... first thing I would try is update the client code to latest version of https://github.com/Geodan/mapbox-3dtiles

fnicollet commented 3 years ago

Update to latest dist, changed the constructor to let tileslayerTree = new Mapbox3DTiles.Layer( {, added THREE.js but getting error:

Error: i3dm tiles not yet implemented

https://dev.business-geografic.com/bdx-3d-data/i3dm/arbres/index-i3dm.html#18.54/44.835528/-0.584797/0/45

bertt commented 3 years ago

can you try develop branch?

fnicollet commented 3 years ago

The develop branch is not built, there is no dist. Can you please try it on your end? Thanks,

bertt commented 3 years ago

I've updated https://github.com/Geodan/i3dm.export/blob/main/docs/Mapbox3DTiles.js to the code from develop branch. Error is now gone but so far I didn't see any tree show up.

bertt commented 3 years ago

There is now a CORS error (see https://geodan.github.io/i3dm.export/samples/bordeaux/) to retrieve https://dev.business-geografic.com/bdx-3d-data/i3dm/arbres/scene.bin . Is this a glTF bin file? Normally the i3dm references a GLB file (or embed the GLB).

fnicollet commented 3 years ago

Yes, i referenced a GLTF file for this processs (I didn't have a GLB file handy). I added the scene.bin file and now, the tree magically appear on your example ! It still doesn't load properly in Cesium, maybe it is a projection issue (as you read the i3dm file with your own code, I guess you read what you produced). The only i3dm tileset.json I can find to compare (which load fine in Cesium) is: https://github.com/CesiumGS/3d-tiles-samples/blob/master/tilesets/TilesetWithTreeBillboards/tileset.json

The coordinates are wildly different, maybe you use 3857 while they use 4326 ? I would need to check the spec on that

bertt commented 3 years ago

Great I see now the trees too:

Screenshot 2021-01-20 at 21 57 02

Note: creating tileset for Cesium is not supported in this tool. Cesium uses an other system (ECEF - earth centric earth fixed) so all the coordinates are different.

fnicollet commented 3 years ago

ah thanks for the hint. Do you think it could be difficult to add as an option to your program ? If it seems feasable, I could try a PR.

bertt commented 3 years ago

Adding Cesium support is not on the roadmap. It's quite a challenge to get it right but feel free to send PR's.

fnicollet commented 3 years ago

Thanks a lot for your help, i'll close this issue for now as at the moment, generated tiles are not meant to be loaded in Cesium

MortezaYaqubkhani commented 3 years ago

Hi bertt,

I've tried to do the steps based on your guidance. I did the first part (creating sample data set in SQL and run the tool on the command line). The files (tilesets and i3dm files) are stored on local storage. It seems that there is a problem with the tilesets when I try to open the Html file (There is no tree on the map) and there are two errors in the console (. I even tried to run your outcome example from the output folder and saw the same error in the console. Is this error have anything to do with storing tileset and .i3dm files on the local storage? Could you please take a look and see if there is anything I can do? image

bertt commented 3 years ago

did you start a webserver? btw: can you open new issues for these kind of questions?

fnicollet commented 3 years ago

Bert is right, you need a local webserver (typically a simple Apache webserver or one in Python) to host your file, so that your webpage and i3dm files can be accessed through a URL like http://localhost/xxxx, otherwise, the web browser will prevent access to anything with the file:// protocol for security reasons.

On Mon, 3 May 2021, 20:21 Bert Temme, @.***> wrote:

did you start a webserver? btw: can you open new issues for these kind of questions?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Geodan/i3dm.export/issues/15#issuecomment-831441886, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJO3IKR2EZ7FM5UAOVJALTTL3SS7ANCNFSM4WKZGCWA .

MortezaYaqubkhani commented 3 years ago

@bertt @fnicollet Thanks for the tip!

MortezaYaqubkhani commented 3 years ago

did you start a webserver? btw: can you open new issues for these kind of questions?

Sure! Will do it.

Regards Morteza