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 | #ifndef GLTF_STATE_H |
32 | #define GLTF_STATE_H |
33 | |
34 | #include "extensions/gltf_light.h" |
35 | #include "structures/gltf_accessor.h" |
36 | #include "structures/gltf_animation.h" |
37 | #include "structures/gltf_buffer_view.h" |
38 | #include "structures/gltf_camera.h" |
39 | #include "structures/gltf_mesh.h" |
40 | #include "structures/gltf_node.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 | class GLTFState : public Resource { |
47 | GDCLASS(GLTFState, Resource); |
48 | friend class GLTFDocument; |
49 | |
50 | String base_path; |
51 | String filename; |
52 | Dictionary json; |
53 | int major_version = 0; |
54 | int minor_version = 0; |
55 | String copyright; |
56 | Vector<uint8_t> glb_data; |
57 | |
58 | bool use_named_skin_binds = false; |
59 | bool use_khr_texture_transform = false; |
60 | bool discard_meshes_and_materials = false; |
61 | bool create_animations = true; |
62 | |
63 | int handle_binary_image = HANDLE_BINARY_EXTRACT_TEXTURES; |
64 | |
65 | Vector<Ref<GLTFNode>> nodes; |
66 | Vector<Vector<uint8_t>> buffers; |
67 | Vector<Ref<GLTFBufferView>> buffer_views; |
68 | Vector<Ref<GLTFAccessor>> accessors; |
69 | |
70 | Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to. |
71 | |
72 | Vector<AnimationPlayer *> animation_players; |
73 | HashMap<Ref<Material>, GLTFMaterialIndex> material_cache; |
74 | Vector<Ref<Material>> materials; |
75 | |
76 | String scene_name; |
77 | Vector<int> root_nodes; |
78 | Vector<Ref<GLTFTexture>> textures; |
79 | Vector<Ref<GLTFTextureSampler>> texture_samplers; |
80 | Ref<GLTFTextureSampler> default_texture_sampler; |
81 | Vector<Ref<Texture2D>> images; |
82 | Vector<String> extensions_used; |
83 | Vector<String> extensions_required; |
84 | Vector<Ref<Image>> source_images; |
85 | |
86 | Vector<Ref<GLTFSkin>> skins; |
87 | Vector<Ref<GLTFCamera>> cameras; |
88 | Vector<Ref<GLTFLight>> lights; |
89 | HashSet<String> unique_names; |
90 | HashSet<String> unique_animation_names; |
91 | |
92 | Vector<Ref<GLTFSkeleton>> skeletons; |
93 | Vector<Ref<GLTFAnimation>> animations; |
94 | HashMap<GLTFNodeIndex, Node *> scene_nodes; |
95 | HashMap<GLTFNodeIndex, ImporterMeshInstance3D *> scene_mesh_instances; |
96 | |
97 | HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton; |
98 | HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin; |
99 | Dictionary additional_data; |
100 | |
101 | protected: |
102 | static void _bind_methods(); |
103 | |
104 | public: |
105 | void add_used_extension(const String &p_extension, bool p_required = false); |
106 | |
107 | enum GLTFHandleBinary { |
108 | HANDLE_BINARY_DISCARD_TEXTURES = 0, |
109 | HANDLE_BINARY_EXTRACT_TEXTURES, |
110 | HANDLE_BINARY_EMBED_AS_BASISU, |
111 | HANDLE_BINARY_EMBED_AS_UNCOMPRESSED, // if this value changes from 3, ResourceImporterScene::pre_import must be changed as well. |
112 | }; |
113 | int32_t get_handle_binary_image() { |
114 | return handle_binary_image; |
115 | } |
116 | void set_handle_binary_image(int32_t p_handle_binary_image) { |
117 | handle_binary_image = p_handle_binary_image; |
118 | } |
119 | |
120 | Dictionary get_json(); |
121 | void set_json(Dictionary p_json); |
122 | |
123 | int get_major_version(); |
124 | void set_major_version(int p_major_version); |
125 | |
126 | int get_minor_version(); |
127 | void set_minor_version(int p_minor_version); |
128 | |
129 | String get_copyright() const; |
130 | void set_copyright(const String &p_copyright); |
131 | |
132 | Vector<uint8_t> get_glb_data(); |
133 | void set_glb_data(Vector<uint8_t> p_glb_data); |
134 | |
135 | bool get_use_named_skin_binds(); |
136 | void set_use_named_skin_binds(bool p_use_named_skin_binds); |
137 | |
138 | bool get_discard_textures(); |
139 | void set_discard_textures(bool p_discard_textures); |
140 | |
141 | bool get_embed_as_basisu(); |
142 | void set_embed_as_basisu(bool p_embed_as_basisu); |
143 | |
144 | bool (); |
145 | void (bool ); |
146 | |
147 | bool get_discard_meshes_and_materials(); |
148 | void set_discard_meshes_and_materials(bool p_discard_meshes_and_materials); |
149 | |
150 | TypedArray<GLTFNode> get_nodes(); |
151 | void set_nodes(TypedArray<GLTFNode> p_nodes); |
152 | |
153 | TypedArray<PackedByteArray> get_buffers(); |
154 | void set_buffers(TypedArray<PackedByteArray> p_buffers); |
155 | |
156 | TypedArray<GLTFBufferView> get_buffer_views(); |
157 | void set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views); |
158 | |
159 | TypedArray<GLTFAccessor> get_accessors(); |
160 | void set_accessors(TypedArray<GLTFAccessor> p_accessors); |
161 | |
162 | TypedArray<GLTFMesh> get_meshes(); |
163 | void set_meshes(TypedArray<GLTFMesh> p_meshes); |
164 | |
165 | TypedArray<Material> get_materials(); |
166 | void set_materials(TypedArray<Material> p_materials); |
167 | |
168 | String get_scene_name(); |
169 | void set_scene_name(String p_scene_name); |
170 | |
171 | String get_base_path(); |
172 | void set_base_path(String p_base_path); |
173 | |
174 | String get_filename() const; |
175 | void set_filename(const String &p_filename); |
176 | |
177 | PackedInt32Array get_root_nodes(); |
178 | void set_root_nodes(PackedInt32Array p_root_nodes); |
179 | |
180 | TypedArray<GLTFTexture> get_textures(); |
181 | void set_textures(TypedArray<GLTFTexture> p_textures); |
182 | |
183 | TypedArray<GLTFTextureSampler> get_texture_samplers(); |
184 | void set_texture_samplers(TypedArray<GLTFTextureSampler> p_texture_samplers); |
185 | |
186 | TypedArray<Texture2D> get_images(); |
187 | void set_images(TypedArray<Texture2D> p_images); |
188 | |
189 | TypedArray<GLTFSkin> get_skins(); |
190 | void set_skins(TypedArray<GLTFSkin> p_skins); |
191 | |
192 | TypedArray<GLTFCamera> get_cameras(); |
193 | void set_cameras(TypedArray<GLTFCamera> p_cameras); |
194 | |
195 | TypedArray<GLTFLight> get_lights(); |
196 | void set_lights(TypedArray<GLTFLight> p_lights); |
197 | |
198 | TypedArray<String> get_unique_names(); |
199 | void set_unique_names(TypedArray<String> p_unique_names); |
200 | |
201 | TypedArray<String> get_unique_animation_names(); |
202 | void set_unique_animation_names(TypedArray<String> p_unique_names); |
203 | |
204 | TypedArray<GLTFSkeleton> get_skeletons(); |
205 | void set_skeletons(TypedArray<GLTFSkeleton> p_skeletons); |
206 | |
207 | bool get_create_animations(); |
208 | void set_create_animations(bool p_create_animations); |
209 | |
210 | TypedArray<GLTFAnimation> get_animations(); |
211 | void set_animations(TypedArray<GLTFAnimation> p_animations); |
212 | |
213 | Node *get_scene_node(GLTFNodeIndex idx); |
214 | GLTFNodeIndex get_node_index(Node *p_node); |
215 | |
216 | int get_animation_players_count(int idx); |
217 | |
218 | AnimationPlayer *get_animation_player(int idx); |
219 | |
220 | Variant get_additional_data(const StringName &p_extension_name); |
221 | void set_additional_data(const StringName &p_extension_name, Variant p_additional_data); |
222 | }; |
223 | |
224 | #endif // GLTF_STATE_H |
225 | |