Skip to content

Commit

Permalink
Fix glb converter
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsdukai committed Aug 30, 2022
1 parent 09b0b2e commit 9ced881
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
25 changes: 18 additions & 7 deletions cjio/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 9ced881

Please sign in to comment.