2022-08-07 20:56:19 +02:00
|
|
|
#ifndef GLTF_DOCUMENT_H
|
|
|
|
#define GLTF_DOCUMENT_H
|
2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* gltf_document.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-08-08 19:45:06 +02:00
|
|
|
#include "scene/3d/camera.h"
|
|
|
|
#include "scene/3d/light.h"
|
2022-08-07 21:52:04 +02:00
|
|
|
#include "scene/3d/mesh_instance.h"
|
2022-08-08 19:45:06 +02:00
|
|
|
#include "scene/3d/spatial.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
#include "scene/animation/animation_player.h"
|
|
|
|
#include "scene/resources/material.h"
|
2022-08-08 19:45:06 +02:00
|
|
|
#include "scene/resources/texture.h"
|
|
|
|
|
2022-12-22 19:24:45 +01:00
|
|
|
#include "extensions/gltf_document_extension.h"
|
2022-11-30 15:50:09 +01:00
|
|
|
#include "gltf_defines.h"
|
2022-12-11 19:39:24 +01:00
|
|
|
#include "structures/gltf_animation.h"
|
2022-08-08 02:53:46 +02:00
|
|
|
|
2022-08-08 19:45:06 +02:00
|
|
|
#include "modules/modules_enabled.gen.h" // For csg, gridmap.
|
|
|
|
|
2022-08-28 16:01:50 +02:00
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-08-28 15:46:12 +02:00
|
|
|
class Skeleton;
|
|
|
|
class BoneAttachment;
|
2022-08-28 16:01:50 +02:00
|
|
|
#endif
|
2022-08-28 15:46:12 +02:00
|
|
|
|
2023-07-11 12:23:46 +02:00
|
|
|
#ifdef MODULE_CSG_ENABLED
|
|
|
|
class CSGShape;
|
|
|
|
#endif // MODULE_CSG_ENABLED
|
|
|
|
|
2022-10-08 23:58:46 +02:00
|
|
|
#ifdef MODULE_GRIDMAP_ENABLED
|
|
|
|
class GridMap;
|
|
|
|
#endif // MODULE_GRIDMAP_ENABLED
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
class GLTFDocument : public Resource {
|
|
|
|
GDCLASS(GLTFDocument, Resource);
|
2022-08-08 19:45:06 +02:00
|
|
|
|
|
|
|
private:
|
2022-12-22 19:24:45 +01:00
|
|
|
static Vector<Ref<GLTFDocumentExtension>> all_document_extensions;
|
|
|
|
Vector<Ref<GLTFDocumentExtension>> document_extensions;
|
|
|
|
|
2022-08-08 19:45:06 +02:00
|
|
|
const float BAKE_FPS = 30.0f;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
const int32_t JOINT_GROUP_SIZE = 4;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARRAY_BUFFER = 34962,
|
|
|
|
ELEMENT_ARRAY_BUFFER = 34963,
|
|
|
|
|
|
|
|
TYPE_BYTE = 5120,
|
|
|
|
TYPE_UNSIGNED_BYTE = 5121,
|
|
|
|
TYPE_SHORT = 5122,
|
|
|
|
TYPE_UNSIGNED_SHORT = 5123,
|
|
|
|
TYPE_UNSIGNED_INT = 5125,
|
|
|
|
TYPE_FLOAT = 5126,
|
|
|
|
|
|
|
|
COMPONENT_TYPE_BYTE = 5120,
|
|
|
|
COMPONENT_TYPE_UNSIGNED_BYTE = 5121,
|
|
|
|
COMPONENT_TYPE_SHORT = 5122,
|
|
|
|
COMPONENT_TYPE_UNSIGNED_SHORT = 5123,
|
|
|
|
COMPONENT_TYPE_INT = 5125,
|
|
|
|
COMPONENT_TYPE_FLOAT = 5126,
|
|
|
|
};
|
|
|
|
|
2022-12-22 19:24:45 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void _register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority = false);
|
|
|
|
void _unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
|
|
|
|
void _unregister_all_gltf_document_extensions();
|
|
|
|
static void register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority = false);
|
|
|
|
static void unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
|
|
|
|
static void unregister_all_gltf_document_extensions();
|
|
|
|
|
2022-08-08 19:45:06 +02:00
|
|
|
private:
|
2022-03-15 13:29:32 +01:00
|
|
|
double _filter_number(double p_float);
|
|
|
|
String _get_component_type_name(const uint32_t p_component);
|
2022-12-11 20:00:56 +01:00
|
|
|
int _get_component_type_size(const int p_component_type);
|
|
|
|
Error _parse_scenes(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_nodes(Ref<GLTFState> p_state);
|
2022-03-15 13:29:32 +01:00
|
|
|
String _get_type_name(const GLTFType p_component);
|
2022-11-30 15:50:09 +01:00
|
|
|
String _get_accessor_type_name(const GLTFType p_type);
|
2022-12-11 20:00:56 +01:00
|
|
|
String _gen_unique_name(Ref<GLTFState> p_state, const String &p_name);
|
|
|
|
String _sanitize_animation_name(const String &p_name);
|
|
|
|
String _gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name);
|
|
|
|
String _sanitize_bone_name(Ref<GLTFState> p_state, const String &p_name);
|
|
|
|
String _gen_unique_bone_name(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFSkeletonIndex skel_i,
|
|
|
|
const String &p_name);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFTextureIndex _set_texture(Ref<GLTFState> p_state, Ref<Texture> p_texture);
|
|
|
|
Ref<Texture> _get_texture(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFTextureIndex p_texture);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFTextureSamplerIndex _set_sampler_for_mode(Ref<GLTFState> p_state,
|
2021-10-04 17:49:42 +02:00
|
|
|
uint32_t p_mode);
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFTextureSampler> _get_sampler_for_texture(Ref<GLTFState> p_state,
|
2021-10-04 17:49:42 +02:00
|
|
|
const GLTFTextureIndex p_texture);
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _parse_json(const String &p_path, Ref<GLTFState> p_state);
|
|
|
|
Error _parse_glb(const String &p_path, Ref<GLTFState> p_state);
|
|
|
|
void _compute_node_heights(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_buffers(Ref<GLTFState> p_state, const String &p_base_path);
|
|
|
|
Error _parse_buffer_views(Ref<GLTFState> p_state);
|
2022-03-15 13:29:32 +01:00
|
|
|
GLTFType _get_type_from_str(const String &p_string);
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _parse_accessors(Ref<GLTFState> p_state);
|
|
|
|
Error _decode_buffer_view(Ref<GLTFState> p_state, double *p_dst,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFBufferViewIndex p_buffer_view,
|
2022-12-11 20:00:56 +01:00
|
|
|
const int p_skip_every, const int p_skip_bytes,
|
|
|
|
const int p_element_size, const int p_count,
|
|
|
|
const GLTFType p_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);
|
|
|
|
Vector<double> _decode_accessor(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<float> _decode_accessor_as_floats(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<int> _decode_accessor_as_ints(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Color> _decode_accessor_as_color(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Quaternion> _decode_accessor_as_quat(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Vector<Transform> _decode_accessor_as_xform(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFAccessorIndex p_accessor,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _parse_meshes(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_textures(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_texture_samplers(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_images(Ref<GLTFState> p_state, const String &p_path);
|
|
|
|
Error _serialize_lights(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_images(Ref<GLTFState> p_state, const String &p_base_path);
|
|
|
|
Error _parse_textures(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_texture_samplers(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_materials(Ref<GLTFState> p_state);
|
|
|
|
void _set_texture_transform_uv1(const Dictionary &p_d, Ref<SpatialMaterial> p_material);
|
|
|
|
void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> p_r_spec_gloss,
|
2022-08-07 22:53:31 +02:00
|
|
|
Ref<SpatialMaterial> p_material);
|
2022-03-15 13:29:32 +01:00
|
|
|
static void spec_gloss_to_metal_base_color(const Color &p_specular_factor,
|
|
|
|
const Color &p_diffuse,
|
2022-12-11 20:00:56 +01:00
|
|
|
Color &p_r_base_color,
|
|
|
|
float &p_r_metallic);
|
|
|
|
GLTFNodeIndex _find_highest_node(Ref<GLTFState> p_state,
|
|
|
|
const Vector<GLTFNodeIndex> &p_subset);
|
|
|
|
bool _capture_nodes_in_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin,
|
|
|
|
const GLTFNodeIndex p_node_index);
|
|
|
|
void _capture_nodes_for_multirooted_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin);
|
|
|
|
Error _expand_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin);
|
|
|
|
Error _verify_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin);
|
|
|
|
Error _parse_skins(Ref<GLTFState> p_state);
|
|
|
|
Error _determine_skeletons(Ref<GLTFState> p_state);
|
|
|
|
Error _reparent_non_joint_skeleton_subtrees(Ref<GLTFState> p_state, Ref<GLTFSkeleton> p_skeleton, const Vector<GLTFNodeIndex> &p_non_joints);
|
|
|
|
Error _determine_skeleton_roots(Ref<GLTFState> p_state, const GLTFSkeletonIndex p_skel_i);
|
2022-08-28 15:46:12 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _create_skeletons(Ref<GLTFState> p_state);
|
2022-08-28 15:46:12 +02:00
|
|
|
#endif
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_skins(Ref<GLTFState> p_state);
|
|
|
|
Error _create_skins(Ref<GLTFState> p_state);
|
2022-08-28 16:01:50 +02:00
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-12-11 20:00:56 +01:00
|
|
|
bool _skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b);
|
2022-08-28 16:01:50 +02:00
|
|
|
#endif
|
2022-12-11 20:00:56 +01:00
|
|
|
void _remove_duplicate_skins(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_cameras(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_cameras(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_lights(Ref<GLTFState> p_state);
|
|
|
|
Error _parse_animations(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_animations(Ref<GLTFState> p_state);
|
2022-08-28 15:46:12 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-12-11 20:00:56 +01:00
|
|
|
BoneAttachment *_generate_bone_attachment(Ref<GLTFState> p_state, Skeleton *p_skeleton, const GLTFNodeIndex p_node_index, const GLTFNodeIndex p_bone_index);
|
2022-08-28 15:46:12 +02:00
|
|
|
#endif
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
Spatial *_generate_mesh_instance(Ref<GLTFState> p_state, Node *p_scene_parent, const GLTFNodeIndex p_node_index);
|
|
|
|
Camera *_generate_camera(Ref<GLTFState> p_state, Node *p_scene_parent,
|
|
|
|
const GLTFNodeIndex p_node_index);
|
|
|
|
Spatial *_generate_light(Ref<GLTFState> p_state, Node *p_scene_parent, const GLTFNodeIndex p_node_index);
|
|
|
|
Spatial *_generate_spatial(Ref<GLTFState> p_state, Node *p_scene_parent,
|
|
|
|
const GLTFNodeIndex p_node_index);
|
|
|
|
void _assign_scene_names(Ref<GLTFState> p_state);
|
2022-03-15 13:29:32 +01:00
|
|
|
template <class T>
|
2022-08-08 19:45:06 +02:00
|
|
|
T _interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values,
|
2022-03-15 13:29:32 +01:00
|
|
|
const float p_time,
|
|
|
|
const GLTFAnimation::Interpolation p_interp);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_quats(Ref<GLTFState> p_state,
|
2022-08-13 15:22:33 +02:00
|
|
|
const Vector<Quaternion> p_attribs,
|
2022-03-15 13:29:32 +01:00
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const Vector<Color> p_attribs,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_joints(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const Vector<Color> p_attribs,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> p_state,
|
2022-08-08 19:45:06 +02:00
|
|
|
const Vector<real_t> p_attribs,
|
2022-03-15 13:29:32 +01:00
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const Vector<Vector2> p_attribs,
|
|
|
|
const bool p_for_vertex);
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
void _calc_accessor_vec2_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector2 p_attribs, Vector<double> &p_type_min) {
|
|
|
|
if (p_i == 0) {
|
|
|
|
for (int32_t type_i = 0; type_i < p_element_count; type_i++) {
|
|
|
|
p_type_max.write[type_i] = p_attribs[(p_i * p_element_count) + type_i];
|
|
|
|
p_type_min.write[type_i] = p_attribs[(p_i * p_element_count) + type_i];
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-11 20:00:56 +01:00
|
|
|
for (int32_t type_i = 0; type_i < p_element_count; type_i++) {
|
|
|
|
p_type_max.write[type_i] = MAX(p_attribs[(p_i * p_element_count) + type_i], p_type_max[type_i]);
|
|
|
|
p_type_min.write[type_i] = MIN(p_attribs[(p_i * p_element_count) + type_i], p_type_min[type_i]);
|
|
|
|
p_type_max.write[type_i] = _filter_number(p_type_max.write[type_i]);
|
|
|
|
p_type_min.write[type_i] = _filter_number(p_type_min.write[type_i]);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> p_state,
|
2022-08-08 19:45:06 +02:00
|
|
|
const Vector<Vector3> p_attribs,
|
2022-03-15 13:29:32 +01:00
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const Vector<Color> p_attribs,
|
|
|
|
const bool p_for_vertex);
|
|
|
|
|
2022-08-08 19:45:06 +02:00
|
|
|
void _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);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_ints(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
const Vector<int32_t> p_attribs,
|
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> p_state,
|
2022-08-07 22:53:31 +02:00
|
|
|
const Vector<Transform> p_attribs,
|
2022-03-15 13:29:32 +01:00
|
|
|
const bool p_for_vertex);
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _encode_buffer_view(Ref<GLTFState> p_state, const double *p_src,
|
|
|
|
const int p_count, const GLTFType p_type,
|
|
|
|
const int p_component_type, const bool p_normalized,
|
|
|
|
const int p_byte_offset, const bool p_for_vertex,
|
|
|
|
GLTFBufferViewIndex &p_r_accessor);
|
|
|
|
Error _encode_accessors(Ref<GLTFState> p_state);
|
|
|
|
Error _encode_buffer_views(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_materials(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_meshes(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_nodes(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_scenes(Ref<GLTFState> p_state);
|
2022-03-15 13:29:32 +01:00
|
|
|
String interpolation_to_string(const GLTFAnimation::Interpolation p_interp);
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> p_state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i);
|
|
|
|
Error _encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path);
|
|
|
|
Error _encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path);
|
2022-08-07 22:53:31 +02:00
|
|
|
Dictionary _serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material);
|
|
|
|
Dictionary _serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material);
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _serialize_version(Ref<GLTFState> p_state);
|
|
|
|
Error _serialize_file(Ref<GLTFState> p_state, const String p_path);
|
2022-12-22 19:24:45 +01:00
|
|
|
Error _serialize_gltf_extensions(Ref<GLTFState> p_state) const;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
public:
|
2022-08-08 19:45:06 +02:00
|
|
|
// http://www.itu.int/rec/R-REC-BT.601
|
|
|
|
// http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf
|
2022-03-15 13:29:32 +01:00
|
|
|
static constexpr float R_BRIGHTNESS_COEFF = 0.299f;
|
|
|
|
static constexpr float G_BRIGHTNESS_COEFF = 0.587f;
|
|
|
|
static constexpr float B_BRIGHTNESS_COEFF = 0.114f;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// https://github.com/microsoft/glTF-SDK/blob/master/GLTFSDK/Source/PBRUtils.cpp#L9
|
|
|
|
// https://bghgary.github.io/glTF/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
|
2022-12-11 20:00:56 +01:00
|
|
|
static float solve_metallic(float p_dielectric_specular, float p_diffuse,
|
|
|
|
float p_specular,
|
2022-03-15 13:29:32 +01:00
|
|
|
float p_one_minus_specular_strength);
|
|
|
|
static float get_perceived_brightness(const Color p_color);
|
|
|
|
static float get_max_component(const Color &p_color);
|
|
|
|
|
|
|
|
public:
|
2022-12-22 19:24:45 +01:00
|
|
|
void extension_generate_scene(Ref<GLTFState> p_state);
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
String _sanitize_scene_name(Ref<GLTFState> p_state, const String &p_name);
|
2022-08-08 19:45:06 +02:00
|
|
|
String _legacy_validate_node_name(const String &p_name);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
Error _parse_gltf_extensions(Ref<GLTFState> p_state);
|
2022-08-08 19:45:06 +02:00
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
void _process_mesh_instances(Ref<GLTFState> p_state, Node *scene_root);
|
|
|
|
void _generate_scene_node(Ref<GLTFState> p_state, Node *scene_parent,
|
|
|
|
Spatial *p_scene_root,
|
|
|
|
const GLTFNodeIndex p_node_index);
|
2022-08-28 15:46:12 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-12-11 20:00:56 +01:00
|
|
|
void _generate_skeleton_bone_node(Ref<GLTFState> p_state, Node *scene_parent, Spatial *scene_root, const GLTFNodeIndex node_index);
|
2022-08-28 15:46:12 +02:00
|
|
|
#endif
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
void _import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ap,
|
|
|
|
const GLTFAnimationIndex p_index, const int p_bake_fps);
|
|
|
|
void _convert_mesh_instances(Ref<GLTFState> p_state);
|
|
|
|
GLTFCameraIndex _convert_camera(Ref<GLTFState> p_state, Camera *p_camera);
|
|
|
|
void _convert_light_to_gltf(Light *p_light, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node);
|
|
|
|
GLTFLightIndex _convert_light(Ref<GLTFState> p_state, Light *p_light);
|
|
|
|
void _convert_spatial(Ref<GLTFState> p_state, Spatial *p_spatial, Ref<GLTFNode> p_node);
|
|
|
|
void _convert_scene_node(Ref<GLTFState> p_state, Node *p_current,
|
2022-03-15 13:29:32 +01:00
|
|
|
const GLTFNodeIndex p_gltf_current,
|
|
|
|
const GLTFNodeIndex p_gltf_root);
|
|
|
|
|
2023-07-11 12:23:46 +02:00
|
|
|
#ifdef MODULE_CSG_ENABLED
|
|
|
|
void _convert_csg_shape_to_gltf(CSGShape *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
|
|
|
|
#endif // MODULE_CSG_ENABLED
|
|
|
|
|
2022-12-11 20:00:56 +01:00
|
|
|
void _create_gltf_node(Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
Node *p_scene_parent,
|
2022-12-11 20:00:56 +01:00
|
|
|
GLTFNodeIndex p_current_node_i,
|
2022-03-15 13:29:32 +01:00
|
|
|
GLTFNodeIndex p_parent_node_index,
|
|
|
|
GLTFNodeIndex p_root_gltf_node,
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFNode> p_gltf_node);
|
2022-03-15 13:29:32 +01:00
|
|
|
void _convert_animation_player_to_gltf(
|
2022-12-11 20:00:56 +01:00
|
|
|
AnimationPlayer *p_animation_player, Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
GLTFNodeIndex p_gltf_current,
|
|
|
|
GLTFNodeIndex p_gltf_root_index,
|
|
|
|
Ref<GLTFNode> p_gltf_node, Node *p_scene_parent);
|
2022-12-11 20:00:56 +01:00
|
|
|
void _check_visibility(Node *p_node, bool &p_retflag);
|
|
|
|
void _convert_camera_to_gltf(Camera *p_camera, Ref<GLTFState> p_state,
|
|
|
|
Ref<GLTFNode> p_gltf_node);
|
2022-10-08 23:58:46 +02:00
|
|
|
#ifdef MODULE_GRIDMAP_ENABLED
|
|
|
|
void _convert_grid_map_to_gltf(
|
|
|
|
GridMap *p_grid_map,
|
|
|
|
GLTFNodeIndex p_parent_node_index,
|
|
|
|
GLTFNodeIndex p_root_node_index,
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
|
2022-10-08 23:58:46 +02:00
|
|
|
#endif // MODULE_GRIDMAP_ENABLED
|
2022-08-08 19:45:06 +02:00
|
|
|
void _convert_mult_mesh_instance_to_gltf(
|
|
|
|
MultiMeshInstance *p_scene_parent,
|
2022-03-15 13:29:32 +01:00
|
|
|
GLTFNodeIndex p_parent_node_index,
|
|
|
|
GLTFNodeIndex p_root_node_index,
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
|
2022-08-28 15:46:12 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-12-11 20:00:56 +01:00
|
|
|
void _convert_skeleton_to_gltf(Skeleton *p_scene_parent, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node);
|
2022-08-28 15:46:12 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_SKELETON_3D_ENABLED
|
2022-08-07 21:00:54 +02:00
|
|
|
void _convert_bone_attachment_to_gltf(BoneAttachment *p_bone_attachment,
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFState> p_state,
|
2022-03-15 13:29:32 +01:00
|
|
|
GLTFNodeIndex p_parent_node_index,
|
|
|
|
GLTFNodeIndex p_root_node_index,
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFNode> p_gltf_node);
|
2022-08-28 15:46:12 +02:00
|
|
|
#endif
|
|
|
|
|
2022-08-08 02:53:46 +02:00
|
|
|
void _convert_mesh_instance_to_gltf(MeshInstance *p_mesh_instance,
|
2022-12-11 20:00:56 +01:00
|
|
|
Ref<GLTFState> p_state,
|
|
|
|
Ref<GLTFNode> p_gltf_node);
|
|
|
|
GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> p_state,
|
2022-08-08 02:53:46 +02:00
|
|
|
MeshInstance *p_mesh_instance);
|
2022-12-11 20:00:56 +01:00
|
|
|
void _convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ap,
|
2022-03-15 13:29:32 +01:00
|
|
|
String p_animation_track_name);
|
2022-12-11 20:00:56 +01:00
|
|
|
Error serialize(Ref<GLTFState> p_state, Node *p_root, const String &p_path);
|
|
|
|
Error parse(Ref<GLTFState> p_state, String p_paths, bool p_read_binary = false);
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GLTF_DOCUMENT_H
|