2020-12-21 15:39:32 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* gltf_state.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef GLTF_STATE_H
|
|
|
|
#define GLTF_STATE_H
|
|
|
|
|
2022-07-24 19:20:50 +00:00
|
|
|
#include "extensions/gltf_light.h"
|
|
|
|
#include "structures/gltf_accessor.h"
|
|
|
|
#include "structures/gltf_animation.h"
|
|
|
|
#include "structures/gltf_buffer_view.h"
|
|
|
|
#include "structures/gltf_camera.h"
|
|
|
|
#include "structures/gltf_mesh.h"
|
|
|
|
#include "structures/gltf_node.h"
|
|
|
|
#include "structures/gltf_skeleton.h"
|
|
|
|
#include "structures/gltf_skin.h"
|
|
|
|
#include "structures/gltf_texture.h"
|
2021-10-04 15:49:42 +00:00
|
|
|
#include "structures/gltf_texture_sampler.h"
|
2021-07-14 22:46:35 +00:00
|
|
|
|
2024-02-16 13:25:15 +00:00
|
|
|
#include "scene/3d/importer_mesh_instance_3d.h"
|
|
|
|
|
2020-12-21 15:39:32 +00:00
|
|
|
class GLTFState : public Resource {
|
|
|
|
GDCLASS(GLTFState, Resource);
|
|
|
|
friend class GLTFDocument;
|
|
|
|
|
2024-02-16 13:25:15 +00:00
|
|
|
protected:
|
2022-04-09 09:35:50 +00:00
|
|
|
String base_path;
|
2023-07-18 19:28:09 +00:00
|
|
|
String filename;
|
2020-12-21 15:39:32 +00:00
|
|
|
Dictionary json;
|
|
|
|
int major_version = 0;
|
|
|
|
int minor_version = 0;
|
2023-07-10 05:18:55 +00:00
|
|
|
String copyright;
|
2020-12-21 15:39:32 +00:00
|
|
|
Vector<uint8_t> glb_data;
|
2024-05-23 15:40:26 +00:00
|
|
|
double bake_fps = 30.0;
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
bool use_named_skin_binds = false;
|
2022-07-23 23:52:46 +00:00
|
|
|
bool use_khr_texture_transform = false;
|
2022-04-13 12:14:26 +00:00
|
|
|
bool discard_meshes_and_materials = false;
|
2023-08-29 19:04:32 +00:00
|
|
|
bool force_generate_tangents = false;
|
2022-08-09 17:39:58 +00:00
|
|
|
bool create_animations = true;
|
2023-08-29 19:04:32 +00:00
|
|
|
bool force_disable_compression = false;
|
2024-02-25 08:36:39 +00:00
|
|
|
bool import_as_skeleton_bones = false;
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-07-19 00:58:27 +00:00
|
|
|
int handle_binary_image = HANDLE_BINARY_EXTRACT_TEXTURES;
|
|
|
|
|
2020-12-21 15:39:32 +00:00
|
|
|
Vector<Ref<GLTFNode>> nodes;
|
|
|
|
Vector<Vector<uint8_t>> buffers;
|
|
|
|
Vector<Ref<GLTFBufferView>> buffer_views;
|
|
|
|
Vector<Ref<GLTFAccessor>> accessors;
|
|
|
|
|
2024-02-16 13:25:15 +00:00
|
|
|
Vector<Ref<GLTFMesh>> meshes; // Meshes are loaded directly, no reason not to.
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
Vector<AnimationPlayer *> animation_players;
|
2022-11-23 23:29:01 +00:00
|
|
|
HashMap<Ref<Material>, GLTFMaterialIndex> material_cache;
|
|
|
|
Vector<Ref<Material>> materials;
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
String scene_name;
|
|
|
|
Vector<int> root_nodes;
|
|
|
|
Vector<Ref<GLTFTexture>> textures;
|
2021-10-04 15:49:42 +00:00
|
|
|
Vector<Ref<GLTFTextureSampler>> texture_samplers;
|
|
|
|
Ref<GLTFTextureSampler> default_texture_sampler;
|
2020-12-21 15:39:32 +00:00
|
|
|
Vector<Ref<Texture2D>> images;
|
2022-09-18 03:06:23 +00:00
|
|
|
Vector<String> extensions_used;
|
|
|
|
Vector<String> extensions_required;
|
2022-07-19 00:58:27 +00:00
|
|
|
Vector<Ref<Image>> source_images;
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
Vector<Ref<GLTFSkin>> skins;
|
|
|
|
Vector<Ref<GLTFCamera>> cameras;
|
|
|
|
Vector<Ref<GLTFLight>> lights;
|
2022-05-19 15:00:06 +00:00
|
|
|
HashSet<String> unique_names;
|
|
|
|
HashSet<String> unique_animation_names;
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
Vector<Ref<GLTFSkeleton>> skeletons;
|
|
|
|
Vector<Ref<GLTFAnimation>> animations;
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<GLTFNodeIndex, Node *> scene_nodes;
|
2023-01-27 06:41:58 +00:00
|
|
|
HashMap<GLTFNodeIndex, ImporterMeshInstance3D *> scene_mesh_instances;
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
|
|
|
|
HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
|
2022-10-15 16:46:02 +00:00
|
|
|
Dictionary additional_data;
|
2021-09-04 01:00:59 +00:00
|
|
|
|
2020-12-21 15:39:32 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2024-05-23 15:40:26 +00:00
|
|
|
double get_bake_fps() const {
|
|
|
|
return bake_fps;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_bake_fps(double value) {
|
|
|
|
bake_fps = value;
|
|
|
|
}
|
|
|
|
|
2022-09-18 03:06:23 +00:00
|
|
|
void add_used_extension(const String &p_extension, bool p_required = false);
|
2024-01-10 22:08:25 +00:00
|
|
|
GLTFBufferViewIndex append_data_to_buffers(const Vector<uint8_t> &p_data, const bool p_deduplication);
|
2024-09-02 08:28:07 +00:00
|
|
|
GLTFNodeIndex append_gltf_node(Ref<GLTFNode> p_gltf_node, Node *p_godot_scene_node, GLTFNodeIndex p_parent_node_index);
|
2022-09-18 03:06:23 +00:00
|
|
|
|
2022-07-19 00:58:27 +00:00
|
|
|
enum GLTFHandleBinary {
|
|
|
|
HANDLE_BINARY_DISCARD_TEXTURES = 0,
|
|
|
|
HANDLE_BINARY_EXTRACT_TEXTURES,
|
|
|
|
HANDLE_BINARY_EMBED_AS_BASISU,
|
2024-02-16 13:25:15 +00:00
|
|
|
HANDLE_BINARY_EMBED_AS_UNCOMPRESSED, // If this value changes from 3, ResourceImporterScene::pre_import must be changed as well.
|
2022-07-19 00:58:27 +00:00
|
|
|
};
|
|
|
|
int32_t get_handle_binary_image() {
|
|
|
|
return handle_binary_image;
|
|
|
|
}
|
|
|
|
void set_handle_binary_image(int32_t p_handle_binary_image) {
|
|
|
|
handle_binary_image = p_handle_binary_image;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:39:32 +00:00
|
|
|
Dictionary get_json();
|
|
|
|
void set_json(Dictionary p_json);
|
|
|
|
|
|
|
|
int get_major_version();
|
|
|
|
void set_major_version(int p_major_version);
|
|
|
|
|
|
|
|
int get_minor_version();
|
|
|
|
void set_minor_version(int p_minor_version);
|
|
|
|
|
2023-07-18 19:28:09 +00:00
|
|
|
String get_copyright() const;
|
|
|
|
void set_copyright(const String &p_copyright);
|
2023-07-10 05:18:55 +00:00
|
|
|
|
2020-12-21 15:39:32 +00:00
|
|
|
Vector<uint8_t> get_glb_data();
|
|
|
|
void set_glb_data(Vector<uint8_t> p_glb_data);
|
|
|
|
|
|
|
|
bool get_use_named_skin_binds();
|
|
|
|
void set_use_named_skin_binds(bool p_use_named_skin_binds);
|
|
|
|
|
2022-07-19 00:58:27 +00:00
|
|
|
bool get_discard_textures();
|
|
|
|
void set_discard_textures(bool p_discard_textures);
|
|
|
|
|
|
|
|
bool get_embed_as_basisu();
|
|
|
|
void set_embed_as_basisu(bool p_embed_as_basisu);
|
|
|
|
|
|
|
|
bool get_extract_textures();
|
|
|
|
void set_extract_textures(bool p_extract_textures);
|
|
|
|
|
2022-04-13 12:14:26 +00:00
|
|
|
bool get_discard_meshes_and_materials();
|
|
|
|
void set_discard_meshes_and_materials(bool p_discard_meshes_and_materials);
|
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFNode> get_nodes();
|
|
|
|
void set_nodes(TypedArray<GLTFNode> p_nodes);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<PackedByteArray> get_buffers();
|
|
|
|
void set_buffers(TypedArray<PackedByteArray> p_buffers);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFBufferView> get_buffer_views();
|
|
|
|
void set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFAccessor> get_accessors();
|
|
|
|
void set_accessors(TypedArray<GLTFAccessor> p_accessors);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFMesh> get_meshes();
|
|
|
|
void set_meshes(TypedArray<GLTFMesh> p_meshes);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-11-23 23:29:01 +00:00
|
|
|
TypedArray<Material> get_materials();
|
|
|
|
void set_materials(TypedArray<Material> p_materials);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
String get_scene_name();
|
|
|
|
void set_scene_name(String p_scene_name);
|
|
|
|
|
2022-04-09 09:35:50 +00:00
|
|
|
String get_base_path();
|
|
|
|
void set_base_path(String p_base_path);
|
|
|
|
|
2023-07-18 19:28:09 +00:00
|
|
|
String get_filename() const;
|
|
|
|
void set_filename(const String &p_filename);
|
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
PackedInt32Array get_root_nodes();
|
|
|
|
void set_root_nodes(PackedInt32Array p_root_nodes);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFTexture> get_textures();
|
|
|
|
void set_textures(TypedArray<GLTFTexture> p_textures);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2021-10-04 15:49:42 +00:00
|
|
|
TypedArray<GLTFTextureSampler> get_texture_samplers();
|
|
|
|
void set_texture_samplers(TypedArray<GLTFTextureSampler> p_texture_samplers);
|
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<Texture2D> get_images();
|
|
|
|
void set_images(TypedArray<Texture2D> p_images);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFSkin> get_skins();
|
|
|
|
void set_skins(TypedArray<GLTFSkin> p_skins);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFCamera> get_cameras();
|
|
|
|
void set_cameras(TypedArray<GLTFCamera> p_cameras);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFLight> get_lights();
|
|
|
|
void set_lights(TypedArray<GLTFLight> p_lights);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<String> get_unique_names();
|
|
|
|
void set_unique_names(TypedArray<String> p_unique_names);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<String> get_unique_animation_names();
|
|
|
|
void set_unique_animation_names(TypedArray<String> p_unique_names);
|
2021-01-28 20:48:12 +00:00
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFSkeleton> get_skeletons();
|
|
|
|
void set_skeletons(TypedArray<GLTFSkeleton> p_skeletons);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
2022-08-09 17:39:58 +00:00
|
|
|
bool get_create_animations();
|
|
|
|
void set_create_animations(bool p_create_animations);
|
|
|
|
|
2024-02-25 08:36:39 +00:00
|
|
|
bool get_import_as_skeleton_bones();
|
|
|
|
void set_import_as_skeleton_bones(bool p_import_as_skeleton_bones);
|
|
|
|
|
2022-08-07 22:52:20 +00:00
|
|
|
TypedArray<GLTFAnimation> get_animations();
|
|
|
|
void set_animations(TypedArray<GLTFAnimation> p_animations);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
Node *get_scene_node(GLTFNodeIndex idx);
|
2023-05-26 22:22:29 +00:00
|
|
|
GLTFNodeIndex get_node_index(Node *p_node);
|
2020-12-21 15:39:32 +00:00
|
|
|
|
|
|
|
int get_animation_players_count(int idx);
|
|
|
|
|
|
|
|
AnimationPlayer *get_animation_player(int idx);
|
|
|
|
|
2022-10-15 16:46:02 +00:00
|
|
|
Variant get_additional_data(const StringName &p_extension_name);
|
|
|
|
void set_additional_data(const StringName &p_extension_name, Variant p_additional_data);
|
2020-12-21 15:39:32 +00:00
|
|
|
};
|
2022-07-23 21:41:51 +00:00
|
|
|
|
2020-12-21 15:39:32 +00:00
|
|
|
#endif // GLTF_STATE_H
|