Debian Codegraph @

modules/gltf/gltf_state.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* gltf_state.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_state.h"
32 #include "gltf_state.compat.inc"
33
34 #include "gltf_template_convert.h"
35
36 void GLTFState::_bind_methods() {
37 ClassDB::bind_method(D_METHOD("add_used_extension", "extension_name", "required"), &GLTFState::add_used_extension);
38 ClassDB::bind_method(D_METHOD("append_data_to_buffers", "data", "deduplication"), &GLTFState::append_data_to_buffers);
39 ClassDB::bind_method(D_METHOD("append_gltf_node", "gltf_node", "godot_scene_node", "parent_node_index"), &GLTFState::append_gltf_node);
40
41 ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
42 ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);
43 ClassDB::bind_method(D_METHOD("get_major_version"), &GLTFState::get_major_version);
44 ClassDB::bind_method(D_METHOD("set_major_version", "major_version"), &GLTFState::set_major_version);
45 ClassDB::bind_method(D_METHOD("get_minor_version"), &GLTFState::get_minor_version);
46 ClassDB::bind_method(D_METHOD("set_minor_version", "minor_version"), &GLTFState::set_minor_version);
47 ClassDB::bind_method(D_METHOD("get_copyright"), &GLTFState::get_copyright);
48 ClassDB::bind_method(D_METHOD("set_copyright", "copyright"), &GLTFState::set_copyright);
49 ClassDB::bind_method(D_METHOD("get_glb_data"), &GLTFState::get_glb_data);
50 ClassDB::bind_method(D_METHOD("set_glb_data", "glb_data"), &GLTFState::set_glb_data);
51 ClassDB::bind_method(D_METHOD("get_use_named_skin_binds"), &GLTFState::get_use_named_skin_binds);
52 ClassDB::bind_method(D_METHOD("set_use_named_skin_binds", "use_named_skin_binds"), &GLTFState::set_use_named_skin_binds);
53 ClassDB::bind_method(D_METHOD("get_nodes"), &GLTFState::get_nodes_bind);
54 ClassDB::bind_method(D_METHOD("set_nodes", "nodes"), &GLTFState::set_nodes_bind);
55 ClassDB::bind_method(D_METHOD("get_buffers"), &GLTFState::get_buffers_bind);
56 ClassDB::bind_method(D_METHOD("set_buffers", "buffers"), &GLTFState::set_buffers_bind);
57 ClassDB::bind_method(D_METHOD("get_buffer_views"), &GLTFState::get_buffer_views_bind);
58 ClassDB::bind_method(D_METHOD("set_buffer_views", "buffer_views"), &GLTFState::set_buffer_views_bind);
59 ClassDB::bind_method(D_METHOD("get_accessors"), &GLTFState::get_accessors_bind);
60 ClassDB::bind_method(D_METHOD("set_accessors", "accessors"), &GLTFState::set_accessors_bind);
61 ClassDB::bind_method(D_METHOD("get_meshes"), &GLTFState::get_meshes_bind);
62 ClassDB::bind_method(D_METHOD("set_meshes", "meshes"), &GLTFState::set_meshes_bind);
63 ClassDB::bind_method(D_METHOD("get_animation_players_count", "anim_player_index"), &GLTFState::get_animation_players_count);
64 ClassDB::bind_method(D_METHOD("get_animation_player", "anim_player_index"), &GLTFState::get_animation_player);
65 ClassDB::bind_method(D_METHOD("get_materials"), &GLTFState::get_materials_bind);
66 ClassDB::bind_method(D_METHOD("set_materials", "materials"), &GLTFState::set_materials_bind);
67 ClassDB::bind_method(D_METHOD("get_scene_name"), &GLTFState::get_scene_name);
68 ClassDB::bind_method(D_METHOD("set_scene_name", "scene_name"), &GLTFState::set_scene_name);
69 ClassDB::bind_method(D_METHOD("get_base_path"), &GLTFState::get_base_path);
70 ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &GLTFState::set_base_path);
71 ClassDB::bind_method(D_METHOD("get_filename"), &GLTFState::get_filename);
72 ClassDB::bind_method(D_METHOD("set_filename", "filename"), &GLTFState::set_filename);
73 ClassDB::bind_method(D_METHOD("get_root_nodes"), &GLTFState::get_root_nodes);
74 ClassDB::bind_method(D_METHOD("set_root_nodes", "root_nodes"), &GLTFState::set_root_nodes);
75 ClassDB::bind_method(D_METHOD("get_textures"), &GLTFState::get_textures_bind);
76 ClassDB::bind_method(D_METHOD("set_textures", "textures"), &GLTFState::set_textures_bind);
77 ClassDB::bind_method(D_METHOD("get_texture_samplers"), &GLTFState::get_texture_samplers_bind);
78 ClassDB::bind_method(D_METHOD("set_texture_samplers", "texture_samplers"), &GLTFState::set_texture_samplers_bind);
79 ClassDB::bind_method(D_METHOD("get_images"), &GLTFState::get_images_bind);
80 ClassDB::bind_method(D_METHOD("set_images", "images"), &GLTFState::set_images_bind);
81 ClassDB::bind_method(D_METHOD("get_skins"), &GLTFState::get_skins_bind);
82 ClassDB::bind_method(D_METHOD("set_skins", "skins"), &GLTFState::set_skins_bind);
83 ClassDB::bind_method(D_METHOD("get_cameras"), &GLTFState::get_cameras_bind);
84 ClassDB::bind_method(D_METHOD("set_cameras", "cameras"), &GLTFState::set_cameras_bind);
85 ClassDB::bind_method(D_METHOD("get_lights"), &GLTFState::get_lights_bind);
86 ClassDB::bind_method(D_METHOD("set_lights", "lights"), &GLTFState::set_lights_bind);
87 ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFState::get_unique_names_bind);
88 ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFState::set_unique_names_bind);
89 ClassDB::bind_method(D_METHOD("get_unique_animation_names"), &GLTFState::get_unique_animation_names_bind);
90 ClassDB::bind_method(D_METHOD("set_unique_animation_names", "unique_animation_names"), &GLTFState::set_unique_animation_names_bind);
91 ClassDB::bind_method(D_METHOD("get_skeletons"), &GLTFState::get_skeletons_bind);
92 ClassDB::bind_method(D_METHOD("set_skeletons", "skeletons"), &GLTFState::set_skeletons_bind);
93 ClassDB::bind_method(D_METHOD("get_create_animations"), &GLTFState::get_create_animations);
94 ClassDB::bind_method(D_METHOD("set_create_animations", "create_animations"), &GLTFState::set_create_animations);
95 ClassDB::bind_method(D_METHOD("get_import_as_skeleton_bones"), &GLTFState::get_import_as_skeleton_bones);
96 ClassDB::bind_method(D_METHOD("set_import_as_skeleton_bones", "import_as_skeleton_bones"), &GLTFState::set_import_as_skeleton_bones);
97 ClassDB::bind_method(D_METHOD("get_animations"), &GLTFState::get_animations_bind);
98 ClassDB::bind_method(D_METHOD("set_animations", "animations"), &GLTFState::set_animations_bind);
99 ClassDB::bind_method(D_METHOD("get_scene_node", "gltf_node_index"), &GLTFState::get_scene_node);
100 ClassDB::bind_method(D_METHOD("get_node_index", "scene_node"), &GLTFState::get_node_index);
101 ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFState::get_additional_data);
102 ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFState::set_additional_data);
103 ClassDB::bind_method(D_METHOD("get_handle_binary_image_mode"), &GLTFState::get_handle_binary_image_mode);
104 ClassDB::bind_method(D_METHOD("set_handle_binary_image_mode", "method"), &GLTFState::set_handle_binary_image_mode);
105 ClassDB::bind_method(D_METHOD("set_bake_fps", "value"), &GLTFState::set_bake_fps);
106 ClassDB::bind_method(D_METHOD("get_bake_fps"), &GLTFState::get_bake_fps);
107
108 ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "json"), "set_json", "get_json"); // Dictionary
109 ADD_PROPERTY(PropertyInfo(Variant::INT, "major_version"), "set_major_version", "get_major_version"); // int
110 ADD_PROPERTY(PropertyInfo(Variant::INT, "minor_version"), "set_minor_version", "get_minor_version"); // int
111 ADD_PROPERTY(PropertyInfo(Variant::STRING, "copyright"), "set_copyright", "get_copyright"); // String
112 ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "glb_data"), "set_glb_data", "get_glb_data"); // Vector<uint8_t>
113 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_named_skin_binds"), "set_use_named_skin_binds", "get_use_named_skin_binds"); // bool
114 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_nodes", "get_nodes"); // Vector<Ref<GLTFNode>>
115 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffers"), "set_buffers", "get_buffers"); // Vector<Vector<uint8_t>
116 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffer_views", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_buffer_views", "get_buffer_views"); // Vector<Ref<GLTFBufferView>>
117 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessors", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_accessors", "get_accessors"); // Vector<Ref<GLTFAccessor>>
118 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_meshes", "get_meshes"); // Vector<Ref<GLTFMesh>>
119 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_materials", "get_materials"); // Vector<Ref<Material>
120 ADD_PROPERTY(PropertyInfo(Variant::STRING, "scene_name"), "set_scene_name", "get_scene_name"); // String
121 ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_path"), "set_base_path", "get_base_path"); // String
122 ADD_PROPERTY(PropertyInfo(Variant::STRING, "filename"), "set_filename", "get_filename"); // String
123 ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int>
124 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_textures", "get_textures"); // Vector<Ref<GLTFTexture>>
125 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "texture_samplers", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_texture_samplers", "get_texture_samplers"); //Vector<Ref<GLTFTextureSampler>>
126 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture>
127 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skins", "get_skins"); // Vector<Ref<GLTFSkin>>
128 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "cameras", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_cameras", "get_cameras"); // Vector<Ref<GLTFCamera>>
129 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "lights", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_lights", "get_lights"); // Vector<Ref<GLTFLight>>
130 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String>
131 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_animation_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_animation_names", "get_unique_animation_names"); // Set<String>
132 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skeletons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeletons", "get_skeletons"); // Vector<Ref<GLTFSkeleton>>
133 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_animations"), "set_create_animations", "get_create_animations"); // bool
134 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "import_as_skeleton_bones"), "set_import_as_skeleton_bones", "get_import_as_skeleton_bones"); // bool
135 ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
136 ADD_PROPERTY(PropertyInfo(Variant::INT, "handle_binary_image_mode", PROPERTY_HINT_ENUM, "Discard All Textures,Extract Textures,Embed as Basis Universal,Embed as Uncompressed"), "set_handle_binary_image_mode", "get_handle_binary_image_mode"); // enum
137 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_fps", PROPERTY_HINT_RANGE, "0.001,120,0.0001,or_greater"), "set_bake_fps", "get_bake_fps");
138
139 BIND_ENUM_CONSTANT(HANDLE_BINARY_IMAGE_MODE_DISCARD_TEXTURES);
140 BIND_ENUM_CONSTANT(HANDLE_BINARY_IMAGE_MODE_EXTRACT_TEXTURES);
141 BIND_ENUM_CONSTANT(HANDLE_BINARY_IMAGE_MODE_EMBED_AS_BASISU);
142 BIND_ENUM_CONSTANT(HANDLE_BINARY_IMAGE_MODE_EMBED_AS_UNCOMPRESSED);
143
144 #ifndef DISABLE_DEPRECATED
145 // Deprecated non-type-safe versions for backward compatibility, remove in Godot 5.0.
146 ClassDB::bind_method(D_METHOD("get_handle_binary_image"), &GLTFState::get_handle_binary_image);
147 ClassDB::bind_method(D_METHOD("set_handle_binary_image", "method"), &GLTFState::set_handle_binary_image);
148 ADD_PROPERTY(PropertyInfo(Variant::INT, "handle_binary_image", PROPERTY_HINT_ENUM, "Discard All Textures,Extract Textures,Embed as Basis Universal,Embed as Uncompressed", PROPERTY_USAGE_INTERNAL), "set_handle_binary_image", "get_handle_binary_image"); // enum as int
149 BIND_CONSTANT(HANDLE_BINARY_DISCARD_TEXTURES);
150 BIND_CONSTANT(HANDLE_BINARY_EXTRACT_TEXTURES);
151 BIND_CONSTANT(HANDLE_BINARY_EMBED_AS_BASISU);
152 BIND_CONSTANT(HANDLE_BINARY_EMBED_AS_UNCOMPRESSED);
153 #endif // DISABLE_DEPRECATED
154 }
155
156 void GLTFState::add_used_extension(const String &p_extension_name, bool p_required) {
157 if (!extensions_used.has(p_extension_name)) {
158 extensions_used.push_back(p_extension_name);
159 }
160 if (p_required) {
161 if (!extensions_required.has(p_extension_name)) {
162 extensions_required.push_back(p_extension_name);
163 }
164 }
165 }
166
167 Dictionary GLTFState::get_json() const {
168 return Dictionary(json);
169 }
170
171 void GLTFState::set_json(const Dictionary &p_json) {
172 json = Dictionary(p_json);
173 }
174
175 int GLTFState::get_major_version() const {
176 return major_version;
177 }
178
179 void GLTFState::set_major_version(int p_major_version) {
180 major_version = p_major_version;
181 }
182
183 int GLTFState::get_minor_version() const {
184 return minor_version;
185 }
186
187 void GLTFState::set_minor_version(int p_minor_version) {
188 minor_version = p_minor_version;
189 }
190
191 String GLTFState::get_copyright() const {
192 return copyright;
193 }
194
195 void GLTFState::set_copyright(const String &p_copyright) {
196 copyright = p_copyright;
197 }
198
199 Vector<uint8_t> GLTFState::get_glb_data() const {
200 return Vector<uint8_t>(glb_data);
201 }
202
203 void GLTFState::set_glb_data(const Vector<uint8_t> &p_glb_data) {
204 glb_data = Vector<uint8_t>(p_glb_data);
205 }
206
207 bool GLTFState::get_use_named_skin_binds() const {
208 return use_named_skin_binds;
209 }
210
211 void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
212 use_named_skin_binds = p_use_named_skin_binds;
213 }
214
215 TypedArray<GLTFNode> GLTFState::get_nodes_bind() const {
216 return GLTFTemplateConvert::to_array(nodes);
217 }
218
219 void GLTFState::set_nodes_bind(const TypedArray<GLTFNode> &p_nodes) {
220 GLTFTemplateConvert::set_from_array(nodes, p_nodes);
221 }
222
223 TypedArray<PackedByteArray> GLTFState::get_buffers_bind() const {
224 return GLTFTemplateConvert::to_array(buffers);
225 }
226
227 void GLTFState::set_buffers_bind(const TypedArray<PackedByteArray> &p_buffers) {
228 GLTFTemplateConvert::set_from_array(buffers, p_buffers);
229 }
230
231 TypedArray<GLTFBufferView> GLTFState::get_buffer_views_bind() const {
232 return GLTFTemplateConvert::to_array(buffer_views);
233 }
234
235 void GLTFState::set_buffer_views_bind(const TypedArray<GLTFBufferView> &p_buffer_views) {
236 GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
237 }
238
239 TypedArray<GLTFAccessor> GLTFState::get_accessors_bind() const {
240 return GLTFTemplateConvert::to_array(accessors);
241 }
242
243 void GLTFState::set_accessors_bind(const TypedArray<GLTFAccessor> &p_accessors) {
244 GLTFTemplateConvert::set_from_array(accessors, p_accessors);
245 }
246
247 TypedArray<GLTFMesh> GLTFState::get_meshes_bind() const {
248 return GLTFTemplateConvert::to_array(meshes);
249 }
250
251 void GLTFState::set_meshes_bind(const TypedArray<GLTFMesh> &p_meshes) {
252 GLTFTemplateConvert::set_from_array(meshes, p_meshes);
253 }
254
255 TypedArray<Material> GLTFState::get_materials_bind() const {
256 return GLTFTemplateConvert::to_array(materials);
257 }
258
259 void GLTFState::set_materials_bind(const TypedArray<Material> &p_materials) {
260 GLTFTemplateConvert::set_from_array(materials, p_materials);
261 }
262
263 String GLTFState::get_scene_name() const {
264 return scene_name;
265 }
266
267 void GLTFState::set_scene_name(const String &p_scene_name) {
268 scene_name = p_scene_name;
269 }
270
271 PackedInt32Array GLTFState::get_root_nodes() const {
272 return root_nodes;
273 }
274
275 void GLTFState::set_root_nodes(const PackedInt32Array &p_root_nodes) {
276 root_nodes = PackedInt32Array(p_root_nodes);
277 }
278
279 TypedArray<GLTFTexture> GLTFState::get_textures_bind() const {
280 return GLTFTemplateConvert::to_array(textures);
281 }
282
283 void GLTFState::set_textures_bind(const TypedArray<GLTFTexture> &p_textures) {
284 GLTFTemplateConvert::set_from_array(textures, p_textures);
285 }
286
287 TypedArray<GLTFTextureSampler> GLTFState::get_texture_samplers_bind() const {
288 return GLTFTemplateConvert::to_array(texture_samplers);
289 }
290
291 void GLTFState::set_texture_samplers_bind(const TypedArray<GLTFTextureSampler> &p_texture_samplers) {
292 GLTFTemplateConvert::set_from_array(texture_samplers, p_texture_samplers);
293 }
294
295 TypedArray<Texture2D> GLTFState::get_images_bind() const {
296 return GLTFTemplateConvert::to_array(images);
297 }
298
299 void GLTFState::set_images_bind(const TypedArray<Texture2D> &p_images) {
300 GLTFTemplateConvert::set_from_array(images, p_images);
301 }
302
303 TypedArray<GLTFSkin> GLTFState::get_skins_bind() const {
304 return GLTFTemplateConvert::to_array(skins);
305 }
306
307 void GLTFState::set_skins_bind(const TypedArray<GLTFSkin> &p_skins) {
308 GLTFTemplateConvert::set_from_array(skins, p_skins);
309 }
310
311 TypedArray<GLTFCamera> GLTFState::get_cameras_bind() const {
312 return GLTFTemplateConvert::to_array(cameras);
313 }
314
315 void GLTFState::set_cameras_bind(const TypedArray<GLTFCamera> &p_cameras) {
316 GLTFTemplateConvert::set_from_array(cameras, p_cameras);
317 }
318
319 TypedArray<GLTFLight> GLTFState::get_lights_bind() const {
320 return GLTFTemplateConvert::to_array(lights);
321 }
322
323 void GLTFState::set_lights_bind(const TypedArray<GLTFLight> &p_lights) {
324 GLTFTemplateConvert::set_from_array(lights, p_lights);
325 }
326
327 TypedArray<String> GLTFState::get_unique_names_bind() const {
328 return GLTFTemplateConvert::to_array(unique_names);
329 }
330
331 void GLTFState::set_unique_names_bind(const TypedArray<String> &p_unique_names) {
332 GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
333 }
334
335 TypedArray<String> GLTFState::get_unique_animation_names_bind() const {
336 return GLTFTemplateConvert::to_array(unique_animation_names);
337 }
338
339 void GLTFState::set_unique_animation_names_bind(const TypedArray<String> &p_unique_animation_names) {
340 GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
341 }
342
343 TypedArray<GLTFSkeleton> GLTFState::get_skeletons_bind() const {
344 return GLTFTemplateConvert::to_array(skeletons);
345 }
346
347 void GLTFState::set_skeletons_bind(const TypedArray<GLTFSkeleton> &p_skeletons) {
348 GLTFTemplateConvert::set_from_array(skeletons, p_skeletons);
349 }
350
351 bool GLTFState::get_create_animations() const {
352 return create_animations;
353 }
354
355 void GLTFState::set_create_animations(bool p_create_animations) {
356 create_animations = p_create_animations;
357 }
358
359 bool GLTFState::get_import_as_skeleton_bones() const {
360 return import_as_skeleton_bones;
361 }
362
363 void GLTFState::set_import_as_skeleton_bones(bool p_import_as_skeleton_bones) {
364 import_as_skeleton_bones = p_import_as_skeleton_bones;
365 }
366
367 TypedArray<GLTFAnimation> GLTFState::get_animations_bind() const {
368 return GLTFTemplateConvert::to_array(animations);
369 }
370
371 void GLTFState::set_animations_bind(const TypedArray<GLTFAnimation> &p_animations) {
372 GLTFTemplateConvert::set_from_array(animations, p_animations);
373 }
374
375 Node *GLTFState::get_scene_node(GLTFNodeIndex p_gltf_node_index) const {
376 if (!scene_nodes.has(p_gltf_node_index)) {
377 return nullptr;
378 }
379 return scene_nodes[p_gltf_node_index];
380 }
381
382 GLTFNodeIndex GLTFState::get_node_index(Node *p_node) const {
383 for (KeyValue<GLTFNodeIndex, Node *> x : scene_nodes) {
384 if (x.value == p_node) {
385 return x.key;
386 }
387 }
388 return -1;
389 }
390
391 int GLTFState::get_animation_players_count(int p_anim_player_index) const {
392 return animation_players.size();
393 }
394
395 AnimationPlayer *GLTFState::get_animation_player(int p_anim_player_index) const {
396 ERR_FAIL_INDEX_V(p_anim_player_index, animation_players.size(), nullptr);
397 return animation_players[p_anim_player_index];
398 }
399
400 void GLTFState::set_discard_meshes_and_materials(bool p_discard_meshes_and_materials) {
401 discard_meshes_and_materials = p_discard_meshes_and_materials;
402 }
403
404 bool GLTFState::get_discard_meshes_and_materials() const {
405 return discard_meshes_and_materials;
406 }
407
408 String GLTFState::get_base_path() const {
409 return base_path;
410 }
411
412 void GLTFState::set_base_path(const String &p_base_path) {
413 base_path = p_base_path;
414 if (extract_path.is_empty()) {
415 extract_path = p_base_path;
416 }
417 }
418
419 String GLTFState::get_extract_path() const {
420 return extract_path;
421 }
422
423 void GLTFState::set_extract_path(const String &p_extract_path) {
424 extract_path = p_extract_path;
425 }
426
427 String GLTFState::get_extract_prefix() const {
428 return extract_prefix;
429 }
430
431 void GLTFState::set_extract_prefix(const String &p_extract_prefix) {
432 extract_prefix = p_extract_prefix;
433 }
434
435 String GLTFState::get_filename() const {
436 return filename;
437 }
438
439 void GLTFState::set_filename(const String &p_filename) {
440 filename = p_filename;
441 if (extract_prefix.is_empty()) {
442 extract_prefix = p_filename.get_basename();
443 }
444 }
445
446 Variant GLTFState::get_additional_data(const StringName &p_extension_name) const {
447 return additional_data[p_extension_name];
448 }
449
450 void GLTFState::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
451 additional_data[p_extension_name] = p_additional_data;
452 }
453
454 GLTFBufferViewIndex GLTFState::append_data_to_buffers(const Vector<uint8_t> &p_data, const bool p_deduplication = false) {
455 if (p_deduplication) {
456 for (int i = 0; i < buffer_views.size(); i++) {
457 Ref<GLTFBufferView> buffer_view = buffer_views[i];
458 Vector<uint8_t> buffer_view_data = buffer_view->load_buffer_view_data(this);
459 if (buffer_view_data == p_data) {
460 return i;
461 }
462 }
463 }
464 // Append the given data to a buffer and create a buffer view for it.
465 if (unlikely(buffers.is_empty())) {
466 buffers.push_back(Vector<uint8_t>());
467 }
468 Vector<uint8_t> &destination_buffer = buffers.write[0];
469 Ref<GLTFBufferView> buffer_view;
470 buffer_view.instantiate();
471 buffer_view->set_buffer(0);
472 buffer_view->set_byte_offset(destination_buffer.size());
473 buffer_view->set_byte_length(p_data.size());
474 destination_buffer.append_array(p_data);
475 const int new_index = buffer_views.size();
476 buffer_views.push_back(buffer_view);
477 return new_index;
478 }
479
480 GLTFNodeIndex GLTFState::append_gltf_node(Ref<GLTFNode> p_gltf_node, Node *p_godot_scene_node, GLTFNodeIndex p_parent_node_index) {
481 p_gltf_node->set_parent(p_parent_node_index);
482 const GLTFNodeIndex new_index = nodes.size();
483 nodes.append(p_gltf_node);
484 scene_nodes.insert(new_index, p_godot_scene_node);
485 if (p_parent_node_index == -1) {
486 root_nodes.append(new_index);
487 } else if (p_parent_node_index < new_index) {
488 nodes.write[p_parent_node_index]->append_child_index(new_index);
489 }
490 return new_index;
491 }