gltf_document_extension.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**************************************************************************/
  2. /* gltf_document_extension.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_document_extension.h"
  31. void GLTFDocumentExtension::_bind_methods() {
  32. // Import process.
  33. GDVIRTUAL_BIND(_import_preflight, "state", "extensions");
  34. GDVIRTUAL_BIND(_get_supported_extensions);
  35. GDVIRTUAL_BIND(_parse_node_extensions, "state", "gltf_node", "extensions");
  36. GDVIRTUAL_BIND(_generate_scene_node, "state", "gltf_node", "scene_parent");
  37. GDVIRTUAL_BIND(_import_post_parse, "state");
  38. GDVIRTUAL_BIND(_import_node, "state", "gltf_node", "json", "node");
  39. GDVIRTUAL_BIND(_import_post, "state", "root");
  40. // Export process.
  41. GDVIRTUAL_BIND(_export_preflight, "state", "root");
  42. GDVIRTUAL_BIND(_convert_scene_node, "state", "gltf_node", "scene_node");
  43. GDVIRTUAL_BIND(_export_node, "state", "gltf_node", "json", "node");
  44. GDVIRTUAL_BIND(_export_post, "state");
  45. }
  46. // Import process.
  47. Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) {
  48. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  49. Error err = OK;
  50. GDVIRTUAL_CALL(_import_preflight, p_state, p_extensions, err);
  51. return err;
  52. }
  53. Vector<String> GLTFDocumentExtension::get_supported_extensions() {
  54. Vector<String> ret;
  55. GDVIRTUAL_CALL(_get_supported_extensions, ret);
  56. return ret;
  57. }
  58. Error GLTFDocumentExtension::parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions) {
  59. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  60. ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER);
  61. Error err = OK;
  62. GDVIRTUAL_CALL(_parse_node_extensions, p_state, p_gltf_node, p_extensions, err);
  63. return err;
  64. }
  65. Node3D *GLTFDocumentExtension::generate_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) {
  66. ERR_FAIL_NULL_V(p_state, nullptr);
  67. ERR_FAIL_NULL_V(p_gltf_node, nullptr);
  68. ERR_FAIL_NULL_V(p_scene_parent, nullptr);
  69. Node3D *ret_node = nullptr;
  70. GDVIRTUAL_CALL(_generate_scene_node, p_state, p_gltf_node, p_scene_parent, ret_node);
  71. return ret_node;
  72. }
  73. Error GLTFDocumentExtension::import_post_parse(Ref<GLTFState> p_state) {
  74. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  75. Error err = OK;
  76. GDVIRTUAL_CALL(_import_post_parse, p_state, err);
  77. return err;
  78. }
  79. Error GLTFDocumentExtension::import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
  80. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  81. ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER);
  82. ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
  83. Error err = OK;
  84. GDVIRTUAL_CALL(_import_node, p_state, p_gltf_node, r_dict, p_node, err);
  85. return err;
  86. }
  87. Error GLTFDocumentExtension::import_post(Ref<GLTFState> p_state, Node *p_root) {
  88. ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
  89. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  90. Error err = OK;
  91. GDVIRTUAL_CALL(_import_post, p_state, p_root, err);
  92. return err;
  93. }
  94. // Export process.
  95. Error GLTFDocumentExtension::export_preflight(Ref<GLTFState> p_state, Node *p_root) {
  96. ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
  97. Error err = OK;
  98. GDVIRTUAL_CALL(_export_preflight, p_state, p_root, err);
  99. return err;
  100. }
  101. void GLTFDocumentExtension::convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node) {
  102. ERR_FAIL_NULL(p_state);
  103. ERR_FAIL_NULL(p_gltf_node);
  104. ERR_FAIL_NULL(p_scene_node);
  105. GDVIRTUAL_CALL(_convert_scene_node, p_state, p_gltf_node, p_scene_node);
  106. }
  107. Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
  108. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  109. ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER);
  110. ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
  111. Error err = OK;
  112. GDVIRTUAL_CALL(_export_node, p_state, p_gltf_node, r_dict, p_node, err);
  113. return err;
  114. }
  115. Error GLTFDocumentExtension::export_post(Ref<GLTFState> p_state) {
  116. ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
  117. Error err = OK;
  118. GDVIRTUAL_CALL(_export_post, p_state, err);
  119. return err;
  120. }