Skip to content

Commit

Permalink
Merge a8823a2 into 3661b38
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Nov 10, 2018
2 parents 3661b38 + a8823a2 commit b07aa4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
24 changes: 12 additions & 12 deletions trimesh/io/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
'json': 1313821514,
'bin': 5130562}

# GLTF data type codes: numpy dtypes
_types = {5120: np.int8,
5121: np.uint8,
5122: np.int16,
5123: np.uint16,
5125: np.uint32,
5126: np.float32}
# GLTF data type codes: numpy dtypes, always little endian
_types = {5120: '<i1',
5121: '<u1',
5122: '<i2',
5123: '<u2',
5125: '<u4',
5126: '<f4'}

# GLTF data formats: numpy shapes
_shapes = {'SCALAR': -1,
Expand Down Expand Up @@ -146,13 +146,13 @@ def export_glb(scene, include_normals=False):
len(content),
# magic number which is 'JSON'
1313821514],
dtype=np.uint32).tobytes())
dtype='<u4').tobytes())

# the header of the binary data section
bin_header = _byte_pad(
np.array([len(buffer_data),
0x004E4942],
dtype=np.uint32).tobytes())
dtype='<u4').tobytes())

exported = bytes().join([header,
content,
Expand Down Expand Up @@ -186,7 +186,7 @@ def load_glb(file_obj, **passed):
# read the first 20 bytes which contain section lengths
head_data = file_obj.read(20)
head = np.frombuffer(head_data,
dtype=np.uint32)
dtype='<u4')

# check to make sure first index is gltf
# and second is 2, for GLTF 2.0
Expand Down Expand Up @@ -223,7 +223,7 @@ def load_glb(file_obj, **passed):
break

chunk_length, chunk_type = np.frombuffer(chunk_head,
dtype=np.uint32)
dtype='<u4')
# make sure we have the right data type
if chunk_type != _magic['bin']:
raise ValueError('not binary GLTF!')
Expand Down Expand Up @@ -572,7 +572,7 @@ def _read_buffers(header, buffers):
# get the base color of the material
try:
color = np.array(mat['pbrMetallicRoughness']['baseColorFactor'],
dtype=np.float)
dtype='<f8')
except BaseException:
color = np.array([.5, .5, .5, 1])

Expand Down
15 changes: 9 additions & 6 deletions trimesh/io/stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class HeaderError(Exception):


# define a numpy datatype for the data section of a binary STL file
_stl_dtype = np.dtype([('normals', np.dtype('<f4'), (3)),
('vertices', np.dtype('<f4'), (3, 3)),
('attributes', np.dtype('<u2'))])
# everything in STL is always Little Endian
# this works natively on Little Endian systems, but blows up on Big Endians
# so we always specify byteorder
_stl_dtype = np.dtype([('normals', '<f4', (3)),
('vertices', '<f4', (3, 3)),
('attributes', '<u2')])
# define a numpy datatype for the header of a binary STL file
_stl_dtype_header = np.dtype([('header', np.void, 80),
('face_count', np.dtype('<i4'))])
('face_count', '<i4')])


def load_stl(file_obj, file_type=None):
Expand Down Expand Up @@ -174,8 +177,8 @@ def load_stl_ascii(file_obj):

# faces are groups of three sequential vertices
faces = np.arange(face_count * 3).reshape((-1, 3))
face_normals = blob[normal_index].astype(np.float64)
vertices = blob[vertex_index.reshape((-1, 3))].astype(np.float64)
face_normals = blob[normal_index].astype('<f8')
vertices = blob[vertex_index.reshape((-1, 3))].astype('<f8')

return {'vertices': vertices,
'faces': faces,
Expand Down

0 comments on commit b07aa4b

Please sign in to comment.