gltf_state.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*************************************************************************/
  2. /* gltf_state.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "core/resource.h"
  33. #include "core/vector.h"
  34. #include "editor_scene_importer_gltf.h"
  35. #include "gltf_accessor.h"
  36. #include "gltf_animation.h"
  37. #include "gltf_buffer_view.h"
  38. #include "gltf_camera.h"
  39. #include "gltf_document.h"
  40. #include "gltf_light.h"
  41. #include "gltf_mesh.h"
  42. #include "gltf_node.h"
  43. #include "gltf_skeleton.h"
  44. #include "gltf_skin.h"
  45. #include "gltf_texture.h"
  46. #include "core/map.h"
  47. #include "core/pair.h"
  48. #include "core/resource.h"
  49. #include "core/vector.h"
  50. #include "scene/animation/animation_player.h"
  51. #include "scene/resources/texture.h"
  52. class GLTFState : public Resource {
  53. GDCLASS(GLTFState, Resource);
  54. friend class GLTFDocument;
  55. friend class PackedSceneGLTF;
  56. String filename;
  57. Dictionary json;
  58. int major_version = 0;
  59. int minor_version = 0;
  60. Vector<uint8_t> glb_data;
  61. bool use_named_skin_binds = false;
  62. bool use_legacy_names = false;
  63. uint32_t compress_flags = 0;
  64. Vector<Ref<GLTFNode>> nodes;
  65. Vector<Vector<uint8_t>> buffers;
  66. Vector<Ref<GLTFBufferView>> buffer_views;
  67. Vector<Ref<GLTFAccessor>> accessors;
  68. Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to.
  69. Vector<AnimationPlayer *> animation_players;
  70. Map<Ref<Material>, GLTFMaterialIndex> material_cache;
  71. Vector<Ref<Material>> materials;
  72. String scene_name;
  73. Vector<int> root_nodes;
  74. Vector<Ref<GLTFTexture>> textures;
  75. Vector<Ref<Texture>> images;
  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. protected:
  88. static void _bind_methods();
  89. public:
  90. Dictionary get_json();
  91. void set_json(Dictionary p_json);
  92. int get_major_version();
  93. void set_major_version(int p_major_version);
  94. int get_minor_version();
  95. void set_minor_version(int p_minor_version);
  96. Vector<uint8_t> get_glb_data();
  97. void set_glb_data(Vector<uint8_t> p_glb_data);
  98. bool get_use_named_skin_binds();
  99. void set_use_named_skin_binds(bool p_use_named_skin_binds);
  100. Array get_nodes();
  101. void set_nodes(Array p_nodes);
  102. Array get_buffers();
  103. void set_buffers(Array p_buffers);
  104. Array get_buffer_views();
  105. void set_buffer_views(Array p_buffer_views);
  106. Array get_accessors();
  107. void set_accessors(Array p_accessors);
  108. Array get_meshes();
  109. void set_meshes(Array p_meshes);
  110. Array get_materials();
  111. void set_materials(Array p_materials);
  112. String get_scene_name();
  113. void set_scene_name(String p_scene_name);
  114. Array get_root_nodes();
  115. void set_root_nodes(Array p_root_nodes);
  116. Array get_textures();
  117. void set_textures(Array p_textures);
  118. Array get_images();
  119. void set_images(Array p_images);
  120. Array get_skins();
  121. void set_skins(Array p_skins);
  122. Array get_cameras();
  123. void set_cameras(Array p_cameras);
  124. Array get_lights();
  125. void set_lights(Array p_lights);
  126. Array get_unique_names();
  127. void set_unique_names(Array p_unique_names);
  128. Array get_unique_animation_names();
  129. void set_unique_animation_names(Array p_unique_names);
  130. Array get_skeletons();
  131. void set_skeletons(Array p_skeletons);
  132. Dictionary get_skeleton_to_node();
  133. void set_skeleton_to_node(Dictionary p_skeleton_to_node);
  134. Array get_animations();
  135. void set_animations(Array p_animations);
  136. Node *get_scene_node(GLTFNodeIndex idx);
  137. int get_animation_players_count(int idx);
  138. AnimationPlayer *get_animation_player(int idx);
  139. //void set_scene_nodes(Map<GLTFNodeIndex, Node *> p_scene_nodes) {
  140. // this->scene_nodes = p_scene_nodes;
  141. //}
  142. //void set_animation_players(Vector<AnimationPlayer *> p_animation_players) {
  143. // this->animation_players = p_animation_players;
  144. //}
  145. //Map<Ref<Material>, GLTFMaterialIndex> get_material_cache() {
  146. // return this->material_cache;
  147. //}
  148. //void set_material_cache(Map<Ref<Material>, GLTFMaterialIndex> p_material_cache) {
  149. // this->material_cache = p_material_cache;
  150. //}
  151. };
  152. #endif // GLTF_STATE_H