Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/structures/gltf_buffer_view.cpp
10278 views
1
/**************************************************************************/
2
/* gltf_buffer_view.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "gltf_buffer_view.h"
32
#include "gltf_buffer_view.compat.inc"
33
34
#include "../gltf_state.h"
35
36
void GLTFBufferView::_bind_methods() {
37
ClassDB::bind_method(D_METHOD("load_buffer_view_data", "state"), &GLTFBufferView::load_buffer_view_data);
38
39
ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);
40
ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer);
41
ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFBufferView::get_byte_offset);
42
ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFBufferView::set_byte_offset);
43
ClassDB::bind_method(D_METHOD("get_byte_length"), &GLTFBufferView::get_byte_length);
44
ClassDB::bind_method(D_METHOD("set_byte_length", "byte_length"), &GLTFBufferView::set_byte_length);
45
ClassDB::bind_method(D_METHOD("get_byte_stride"), &GLTFBufferView::get_byte_stride);
46
ClassDB::bind_method(D_METHOD("set_byte_stride", "byte_stride"), &GLTFBufferView::set_byte_stride);
47
ClassDB::bind_method(D_METHOD("get_indices"), &GLTFBufferView::get_indices);
48
ClassDB::bind_method(D_METHOD("set_indices", "indices"), &GLTFBufferView::set_indices);
49
ClassDB::bind_method(D_METHOD("get_vertex_attributes"), &GLTFBufferView::get_vertex_attributes);
50
ClassDB::bind_method(D_METHOD("set_vertex_attributes", "is_attributes"), &GLTFBufferView::set_vertex_attributes);
51
52
ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer"), "set_buffer", "get_buffer"); // GLTFBufferIndex
53
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
54
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_length"), "set_byte_length", "get_byte_length"); // int
55
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_stride"), "set_byte_stride", "get_byte_stride"); // int
56
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indices"), "set_indices", "get_indices"); // bool
57
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertex_attributes"), "set_vertex_attributes", "get_vertex_attributes"); // bool
58
}
59
60
GLTFBufferIndex GLTFBufferView::get_buffer() const {
61
return buffer;
62
}
63
64
void GLTFBufferView::set_buffer(GLTFBufferIndex p_buffer) {
65
buffer = p_buffer;
66
}
67
68
int64_t GLTFBufferView::get_byte_offset() const {
69
return byte_offset;
70
}
71
72
void GLTFBufferView::set_byte_offset(int64_t p_byte_offset) {
73
byte_offset = p_byte_offset;
74
}
75
76
int64_t GLTFBufferView::get_byte_length() const {
77
return byte_length;
78
}
79
80
void GLTFBufferView::set_byte_length(int64_t p_byte_length) {
81
byte_length = p_byte_length;
82
}
83
84
int64_t GLTFBufferView::get_byte_stride() const {
85
return byte_stride;
86
}
87
88
void GLTFBufferView::set_byte_stride(int64_t p_byte_stride) {
89
byte_stride = p_byte_stride;
90
}
91
92
bool GLTFBufferView::get_indices() const {
93
return indices;
94
}
95
96
void GLTFBufferView::set_indices(bool p_indices) {
97
indices = p_indices;
98
}
99
100
bool GLTFBufferView::get_vertex_attributes() const {
101
return vertex_attributes;
102
}
103
104
void GLTFBufferView::set_vertex_attributes(bool p_attributes) {
105
vertex_attributes = p_attributes;
106
}
107
108
Vector<uint8_t> GLTFBufferView::load_buffer_view_data(const Ref<GLTFState> p_state) const {
109
ERR_FAIL_COND_V(p_state.is_null(), Vector<uint8_t>());
110
ERR_FAIL_COND_V_MSG(byte_stride > 0, Vector<uint8_t>(), "Buffer views with byte stride are not yet supported by this method.");
111
const TypedArray<Vector<uint8_t>> &buffers = p_state->get_buffers();
112
ERR_FAIL_INDEX_V(buffer, buffers.size(), Vector<uint8_t>());
113
const PackedByteArray &buffer_data = buffers[buffer];
114
const int64_t byte_end = byte_offset + byte_length;
115
return buffer_data.slice(byte_offset, byte_end);
116
}
117
118