glTF importer: refactoring/code cleanup

This commit is contained in:
Julien Duroure 2020-09-05 15:42:56 +02:00
parent 0c2ff8fa7c
commit b0b94bf49e
3 changed files with 4 additions and 30 deletions

View File

@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (1, 4, 18),
"version": (1, 4, 19),
'blender': (2, 90, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -16,6 +16,7 @@ import struct
import numpy as np
from ..com.gltf2_io import Accessor
from ..com.gltf2_io_constants import ComponentType, DataType
class BinaryData():
@ -93,14 +94,8 @@ class BinaryData():
# doesn't matter because nothing uses them.
assert accessor.type not in ['MAT2', 'MAT3']
dtype = {
5120: np.int8,
5121: np.uint8,
5122: np.int16,
5123: np.uint16,
5125: np.uint32,
5126: np.float32,
}[accessor.component_type]
dtype = ComponentType.to_numpy_dtype(accessor.component_type)
component_nb = DataType.num_elements(accessor.type)
if accessor.buffer_view is not None:
bufferView = gltf.data.buffer_views[accessor.buffer_view]
@ -109,9 +104,7 @@ class BinaryData():
accessor_offset = accessor.byte_offset or 0
buffer_data = buffer_data[accessor_offset:]
component_nb = gltf.component_nb_dict[accessor.type]
bytes_per_elem = dtype(1).nbytes
default_stride = bytes_per_elem * component_nb
stride = bufferView.byte_stride or default_stride
@ -146,7 +139,6 @@ class BinaryData():
else:
# No buffer view; initialize to zeros
component_nb = gltf.component_nb_dict[accessor.type]
array = np.zeros((accessor.count, component_nb), dtype=dtype)
if accessor.sparse:

View File

@ -51,24 +51,6 @@ class glTFImporter():
'KHR_mesh_quantization',
]
# TODO : merge with io_constants
self.fmt_char_dict = {}
self.fmt_char_dict[5120] = 'b' # Byte
self.fmt_char_dict[5121] = 'B' # Unsigned Byte
self.fmt_char_dict[5122] = 'h' # Short
self.fmt_char_dict[5123] = 'H' # Unsigned Short
self.fmt_char_dict[5125] = 'I' # Unsigned Int
self.fmt_char_dict[5126] = 'f' # Float
self.component_nb_dict = {}
self.component_nb_dict['SCALAR'] = 1
self.component_nb_dict['VEC2'] = 2
self.component_nb_dict['VEC3'] = 3
self.component_nb_dict['VEC4'] = 4
self.component_nb_dict['MAT2'] = 4
self.component_nb_dict['MAT3'] = 9
self.component_nb_dict['MAT4'] = 16
@staticmethod
def bad_json_value(val):
"""Bad Json value."""