gltf_accessor.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*************************************************************************/
  2. /* gltf_accessor.cpp */
  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. #include "gltf_accessor.h"
  31. #include "gltf_document_extension.h"
  32. void GLTFAccessor::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("get_buffer_view"), &GLTFAccessor::get_buffer_view);
  34. ClassDB::bind_method(D_METHOD("set_buffer_view", "buffer_view"), &GLTFAccessor::set_buffer_view);
  35. ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFAccessor::get_byte_offset);
  36. ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFAccessor::set_byte_offset);
  37. ClassDB::bind_method(D_METHOD("get_component_type"), &GLTFAccessor::get_component_type);
  38. ClassDB::bind_method(D_METHOD("set_component_type", "component_type"), &GLTFAccessor::set_component_type);
  39. ClassDB::bind_method(D_METHOD("get_normalized"), &GLTFAccessor::get_normalized);
  40. ClassDB::bind_method(D_METHOD("set_normalized", "normalized"), &GLTFAccessor::set_normalized);
  41. ClassDB::bind_method(D_METHOD("get_count"), &GLTFAccessor::get_count);
  42. ClassDB::bind_method(D_METHOD("set_count", "count"), &GLTFAccessor::set_count);
  43. ClassDB::bind_method(D_METHOD("get_type"), &GLTFAccessor::get_type);
  44. ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFAccessor::set_type);
  45. ClassDB::bind_method(D_METHOD("get_min"), &GLTFAccessor::get_min);
  46. ClassDB::bind_method(D_METHOD("set_min", "min"), &GLTFAccessor::set_min);
  47. ClassDB::bind_method(D_METHOD("get_max"), &GLTFAccessor::get_max);
  48. ClassDB::bind_method(D_METHOD("set_max", "max"), &GLTFAccessor::set_max);
  49. ClassDB::bind_method(D_METHOD("get_sparse_count"), &GLTFAccessor::get_sparse_count);
  50. ClassDB::bind_method(D_METHOD("set_sparse_count", "sparse_count"), &GLTFAccessor::set_sparse_count);
  51. ClassDB::bind_method(D_METHOD("get_sparse_indices_buffer_view"), &GLTFAccessor::get_sparse_indices_buffer_view);
  52. ClassDB::bind_method(D_METHOD("set_sparse_indices_buffer_view", "sparse_indices_buffer_view"), &GLTFAccessor::set_sparse_indices_buffer_view);
  53. ClassDB::bind_method(D_METHOD("get_sparse_indices_byte_offset"), &GLTFAccessor::get_sparse_indices_byte_offset);
  54. ClassDB::bind_method(D_METHOD("set_sparse_indices_byte_offset", "sparse_indices_byte_offset"), &GLTFAccessor::set_sparse_indices_byte_offset);
  55. ClassDB::bind_method(D_METHOD("get_sparse_indices_component_type"), &GLTFAccessor::get_sparse_indices_component_type);
  56. ClassDB::bind_method(D_METHOD("set_sparse_indices_component_type", "sparse_indices_component_type"), &GLTFAccessor::set_sparse_indices_component_type);
  57. ClassDB::bind_method(D_METHOD("get_sparse_values_buffer_view"), &GLTFAccessor::get_sparse_values_buffer_view);
  58. ClassDB::bind_method(D_METHOD("set_sparse_values_buffer_view", "sparse_values_buffer_view"), &GLTFAccessor::set_sparse_values_buffer_view);
  59. ClassDB::bind_method(D_METHOD("get_sparse_values_byte_offset"), &GLTFAccessor::get_sparse_values_byte_offset);
  60. ClassDB::bind_method(D_METHOD("set_sparse_values_byte_offset", "sparse_values_byte_offset"), &GLTFAccessor::set_sparse_values_byte_offset);
  61. ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer_view"), "set_buffer_view", "get_buffer_view"); // GLTFBufferViewIndex
  62. ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
  63. ADD_PROPERTY(PropertyInfo(Variant::INT, "component_type"), "set_component_type", "get_component_type"); // int
  64. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalized"), "set_normalized", "get_normalized"); // bool
  65. ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); // int
  66. ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); // GLTFDocument::GLTFType
  67. ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
  68. ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "max"), "set_max", "get_max"); // Vector<real_t>
  69. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_count"), "set_sparse_count", "get_sparse_count"); // int
  70. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_buffer_view"), "set_sparse_indices_buffer_view", "get_sparse_indices_buffer_view"); // int
  71. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_byte_offset"), "set_sparse_indices_byte_offset", "get_sparse_indices_byte_offset"); // int
  72. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_component_type"), "set_sparse_indices_component_type", "get_sparse_indices_component_type"); // int
  73. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_buffer_view"), "set_sparse_values_buffer_view", "get_sparse_values_buffer_view"); // int
  74. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_byte_offset"), "set_sparse_values_byte_offset", "get_sparse_values_byte_offset"); // int
  75. }
  76. GLTFBufferViewIndex GLTFAccessor::get_buffer_view() {
  77. return buffer_view;
  78. }
  79. void GLTFAccessor::set_buffer_view(GLTFBufferViewIndex p_buffer_view) {
  80. buffer_view = p_buffer_view;
  81. }
  82. int GLTFAccessor::get_byte_offset() {
  83. return byte_offset;
  84. }
  85. void GLTFAccessor::set_byte_offset(int p_byte_offset) {
  86. byte_offset = p_byte_offset;
  87. }
  88. int GLTFAccessor::get_component_type() {
  89. return component_type;
  90. }
  91. void GLTFAccessor::set_component_type(int p_component_type) {
  92. component_type = p_component_type;
  93. }
  94. bool GLTFAccessor::get_normalized() {
  95. return normalized;
  96. }
  97. void GLTFAccessor::set_normalized(bool p_normalized) {
  98. normalized = p_normalized;
  99. }
  100. int GLTFAccessor::get_count() {
  101. return count;
  102. }
  103. void GLTFAccessor::set_count(int p_count) {
  104. count = p_count;
  105. }
  106. int GLTFAccessor::get_type() {
  107. return (int)type;
  108. }
  109. void GLTFAccessor::set_type(int p_type) {
  110. type = (GLTFDocument::GLTFType)p_type; // TODO: Register enum
  111. }
  112. Vector<double> GLTFAccessor::get_min() {
  113. return min;
  114. }
  115. void GLTFAccessor::set_min(Vector<double> p_min) {
  116. min = p_min;
  117. }
  118. Vector<double> GLTFAccessor::get_max() {
  119. return max;
  120. }
  121. void GLTFAccessor::set_max(Vector<double> p_max) {
  122. max = p_max;
  123. }
  124. int GLTFAccessor::get_sparse_count() {
  125. return sparse_count;
  126. }
  127. void GLTFAccessor::set_sparse_count(int p_sparse_count) {
  128. sparse_count = p_sparse_count;
  129. }
  130. int GLTFAccessor::get_sparse_indices_buffer_view() {
  131. return sparse_indices_buffer_view;
  132. }
  133. void GLTFAccessor::set_sparse_indices_buffer_view(int p_sparse_indices_buffer_view) {
  134. sparse_indices_buffer_view = p_sparse_indices_buffer_view;
  135. }
  136. int GLTFAccessor::get_sparse_indices_byte_offset() {
  137. return sparse_indices_byte_offset;
  138. }
  139. void GLTFAccessor::set_sparse_indices_byte_offset(int p_sparse_indices_byte_offset) {
  140. sparse_indices_byte_offset = p_sparse_indices_byte_offset;
  141. }
  142. int GLTFAccessor::get_sparse_indices_component_type() {
  143. return sparse_indices_component_type;
  144. }
  145. void GLTFAccessor::set_sparse_indices_component_type(int p_sparse_indices_component_type) {
  146. sparse_indices_component_type = p_sparse_indices_component_type;
  147. }
  148. int GLTFAccessor::get_sparse_values_buffer_view() {
  149. return sparse_values_buffer_view;
  150. }
  151. void GLTFAccessor::set_sparse_values_buffer_view(int p_sparse_values_buffer_view) {
  152. sparse_values_buffer_view = p_sparse_values_buffer_view;
  153. }
  154. int GLTFAccessor::get_sparse_values_byte_offset() {
  155. return sparse_values_byte_offset;
  156. }
  157. void GLTFAccessor::set_sparse_values_byte_offset(int p_sparse_values_byte_offset) {
  158. sparse_values_byte_offset = p_sparse_values_byte_offset;
  159. }