Need help with CityJSON Viewer - Able to display just one building but unable to display all buildings using CreatePolyhedron functionality

So I have this extracted CityJSON building (B-201391182746-80FE6BE00A9C) from the Montreal dataset found at Datasets - CityJSON .

I can display it when it is extracted, but when I try to loop through the entire dataset I get the following error on chrome:

error:  TypeError: Cannot read property '0' of undefined
    at Function.$i.a.CreatePolyhedron (babylon.min.js:16)
    at Function.e.CreatePolyhedron (babylon.min.js:16)
    at Function.e.CreatePolyhedron (babylon.min.js:16)
    at createScene (cities-viewer.js:192)
    at cities-viewer.js:216

On firefox I get:

error:  TypeError: _.vertex[_.face[M][O]] is undefined
    CreatePolyhedron http://localhost:5555/public/js/babylon.min.js:16
    CreatePolyhedron http://localhost:5555/public/js/babylon.min.js:16
    CreatePolyhedron http://localhost:5555/public/js/babylon.min.js:16
    createScene http://localhost:5555/public/js/cities-viewer.js:192
    onFileChange http://localhost:5555/public/js/cities-viewer.js:216
    promise callback*onFileChange http://localhost:5555/public/js/cities-viewer.js:19

Here is an example playground: https://www.babylonjs-playground.com/#YGFJU8#1
You just have to zoom out and you should see the building.
When you uncomment the entire dataset and comment out the extracted building and try to run it you can see the error.

I am console logging both the faces, extracted vertices and the entire vertices array. You can see that they are the same but for some reason it doesn’t work when I try with the entire dataset instead of the extracted building.

What can I try to fix it? What are the possible reasons this happens?

There is a problem in the vertex indices used by the faces.

For the first object, faces[0] == 22432 whereas there are only 141 vertices. It seems you forget to update the vertex indices in the extractFacesAndVertices function.

1 Like