gltf_document.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /**************************************************************************/
  2. /* gltf_document.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. #pragma once
  31. #include "extensions/gltf_document_extension.h"
  32. #include "extensions/gltf_spec_gloss.h"
  33. #include "gltf_defines.h"
  34. #include "gltf_state.h"
  35. #include "scene/3d/mesh_instance_3d.h"
  36. #include "scene/3d/multimesh_instance_3d.h"
  37. class CSGShape3D;
  38. class GridMap;
  39. class GLTFDocument : public Resource {
  40. GDCLASS(GLTFDocument, Resource);
  41. public:
  42. const int32_t JOINT_GROUP_SIZE = 4;
  43. enum {
  44. ARRAY_BUFFER = 34962,
  45. ELEMENT_ARRAY_BUFFER = 34963,
  46. };
  47. enum {
  48. TEXTURE_TYPE_GENERIC = 0,
  49. TEXTURE_TYPE_NORMAL = 1,
  50. };
  51. enum RootNodeMode {
  52. ROOT_NODE_MODE_SINGLE_ROOT,
  53. ROOT_NODE_MODE_KEEP_ROOT,
  54. ROOT_NODE_MODE_MULTI_ROOT,
  55. };
  56. enum VisibilityMode {
  57. VISIBILITY_MODE_INCLUDE_REQUIRED,
  58. VISIBILITY_MODE_INCLUDE_OPTIONAL,
  59. VISIBILITY_MODE_EXCLUDE,
  60. };
  61. private:
  62. int _naming_version = 2;
  63. String _image_format = "PNG";
  64. float _lossy_quality = 0.75f;
  65. String _fallback_image_format = "None";
  66. float _fallback_image_quality = 0.25f;
  67. Ref<GLTFDocumentExtension> _image_save_extension;
  68. RootNodeMode _root_node_mode = RootNodeMode::ROOT_NODE_MODE_SINGLE_ROOT;
  69. VisibilityMode _visibility_mode = VisibilityMode::VISIBILITY_MODE_INCLUDE_REQUIRED;
  70. protected:
  71. static void _bind_methods();
  72. String _gen_unique_name(Ref<GLTFState> p_state, const String &p_name);
  73. static Vector<Ref<GLTFDocumentExtension>> all_document_extensions;
  74. Vector<Ref<GLTFDocumentExtension>> document_extensions;
  75. public:
  76. static void register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority = false);
  77. static void unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
  78. static void unregister_all_gltf_document_extensions();
  79. static Vector<Ref<GLTFDocumentExtension>> get_all_gltf_document_extensions();
  80. static Vector<String> get_supported_gltf_extensions();
  81. static HashSet<String> get_supported_gltf_extensions_hashset();
  82. static NodePath _find_material_node_path(Ref<GLTFState> p_state, Ref<Material> p_material);
  83. static Ref<GLTFObjectModelProperty> import_object_model_property(Ref<GLTFState> p_state, const String &p_json_pointer);
  84. static Ref<GLTFObjectModelProperty> export_object_model_property(Ref<GLTFState> p_state, const NodePath &p_node_path, const Node *p_godot_node, GLTFNodeIndex p_gltf_node_index);
  85. void set_naming_version(int p_version);
  86. int get_naming_version() const;
  87. void set_image_format(const String &p_image_format);
  88. String get_image_format() const;
  89. void set_lossy_quality(float p_lossy_quality);
  90. float get_lossy_quality() const;
  91. void set_fallback_image_format(const String &p_fallback_image_format);
  92. String get_fallback_image_format() const;
  93. void set_fallback_image_quality(float p_fallback_image_quality);
  94. float get_fallback_image_quality() const;
  95. void set_root_node_mode(RootNodeMode p_root_node_mode);
  96. RootNodeMode get_root_node_mode() const;
  97. void set_visibility_mode(VisibilityMode p_visibility_mode);
  98. VisibilityMode get_visibility_mode() const;
  99. static String _gen_unique_name_static(HashSet<String> &r_unique_names, const String &p_name);
  100. private:
  101. void _build_parent_hierarchy(Ref<GLTFState> p_state);
  102. double _filter_number(double p_float);
  103. void _round_min_max_components(Vector<double> &r_type_min, Vector<double> &r_type_max);
  104. String _get_component_type_name(const GLTFAccessor::GLTFComponentType p_component_type);
  105. int _get_component_type_size(const GLTFAccessor::GLTFComponentType p_component_type);
  106. Error _parse_scenes(Ref<GLTFState> p_state);
  107. Error _parse_nodes(Ref<GLTFState> p_state);
  108. String _get_accessor_type_name(const GLTFAccessor::GLTFAccessorType p_accessor_type);
  109. String _sanitize_animation_name(const String &p_name);
  110. String _gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name);
  111. String _sanitize_bone_name(const String &p_name);
  112. String _gen_unique_bone_name(Ref<GLTFState> p_state,
  113. const GLTFSkeletonIndex p_skel_i,
  114. const String &p_name);
  115. GLTFTextureIndex _set_texture(Ref<GLTFState> p_state, Ref<Texture2D> p_texture,
  116. StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats);
  117. Ref<Texture2D> _get_texture(Ref<GLTFState> p_state,
  118. const GLTFTextureIndex p_texture, int p_texture_type);
  119. GLTFTextureSamplerIndex _set_sampler_for_mode(Ref<GLTFState> p_state,
  120. StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats);
  121. Ref<GLTFTextureSampler> _get_sampler_for_texture(Ref<GLTFState> p_state,
  122. const GLTFTextureIndex p_texture);
  123. Error _parse_json(const String &p_path, Ref<GLTFState> p_state);
  124. Error _parse_glb(Ref<FileAccess> p_file, Ref<GLTFState> p_state);
  125. void _compute_node_heights(Ref<GLTFState> p_state);
  126. Error _parse_buffers(Ref<GLTFState> p_state, const String &p_base_path);
  127. Error _parse_buffer_views(Ref<GLTFState> p_state);
  128. GLTFAccessor::GLTFAccessorType _get_accessor_type_from_str(const String &p_string);
  129. Error _parse_accessors(Ref<GLTFState> p_state);
  130. Error _decode_buffer_view(Ref<GLTFState> p_state, double *p_dst,
  131. const GLTFBufferViewIndex p_buffer_view,
  132. const int64_t p_skip_every, const int64_t p_skip_bytes,
  133. const int64_t p_element_size, const int64_t p_count,
  134. const GLTFAccessor::GLTFAccessorType p_accessor_type, const int64_t p_component_count,
  135. const GLTFAccessor::GLTFComponentType p_component_type, const int64_t p_component_size,
  136. const bool p_normalized, const int64_t p_byte_offset,
  137. const bool p_for_vertex);
  138. Vector<double> _decode_accessor(Ref<GLTFState> p_state,
  139. const GLTFAccessorIndex p_accessor,
  140. const bool p_for_vertex);
  141. Vector<float> _decode_accessor_as_floats(Ref<GLTFState> p_state,
  142. const GLTFAccessorIndex p_accessor,
  143. const bool p_for_vertex,
  144. const Vector<int> &p_packed_vertex_ids = Vector<int>());
  145. Vector<int> _decode_accessor_as_ints(Ref<GLTFState> p_state,
  146. const GLTFAccessorIndex p_accessor,
  147. const bool p_for_vertex,
  148. const Vector<int> &p_packed_vertex_ids = Vector<int>());
  149. Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> p_state,
  150. const GLTFAccessorIndex p_accessor,
  151. const bool p_for_vertex,
  152. const Vector<int> &p_packed_vertex_ids = Vector<int>());
  153. Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> p_state,
  154. const GLTFAccessorIndex p_accessor,
  155. const bool p_for_vertex,
  156. const Vector<int> &p_packed_vertex_ids = Vector<int>());
  157. Vector<Color> _decode_accessor_as_color(Ref<GLTFState> p_state,
  158. const GLTFAccessorIndex p_accessor,
  159. const bool p_for_vertex,
  160. const Vector<int> &p_packed_vertex_ids = Vector<int>());
  161. Vector<Quaternion> _decode_accessor_as_quaternion(Ref<GLTFState> p_state,
  162. const GLTFAccessorIndex p_accessor,
  163. const bool p_for_vertex);
  164. Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> p_state,
  165. const GLTFAccessorIndex p_accessor,
  166. const bool p_for_vertex);
  167. Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> p_state,
  168. const GLTFAccessorIndex p_accessor,
  169. const bool p_for_vertex);
  170. Vector<Transform3D> _decode_accessor_as_xform(Ref<GLTFState> p_state,
  171. const GLTFAccessorIndex p_accessor,
  172. const bool p_for_vertex);
  173. Vector<Variant> _decode_accessor_as_variant(Ref<GLTFState> p_state,
  174. const GLTFAccessorIndex p_accessor,
  175. Variant::Type p_variant_type,
  176. GLTFAccessor::GLTFAccessorType p_accessor_type);
  177. GLTFAccessorIndex _encode_accessor_as_variant(Ref<GLTFState> p_state,
  178. Vector<Variant> p_attribs,
  179. Variant::Type p_variant_type,
  180. GLTFAccessor::GLTFAccessorType p_accessor_type,
  181. GLTFAccessor::GLTFComponentType p_component_type = GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT);
  182. Error _parse_meshes(Ref<GLTFState> p_state);
  183. Error _serialize_textures(Ref<GLTFState> p_state);
  184. Error _serialize_texture_samplers(Ref<GLTFState> p_state);
  185. Error _serialize_images(Ref<GLTFState> p_state);
  186. Dictionary _serialize_image(Ref<GLTFState> p_state, Ref<Image> p_image, const String &p_image_format, float p_lossy_quality, Ref<GLTFDocumentExtension> p_image_save_extension);
  187. Error _serialize_lights(Ref<GLTFState> p_state);
  188. Ref<Image> _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);
  189. void _parse_image_save_image(Ref<GLTFState> p_state, const Vector<uint8_t> &p_bytes, const String &p_resource_uri, const String &p_file_extension, int p_index, Ref<Image> p_image);
  190. Error _parse_images(Ref<GLTFState> p_state, const String &p_base_path);
  191. Error _parse_textures(Ref<GLTFState> p_state);
  192. Error _parse_texture_samplers(Ref<GLTFState> p_state);
  193. Error _parse_materials(Ref<GLTFState> p_state);
  194. void _set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> p_material);
  195. void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss,
  196. Ref<BaseMaterial3D> p_material);
  197. static void spec_gloss_to_metal_base_color(const Color &p_specular_factor,
  198. const Color &p_diffuse,
  199. Color &r_base_color,
  200. float &r_metallic);
  201. Error _parse_skins(Ref<GLTFState> p_state);
  202. Error _serialize_skins(Ref<GLTFState> p_state);
  203. Error _create_skins(Ref<GLTFState> p_state);
  204. bool _skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b);
  205. void _remove_duplicate_skins(Ref<GLTFState> p_state);
  206. Error _serialize_cameras(Ref<GLTFState> p_state);
  207. Error _parse_cameras(Ref<GLTFState> p_state);
  208. Error _parse_lights(Ref<GLTFState> p_state);
  209. Error _parse_animations(Ref<GLTFState> p_state);
  210. void _parse_animation_pointer(Ref<GLTFState> p_state, const String &p_animation_json_pointer, const Ref<GLTFAnimation> p_gltf_animation, const GLTFAnimation::Interpolation p_interp, const Vector<double> &p_times, const int p_output_value_accessor_index);
  211. Error _serialize_animations(Ref<GLTFState> p_state);
  212. bool _does_skinned_mesh_require_placeholder_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node);
  213. BoneAttachment3D *_generate_bone_attachment(Skeleton3D *p_godot_skeleton, const Ref<GLTFNode> &p_bone_node);
  214. BoneAttachment3D *_generate_bone_attachment_compat_4pt4(Ref<GLTFState> p_state, Skeleton3D *p_skeleton, const GLTFNodeIndex p_node_index, const GLTFNodeIndex p_bone_index);
  215. ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index);
  216. Camera3D *_generate_camera(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index);
  217. Light3D *_generate_light(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index);
  218. Node3D *_generate_spatial(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index);
  219. void _assign_node_names(Ref<GLTFState> p_state);
  220. template <typename T>
  221. T _interpolate_track(const Vector<double> &p_times, const Vector<T> &p_values,
  222. const float p_time,
  223. const GLTFAnimation::Interpolation p_interp);
  224. GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> p_state,
  225. const Vector<Quaternion> p_attribs,
  226. const bool p_for_vertex);
  227. GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> p_state,
  228. const Vector<Color> p_attribs,
  229. const bool p_for_vertex);
  230. GLTFAccessorIndex _encode_accessor_as_joints(Ref<GLTFState> p_state,
  231. const Vector<Color> p_attribs,
  232. const bool p_for_vertex);
  233. GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> p_state,
  234. const Vector<double> p_attribs,
  235. const bool p_for_vertex);
  236. GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> p_state,
  237. const Vector<Vector2> p_attribs,
  238. const bool p_for_vertex);
  239. void _calc_accessor_vec2_min_max(int p_i, const int64_t p_element_count, Vector<double> &p_type_max, Vector2 p_attribs, Vector<double> &p_type_min) {
  240. if (p_i == 0) {
  241. for (int64_t type_i = 0; type_i < p_element_count; type_i++) {
  242. p_type_max.write[type_i] = p_attribs[(p_i * p_element_count) + type_i];
  243. p_type_min.write[type_i] = p_attribs[(p_i * p_element_count) + type_i];
  244. }
  245. }
  246. for (int64_t type_i = 0; type_i < p_element_count; type_i++) {
  247. p_type_max.write[type_i] = MAX(p_attribs[(p_i * p_element_count) + type_i], p_type_max[type_i]);
  248. p_type_min.write[type_i] = MIN(p_attribs[(p_i * p_element_count) + type_i], p_type_min[type_i]);
  249. p_type_max.write[type_i] = _filter_number(p_type_max.write[type_i]);
  250. p_type_min.write[type_i] = _filter_number(p_type_min.write[type_i]);
  251. }
  252. }
  253. GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> p_state,
  254. const Vector<Vector3> p_attribs,
  255. const bool p_for_vertex);
  256. GLTFAccessorIndex _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);
  257. GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> p_state,
  258. const Vector<Color> p_attribs,
  259. const bool p_for_vertex);
  260. void _calc_accessor_min_max(int p_i, const int64_t p_element_count, Vector<double> &p_type_max, Vector<double> p_attribs, Vector<double> &p_type_min);
  261. GLTFAccessorIndex _encode_accessor_as_ints(Ref<GLTFState> p_state,
  262. const Vector<int32_t> p_attribs,
  263. const bool p_for_vertex,
  264. const bool p_for_indices);
  265. GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> p_state,
  266. const Vector<Transform3D> p_attribs,
  267. const bool p_for_vertex);
  268. Error _encode_accessor_into_buffer_view(Ref<GLTFState> p_state, const double *p_src,
  269. const int64_t p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type,
  270. const GLTFAccessor::GLTFComponentType p_component_type, const bool p_normalized,
  271. const int64_t p_byte_offset, const bool p_for_vertex,
  272. GLTFBufferViewIndex &r_buffer_view, const bool p_for_indices = false);
  273. Error _encode_accessors(Ref<GLTFState> p_state);
  274. Error _encode_buffer_views(Ref<GLTFState> p_state);
  275. Error _serialize_materials(Ref<GLTFState> p_state);
  276. Error _serialize_meshes(Ref<GLTFState> p_state);
  277. Error _serialize_nodes(Ref<GLTFState> p_state);
  278. Error _serialize_scenes(Ref<GLTFState> p_state);
  279. String interpolation_to_string(const GLTFAnimation::Interpolation p_interp);
  280. Error _encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path);
  281. Error _encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path);
  282. PackedByteArray _serialize_glb_buffer(Ref<GLTFState> p_state, Error *r_err);
  283. Dictionary _serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material);
  284. Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material);
  285. Error _serialize_asset_header(Ref<GLTFState> p_state);
  286. Error _serialize_file(Ref<GLTFState> p_state, const String p_path);
  287. Error _serialize_gltf_extensions(Ref<GLTFState> p_state) const;
  288. public:
  289. // https://www.itu.int/rec/R-REC-BT.601
  290. // https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf
  291. static constexpr float R_BRIGHTNESS_COEFF = 0.299f;
  292. static constexpr float G_BRIGHTNESS_COEFF = 0.587f;
  293. static constexpr float B_BRIGHTNESS_COEFF = 0.114f;
  294. private:
  295. // https://github.com/microsoft/glTF-SDK/blob/master/GLTFSDK/Source/PBRUtils.cpp#L9
  296. // https://bghgary.github.io/glTF/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  297. static float solve_metallic(float p_dielectric_specular, float p_diffuse,
  298. float p_specular,
  299. float p_one_minus_specular_strength);
  300. static float get_perceived_brightness(const Color p_color);
  301. static float get_max_component(const Color &p_color);
  302. public:
  303. virtual Error append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, String p_base_path = String());
  304. virtual Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags = 0);
  305. virtual Error append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags = 0);
  306. virtual Node *generate_scene(Ref<GLTFState> p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true);
  307. virtual PackedByteArray generate_buffer(Ref<GLTFState> p_state);
  308. virtual Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path);
  309. public:
  310. Error _parse_gltf_state(Ref<GLTFState> p_state, const String &p_search_path);
  311. Error _parse_asset_header(Ref<GLTFState> p_state);
  312. Error _parse_gltf_extensions(Ref<GLTFState> p_state);
  313. void _process_mesh_instances(Ref<GLTFState> p_state, Node *p_scene_root);
  314. Node *_generate_scene_node_tree(Ref<GLTFState> p_state);
  315. void _generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
  316. void _generate_skeleton_bone_node(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node3D *p_current_node, Node *p_scene_parent, Node *p_scene_root);
  317. void _attach_node_to_skeleton(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node3D *p_current_node, Skeleton3D *p_godot_skeleton, Node *p_scene_root, GLTFNodeIndex p_bone_node_index = -1);
  318. void _generate_scene_node_compat_4pt4(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
  319. void _generate_skeleton_bone_node_compat_4pt4(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
  320. void _import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player,
  321. const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks);
  322. void _convert_mesh_instances(Ref<GLTFState> p_state);
  323. GLTFCameraIndex _convert_camera(Ref<GLTFState> p_state, Camera3D *p_camera);
  324. void _convert_light_to_gltf(Light3D *p_light, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node);
  325. GLTFLightIndex _convert_light(Ref<GLTFState> p_state, Light3D *p_light);
  326. void _convert_spatial(Ref<GLTFState> p_state, Node3D *p_spatial, Ref<GLTFNode> p_node);
  327. void _convert_scene_node(Ref<GLTFState> p_state, Node *p_current,
  328. const GLTFNodeIndex p_gltf_current,
  329. const GLTFNodeIndex p_gltf_root);
  330. void _convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
  331. void _check_visibility(Node *p_node, bool &r_retflag);
  332. void _convert_camera_to_gltf(Camera3D *p_camera, Ref<GLTFState> p_state,
  333. Ref<GLTFNode> p_gltf_node);
  334. void _convert_grid_map_to_gltf(
  335. GridMap *p_grid_map,
  336. GLTFNodeIndex p_parent_node_index,
  337. GLTFNodeIndex p_root_node_index,
  338. Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
  339. void _convert_multi_mesh_instance_to_gltf(
  340. MultiMeshInstance3D *p_multi_mesh_instance,
  341. GLTFNodeIndex p_parent_node_index,
  342. GLTFNodeIndex p_root_node_index,
  343. Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
  344. void _convert_skeleton_to_gltf(
  345. Skeleton3D *p_scene_parent, Ref<GLTFState> p_state,
  346. GLTFNodeIndex p_parent_node_index,
  347. GLTFNodeIndex p_root_node_index,
  348. Ref<GLTFNode> p_gltf_node);
  349. void _convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment,
  350. Ref<GLTFState> p_state,
  351. GLTFNodeIndex p_parent_node_index,
  352. GLTFNodeIndex p_root_node_index,
  353. Ref<GLTFNode> p_gltf_node);
  354. void _convert_mesh_instance_to_gltf(MeshInstance3D *p_mesh_instance,
  355. Ref<GLTFState> p_state,
  356. Ref<GLTFNode> p_gltf_node);
  357. GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> p_state,
  358. MeshInstance3D *p_mesh_instance);
  359. GLTFNodeIndex _node_and_or_bone_to_gltf_node_index(Ref<GLTFState> p_state, const Vector<StringName> &p_node_subpath, const Node *p_godot_node);
  360. bool _convert_animation_node_track(Ref<GLTFState> p_state,
  361. GLTFAnimation::NodeTrack &p_gltf_node_track,
  362. const Ref<Animation> &p_godot_animation,
  363. int32_t p_godot_anim_track_index,
  364. Vector<double> &p_times);
  365. void _convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, const String &p_animation_track_name);
  366. Error _serialize(Ref<GLTFState> p_state);
  367. Error _parse(Ref<GLTFState> p_state, String p_path, Ref<FileAccess> p_file);
  368. };
  369. VARIANT_ENUM_CAST(GLTFDocument::RootNodeMode);
  370. VARIANT_ENUM_CAST(GLTFDocument::VisibilityMode);