gltf_state.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #ifndef GLTF_STATE_H
  31. #define GLTF_STATE_H
  32. #include "extensions/gltf_light.h"
  33. #include "gltf_template_convert.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_skeleton.h"
  41. #include "structures/gltf_skin.h"
  42. #include "structures/gltf_texture.h"
  43. #include "structures/gltf_texture_sampler.h"
  44. class GLTFState : public Resource {
  45. GDCLASS(GLTFState, Resource);
  46. friend class GLTFDocument;
  47. friend class PackedSceneGLTF;
  48. String filename;
  49. Dictionary json;
  50. int major_version = 0;
  51. int minor_version = 0;
  52. Vector<uint8_t> glb_data;
  53. bool use_named_skin_binds = false;
  54. bool use_khr_texture_transform = false;
  55. bool use_legacy_names = false;
  56. uint32_t compress_flags = 0;
  57. bool create_animations = true;
  58. Vector<Ref<GLTFNode>> nodes;
  59. Vector<Vector<uint8_t>> buffers;
  60. Vector<Ref<GLTFBufferView>> buffer_views;
  61. Vector<Ref<GLTFAccessor>> accessors;
  62. Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to.
  63. Vector<AnimationPlayer *> animation_players;
  64. Map<Ref<Material>, GLTFMaterialIndex> material_cache;
  65. Vector<Ref<Material>> materials;
  66. String scene_name;
  67. Vector<int> root_nodes;
  68. Vector<Ref<GLTFTexture>> textures;
  69. Vector<Ref<GLTFTextureSampler>> texture_samplers;
  70. Ref<GLTFTextureSampler> default_texture_sampler;
  71. Vector<Ref<Image>> images;
  72. Map<GLTFImageIndex, String> external_images_paths;
  73. Map<GLTFTextureIndex, Ref<Texture>> texture_cache;
  74. Vector<String> extensions_used;
  75. Vector<String> extensions_required;
  76. Vector<Ref<GLTFSkin>> skins;
  77. Vector<Ref<GLTFCamera>> cameras;
  78. Vector<Ref<GLTFLight>> lights;
  79. Set<String> unique_names;
  80. Set<String> unique_animation_names;
  81. Vector<Ref<GLTFSkeleton>> skeletons;
  82. Map<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
  83. Vector<Ref<GLTFAnimation>> animations;
  84. Map<GLTFNodeIndex, Node *> scene_nodes;
  85. Map<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
  86. Map<ObjectID, Map<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
  87. Dictionary additional_data;
  88. protected:
  89. static void _bind_methods();
  90. public:
  91. void add_used_extension(const String &p_extension, bool p_required = false);
  92. Dictionary get_json();
  93. void set_json(Dictionary p_json);
  94. int get_major_version();
  95. void set_major_version(int p_major_version);
  96. int get_minor_version();
  97. void set_minor_version(int p_minor_version);
  98. Vector<uint8_t> get_glb_data();
  99. void set_glb_data(Vector<uint8_t> p_glb_data);
  100. bool get_use_named_skin_binds();
  101. void set_use_named_skin_binds(bool p_use_named_skin_binds);
  102. Array get_nodes();
  103. void set_nodes(Array p_nodes);
  104. Array get_buffers();
  105. void set_buffers(Array p_buffers);
  106. Array get_buffer_views();
  107. void set_buffer_views(Array p_buffer_views);
  108. Array get_accessors();
  109. void set_accessors(Array p_accessors);
  110. Array get_meshes();
  111. void set_meshes(Array p_meshes);
  112. Array get_materials();
  113. void set_materials(Array p_materials);
  114. String get_scene_name();
  115. void set_scene_name(String p_scene_name);
  116. Array get_root_nodes();
  117. void set_root_nodes(Array p_root_nodes);
  118. Array get_textures();
  119. void set_textures(Array p_textures);
  120. Array get_texture_samplers();
  121. void set_texture_samplers(Array p_texture_samplers);
  122. Array get_images();
  123. void set_images(Array p_images);
  124. Array get_skins();
  125. void set_skins(Array p_skins);
  126. Array get_cameras();
  127. void set_cameras(Array p_cameras);
  128. Array get_lights();
  129. void set_lights(Array p_lights);
  130. Array get_unique_names();
  131. void set_unique_names(Array p_unique_names);
  132. Array get_unique_animation_names();
  133. void set_unique_animation_names(Array p_unique_names);
  134. Array get_skeletons();
  135. void set_skeletons(Array p_skeletons);
  136. Dictionary get_skeleton_to_node();
  137. void set_skeleton_to_node(Dictionary p_skeleton_to_node);
  138. bool get_create_animations();
  139. void set_create_animations(bool p_create_animations);
  140. Array get_animations();
  141. void set_animations(Array p_animations);
  142. Node *get_scene_node(GLTFNodeIndex idx);
  143. int get_animation_players_count(int idx);
  144. AnimationPlayer *get_animation_player(int idx);
  145. Variant get_additional_data(const String &p_extension_name);
  146. void set_additional_data(const String &p_extension_name, Variant p_additional_data);
  147. };
  148. #endif // GLTF_STATE_H