gltf_accessor.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**************************************************************************/
  2. /* gltf_accessor.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_accessor.h"
  31. void GLTFAccessor::_bind_methods() {
  32. BIND_ENUM_CONSTANT(TYPE_SCALAR);
  33. BIND_ENUM_CONSTANT(TYPE_VEC2);
  34. BIND_ENUM_CONSTANT(TYPE_VEC3);
  35. BIND_ENUM_CONSTANT(TYPE_VEC4);
  36. BIND_ENUM_CONSTANT(TYPE_MAT2);
  37. BIND_ENUM_CONSTANT(TYPE_MAT3);
  38. BIND_ENUM_CONSTANT(TYPE_MAT4);
  39. BIND_ENUM_CONSTANT(COMPONENT_TYPE_NONE);
  40. BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_BYTE);
  41. BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_BYTE);
  42. BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_SHORT);
  43. BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_SHORT);
  44. BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_INT);
  45. BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_INT);
  46. BIND_ENUM_CONSTANT(COMPONENT_TYPE_SINGLE_FLOAT);
  47. BIND_ENUM_CONSTANT(COMPONENT_TYPE_DOUBLE_FLOAT);
  48. BIND_ENUM_CONSTANT(COMPONENT_TYPE_HALF_FLOAT);
  49. BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_LONG);
  50. BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_LONG);
  51. ClassDB::bind_method(D_METHOD("get_buffer_view"), &GLTFAccessor::get_buffer_view);
  52. ClassDB::bind_method(D_METHOD("set_buffer_view", "buffer_view"), &GLTFAccessor::set_buffer_view);
  53. ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFAccessor::get_byte_offset);
  54. ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFAccessor::set_byte_offset);
  55. ClassDB::bind_method(D_METHOD("get_component_type"), &GLTFAccessor::get_component_type);
  56. ClassDB::bind_method(D_METHOD("set_component_type", "component_type"), &GLTFAccessor::set_component_type);
  57. ClassDB::bind_method(D_METHOD("get_normalized"), &GLTFAccessor::get_normalized);
  58. ClassDB::bind_method(D_METHOD("set_normalized", "normalized"), &GLTFAccessor::set_normalized);
  59. ClassDB::bind_method(D_METHOD("get_count"), &GLTFAccessor::get_count);
  60. ClassDB::bind_method(D_METHOD("set_count", "count"), &GLTFAccessor::set_count);
  61. ClassDB::bind_method(D_METHOD("get_accessor_type"), &GLTFAccessor::get_accessor_type);
  62. ClassDB::bind_method(D_METHOD("set_accessor_type", "accessor_type"), &GLTFAccessor::set_accessor_type);
  63. ClassDB::bind_method(D_METHOD("get_type"), &GLTFAccessor::get_type);
  64. ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFAccessor::set_type);
  65. ClassDB::bind_method(D_METHOD("get_min"), &GLTFAccessor::get_min);
  66. ClassDB::bind_method(D_METHOD("set_min", "min"), &GLTFAccessor::set_min);
  67. ClassDB::bind_method(D_METHOD("get_max"), &GLTFAccessor::get_max);
  68. ClassDB::bind_method(D_METHOD("set_max", "max"), &GLTFAccessor::set_max);
  69. ClassDB::bind_method(D_METHOD("get_sparse_count"), &GLTFAccessor::get_sparse_count);
  70. ClassDB::bind_method(D_METHOD("set_sparse_count", "sparse_count"), &GLTFAccessor::set_sparse_count);
  71. ClassDB::bind_method(D_METHOD("get_sparse_indices_buffer_view"), &GLTFAccessor::get_sparse_indices_buffer_view);
  72. ClassDB::bind_method(D_METHOD("set_sparse_indices_buffer_view", "sparse_indices_buffer_view"), &GLTFAccessor::set_sparse_indices_buffer_view);
  73. ClassDB::bind_method(D_METHOD("get_sparse_indices_byte_offset"), &GLTFAccessor::get_sparse_indices_byte_offset);
  74. ClassDB::bind_method(D_METHOD("set_sparse_indices_byte_offset", "sparse_indices_byte_offset"), &GLTFAccessor::set_sparse_indices_byte_offset);
  75. ClassDB::bind_method(D_METHOD("get_sparse_indices_component_type"), &GLTFAccessor::get_sparse_indices_component_type);
  76. ClassDB::bind_method(D_METHOD("set_sparse_indices_component_type", "sparse_indices_component_type"), &GLTFAccessor::set_sparse_indices_component_type);
  77. ClassDB::bind_method(D_METHOD("get_sparse_values_buffer_view"), &GLTFAccessor::get_sparse_values_buffer_view);
  78. ClassDB::bind_method(D_METHOD("set_sparse_values_buffer_view", "sparse_values_buffer_view"), &GLTFAccessor::set_sparse_values_buffer_view);
  79. ClassDB::bind_method(D_METHOD("get_sparse_values_byte_offset"), &GLTFAccessor::get_sparse_values_byte_offset);
  80. ClassDB::bind_method(D_METHOD("set_sparse_values_byte_offset", "sparse_values_byte_offset"), &GLTFAccessor::set_sparse_values_byte_offset);
  81. ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer_view"), "set_buffer_view", "get_buffer_view"); // GLTFBufferViewIndex
  82. ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
  83. ADD_PROPERTY(PropertyInfo(Variant::INT, "component_type"), "set_component_type", "get_component_type"); // int
  84. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalized"), "set_normalized", "get_normalized"); // bool
  85. ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); // int
  86. ADD_PROPERTY(PropertyInfo(Variant::INT, "accessor_type"), "set_accessor_type", "get_accessor_type"); // GLTFAccessor::GLTFAccessorType
  87. ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_type", "get_type"); // Deprecated, int for GLTFAccessor::GLTFAccessorType
  88. ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
  89. ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "max"), "set_max", "get_max"); // Vector<real_t>
  90. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_count"), "set_sparse_count", "get_sparse_count"); // int
  91. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_buffer_view"), "set_sparse_indices_buffer_view", "get_sparse_indices_buffer_view"); // int
  92. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_byte_offset"), "set_sparse_indices_byte_offset", "get_sparse_indices_byte_offset"); // int
  93. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_component_type"), "set_sparse_indices_component_type", "get_sparse_indices_component_type"); // int
  94. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_buffer_view"), "set_sparse_values_buffer_view", "get_sparse_values_buffer_view"); // int
  95. ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_byte_offset"), "set_sparse_values_byte_offset", "get_sparse_values_byte_offset"); // int
  96. }
  97. GLTFBufferViewIndex GLTFAccessor::get_buffer_view() {
  98. return buffer_view;
  99. }
  100. void GLTFAccessor::set_buffer_view(GLTFBufferViewIndex p_buffer_view) {
  101. buffer_view = p_buffer_view;
  102. }
  103. int GLTFAccessor::get_byte_offset() {
  104. return byte_offset;
  105. }
  106. void GLTFAccessor::set_byte_offset(int p_byte_offset) {
  107. byte_offset = p_byte_offset;
  108. }
  109. int GLTFAccessor::get_component_type() {
  110. return component_type;
  111. }
  112. void GLTFAccessor::set_component_type(int p_component_type) {
  113. component_type = (GLTFComponentType)p_component_type;
  114. }
  115. bool GLTFAccessor::get_normalized() {
  116. return normalized;
  117. }
  118. void GLTFAccessor::set_normalized(bool p_normalized) {
  119. normalized = p_normalized;
  120. }
  121. int GLTFAccessor::get_count() {
  122. return count;
  123. }
  124. void GLTFAccessor::set_count(int p_count) {
  125. count = p_count;
  126. }
  127. GLTFAccessor::GLTFAccessorType GLTFAccessor::get_accessor_type() {
  128. return accessor_type;
  129. }
  130. void GLTFAccessor::set_accessor_type(GLTFAccessorType p_accessor_type) {
  131. accessor_type = p_accessor_type;
  132. }
  133. int GLTFAccessor::get_type() {
  134. return (int)accessor_type;
  135. }
  136. void GLTFAccessor::set_type(int p_accessor_type) {
  137. accessor_type = (GLTFAccessorType)p_accessor_type; // TODO: Register enum
  138. }
  139. Vector<double> GLTFAccessor::get_min() {
  140. return min;
  141. }
  142. void GLTFAccessor::set_min(Vector<double> p_min) {
  143. min = p_min;
  144. }
  145. Vector<double> GLTFAccessor::get_max() {
  146. return max;
  147. }
  148. void GLTFAccessor::set_max(Vector<double> p_max) {
  149. max = p_max;
  150. }
  151. int GLTFAccessor::get_sparse_count() {
  152. return sparse_count;
  153. }
  154. void GLTFAccessor::set_sparse_count(int p_sparse_count) {
  155. sparse_count = p_sparse_count;
  156. }
  157. int GLTFAccessor::get_sparse_indices_buffer_view() {
  158. return sparse_indices_buffer_view;
  159. }
  160. void GLTFAccessor::set_sparse_indices_buffer_view(int p_sparse_indices_buffer_view) {
  161. sparse_indices_buffer_view = p_sparse_indices_buffer_view;
  162. }
  163. int GLTFAccessor::get_sparse_indices_byte_offset() {
  164. return sparse_indices_byte_offset;
  165. }
  166. void GLTFAccessor::set_sparse_indices_byte_offset(int p_sparse_indices_byte_offset) {
  167. sparse_indices_byte_offset = p_sparse_indices_byte_offset;
  168. }
  169. int GLTFAccessor::get_sparse_indices_component_type() {
  170. return sparse_indices_component_type;
  171. }
  172. void GLTFAccessor::set_sparse_indices_component_type(int p_sparse_indices_component_type) {
  173. sparse_indices_component_type = (GLTFComponentType)p_sparse_indices_component_type;
  174. }
  175. int GLTFAccessor::get_sparse_values_buffer_view() {
  176. return sparse_values_buffer_view;
  177. }
  178. void GLTFAccessor::set_sparse_values_buffer_view(int p_sparse_values_buffer_view) {
  179. sparse_values_buffer_view = p_sparse_values_buffer_view;
  180. }
  181. int GLTFAccessor::get_sparse_values_byte_offset() {
  182. return sparse_values_byte_offset;
  183. }
  184. void GLTFAccessor::set_sparse_values_byte_offset(int p_sparse_values_byte_offset) {
  185. sparse_values_byte_offset = p_sparse_values_byte_offset;
  186. }