[Bf-extensions-cvs] [b0b94bf4] master: glTF importer: refactoring/code cleanup
Julien Duroure
noreply at git.blender.org
Sat Sep 5 15:43:05 CEST 2020
Commit: b0b94bf49e8b8a832a962266a2c141b163850e3c
Author: Julien Duroure
Date: Sat Sep 5 15:42:56 2020 +0200
Branches: master
https://developer.blender.org/rBAb0b94bf49e8b8a832a962266a2c141b163850e3c
glTF importer: refactoring/code cleanup
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/io/imp/gltf2_io_binary.py
M io_scene_gltf2/io/imp/gltf2_io_gltf.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 35380dd9..e1a80862 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -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',
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."""
More information about the Bf-extensions-cvs
mailing list