gltf_state.h 6.1 KB

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