From 564fdcdf7159013bc7087c9d12f2a034cfa3a945 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Tue, 29 Mar 2022 17:44:36 +0200 Subject: glTF exporter: Manage skinning when some vertices are not weights at all --- io_scene_gltf2/io/imp/gltf2_io_binary.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'io_scene_gltf2/io') diff --git a/io_scene_gltf2/io/imp/gltf2_io_binary.py b/io_scene_gltf2/io/imp/gltf2_io_binary.py index 21bbb41b..995fd3c9 100755 --- a/io_scene_gltf2/io/imp/gltf2_io_binary.py +++ b/io_scene_gltf2/io/imp/gltf2_io_binary.py @@ -77,6 +77,37 @@ class BinaryData(): return array + + @staticmethod + def decode_accessor_internal(accessor): + # Is use internally when accessor binary data is not yet in a glTF buffer_view + # MAT2/3 have special alignment requirements that aren't handled. But it + # doesn't matter because nothing uses them. + assert accessor.type not in ['MAT2', 'MAT3'] + + dtype = ComponentType.to_numpy_dtype(accessor.component_type) + component_nb = DataType.num_elements(accessor.type) + + buffer_data = accessor.buffer_view.data + + accessor_offset = accessor.byte_offset or 0 + buffer_data = buffer_data[accessor_offset:] + + bytes_per_elem = dtype(1).nbytes + default_stride = bytes_per_elem * component_nb + stride = default_stride + + array = np.frombuffer( + buffer_data, + dtype=np.dtype(dtype).newbyteorder('<'), + count=accessor.count * component_nb, + ) + array = array.reshape(accessor.count, component_nb) + + return array + + + @staticmethod def decode_accessor_obj(gltf, accessor): # MAT2/3 have special alignment requirements that aren't handled. But it -- cgit v1.2.3