Debian Codegraph @

modules/gltf/gltf_state.h

raw symbols SCIP
1 /**************************************************************************/
2 /* gltf_state.h */
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 #pragma once
32
33 #include "extensions/gltf_light.h"
34 #include "structures/gltf_accessor.h"
35 #include "structures/gltf_animation.h"
36 #include "structures/gltf_buffer_view.h"
37 #include "structures/gltf_camera.h"
38 #include "structures/gltf_mesh.h"
39 #include "structures/gltf_node.h"
40 #include "structures/gltf_object_model_property.h"
41 #include "structures/gltf_skeleton.h"
42 #include "structures/gltf_skin.h"
43 #include "structures/gltf_texture.h"
44 #include "structures/gltf_texture_sampler.h"
45
46 #include "scene/3d/importer_mesh_instance_3d.h"
47 #include "scene/animation/animation_player.h"
48
49 class GLTFState : public Resource {
50 GDCLASS(GLTFState, Resource);
51 friend class GLTFDocument;
52 friend class GLTFNode;
53
54 public:
55 enum HandleBinaryImageMode {
56 HANDLE_BINARY_IMAGE_MODE_DISCARD_TEXTURES = 0,
57 HANDLE_BINARY_IMAGE_MODE_EXTRACT_TEXTURES,
58 HANDLE_BINARY_IMAGE_MODE_EMBED_AS_BASISU,
59 HANDLE_BINARY_IMAGE_MODE_EMBED_AS_UNCOMPRESSED, // If this value changes from 3, ResourceImporterScene::pre_import must be changed as well.
60 };
61
62 protected:
63 String base_path;
64 String extract_path;
65 String extract_prefix;
66 String filename;
67 Dictionary json;
68 int major_version = 0;
69 int minor_version = 0;
70 String copyright;
71 Vector<uint8_t> glb_data;
72 double bake_fps = 30.0;
73
74 bool use_named_skin_binds = false;
75 bool use_khr_texture_transform = false;
76 bool discard_meshes_and_materials = false;
77 bool force_generate_tangents = false;
78 bool create_animations = true;
79 bool force_disable_compression = false;
80 bool import_as_skeleton_bones = false;
81
82 HandleBinaryImageMode handle_binary_image_mode = HANDLE_BINARY_IMAGE_MODE_EXTRACT_TEXTURES;
83
84 Vector<Ref<GLTFNode>> nodes;
85 Vector<Vector<uint8_t>> buffers;
86 Vector<Ref<GLTFBufferView>> buffer_views;
87 Vector<Ref<GLTFAccessor>> accessors;
88
89 Vector<Ref<GLTFMesh>> meshes; // Meshes are loaded directly, no reason not to.
90
91 Vector<AnimationPlayer *> animation_players;
92 HashMap<Ref<Material>, GLTFMaterialIndex> material_cache;
93 Vector<Ref<Material>> materials;
94
95 String scene_name;
96 Vector<int> root_nodes;
97 Vector<Ref<GLTFTexture>> textures;
98 Vector<Ref<GLTFTextureSampler>> texture_samplers;
99 Ref<GLTFTextureSampler> default_texture_sampler;
100 Vector<Ref<Texture2D>> images;
101 Vector<String> extensions_used;
102 Vector<String> extensions_required;
103 Vector<Ref<Image>> source_images;
104
105 Vector<Ref<GLTFSkin>> skins;
106 Vector<Ref<GLTFCamera>> cameras;
107 Vector<Ref<GLTFLight>> lights;
108 HashSet<String> unique_names;
109 HashSet<String> unique_animation_names;
110
111 Vector<Ref<GLTFSkeleton>> skeletons;
112 Vector<Ref<GLTFAnimation>> animations;
113 HashMap<GLTFNodeIndex, Node *> scene_nodes;
114 HashMap<GLTFNodeIndex, ImporterMeshInstance3D *> scene_mesh_instances;
115 HashMap<String, Ref<GLTFObjectModelProperty>> object_model_properties;
116
117 HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
118 HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
119 Dictionary additional_data;
120
121 protected:
122 static void _bind_methods();
123
124 #ifndef DISABLE_DEPRECATED
125 // Non-const getters for compatibility.
126 int32_t _get_handle_binary_image_bind_compat_113172();
127 Dictionary _get_json_bind_compat_113172();
128 int _get_major_version_bind_compat_113172();
129 int _get_minor_version_bind_compat_113172();
130 Vector<uint8_t> _get_glb_data_bind_compat_113172();
131 bool _get_use_named_skin_binds_bind_compat_113172();
132 bool _get_discard_meshes_and_materials_bind_compat_113172();
133 TypedArray<GLTFNode> _get_nodes_bind_compat_113172();
134 TypedArray<PackedByteArray> _get_buffers_bind_compat_113172();
135 TypedArray<GLTFBufferView> _get_buffer_views_bind_compat_113172();
136 TypedArray<GLTFAccessor> _get_accessors_bind_compat_113172();
137 TypedArray<GLTFMesh> _get_meshes_bind_compat_113172();
138 TypedArray<Material> _get_materials_bind_compat_113172();
139 String _get_scene_name_bind_compat_113172();
140 String _get_base_path_bind_compat_113172();
141 String _get_extract_path_bind_compat_113172();
142 String _get_extract_prefix_bind_compat_113172();
143 PackedInt32Array _get_root_nodes_bind_compat_113172();
144 TypedArray<GLTFTexture> _get_textures_bind_compat_113172();
145 TypedArray<GLTFTextureSampler> _get_texture_samplers_bind_compat_113172();
146 TypedArray<Texture2D> _get_images_bind_compat_113172();
147 TypedArray<GLTFSkin> _get_skins_bind_compat_113172();
148 TypedArray<GLTFCamera> _get_cameras_bind_compat_113172();
149 TypedArray<GLTFLight> _get_lights_bind_compat_113172();
150 TypedArray<String> _get_unique_names_bind_compat_113172();
151 TypedArray<String> _get_unique_animation_names_bind_compat_113172();
152 TypedArray<GLTFSkeleton> _get_skeletons_bind_compat_113172();
153 bool _get_create_animations_bind_compat_113172();
154 bool _get_import_as_skeleton_bones_bind_compat_113172();
155 TypedArray<GLTFAnimation> _get_animations_bind_compat_113172();
156 Node *_get_scene_node_bind_compat_113172(GLTFNodeIndex p_gltf_node_index);
157 GLTFNodeIndex _get_node_index_bind_compat_113172(Node *p_node);
158 int _get_animation_players_count_bind_compat_113172(int p_anim_player_index);
159 AnimationPlayer *_get_animation_player_bind_compat_113172(int p_anim_player_index);
160 Variant _get_additional_data_bind_compat_113172(const StringName &p_extension_name);
161 static void _bind_compatibility_methods();
162 #endif // DISABLE_DEPRECATED
163
164 public:
165 double get_bake_fps() const {
166 return bake_fps;
167 }
168
169 void set_bake_fps(double value) {
170 bake_fps = value;
171 }
172
173 void add_used_extension(const String &p_extension, bool p_required = false);
174 GLTFBufferViewIndex append_data_to_buffers(const Vector<uint8_t> &p_data, const bool p_deduplication);
175 GLTFNodeIndex append_gltf_node(Ref<GLTFNode> p_gltf_node, Node *p_godot_scene_node, GLTFNodeIndex p_parent_node_index);
176
177 // Deprecated, use HandleBinaryImageMode instead.
178 enum GLTFHandleBinary {
179 HANDLE_BINARY_DISCARD_TEXTURES = 0,
180 HANDLE_BINARY_EXTRACT_TEXTURES,
181 HANDLE_BINARY_EMBED_AS_BASISU,
182 HANDLE_BINARY_EMBED_AS_UNCOMPRESSED, // If this value changes from 3, ResourceImporterScene::pre_import must be changed as well.
183 };
184 int32_t get_handle_binary_image() const {
185 return handle_binary_image_mode;
186 }
187 void set_handle_binary_image(int32_t p_handle_binary_image) {
188 handle_binary_image_mode = (HandleBinaryImageMode)p_handle_binary_image;
189 }
190 HandleBinaryImageMode get_handle_binary_image_mode() const { return handle_binary_image_mode; }
191 void set_handle_binary_image_mode(HandleBinaryImageMode p_handle_binary_image) { handle_binary_image_mode = p_handle_binary_image; }
192
193 Dictionary get_json() const;
194 void set_json(const Dictionary &p_json);
195
196 int get_major_version() const;
197 void set_major_version(int p_major_version);
198
199 int get_minor_version() const;
200 void set_minor_version(int p_minor_version);
201
202 String get_copyright() const;
203 void set_copyright(const String &p_copyright);
204
205 Vector<uint8_t> get_glb_data() const;
206 void set_glb_data(const Vector<uint8_t> &p_glb_data);
207
208 bool get_use_named_skin_binds() const;
209 void set_use_named_skin_binds(bool p_use_named_skin_binds);
210
211 bool get_discard_meshes_and_materials() const;
212 void set_discard_meshes_and_materials(bool p_discard_meshes_and_materials);
213
214 const Vector<Ref<GLTFNode>> &get_nodes() const { return nodes; }
215 void set_nodes(const Vector<Ref<GLTFNode>> &p_nodes) { nodes = p_nodes; }
216 TypedArray<GLTFNode> get_nodes_bind() const;
217 void set_nodes_bind(const TypedArray<GLTFNode> &p_nodes);
218
219 const Vector<PackedByteArray> &get_buffers() const { return buffers; }
220 void set_buffers(const Vector<PackedByteArray> &p_buffers) { buffers = p_buffers; }
221 TypedArray<PackedByteArray> get_buffers_bind() const;
222 void set_buffers_bind(const TypedArray<PackedByteArray> &p_buffers);
223
224 const Vector<Ref<GLTFBufferView>> &get_buffer_views() const { return buffer_views; }
225 void set_buffer_views(const Vector<Ref<GLTFBufferView>> &p_buffer_views) { buffer_views = p_buffer_views; }
226 TypedArray<GLTFBufferView> get_buffer_views_bind() const;
227 void set_buffer_views_bind(const TypedArray<GLTFBufferView> &p_buffer_views);
228
229 const Vector<Ref<GLTFAccessor>> &get_accessors() const { return accessors; }
230 void set_accessors(const Vector<Ref<GLTFAccessor>> &p_accessors) { accessors = p_accessors; }
231 TypedArray<GLTFAccessor> get_accessors_bind() const;
232 void set_accessors_bind(const TypedArray<GLTFAccessor> &p_accessors);
233
234 const Vector<Ref<GLTFMesh>> &get_meshes() const { return meshes; }
235 void set_meshes(const Vector<Ref<GLTFMesh>> &p_meshes) { meshes = p_meshes; }
236 TypedArray<GLTFMesh> get_meshes_bind() const;
237 void set_meshes_bind(const TypedArray<GLTFMesh> &p_meshes);
238
239 const Vector<Ref<Material>> &get_materials() const { return materials; }
240 void set_materials(const Vector<Ref<Material>> &p_materials) { materials = p_materials; }
241 TypedArray<Material> get_materials_bind() const;
242 void set_materials_bind(const TypedArray<Material> &p_materials);
243
244 String get_scene_name() const;
245 void set_scene_name(const String &p_scene_name);
246
247 String get_base_path() const;
248 void set_base_path(const String &p_base_path);
249
250 String get_extract_path() const;
251 void set_extract_path(const String &p_extract_path);
252
253 String get_extract_prefix() const;
254 void set_extract_prefix(const String &p_extract_prefix);
255
256 String get_filename() const;
257 void set_filename(const String &p_filename);
258
259 PackedInt32Array get_root_nodes() const;
260 void set_root_nodes(const PackedInt32Array &p_root_nodes);
261
262 const Vector<Ref<GLTFTexture>> &get_textures() const { return textures; }
263 void set_textures(const Vector<Ref<GLTFTexture>> &p_textures) { textures = p_textures; }
264 TypedArray<GLTFTexture> get_textures_bind() const;
265 void set_textures_bind(const TypedArray<GLTFTexture> &p_textures);
266
267 const Vector<Ref<GLTFTextureSampler>> &get_texture_samplers() const { return texture_samplers; }
268 void set_texture_samplers(const Vector<Ref<GLTFTextureSampler>> &p_texture_samplers) { texture_samplers = p_texture_samplers; }
269 TypedArray<GLTFTextureSampler> get_texture_samplers_bind() const;
270 void set_texture_samplers_bind(const TypedArray<GLTFTextureSampler> &p_texture_samplers);
271
272 const Vector<Ref<Texture2D>> &get_images() const { return images; }
273 void set_images(const Vector<Ref<Texture2D>> &p_images) { images = p_images; }
274 TypedArray<Texture2D> get_images_bind() const;
275 void set_images_bind(const TypedArray<Texture2D> &p_images);
276
277 const Vector<Ref<GLTFSkin>> &get_skins() const { return skins; }
278 void set_skins(const Vector<Ref<GLTFSkin>> &p_skins) { skins = p_skins; }
279 TypedArray<GLTFSkin> get_skins_bind() const;
280 void set_skins_bind(const TypedArray<GLTFSkin> &p_skins);
281
282 const Vector<Ref<GLTFCamera>> &get_cameras() const { return cameras; }
283 void set_cameras(const Vector<Ref<GLTFCamera>> &p_cameras) { cameras = p_cameras; }
284 TypedArray<GLTFCamera> get_cameras_bind() const;
285 void set_cameras_bind(const TypedArray<GLTFCamera> &p_cameras);
286
287 const Vector<Ref<GLTFLight>> &get_lights() const { return lights; }
288 void set_lights(const Vector<Ref<GLTFLight>> &p_lights) { lights = p_lights; }
289 TypedArray<GLTFLight> get_lights_bind() const;
290 void set_lights_bind(const TypedArray<GLTFLight> &p_lights);
291
292 const HashSet<String> &get_unique_names() const { return unique_names; }
293 void set_unique_names(const HashSet<String> &p_unique_names) { unique_names = p_unique_names; }
294 TypedArray<String> get_unique_names_bind() const;
295 void set_unique_names_bind(const TypedArray<String> &p_unique_names);
296
297 const HashSet<String> &get_unique_animation_names() const { return unique_animation_names; }
298 void set_unique_animation_names(const HashSet<String> &p_unique_animation_names) { unique_animation_names = p_unique_animation_names; }
299 TypedArray<String> get_unique_animation_names_bind() const;
300 void set_unique_animation_names_bind(const TypedArray<String> &p_unique_names);
301
302 const Vector<Ref<GLTFSkeleton>> &get_skeletons() const { return skeletons; }
303 void set_skeletons(const Vector<Ref<GLTFSkeleton>> &p_skeletons) { skeletons = p_skeletons; }
304 TypedArray<GLTFSkeleton> get_skeletons_bind() const;
305 void set_skeletons_bind(const TypedArray<GLTFSkeleton> &p_skeletons);
306
307 bool get_create_animations() const;
308 void set_create_animations(bool p_create_animations);
309
310 bool get_import_as_skeleton_bones() const;
311 void set_import_as_skeleton_bones(bool p_import_as_skeleton_bones);
312
313 const Vector<Ref<GLTFAnimation>> &get_animations() const { return animations; }
314 void set_animations(const Vector<Ref<GLTFAnimation>> &p_animations) { animations = p_animations; }
315 TypedArray<GLTFAnimation> get_animations_bind() const;
316 void set_animations_bind(const TypedArray<GLTFAnimation> &p_animations);
317
318 Node *get_scene_node(GLTFNodeIndex p_gltf_node_index) const;
319 GLTFNodeIndex get_node_index(Node *p_node) const;
320
321 int get_animation_players_count(int p_anim_player_index) const;
322
323 AnimationPlayer *get_animation_player(int p_anim_player_index) const;
324
325 Variant get_additional_data(const StringName &p_extension_name) const;
326 void set_additional_data(const StringName &p_extension_name, Variant p_additional_data);
327 };
328
329 VARIANT_ENUM_CAST(GLTFState::HandleBinaryImageMode);