glTF exporter: add bufferView Target at export

This commit is contained in:
Julien Duroure 2022-08-06 12:11:15 +02:00
parent c58c8f3c35
commit ef0027e72d
6 changed files with 12 additions and 8 deletions

View File

@ -4,7 +4,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": (3, 3, 21),
"version": (3, 3, 22),
'blender': (3, 3, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -44,7 +44,7 @@ def array_to_accessor(array, component_type, data_type, include_max_and_min=Fals
amin = np.amin(array, axis=0).tolist()
return gltf2_io.Accessor(
buffer_view=gltf2_io_binary_data.BinaryData(array.tobytes()),
buffer_view=gltf2_io_binary_data.BinaryData(array.tobytes(), gltf2_io_constants.BufferViewTarget.ARRAY_BUFFER),
byte_offset=None,
component_type=component_type,
count=len(array),
@ -142,7 +142,7 @@ def __gather_colors(blender_primitive, export_settings):
comp_type = gltf2_io_constants.ComponentType.Float
attributes[color_id] = gltf2_io.Accessor(
buffer_view=gltf2_io_binary_data.BinaryData(colors.tobytes()),
buffer_view=gltf2_io_binary_data.BinaryData(colors.tobytes(), gltf2_io_constants.BufferViewTarget.ARRAY_BUFFER),
byte_offset=None,
component_type=comp_type,
count=len(colors),

View File

@ -150,7 +150,7 @@ def __gather_indices(blender_primitive, blender_mesh, modifiers, export_settings
return None
element_type = gltf2_io_constants.DataType.Scalar
binary_data = gltf2_io_binary_data.BinaryData(indices.tobytes())
binary_data = gltf2_io_binary_data.BinaryData(indices.tobytes(), bufferViewTarget=gltf2_io_constants.BufferViewTarget.ELEMENT_ARRAY_BUFFER)
return gltf2_blender_gather_accessors.gather_accessor(
binary_data,
component_type,

View File

@ -118,6 +118,9 @@ class TextureWrap(IntEnum):
MirroredRepeat = 33648
Repeat = 10497
class BufferViewTarget(IntEnum):
ARRAY_BUFFER = 34962
ELEMENT_ARRAY_BUFFER = 34963
#################
# LEGACY DEFINES

View File

@ -9,10 +9,11 @@ from io_scene_gltf2.io.com import gltf2_io_constants
class BinaryData:
"""Store for gltf binary data that can later be stored in a buffer."""
def __init__(self, data: bytes):
def __init__(self, data: bytes, bufferViewTarget=None):
if not isinstance(data, bytes):
raise TypeError("Data is not a bytes array")
self.data = data
self.bufferViewTarget = bufferViewTarget
def __eq__(self, other):
return self.data == other.data
@ -21,9 +22,9 @@ class BinaryData:
return hash(self.data)
@classmethod
def from_list(cls, lst: typing.List[typing.Any], gltf_component_type: gltf2_io_constants.ComponentType):
def from_list(cls, lst: typing.List[typing.Any], gltf_component_type: gltf2_io_constants.ComponentType, bufferViewTarget=None):
format_char = gltf2_io_constants.ComponentType.to_type_code(gltf_component_type)
return BinaryData(array.array(format_char, lst).tobytes())
return BinaryData(array.array(format_char, lst).tobytes(), bufferViewTarget)
@property
def byte_length(self):

View File

@ -35,7 +35,7 @@ class Buffer:
extensions=None,
extras=None,
name=None,
target=None
target=binary_data.bufferViewTarget
)
return buffer_view