#include "gltf_document.h"
#include "extensions/gltf_spec_gloss.h"
#include "gltf_state.h"
#include "skin_tool.h"
#include "core/config/project_settings.h"
#include "core/crypto/crypto_core.h"
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/file_access_memory.h"
#include "core/io/json.h"
#include "core/io/stream_peer.h"
#include "core/object/object_id.h"
#include "core/version.h"
#include "scene/3d/bone_attachment_3d.h"
#include "scene/3d/camera_3d.h"
#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/multimesh_instance_3d.h"
#include "scene/resources/3d/skin.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/portable_compressed_texture.h"
#include "scene/resources/surface_tool.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_file_system.h"
#endif
#define GLTF_IMPORT_GENERATE_TANGENT_ARRAYS …
#define GLTF_IMPORT_USE_NAMED_SKIN_BINDS …
#define GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS …
#define GLTF_IMPORT_FORCE_DISABLE_MESH_COMPRESSION …
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
static void _attach_extras_to_meta(const Dictionary &p_extras, Ref<Resource> p_node) { … }
static void _attach_meta_to_extras(Ref<Resource> p_node, Dictionary &p_json) { … }
static Ref<ImporterMesh> _mesh_to_importer_mesh(Ref<Mesh> p_mesh) { … }
Error GLTFDocument::_serialize(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_serialize_gltf_extensions(Ref<GLTFState> p_state) const { … }
Error GLTFDocument::_serialize_scenes(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_glb(Ref<FileAccess> p_file, Ref<GLTFState> p_state) { … }
static Array _vec3_to_arr(const Vector3 &p_vec3) { … }
static Vector3 _arr_to_vec3(const Array &p_array) { … }
static Array _quaternion_to_array(const Quaternion &p_quaternion) { … }
static Quaternion _arr_to_quaternion(const Array &p_array) { … }
static Transform3D _arr_to_xform(const Array &p_array) { … }
static Vector<real_t> _xform_to_array(const Transform3D p_transform) { … }
Error GLTFDocument::_serialize_nodes(Ref<GLTFState> p_state) { … }
String GLTFDocument::_gen_unique_name(Ref<GLTFState> p_state, const String &p_name) { … }
String GLTFDocument::_sanitize_animation_name(const String &p_name) { … }
String GLTFDocument::_gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name) { … }
String GLTFDocument::_sanitize_bone_name(const String &p_name) { … }
String GLTFDocument::_gen_unique_bone_name(Ref<GLTFState> p_state, const GLTFSkeletonIndex p_skel_i, const String &p_name) { … }
Error GLTFDocument::_parse_scenes(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_nodes(Ref<GLTFState> p_state) { … }
void GLTFDocument::_compute_node_heights(Ref<GLTFState> p_state) { … }
static Vector<uint8_t> _parse_base64_uri(const String &p_uri) { … }
Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path) { … }
Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path) { … }
Error GLTFDocument::_parse_buffers(Ref<GLTFState> p_state, const String &p_base_path) { … }
Error GLTFDocument::_encode_buffer_views(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_buffer_views(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_encode_accessors(Ref<GLTFState> p_state) { … }
String GLTFDocument::_get_accessor_type_name(const GLTFAccessor::GLTFAccessorType p_accessor_type) { … }
GLTFAccessor::GLTFAccessorType GLTFDocument::_get_accessor_type_from_str(const String &p_string) { … }
Error GLTFDocument::_parse_accessors(Ref<GLTFState> p_state) { … }
double GLTFDocument::_filter_number(double p_float) { … }
String GLTFDocument::_get_component_type_name(const uint32_t p_component) { … }
Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_src, const int p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type, const int p_component_type, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex, GLTFBufferViewIndex &r_accessor, const bool p_for_vertex_indices) { … }
Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> p_state, double *p_dst, const GLTFBufferViewIndex p_buffer_view, const int p_skip_every, const int p_skip_bytes, const int p_element_size, const int p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type, const int p_component_count, const int p_component_type, const int p_component_size, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex) { … }
int GLTFDocument::_get_component_type_size(const int p_component_type) { … }
Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state, const Vector<int32_t> p_attribs, const bool p_for_vertex, const bool p_for_vertex_indices) { … }
Vector<int> GLTFDocument::_decode_accessor_as_ints(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex, const Vector<int> &p_packed_vertex_ids) { … }
Vector<float> GLTFDocument::_decode_accessor_as_floats(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex, const Vector<int> &p_packed_vertex_ids) { … }
void GLTFDocument::_round_min_max_components(Vector<double> &r_type_min, Vector<double> &r_type_max) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> p_state, const Vector<Vector2> p_attribs, const bool p_for_vertex) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) { … }
void GLTFDocument::_calc_accessor_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector<double> p_attribs, Vector<double> &p_type_min) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> p_state, const Vector<Quaternion> p_attribs, const bool p_for_vertex) { … }
Vector<Vector2> GLTFDocument::_decode_accessor_as_vec2(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex, const Vector<int> &p_packed_vertex_ids) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_state, const Vector<real_t> p_attribs, const bool p_for_vertex) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> p_state, const Vector<Vector3> p_attribs, const bool p_for_vertex) { … }
GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p_state, const Vector<Vector3> p_attribs, const Vector<Vector3> p_reference_attribs, const float p_reference_multiplier, const bool p_for_vertex, const GLTFAccessorIndex p_reference_accessor) { … }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> p_state, const Vector<Transform3D> p_attribs, const bool p_for_vertex) { … }
Vector<Vector3> GLTFDocument::_decode_accessor_as_vec3(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex, const Vector<int> &p_packed_vertex_ids) { … }
Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex, const Vector<int> &p_packed_vertex_ids) { … }
Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { … }
Vector<Transform2D> GLTFDocument::_decode_accessor_as_xform2d(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { … }
Vector<Basis> GLTFDocument::_decode_accessor_as_basis(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { … }
Vector<Transform3D> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { … }
Error GLTFDocument::_serialize_meshes(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { … }
void GLTFDocument::set_naming_version(int p_version) { … }
int GLTFDocument::get_naming_version() const { … }
void GLTFDocument::set_image_format(const String &p_image_format) { … }
String GLTFDocument::get_image_format() const { … }
void GLTFDocument::set_lossy_quality(float p_lossy_quality) { … }
float GLTFDocument::get_lossy_quality() const { … }
Error GLTFDocument::_serialize_images(Ref<GLTFState> p_state) { … }
Ref<Image> GLTFDocument::_parse_image_bytes_into_image(Ref<GLTFState> p_state, const Vector<uint8_t> &p_bytes, const String &p_mime_type, int p_index, String &r_file_extension) { … }
void GLTFDocument::_parse_image_save_image(Ref<GLTFState> p_state, const Vector<uint8_t> &p_bytes, const String &p_file_extension, int p_index, Ref<Image> p_image) { … }
Error GLTFDocument::_parse_images(Ref<GLTFState> p_state, const String &p_base_path) { … }
Error GLTFDocument::_serialize_textures(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_textures(Ref<GLTFState> p_state) { … }
GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> p_state, Ref<Texture2D> p_texture, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats) { … }
Ref<Texture2D> GLTFDocument::_get_texture(Ref<GLTFState> p_state, const GLTFTextureIndex p_texture, int p_texture_types) { … }
GLTFTextureSamplerIndex GLTFDocument::_set_sampler_for_mode(Ref<GLTFState> p_state, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats) { … }
Ref<GLTFTextureSampler> GLTFDocument::_get_sampler_for_texture(Ref<GLTFState> p_state, const GLTFTextureIndex p_texture) { … }
Error GLTFDocument::_serialize_texture_samplers(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_texture_samplers(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_serialize_materials(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_materials(Ref<GLTFState> p_state) { … }
void GLTFDocument::_set_texture_transform_uv1(const Dictionary &p_dict, Ref<BaseMaterial3D> p_material) { … }
void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Ref<BaseMaterial3D> p_material) { … }
void GLTFDocument::spec_gloss_to_metal_base_color(const Color &p_specular_factor, const Color &p_diffuse, Color &r_base_color, float &r_metallic) { … }
Error GLTFDocument::_parse_skins(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_serialize_skins(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_create_skins(Ref<GLTFState> p_state) { … }
bool GLTFDocument::_skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b) { … }
void GLTFDocument::_remove_duplicate_skins(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_serialize_lights(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_serialize_cameras(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_lights(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_cameras(Ref<GLTFState> p_state) { … }
String GLTFDocument::interpolation_to_string(const GLTFAnimation::Interpolation p_interp) { … }
Error GLTFDocument::_serialize_animations(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_animations(Ref<GLTFState> p_state) { … }
void GLTFDocument::_assign_node_names(Ref<GLTFState> p_state) { … }
BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> p_state, Skeleton3D *p_skeleton, const GLTFNodeIndex p_node_index, const GLTFNodeIndex p_bone_index) { … }
GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> p_state, MeshInstance3D *p_mesh_instance) { … }
ImporterMeshInstance3D *GLTFDocument::_generate_mesh_instance(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { … }
Light3D *GLTFDocument::_generate_light(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { … }
Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { … }
GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> p_state, Camera3D *p_camera) { … }
GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> p_state, Light3D *p_light) { … }
void GLTFDocument::_convert_spatial(Ref<GLTFState> p_state, Node3D *p_spatial, Ref<GLTFNode> p_node) { … }
Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { … }
void GLTFDocument::_convert_scene_node(Ref<GLTFState> p_state, Node *p_current, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) { … }
#ifdef MODULE_CSG_ENABLED
void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state) { … }
#endif
void GLTFDocument::_create_gltf_node(Ref<GLTFState> p_state, Node *p_scene_parent, GLTFNodeIndex p_current_node_i,
GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_gltf_node, Ref<GLTFNode> p_gltf_node) { … }
void GLTFDocument::_convert_animation_player_to_gltf(AnimationPlayer *p_animation_player, Ref<GLTFState> p_state, GLTFNodeIndex p_gltf_current, GLTFNodeIndex p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) { … }
void GLTFDocument::_check_visibility(Node *p_node, bool &r_retflag) { … }
void GLTFDocument::_convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node) { … }
void GLTFDocument::_convert_light_to_gltf(Light3D *light, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node) { … }
#ifdef MODULE_GRIDMAP_ENABLED
void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state) { … }
#endif
void GLTFDocument::_convert_multi_mesh_instance_to_gltf(
MultiMeshInstance3D *p_multi_mesh_instance,
GLTFNodeIndex p_parent_node_index,
GLTFNodeIndex p_root_node_index,
Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state) { … }
void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node) { … }
void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node) { … }
void GLTFDocument::_convert_mesh_instance_to_gltf(MeshInstance3D *p_scene_parent, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node) { … }
void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root) { … }
void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root) { … }
template <typename T>
struct SceneFormatImporterGLTFInterpolate { … };
template <>
struct SceneFormatImporterGLTFInterpolate<Quaternion> { … };
template <typename T>
T GLTFDocument::_interpolate_track(const Vector<real_t> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) { … }
void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks) { … }
void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> p_state) { … }
float GLTFDocument::solve_metallic(float p_dielectric_specular, float p_diffuse, float p_specular, float p_one_minus_specular_strength) { … }
float GLTFDocument::get_perceived_brightness(const Color p_color) { … }
float GLTFDocument::get_max_component(const Color &p_color) { … }
void GLTFDocument::_process_mesh_instances(Ref<GLTFState> p_state, Node *p_scene_root) { … }
GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i) { … }
void GLTFDocument::_convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, String p_animation_track_name) { … }
Error GLTFDocument::_parse(Ref<GLTFState> p_state, String p_path, Ref<FileAccess> p_file) { … }
Dictionary _serialize_texture_transform_uv(Vector2 p_offset, Vector2 p_scale) { … }
Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material) { … }
Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material) { … }
Error GLTFDocument::_serialize_asset_header(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_serialize_file(Ref<GLTFState> p_state, const String p_path) { … }
void GLTFDocument::_bind_methods() { … }
void GLTFDocument::_build_parent_hierachy(Ref<GLTFState> p_state) { … }
Vector<Ref<GLTFDocumentExtension>> GLTFDocument::all_document_extensions;
void GLTFDocument::register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority) { … }
void GLTFDocument::unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension) { … }
void GLTFDocument::unregister_all_gltf_document_extensions() { … }
Vector<Ref<GLTFDocumentExtension>> GLTFDocument::get_all_gltf_document_extensions() { … }
Vector<String> GLTFDocument::get_supported_gltf_extensions() { … }
HashSet<String> GLTFDocument::get_supported_gltf_extensions_hashset() { … }
PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> p_state, Error *r_err) { … }
Node *GLTFDocument::_generate_scene_node_tree(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_asset_header(Ref<GLTFState> p_state) { … }
Error GLTFDocument::_parse_gltf_state(Ref<GLTFState> p_state, const String &p_search_path) { … }
PackedByteArray GLTFDocument::generate_buffer(Ref<GLTFState> p_state) { … }
Error GLTFDocument::write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) { … }
Node *GLTFDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) { … }
Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags) { … }
Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags) { … }
Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags, String p_base_path) { … }
Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> p_state) { … }
void GLTFDocument::set_root_node_mode(GLTFDocument::RootNodeMode p_root_node_mode) { … }
GLTFDocument::RootNodeMode GLTFDocument::get_root_node_mode() const { … }
String GLTFDocument::_gen_unique_name_static(HashSet<String> &r_unique_names, const String &p_name) { … }