Skip to content

Commit

Permalink
Gltf triangulate argument
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsdukai committed Jan 9, 2023
1 parent e6c5119 commit f084f92
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- Added the `translate` paramter to `cityjson.compress` to manually set the tranlation properties instead of computing from the data.
- The `cityjson.cityjson_for_features` and `cityjson.generate_features` methods.

### Changed
- The glb converter (`to_glb`) sets a root transformation matrix for z-up to y-up, instead of swapping the vertex coordinates directly.
- The glb converter takes a `do_triangulate` argument to completely skip triangulation.

## [0.8.0] – 2022-11-28
### Added
- added functions for reading/writing CityJSONL (CityJSONFeatures) from stdin/stdout, so cjio can be part of a pipeline of operators processing 3D city models 🚀
Expand Down
4 changes: 2 additions & 2 deletions cjio/cityjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,9 +1571,9 @@ def export2b3dm(self):
return b3dm


def export2glb(self):
def export2glb(self, do_triangulate=True):
self.decompress()
glb = convert.to_glb(self)
glb = convert.to_glb(self, do_triangulate=do_triangulate)
return glb

def export2jsonl(self):
Expand Down
66 changes: 43 additions & 23 deletions cjio/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def to_b3dm(cm, glb):

return b3dm_bin

def to_glb(cm):
def to_glb(cm, do_triangulate=True):
"""Convert to Binary glTF (.glb)
Adapted from CityJSON2glTF: https://github.com/tudelft3d/CityJSON2glTF
Expand Down Expand Up @@ -188,35 +188,55 @@ def to_glb(cm):
matid = 9
material_ids.append(matid)

# TODO: skip triangulation if already triangulated
for geom in cm.j['CityObjects'][theid]['geometry']:
poscount = poscount + 1
if geom['type'] == "Solid":
triList = []
for shell in geom['boundaries']:
for face in shell:
if do_triangulate:
for geom in cm.j['CityObjects'][theid]['geometry']:
poscount = poscount + 1
if geom['type'] == "Solid":
triList = []
for shell in geom['boundaries']:
for face in shell:
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, success = geom_help.triangulate_face(face, vertexlist)
if success:
for t in tri:
triList.append(list(t))
triList.append(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, success = geom_help.triangulate_face(face, vertexlist)
if success:
for t in tri:
trigeom = (flatten(triList))
else:
# If the caller says it's triangulate, then we trust that it's
# triangulated.
for geom in cm.j['CityObjects'][theid]['geometry']:
poscount = poscount + 1
if geom['type'] == "Solid":
triList = []
for shell in geom['boundaries']:
for face in shell:
for t in face:
triList.append(list(t))
trigeom = (flatten(triList))

elif (geom['type'] == 'MultiSurface') or (
geom['type'] == 'CompositeSurface'):
triList = []
for face in geom['boundaries']:
for t in face:
triList.append(t)
else:
# TODO: logging
print(f"Failed to triangulate face in CityObject {theid}")
trigeom = (flatten(triList))
flatgeom = trigeom
forimax.append(flatgeom)
trigeom = (flatten(triList))
flatgeom = trigeom
forimax.append(flatgeom)

#----- buffer and bufferView
flatgeom = flatten(forimax)
Expand Down

0 comments on commit f084f92

Please sign in to comment.