Skip to content

Commit

Permalink
roundtrip metadata to json
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Mar 16, 2022
1 parent 545462c commit a41d03e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions trimesh/exchange/export.py
Expand Up @@ -145,7 +145,7 @@ def encode(item, dtype=None):
return export


def scene_to_dict(scene, use_base64=False):
def scene_to_dict(scene, use_base64=False, include_metadata=True):
"""
Export a Scene object as a dict.
Expand All @@ -163,12 +163,19 @@ def scene_to_dict(scene, use_base64=False):
# save some basic data about the scene
export = {'graph': scene.graph.to_edgelist(),
'geometry': {},
'metadata': scene.metadata.copy(),
'scene_cache': {'bounds': scene.bounds.tolist(),
'extents': scene.extents.tolist(),
'centroid': scene.centroid.tolist(),
'scale': scene.scale}}

if include_metadata:
try:
# jsonify will convert numpy arrays to lists recursively
# a little silly round-tripping to json but it is pretty fast
export['metadata'] = json.loads(util.jsonify(scene.metadata))
except BaseException:
log.warning('failed to serialize metadata', exc_info=True)

# encode arrays with base64 or not
if use_base64:
file_type = 'dict64'
Expand Down

0 comments on commit a41d03e

Please sign in to comment.