gltf_state.cpp 21 KB

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