summaryrefslogtreecommitdiffstats
path: root/modules/gltf/structures/gltf_buffer_view.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gltf/structures/gltf_buffer_view.cpp')
-rw-r--r--modules/gltf/structures/gltf_buffer_view.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/modules/gltf/structures/gltf_buffer_view.cpp b/modules/gltf/structures/gltf_buffer_view.cpp
index 7678f23f57..997c219bf0 100644
--- a/modules/gltf/structures/gltf_buffer_view.cpp
+++ b/modules/gltf/structures/gltf_buffer_view.cpp
@@ -29,8 +29,13 @@
/**************************************************************************/
#include "gltf_buffer_view.h"
+#include "gltf_buffer_view.compat.inc"
+
+#include "../gltf_state.h"
void GLTFBufferView::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("load_buffer_view_data", "state"), &GLTFBufferView::load_buffer_view_data);
+
ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);
ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer);
ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFBufferView::get_byte_offset);
@@ -49,7 +54,7 @@ void GLTFBufferView::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indices"), "set_indices", "get_indices"); // bool
}
-GLTFBufferIndex GLTFBufferView::get_buffer() {
+GLTFBufferIndex GLTFBufferView::get_buffer() const {
return buffer;
}
@@ -57,7 +62,7 @@ void GLTFBufferView::set_buffer(GLTFBufferIndex p_buffer) {
buffer = p_buffer;
}
-int GLTFBufferView::get_byte_offset() {
+int GLTFBufferView::get_byte_offset() const {
return byte_offset;
}
@@ -65,7 +70,7 @@ void GLTFBufferView::set_byte_offset(int p_byte_offset) {
byte_offset = p_byte_offset;
}
-int GLTFBufferView::get_byte_length() {
+int GLTFBufferView::get_byte_length() const {
return byte_length;
}
@@ -73,7 +78,7 @@ void GLTFBufferView::set_byte_length(int p_byte_length) {
byte_length = p_byte_length;
}
-int GLTFBufferView::get_byte_stride() {
+int GLTFBufferView::get_byte_stride() const {
return byte_stride;
}
@@ -81,10 +86,20 @@ void GLTFBufferView::set_byte_stride(int p_byte_stride) {
byte_stride = p_byte_stride;
}
-bool GLTFBufferView::get_indices() {
+bool GLTFBufferView::get_indices() const {
return indices;
}
void GLTFBufferView::set_indices(bool p_indices) {
indices = p_indices;
}
+
+Vector<uint8_t> GLTFBufferView::load_buffer_view_data(const Ref<GLTFState> p_state) const {
+ ERR_FAIL_COND_V(p_state.is_null(), Vector<uint8_t>());
+ ERR_FAIL_COND_V_MSG(byte_stride > 0, Vector<uint8_t>(), "Buffer views with byte stride are not yet supported by this method.");
+ const TypedArray<Vector<uint8_t>> &buffers = p_state->get_buffers();
+ ERR_FAIL_INDEX_V(buffer, buffers.size(), Vector<uint8_t>());
+ const PackedByteArray &buffer_data = buffers[buffer];
+ const int64_t byte_end = byte_offset + byte_length;
+ return buffer_data.slice(byte_offset, byte_end);
+}