Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/gltf_state.h
10277 views
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
protected:
55
String base_path;
56
String extract_path;
57
String extract_prefix;
58
String filename;
59
Dictionary json;
60
int major_version = 0;
61
int minor_version = 0;
62
String copyright;
63
Vector<uint8_t> glb_data;
64
double bake_fps = 30.0;
65
66
bool use_named_skin_binds = false;
67
bool use_khr_texture_transform = false;
68
bool discard_meshes_and_materials = false;
69
bool force_generate_tangents = false;
70
bool create_animations = true;
71
bool force_disable_compression = false;
72
bool import_as_skeleton_bones = false;
73
74
int handle_binary_image = HANDLE_BINARY_EXTRACT_TEXTURES;
75
76
Vector<Ref<GLTFNode>> nodes;
77
Vector<Vector<uint8_t>> buffers;
78
Vector<Ref<GLTFBufferView>> buffer_views;
79
Vector<Ref<GLTFAccessor>> accessors;
80
81
Vector<Ref<GLTFMesh>> meshes; // Meshes are loaded directly, no reason not to.
82
83
Vector<AnimationPlayer *> animation_players;
84
HashMap<Ref<Material>, GLTFMaterialIndex> material_cache;
85
Vector<Ref<Material>> materials;
86
87
String scene_name;
88
Vector<int> root_nodes;
89
Vector<Ref<GLTFTexture>> textures;
90
Vector<Ref<GLTFTextureSampler>> texture_samplers;
91
Ref<GLTFTextureSampler> default_texture_sampler;
92
Vector<Ref<Texture2D>> images;
93
Vector<String> extensions_used;
94
Vector<String> extensions_required;
95
Vector<Ref<Image>> source_images;
96
97
Vector<Ref<GLTFSkin>> skins;
98
Vector<Ref<GLTFCamera>> cameras;
99
Vector<Ref<GLTFLight>> lights;
100
HashSet<String> unique_names;
101
HashSet<String> unique_animation_names;
102
103
Vector<Ref<GLTFSkeleton>> skeletons;
104
Vector<Ref<GLTFAnimation>> animations;
105
HashMap<GLTFNodeIndex, Node *> scene_nodes;
106
HashMap<GLTFNodeIndex, ImporterMeshInstance3D *> scene_mesh_instances;
107
HashMap<String, Ref<GLTFObjectModelProperty>> object_model_properties;
108
109
HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
110
HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
111
Dictionary additional_data;
112
113
protected:
114
static void _bind_methods();
115
116
public:
117
double get_bake_fps() const {
118
return bake_fps;
119
}
120
121
void set_bake_fps(double value) {
122
bake_fps = value;
123
}
124
125
void add_used_extension(const String &p_extension, bool p_required = false);
126
GLTFBufferViewIndex append_data_to_buffers(const Vector<uint8_t> &p_data, const bool p_deduplication);
127
GLTFNodeIndex append_gltf_node(Ref<GLTFNode> p_gltf_node, Node *p_godot_scene_node, GLTFNodeIndex p_parent_node_index);
128
129
enum GLTFHandleBinary {
130
HANDLE_BINARY_DISCARD_TEXTURES = 0,
131
HANDLE_BINARY_EXTRACT_TEXTURES,
132
HANDLE_BINARY_EMBED_AS_BASISU,
133
HANDLE_BINARY_EMBED_AS_UNCOMPRESSED, // If this value changes from 3, ResourceImporterScene::pre_import must be changed as well.
134
};
135
int32_t get_handle_binary_image() {
136
return handle_binary_image;
137
}
138
void set_handle_binary_image(int32_t p_handle_binary_image) {
139
handle_binary_image = p_handle_binary_image;
140
}
141
142
Dictionary get_json();
143
void set_json(Dictionary p_json);
144
145
int get_major_version();
146
void set_major_version(int p_major_version);
147
148
int get_minor_version();
149
void set_minor_version(int p_minor_version);
150
151
String get_copyright() const;
152
void set_copyright(const String &p_copyright);
153
154
Vector<uint8_t> get_glb_data();
155
void set_glb_data(Vector<uint8_t> p_glb_data);
156
157
bool get_use_named_skin_binds();
158
void set_use_named_skin_binds(bool p_use_named_skin_binds);
159
160
bool get_discard_textures();
161
void set_discard_textures(bool p_discard_textures);
162
163
bool get_embed_as_basisu();
164
void set_embed_as_basisu(bool p_embed_as_basisu);
165
166
bool get_extract_textures();
167
void set_extract_textures(bool p_extract_textures);
168
169
bool get_discard_meshes_and_materials();
170
void set_discard_meshes_and_materials(bool p_discard_meshes_and_materials);
171
172
TypedArray<GLTFNode> get_nodes();
173
void set_nodes(TypedArray<GLTFNode> p_nodes);
174
175
TypedArray<PackedByteArray> get_buffers();
176
void set_buffers(TypedArray<PackedByteArray> p_buffers);
177
178
TypedArray<GLTFBufferView> get_buffer_views();
179
void set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views);
180
181
TypedArray<GLTFAccessor> get_accessors();
182
void set_accessors(TypedArray<GLTFAccessor> p_accessors);
183
184
TypedArray<GLTFMesh> get_meshes();
185
void set_meshes(TypedArray<GLTFMesh> p_meshes);
186
187
TypedArray<Material> get_materials();
188
void set_materials(TypedArray<Material> p_materials);
189
190
String get_scene_name();
191
void set_scene_name(String p_scene_name);
192
193
String get_base_path();
194
void set_base_path(const String &p_base_path);
195
196
String get_extract_path();
197
void set_extract_path(const String &p_extract_path);
198
199
String get_extract_prefix();
200
void set_extract_prefix(const String &p_extract_prefix);
201
202
String get_filename() const;
203
void set_filename(const String &p_filename);
204
205
PackedInt32Array get_root_nodes();
206
void set_root_nodes(PackedInt32Array p_root_nodes);
207
208
TypedArray<GLTFTexture> get_textures();
209
void set_textures(TypedArray<GLTFTexture> p_textures);
210
211
TypedArray<GLTFTextureSampler> get_texture_samplers();
212
void set_texture_samplers(TypedArray<GLTFTextureSampler> p_texture_samplers);
213
214
TypedArray<Texture2D> get_images();
215
void set_images(TypedArray<Texture2D> p_images);
216
217
TypedArray<GLTFSkin> get_skins();
218
void set_skins(TypedArray<GLTFSkin> p_skins);
219
220
TypedArray<GLTFCamera> get_cameras();
221
void set_cameras(TypedArray<GLTFCamera> p_cameras);
222
223
TypedArray<GLTFLight> get_lights();
224
void set_lights(TypedArray<GLTFLight> p_lights);
225
226
TypedArray<String> get_unique_names();
227
void set_unique_names(TypedArray<String> p_unique_names);
228
229
TypedArray<String> get_unique_animation_names();
230
void set_unique_animation_names(TypedArray<String> p_unique_names);
231
232
TypedArray<GLTFSkeleton> get_skeletons();
233
void set_skeletons(TypedArray<GLTFSkeleton> p_skeletons);
234
235
bool get_create_animations();
236
void set_create_animations(bool p_create_animations);
237
238
bool get_import_as_skeleton_bones();
239
void set_import_as_skeleton_bones(bool p_import_as_skeleton_bones);
240
241
TypedArray<GLTFAnimation> get_animations();
242
void set_animations(TypedArray<GLTFAnimation> p_animations);
243
244
Node *get_scene_node(GLTFNodeIndex idx);
245
GLTFNodeIndex get_node_index(Node *p_node);
246
247
int get_animation_players_count(int idx);
248
249
AnimationPlayer *get_animation_player(int idx);
250
251
Variant get_additional_data(const StringName &p_extension_name);
252
void set_additional_data(const StringName &p_extension_name, Variant p_additional_data);
253
};
254
255