From 9ced88127b5e6039df529d1a16883a69d4f5effd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Dukai?= Date: Tue, 30 Aug 2022 10:13:33 +0200 Subject: [PATCH] Fix glb converter --- CHANGELOG.md | 6 +++++- cjio/convert.py | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4e675..6de104c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Added - Subset more than one CityObject type (#9) - `models.Geometry.reproject()` for reprojecting dereferenced geometry boundaries +- Read from `stdin` and save to `stdout` +- `--suppress_msg` to suppress all messages. Required when saving to `stdout` ### Fixed - Subset with BBOX does not modify the input model anymore (#10) @@ -13,15 +15,17 @@ - `texture` and `material` are correctly removed from the geometries of the CityObjects with `textures/materials_remove` - `vertex-texture` is removed from the CityJSON with `textures_remove` - Docker image build (#77, #132) +- Other minor fixes ### Changed - Export format is an argument, not an option (#35), e.g. `cjio ... export obj out.obj` - NumPy is a hard requirement - Require pyproj >= 3.0.0 (#142) +- Refactor warnings and alert printing (#143) ## [0.7.4] - 2022-06-20 ### Fixed -- crash wiht new version of Click (>=8.1) (#140) +- crash with new version of Click (>=8.1) (#140) ### Added - templates for bug reporting diff --git a/cjio/convert.py b/cjio/convert.py index 1c9579b..c800fa2 100644 --- a/cjio/convert.py +++ b/cjio/convert.py @@ -174,17 +174,25 @@ def to_glb(cm): triList = [] for shell in geom['boundaries']: for face in shell: - tri = geom_help.triangulate_face(face, vertexlist) - for t in tri: - triList.append(list(t)) + tri, success = geom_help.triangulate_face(face, vertexlist) + if success: + for t in tri: + triList.append(list(t)) + else: + # TODO: logging + print(f"Failed to triangulate face in CityObject {theid}") trigeom = (flatten(triList)) elif (geom['type'] == 'MultiSurface') or (geom['type'] == 'CompositeSurface'): triList = [] for face in geom['boundaries']: - tri = geom_help.triangulate_face(face, vertexlist) - for t in tri: - triList.append(t) + tri, success = geom_help.triangulate_face(face, vertexlist) + if success: + for t in tri: + triList.append(t) + else: + # TODO: logging + print(f"Failed to triangulate face in CityObject {theid}") trigeom = (flatten(triList)) flatgeom = trigeom forimax.append(flatgeom) @@ -199,7 +207,10 @@ def to_glb(cm): # Need to swap the axis, because gltf uses a right-handed coordinate # system. glTF defines +Y as up, +Z as forward, and -X as right; # the front of a glTF asset faces +Z. - vtx_np[i] = np.array((vertexlist[v][1], vertexlist[v][2], vertexlist[v][0])) + try: + vtx_np[i] = np.array((vertexlist[v][1], vertexlist[v][2], vertexlist[v][0])) + except IndexError as e: + print(i, v) vtx_idx_np[i] = i bin_vtx = vtx_np.astype(np.float32).tostring() # convert geometry indices to binary