Skip to content
Snippets Groups Projects
Commit 495dd7bd authored by Julien Duroure's avatar Julien Duroure
Browse files

glTF exporter: perf: use bytearrays

parent f3cf3a16
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
bl_info = { bl_info = {
'name': 'glTF 2.0 format', 'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (1, 4, 25), "version": (1, 4, 26),
'blender': (2, 90, 0), 'blender': (2, 90, 0),
'location': 'File > Import-Export', 'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0', 'description': 'Import-Export as glTF 2.0',
......
...@@ -22,21 +22,23 @@ class Buffer: ...@@ -22,21 +22,23 @@ class Buffer:
"""Class representing binary data for use in a glTF file as 'buffer' property.""" """Class representing binary data for use in a glTF file as 'buffer' property."""
def __init__(self, buffer_index=0): def __init__(self, buffer_index=0):
self.__data = b"" self.__data = bytearray(b"")
self.__buffer_index = buffer_index self.__buffer_index = buffer_index
def add_and_get_view(self, binary_data: gltf2_io_binary_data.BinaryData) -> gltf2_io.BufferView: def add_and_get_view(self, binary_data: gltf2_io_binary_data.BinaryData) -> gltf2_io.BufferView:
"""Add binary data to the buffer. Return a glTF BufferView.""" """Add binary data to the buffer. Return a glTF BufferView."""
offset = len(self.__data) offset = len(self.__data)
self.__data += binary_data.data self.__data.extend(binary_data.data)
length = binary_data.byte_length
# offsets should be a multiple of 4 --> therefore add padding if necessary # offsets should be a multiple of 4 --> therefore add padding if necessary
padding = (4 - (binary_data.byte_length % 4)) % 4 padding = (4 - (length % 4)) % 4
self.__data += b"\x00" * padding self.__data.extend(b"\x00" * padding)
buffer_view = gltf2_io.BufferView( buffer_view = gltf2_io.BufferView(
buffer=self.__buffer_index, buffer=self.__buffer_index,
byte_length=binary_data.byte_length, byte_length=length,
byte_offset=offset, byte_offset=offset,
byte_stride=None, byte_stride=None,
extensions=None, extensions=None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment