Skip to content

Commit

Permalink
use jsonify for tolist
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Sep 10, 2018
1 parent 2d0f29f commit 1aca24c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion tests/notebook_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def to_pass(line):
passed : str, line of code with same leading spaces
but code replaced with pass statement
"""
spaces = np.nonzero([i != ' ' for i in line])[0][0]
# the number of leading spaces on the line
spaces = len(line) - len(line.lstrip(' '))
# replace statement with pass and correct leading spaces
passed = (' ' * spaces) + 'pass'
return passed

Expand Down
2 changes: 0 additions & 2 deletions tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
log = logging.getLogger('trimesh')
log.addHandler(logging.NullHandler())

_QUICK = '-q' in sys.argv


class VectorTests(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion trimesh/io/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def encode(item, dtype=None):
return util.array_to_encoded(item,
dtype=dtype,
encoding=encoding)
export = {'metadata': util.tolist_dict(mesh.metadata),
export = {'metadata': util.tolist(mesh.metadata),
'faces': encode(mesh.faces),
'face_normals': encode(mesh.face_normals),
'vertices': encode(mesh.vertices)}
Expand Down
2 changes: 1 addition & 1 deletion trimesh/io/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _mesh_to_material(mesh, metallic=.02, rough=.1):
# just get the most commonly occurring color
color = mesh.visual.main_color
# convert uint color to 0-1.0 float color
color = color.astype(float) / (2 ** (8 * color.dtype.itemsize))
color = color.astype(float) / ((2 ** (8 * color.dtype.itemsize)) - 1)

material = {'pbrMetallicRoughness':
{'baseColorFactor': color.tolist(),
Expand Down
23 changes: 16 additions & 7 deletions trimesh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,22 @@ def multi_dict(pairs):
return result


def tolist_dict(data):
def tolist(item):
if hasattr(item, 'tolist'):
return item.tolist()
else:
return item
result = {k: tolist(v) for k, v in data.items()}
def tolist(data):
"""
Ensure that any arrays or dicts passed containing
numpy arrays are properly converted to lists
Parameters
-----------------
data : any
Usually a dict with some numpy arrays as values
Returns
------------
result : any
JSON- serializable version of data
"""
result = json.loads(jsonify(data))
return result


Expand Down
2 changes: 1 addition & 1 deletion trimesh/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.33.26'
__version__ = '2.33.27'

0 comments on commit 1aca24c

Please sign in to comment.