Skip to content

Commit 1aca24c

Browse files
committed
use jsonify for tolist
1 parent 2d0f29f commit 1aca24c

6 files changed

Lines changed: 22 additions & 13 deletions

File tree

tests/notebook_run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def to_pass(line):
7676
passed : str, line of code with same leading spaces
7777
but code replaced with pass statement
7878
"""
79-
spaces = np.nonzero([i != ' ' for i in line])[0][0]
79+
# the number of leading spaces on the line
80+
spaces = len(line) - len(line.lstrip(' '))
81+
# replace statement with pass and correct leading spaces
8082
passed = (' ' * spaces) + 'pass'
8183
return passed
8284

tests/test_utility.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
log = logging.getLogger('trimesh')
2222
log.addHandler(logging.NullHandler())
2323

24-
_QUICK = '-q' in sys.argv
25-
2624

2725
class VectorTests(unittest.TestCase):
2826

trimesh/io/export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def encode(item, dtype=None):
164164
return util.array_to_encoded(item,
165165
dtype=dtype,
166166
encoding=encoding)
167-
export = {'metadata': util.tolist_dict(mesh.metadata),
167+
export = {'metadata': util.tolist(mesh.metadata),
168168
'faces': encode(mesh.faces),
169169
'face_normals': encode(mesh.face_normals),
170170
'vertices': encode(mesh.vertices)}

trimesh/io/gltf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _mesh_to_material(mesh, metallic=.02, rough=.1):
244244
# just get the most commonly occurring color
245245
color = mesh.visual.main_color
246246
# convert uint color to 0-1.0 float color
247-
color = color.astype(float) / (2 ** (8 * color.dtype.itemsize))
247+
color = color.astype(float) / ((2 ** (8 * color.dtype.itemsize)) - 1)
248248

249249
material = {'pbrMetallicRoughness':
250250
{'baseColorFactor': color.tolist(),

trimesh/util.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,22 @@ def multi_dict(pairs):
629629
return result
630630

631631

632-
def tolist_dict(data):
633-
def tolist(item):
634-
if hasattr(item, 'tolist'):
635-
return item.tolist()
636-
else:
637-
return item
638-
result = {k: tolist(v) for k, v in data.items()}
632+
def tolist(data):
633+
"""
634+
Ensure that any arrays or dicts passed containing
635+
numpy arrays are properly converted to lists
636+
637+
Parameters
638+
-----------------
639+
data : any
640+
Usually a dict with some numpy arrays as values
641+
642+
Returns
643+
------------
644+
result : any
645+
JSON- serializable version of data
646+
"""
647+
result = json.loads(jsonify(data))
639648
return result
640649

641650

trimesh/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.33.26'
1+
__version__ = '2.33.27'

0 commit comments

Comments
 (0)