Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-09-05 16:42:56 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-09-05 16:42:56 +0300
commitb0b94bf49e8b8a832a962266a2c141b163850e3c (patch)
treef5ed494b5f012058121221277a59001265c3ac42 /io_scene_gltf2/io
parent0c2ff8fa7c7266de4349fb38c8b59b7678755ded (diff)
glTF importer: refactoring/code cleanup
Diffstat (limited to 'io_scene_gltf2/io')
-rwxr-xr-xio_scene_gltf2/io/imp/gltf2_io_binary.py14
-rwxr-xr-xio_scene_gltf2/io/imp/gltf2_io_gltf.py18
2 files changed, 3 insertions, 29 deletions
diff --git a/io_scene_gltf2/io/imp/gltf2_io_binary.py b/io_scene_gltf2/io/imp/gltf2_io_binary.py
index 5346d9f5..fddc8030 100755
--- a/io_scene_gltf2/io/imp/gltf2_io_binary.py
+++ b/io_scene_gltf2/io/imp/gltf2_io_binary.py
@@ -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:
diff --git a/io_scene_gltf2/io/imp/gltf2_io_gltf.py b/io_scene_gltf2/io/imp/gltf2_io_gltf.py
index 49eee2d5..1607979a 100755
--- a/io_scene_gltf2/io/imp/gltf2_io_gltf.py
+++ b/io_scene_gltf2/io/imp/gltf2_io_gltf.py
@@ -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."""