gltf_state.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /**************************************************************************/
  2. /* gltf_state.cpp */
  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. #include "gltf_state.h"
  31. #include "gltf_template_convert.h"
  32. void GLTFState::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("add_used_extension", "extension_name", "required"), &GLTFState::add_used_extension);
  34. ClassDB::bind_method(D_METHOD("append_data_to_buffers", "data", "deduplication"), &GLTFState::append_data_to_buffers);
  35. ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
  36. ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);
  37. ClassDB::bind_method(D_METHOD("get_major_version"), &GLTFState::get_major_version);
  38. ClassDB::bind_method(D_METHOD("set_major_version", "major_version"), &GLTFState::set_major_version);
  39. ClassDB::bind_method(D_METHOD("get_minor_version"), &GLTFState::get_minor_version);
  40. ClassDB::bind_method(D_METHOD("set_minor_version", "minor_version"), &GLTFState::set_minor_version);
  41. ClassDB::bind_method(D_METHOD("get_copyright"), &GLTFState::get_copyright);
  42. ClassDB::bind_method(D_METHOD("set_copyright", "copyright"), &GLTFState::set_copyright);
  43. ClassDB::bind_method(D_METHOD("get_glb_data"), &GLTFState::get_glb_data);
  44. ClassDB::bind_method(D_METHOD("set_glb_data", "glb_data"), &GLTFState::set_glb_data);
  45. ClassDB::bind_method(D_METHOD("get_use_named_skin_binds"), &GLTFState::get_use_named_skin_binds);
  46. ClassDB::bind_method(D_METHOD("set_use_named_skin_binds", "use_named_skin_binds"), &GLTFState::set_use_named_skin_binds);
  47. ClassDB::bind_method(D_METHOD("get_nodes"), &GLTFState::get_nodes);
  48. ClassDB::bind_method(D_METHOD("set_nodes", "nodes"), &GLTFState::set_nodes);
  49. ClassDB::bind_method(D_METHOD("get_buffers"), &GLTFState::get_buffers);
  50. ClassDB::bind_method(D_METHOD("set_buffers", "buffers"), &GLTFState::set_buffers);
  51. ClassDB::bind_method(D_METHOD("get_buffer_views"), &GLTFState::get_buffer_views);
  52. ClassDB::bind_method(D_METHOD("set_buffer_views", "buffer_views"), &GLTFState::set_buffer_views);
  53. ClassDB::bind_method(D_METHOD("get_accessors"), &GLTFState::get_accessors);
  54. ClassDB::bind_method(D_METHOD("set_accessors", "accessors"), &GLTFState::set_accessors);
  55. ClassDB::bind_method(D_METHOD("get_meshes"), &GLTFState::get_meshes);
  56. ClassDB::bind_method(D_METHOD("set_meshes", "meshes"), &GLTFState::set_meshes);
  57. ClassDB::bind_method(D_METHOD("get_animation_players_count", "idx"), &GLTFState::get_animation_players_count);
  58. ClassDB::bind_method(D_METHOD("get_animation_player", "idx"), &GLTFState::get_animation_player);
  59. ClassDB::bind_method(D_METHOD("get_materials"), &GLTFState::get_materials);
  60. ClassDB::bind_method(D_METHOD("set_materials", "materials"), &GLTFState::set_materials);
  61. ClassDB::bind_method(D_METHOD("get_scene_name"), &GLTFState::get_scene_name);
  62. ClassDB::bind_method(D_METHOD("set_scene_name", "scene_name"), &GLTFState::set_scene_name);
  63. ClassDB::bind_method(D_METHOD("get_base_path"), &GLTFState::get_base_path);
  64. ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &GLTFState::set_base_path);
  65. ClassDB::bind_method(D_METHOD("get_filename"), &GLTFState::get_filename);
  66. ClassDB::bind_method(D_METHOD("set_filename", "filename"), &GLTFState::set_filename);
  67. ClassDB::bind_method(D_METHOD("get_root_nodes"), &GLTFState::get_root_nodes);
  68. ClassDB::bind_method(D_METHOD("set_root_nodes", "root_nodes"), &GLTFState::set_root_nodes);
  69. ClassDB::bind_method(D_METHOD("get_textures"), &GLTFState::get_textures);
  70. ClassDB::bind_method(D_METHOD("set_textures", "textures"), &GLTFState::set_textures);
  71. ClassDB::bind_method(D_METHOD("get_texture_samplers"), &GLTFState::get_texture_samplers);
  72. ClassDB::bind_method(D_METHOD("set_texture_samplers", "texture_samplers"), &GLTFState::set_texture_samplers);
  73. ClassDB::bind_method(D_METHOD("get_images"), &GLTFState::get_images);
  74. ClassDB::bind_method(D_METHOD("set_images", "images"), &GLTFState::set_images);
  75. ClassDB::bind_method(D_METHOD("get_skins"), &GLTFState::get_skins);
  76. ClassDB::bind_method(D_METHOD("set_skins", "skins"), &GLTFState::set_skins);
  77. ClassDB::bind_method(D_METHOD("get_cameras"), &GLTFState::get_cameras);
  78. ClassDB::bind_method(D_METHOD("set_cameras", "cameras"), &GLTFState::set_cameras);
  79. ClassDB::bind_method(D_METHOD("get_lights"), &GLTFState::get_lights);
  80. ClassDB::bind_method(D_METHOD("set_lights", "lights"), &GLTFState::set_lights);
  81. ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFState::get_unique_names);
  82. ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFState::set_unique_names);
  83. ClassDB::bind_method(D_METHOD("get_unique_animation_names"), &GLTFState::get_unique_animation_names);
  84. ClassDB::bind_method(D_METHOD("set_unique_animation_names", "unique_animation_names"), &GLTFState::set_unique_animation_names);
  85. ClassDB::bind_method(D_METHOD("get_skeletons"), &GLTFState::get_skeletons);
  86. ClassDB::bind_method(D_METHOD("set_skeletons", "skeletons"), &GLTFState::set_skeletons);
  87. ClassDB::bind_method(D_METHOD("get_create_animations"), &GLTFState::get_create_animations);
  88. ClassDB::bind_method(D_METHOD("set_create_animations", "create_animations"), &GLTFState::set_create_animations);
  89. ClassDB::bind_method(D_METHOD("get_import_as_skeleton_bones"), &GLTFState::get_import_as_skeleton_bones);
  90. ClassDB::bind_method(D_METHOD("set_import_as_skeleton_bones", "import_as_skeleton_bones"), &GLTFState::set_import_as_skeleton_bones);
  91. ClassDB::bind_method(D_METHOD("get_animations"), &GLTFState::get_animations);
  92. ClassDB::bind_method(D_METHOD("set_animations", "animations"), &GLTFState::set_animations);
  93. ClassDB::bind_method(D_METHOD("get_scene_node", "idx"), &GLTFState::get_scene_node);
  94. ClassDB::bind_method(D_METHOD("get_node_index", "scene_node"), &GLTFState::get_node_index);
  95. ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFState::get_additional_data);
  96. ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFState::set_additional_data);
  97. ClassDB::bind_method(D_METHOD("get_handle_binary_image"), &GLTFState::get_handle_binary_image);
  98. ClassDB::bind_method(D_METHOD("set_handle_binary_image", "method"), &GLTFState::set_handle_binary_image);
  99. ClassDB::bind_method(D_METHOD("set_bake_fps", "value"), &GLTFState::set_bake_fps);
  100. ClassDB::bind_method(D_METHOD("get_bake_fps"), &GLTFState::get_bake_fps);
  101. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "json"), "set_json", "get_json"); // Dictionary
  102. ADD_PROPERTY(PropertyInfo(Variant::INT, "major_version"), "set_major_version", "get_major_version"); // int
  103. ADD_PROPERTY(PropertyInfo(Variant::INT, "minor_version"), "set_minor_version", "get_minor_version"); // int
  104. ADD_PROPERTY(PropertyInfo(Variant::STRING, "copyright"), "set_copyright", "get_copyright"); // String
  105. ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "glb_data"), "set_glb_data", "get_glb_data"); // Vector<uint8_t>
  106. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_named_skin_binds"), "set_use_named_skin_binds", "get_use_named_skin_binds"); // bool
  107. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_nodes", "get_nodes"); // Vector<Ref<GLTFNode>>
  108. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffers"), "set_buffers", "get_buffers"); // Vector<Vector<uint8_t>
  109. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffer_views", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_buffer_views", "get_buffer_views"); // Vector<Ref<GLTFBufferView>>
  110. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessors", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_accessors", "get_accessors"); // Vector<Ref<GLTFAccessor>>
  111. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_meshes", "get_meshes"); // Vector<Ref<GLTFMesh>>
  112. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_materials", "get_materials"); // Vector<Ref<Material>
  113. ADD_PROPERTY(PropertyInfo(Variant::STRING, "scene_name"), "set_scene_name", "get_scene_name"); // String
  114. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_path"), "set_base_path", "get_base_path"); // String
  115. ADD_PROPERTY(PropertyInfo(Variant::STRING, "filename"), "set_filename", "get_filename"); // String
  116. ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int>
  117. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_textures", "get_textures"); // Vector<Ref<GLTFTexture>>
  118. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "texture_samplers", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_texture_samplers", "get_texture_samplers"); //Vector<Ref<GLTFTextureSampler>>
  119. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture>
  120. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skins", "get_skins"); // Vector<Ref<GLTFSkin>>
  121. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "cameras", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_cameras", "get_cameras"); // Vector<Ref<GLTFCamera>>
  122. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "lights", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_lights", "get_lights"); // Vector<Ref<GLTFLight>>
  123. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String>
  124. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_animation_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_animation_names", "get_unique_animation_names"); // Set<String>
  125. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skeletons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeletons", "get_skeletons"); // Vector<Ref<GLTFSkeleton>>
  126. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_animations"), "set_create_animations", "get_create_animations"); // bool
  127. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "import_as_skeleton_bones"), "set_import_as_skeleton_bones", "get_import_as_skeleton_bones"); // bool
  128. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
  129. ADD_PROPERTY(PropertyInfo(Variant::INT, "handle_binary_image", PROPERTY_HINT_ENUM, "Discard All Textures,Extract Textures,Embed as Basis Universal,Embed as Uncompressed", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_handle_binary_image", "get_handle_binary_image"); // enum
  130. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_fps"), "set_bake_fps", "get_bake_fps");
  131. BIND_CONSTANT(HANDLE_BINARY_DISCARD_TEXTURES);
  132. BIND_CONSTANT(HANDLE_BINARY_EXTRACT_TEXTURES);
  133. BIND_CONSTANT(HANDLE_BINARY_EMBED_AS_BASISU);
  134. BIND_CONSTANT(HANDLE_BINARY_EMBED_AS_UNCOMPRESSED);
  135. }
  136. void GLTFState::add_used_extension(const String &p_extension_name, bool p_required) {
  137. if (!extensions_used.has(p_extension_name)) {
  138. extensions_used.push_back(p_extension_name);
  139. }
  140. if (p_required) {
  141. if (!extensions_required.has(p_extension_name)) {
  142. extensions_required.push_back(p_extension_name);
  143. }
  144. }
  145. }
  146. Dictionary GLTFState::get_json() {
  147. return json;
  148. }
  149. void GLTFState::set_json(Dictionary p_json) {
  150. json = p_json;
  151. }
  152. int GLTFState::get_major_version() {
  153. return major_version;
  154. }
  155. void GLTFState::set_major_version(int p_major_version) {
  156. major_version = p_major_version;
  157. }
  158. int GLTFState::get_minor_version() {
  159. return minor_version;
  160. }
  161. void GLTFState::set_minor_version(int p_minor_version) {
  162. minor_version = p_minor_version;
  163. }
  164. String GLTFState::get_copyright() const {
  165. return copyright;
  166. }
  167. void GLTFState::set_copyright(const String &p_copyright) {
  168. copyright = p_copyright;
  169. }
  170. Vector<uint8_t> GLTFState::get_glb_data() {
  171. return glb_data;
  172. }
  173. void GLTFState::set_glb_data(Vector<uint8_t> p_glb_data) {
  174. glb_data = p_glb_data;
  175. }
  176. bool GLTFState::get_use_named_skin_binds() {
  177. return use_named_skin_binds;
  178. }
  179. void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
  180. use_named_skin_binds = p_use_named_skin_binds;
  181. }
  182. TypedArray<GLTFNode> GLTFState::get_nodes() {
  183. return GLTFTemplateConvert::to_array(nodes);
  184. }
  185. void GLTFState::set_nodes(TypedArray<GLTFNode> p_nodes) {
  186. GLTFTemplateConvert::set_from_array(nodes, p_nodes);
  187. }
  188. TypedArray<PackedByteArray> GLTFState::get_buffers() {
  189. return GLTFTemplateConvert::to_array(buffers);
  190. }
  191. void GLTFState::set_buffers(TypedArray<PackedByteArray> p_buffers) {
  192. GLTFTemplateConvert::set_from_array(buffers, p_buffers);
  193. }
  194. TypedArray<GLTFBufferView> GLTFState::get_buffer_views() {
  195. return GLTFTemplateConvert::to_array(buffer_views);
  196. }
  197. void GLTFState::set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views) {
  198. GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
  199. }
  200. TypedArray<GLTFAccessor> GLTFState::get_accessors() {
  201. return GLTFTemplateConvert::to_array(accessors);
  202. }
  203. void GLTFState::set_accessors(TypedArray<GLTFAccessor> p_accessors) {
  204. GLTFTemplateConvert::set_from_array(accessors, p_accessors);
  205. }
  206. TypedArray<GLTFMesh> GLTFState::get_meshes() {
  207. return GLTFTemplateConvert::to_array(meshes);
  208. }
  209. void GLTFState::set_meshes(TypedArray<GLTFMesh> p_meshes) {
  210. GLTFTemplateConvert::set_from_array(meshes, p_meshes);
  211. }
  212. TypedArray<Material> GLTFState::get_materials() {
  213. return GLTFTemplateConvert::to_array(materials);
  214. }
  215. void GLTFState::set_materials(TypedArray<Material> p_materials) {
  216. GLTFTemplateConvert::set_from_array(materials, p_materials);
  217. }
  218. String GLTFState::get_scene_name() {
  219. return scene_name;
  220. }
  221. void GLTFState::set_scene_name(String p_scene_name) {
  222. scene_name = p_scene_name;
  223. }
  224. PackedInt32Array GLTFState::get_root_nodes() {
  225. return root_nodes;
  226. }
  227. void GLTFState::set_root_nodes(PackedInt32Array p_root_nodes) {
  228. root_nodes = p_root_nodes;
  229. }
  230. TypedArray<GLTFTexture> GLTFState::get_textures() {
  231. return GLTFTemplateConvert::to_array(textures);
  232. }
  233. void GLTFState::set_textures(TypedArray<GLTFTexture> p_textures) {
  234. GLTFTemplateConvert::set_from_array(textures, p_textures);
  235. }
  236. TypedArray<GLTFTextureSampler> GLTFState::get_texture_samplers() {
  237. return GLTFTemplateConvert::to_array(texture_samplers);
  238. }
  239. void GLTFState::set_texture_samplers(TypedArray<GLTFTextureSampler> p_texture_samplers) {
  240. GLTFTemplateConvert::set_from_array(texture_samplers, p_texture_samplers);
  241. }
  242. TypedArray<Texture2D> GLTFState::get_images() {
  243. return GLTFTemplateConvert::to_array(images);
  244. }
  245. void GLTFState::set_images(TypedArray<Texture2D> p_images) {
  246. GLTFTemplateConvert::set_from_array(images, p_images);
  247. }
  248. TypedArray<GLTFSkin> GLTFState::get_skins() {
  249. return GLTFTemplateConvert::to_array(skins);
  250. }
  251. void GLTFState::set_skins(TypedArray<GLTFSkin> p_skins) {
  252. GLTFTemplateConvert::set_from_array(skins, p_skins);
  253. }
  254. TypedArray<GLTFCamera> GLTFState::get_cameras() {
  255. return GLTFTemplateConvert::to_array(cameras);
  256. }
  257. void GLTFState::set_cameras(TypedArray<GLTFCamera> p_cameras) {
  258. GLTFTemplateConvert::set_from_array(cameras, p_cameras);
  259. }
  260. TypedArray<GLTFLight> GLTFState::get_lights() {
  261. return GLTFTemplateConvert::to_array(lights);
  262. }
  263. void GLTFState::set_lights(TypedArray<GLTFLight> p_lights) {
  264. GLTFTemplateConvert::set_from_array(lights, p_lights);
  265. }
  266. TypedArray<String> GLTFState::get_unique_names() {
  267. return GLTFTemplateConvert::to_array(unique_names);
  268. }
  269. void GLTFState::set_unique_names(TypedArray<String> p_unique_names) {
  270. GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
  271. }
  272. TypedArray<String> GLTFState::get_unique_animation_names() {
  273. return GLTFTemplateConvert::to_array(unique_animation_names);
  274. }
  275. void GLTFState::set_unique_animation_names(TypedArray<String> p_unique_animation_names) {
  276. GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
  277. }
  278. TypedArray<GLTFSkeleton> GLTFState::get_skeletons() {
  279. return GLTFTemplateConvert::to_array(skeletons);
  280. }
  281. void GLTFState::set_skeletons(TypedArray<GLTFSkeleton> p_skeletons) {
  282. GLTFTemplateConvert::set_from_array(skeletons, p_skeletons);
  283. }
  284. bool GLTFState::get_create_animations() {
  285. return create_animations;
  286. }
  287. void GLTFState::set_create_animations(bool p_create_animations) {
  288. create_animations = p_create_animations;
  289. }
  290. bool GLTFState::get_import_as_skeleton_bones() {
  291. return import_as_skeleton_bones;
  292. }
  293. void GLTFState::set_import_as_skeleton_bones(bool p_import_as_skeleton_bones) {
  294. import_as_skeleton_bones = p_import_as_skeleton_bones;
  295. }
  296. TypedArray<GLTFAnimation> GLTFState::get_animations() {
  297. return GLTFTemplateConvert::to_array(animations);
  298. }
  299. void GLTFState::set_animations(TypedArray<GLTFAnimation> p_animations) {
  300. GLTFTemplateConvert::set_from_array(animations, p_animations);
  301. }
  302. Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
  303. if (!scene_nodes.has(idx)) {
  304. return nullptr;
  305. }
  306. return scene_nodes[idx];
  307. }
  308. GLTFNodeIndex GLTFState::get_node_index(Node *p_node) {
  309. for (KeyValue<GLTFNodeIndex, Node *> x : scene_nodes) {
  310. if (x.value == p_node) {
  311. return x.key;
  312. }
  313. }
  314. return -1;
  315. }
  316. int GLTFState::get_animation_players_count(int idx) {
  317. return animation_players.size();
  318. }
  319. AnimationPlayer *GLTFState::get_animation_player(int idx) {
  320. ERR_FAIL_INDEX_V(idx, animation_players.size(), nullptr);
  321. return animation_players[idx];
  322. }
  323. void GLTFState::set_discard_meshes_and_materials(bool p_discard_meshes_and_materials) {
  324. discard_meshes_and_materials = p_discard_meshes_and_materials;
  325. }
  326. bool GLTFState::get_discard_meshes_and_materials() {
  327. return discard_meshes_and_materials;
  328. }
  329. String GLTFState::get_base_path() {
  330. return base_path;
  331. }
  332. void GLTFState::set_base_path(String p_base_path) {
  333. base_path = p_base_path;
  334. }
  335. String GLTFState::get_filename() const {
  336. return filename;
  337. }
  338. void GLTFState::set_filename(const String &p_filename) {
  339. filename = p_filename;
  340. }
  341. Variant GLTFState::get_additional_data(const StringName &p_extension_name) {
  342. return additional_data[p_extension_name];
  343. }
  344. void GLTFState::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
  345. additional_data[p_extension_name] = p_additional_data;
  346. }
  347. GLTFBufferViewIndex GLTFState::append_data_to_buffers(const Vector<uint8_t> &p_data, const bool p_deduplication = false) {
  348. if (p_deduplication) {
  349. for (int i = 0; i < buffer_views.size(); i++) {
  350. Ref<GLTFBufferView> buffer_view = buffer_views[i];
  351. Vector<uint8_t> buffer_view_data = buffer_view->load_buffer_view_data(this);
  352. if (buffer_view_data == p_data) {
  353. return i;
  354. }
  355. }
  356. }
  357. // Append the given data to a buffer and create a buffer view for it.
  358. if (unlikely(buffers.is_empty())) {
  359. buffers.push_back(Vector<uint8_t>());
  360. }
  361. Vector<uint8_t> &destination_buffer = buffers.write[0];
  362. Ref<GLTFBufferView> buffer_view;
  363. buffer_view.instantiate();
  364. buffer_view->set_buffer(0);
  365. buffer_view->set_byte_offset(destination_buffer.size());
  366. buffer_view->set_byte_length(p_data.size());
  367. destination_buffer.append_array(p_data);
  368. const int new_index = buffer_views.size();
  369. buffer_views.push_back(buffer_view);
  370. return new_index;
  371. }