diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2024-07-03 19:57:17 -0700 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2024-07-04 15:46:48 -0700 |
commit | 923a8eb5d3e9fa9b949624844f96266f301c2b01 (patch) | |
tree | 835a05095651b10e8e416b5dbb3bd0c51f037858 /modules/gltf/gltf_document.cpp | |
parent | 20ba2f00bd9199b675176a8e1ac151f96bfb5cfa (diff) | |
download | redot-engine-923a8eb5d3e9fa9b949624844f96266f301c2b01.tar.gz |
Move GLTFAccessorType into GLTFAccessor
Diffstat (limited to 'modules/gltf/gltf_document.cpp')
-rw-r--r-- | modules/gltf/gltf_document.cpp | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index e0bdd4cf33..c0232e6d0c 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -934,58 +934,58 @@ Error GLTFDocument::_encode_accessors(Ref<GLTFState> p_state) { return OK; } -String GLTFDocument::_get_accessor_type_name(const GLTFAccessorType p_accessor_type) { - if (p_accessor_type == GLTFAccessorType::TYPE_SCALAR) { +String GLTFDocument::_get_accessor_type_name(const GLTFAccessor::GLTFAccessorType p_accessor_type) { + if (p_accessor_type == GLTFAccessor::TYPE_SCALAR) { return "SCALAR"; } - if (p_accessor_type == GLTFAccessorType::TYPE_VEC2) { + if (p_accessor_type == GLTFAccessor::TYPE_VEC2) { return "VEC2"; } - if (p_accessor_type == GLTFAccessorType::TYPE_VEC3) { + if (p_accessor_type == GLTFAccessor::TYPE_VEC3) { return "VEC3"; } - if (p_accessor_type == GLTFAccessorType::TYPE_VEC4) { + if (p_accessor_type == GLTFAccessor::TYPE_VEC4) { return "VEC4"; } - if (p_accessor_type == GLTFAccessorType::TYPE_MAT2) { + if (p_accessor_type == GLTFAccessor::TYPE_MAT2) { return "MAT2"; } - if (p_accessor_type == GLTFAccessorType::TYPE_MAT3) { + if (p_accessor_type == GLTFAccessor::TYPE_MAT3) { return "MAT3"; } - if (p_accessor_type == GLTFAccessorType::TYPE_MAT4) { + if (p_accessor_type == GLTFAccessor::TYPE_MAT4) { return "MAT4"; } ERR_FAIL_V("SCALAR"); } -GLTFAccessorType GLTFDocument::_get_accessor_type_from_str(const String &p_string) { +GLTFAccessor::GLTFAccessorType GLTFDocument::_get_accessor_type_from_str(const String &p_string) { if (p_string == "SCALAR") { - return GLTFAccessorType::TYPE_SCALAR; + return GLTFAccessor::TYPE_SCALAR; } if (p_string == "VEC2") { - return GLTFAccessorType::TYPE_VEC2; + return GLTFAccessor::TYPE_VEC2; } if (p_string == "VEC3") { - return GLTFAccessorType::TYPE_VEC3; + return GLTFAccessor::TYPE_VEC3; } if (p_string == "VEC4") { - return GLTFAccessorType::TYPE_VEC4; + return GLTFAccessor::TYPE_VEC4; } if (p_string == "MAT2") { - return GLTFAccessorType::TYPE_MAT2; + return GLTFAccessor::TYPE_MAT2; } if (p_string == "MAT3") { - return GLTFAccessorType::TYPE_MAT3; + return GLTFAccessor::TYPE_MAT3; } if (p_string == "MAT4") { - return GLTFAccessorType::TYPE_MAT4; + return GLTFAccessor::TYPE_MAT4; } - ERR_FAIL_V(GLTFAccessorType::TYPE_SCALAR); + ERR_FAIL_V(GLTFAccessor::TYPE_SCALAR); } Error GLTFDocument::_parse_accessors(Ref<GLTFState> p_state) { @@ -1088,7 +1088,7 @@ String GLTFDocument::_get_component_type_name(const uint32_t p_component) { return "<Error>"; } -Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_src, const int p_count, const GLTFAccessorType p_accessor_type, const int p_component_type, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex, GLTFBufferViewIndex &r_accessor, const bool p_for_vertex_indices) { +Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_src, const int p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type, const int p_component_type, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex, GLTFBufferViewIndex &r_accessor, const bool p_for_vertex_indices) { const int component_count_for_type[7] = { 1, 2, 3, 4, 4, 9, 16 }; @@ -1103,18 +1103,18 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_ switch (p_component_type) { case COMPONENT_TYPE_BYTE: case COMPONENT_TYPE_UNSIGNED_BYTE: { - if (p_accessor_type == TYPE_MAT2) { + if (p_accessor_type == GLTFAccessor::TYPE_MAT2) { skip_every = 2; skip_bytes = 2; } - if (p_accessor_type == TYPE_MAT3) { + if (p_accessor_type == GLTFAccessor::TYPE_MAT3) { skip_every = 3; skip_bytes = 1; } } break; case COMPONENT_TYPE_SHORT: case COMPONENT_TYPE_UNSIGNED_SHORT: { - if (p_accessor_type == TYPE_MAT3) { + if (p_accessor_type == GLTFAccessor::TYPE_MAT3) { skip_every = 6; skip_bytes = 4; } @@ -1296,7 +1296,7 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_ return OK; } -Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> p_state, double *p_dst, const GLTFBufferViewIndex p_buffer_view, const int p_skip_every, const int p_skip_bytes, const int p_element_size, const int p_count, const GLTFAccessorType p_accessor_type, const int p_component_count, const int p_component_type, const int p_component_size, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex) { +Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> p_state, double *p_dst, const GLTFBufferViewIndex p_buffer_view, const int p_skip_every, const int p_skip_bytes, const int p_element_size, const int p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type, const int p_component_count, const int p_component_type, const int p_component_size, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex) { const Ref<GLTFBufferView> bv = p_state->buffer_views[p_buffer_view]; int stride = p_element_size; @@ -1427,12 +1427,12 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> p_state, const GLTF switch (a->component_type) { case COMPONENT_TYPE_BYTE: case COMPONENT_TYPE_UNSIGNED_BYTE: { - if (a->accessor_type == TYPE_MAT2) { + if (a->accessor_type == GLTFAccessor::TYPE_MAT2) { skip_every = 2; skip_bytes = 2; element_size = 8; //override for this case } - if (a->accessor_type == TYPE_MAT3) { + if (a->accessor_type == GLTFAccessor::TYPE_MAT3) { skip_every = 3; skip_bytes = 1; element_size = 12; //override for this case @@ -1440,7 +1440,7 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> p_state, const GLTF } break; case COMPONENT_TYPE_SHORT: case COMPONENT_TYPE_UNSIGNED_SHORT: { - if (a->accessor_type == TYPE_MAT3) { + if (a->accessor_type == GLTFAccessor::TYPE_MAT3) { skip_every = 6; skip_bytes = 4; element_size = 16; //override for this case @@ -1474,7 +1474,7 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> p_state, const GLTF indices.resize(a->sparse_count); const int indices_component_size = _get_component_type_size(a->sparse_indices_component_type); - Error err = _decode_buffer_view(p_state, indices.ptrw(), a->sparse_indices_buffer_view, 0, 0, indices_component_size, a->sparse_count, TYPE_SCALAR, 1, a->sparse_indices_component_type, indices_component_size, false, a->sparse_indices_byte_offset, false); + Error err = _decode_buffer_view(p_state, indices.ptrw(), a->sparse_indices_buffer_view, 0, 0, indices_component_size, a->sparse_count, GLTFAccessor::TYPE_SCALAR, 1, a->sparse_indices_component_type, indices_component_size, false, a->sparse_indices_byte_offset, false); if (err != OK) { return Vector<double>(); } @@ -1536,7 +1536,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state, p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_SCALAR; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_SCALAR; int component_type; if (max_index > 65535 || p_for_vertex) { component_type = GLTFDocument::COMPONENT_TYPE_INT; @@ -1650,7 +1650,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> p_state, p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC2; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC2; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -1703,7 +1703,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> p_state p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC4; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -1770,7 +1770,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> p_sta p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC4; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -1821,7 +1821,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> p_stat p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC4; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_UNSIGNED_SHORT; accessor->max = type_max; @@ -1874,7 +1874,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> p p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC4; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -1949,7 +1949,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_stat p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_SCALAR; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_SCALAR; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -1999,7 +1999,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> p_state, p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC3; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC3; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -2075,7 +2075,7 @@ GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_VEC3; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_VEC3; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; sparse_accessor->normalized = false; @@ -2103,7 +2103,7 @@ GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p } else { sparse_accessor->sparse_indices_component_type = GLTFDocument::COMPONENT_TYPE_UNSIGNED_SHORT; } - if (_encode_buffer_view(p_state, changed_indices.ptr(), changed_indices.size(), GLTFAccessorType::TYPE_SCALAR, sparse_accessor->sparse_indices_component_type, sparse_accessor->normalized, sparse_accessor->sparse_indices_byte_offset, false, buffer_view_i_indices) != OK) { + if (_encode_buffer_view(p_state, changed_indices.ptr(), changed_indices.size(), GLTFAccessor::TYPE_SCALAR, sparse_accessor->sparse_indices_component_type, sparse_accessor->normalized, sparse_accessor->sparse_indices_byte_offset, false, buffer_view_i_indices) != OK) { return -1; } // We use changed_indices.size() here, because we must pass the number of vec3 values rather than the number of components. @@ -2180,7 +2180,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> p_state p_state->buffers.push_back(Vector<uint8_t>()); } int64_t size = p_state->buffers[0].size(); - const GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_MAT4; + const GLTFAccessor::GLTFAccessorType accessor_type = GLTFAccessor::TYPE_MAT4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; accessor->max = type_max; @@ -2234,9 +2234,9 @@ Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> p_state, co } const int accessor_type = p_state->accessors[p_accessor]->accessor_type; - ERR_FAIL_COND_V(!(accessor_type == TYPE_VEC3 || accessor_type == TYPE_VEC4), ret); + ERR_FAIL_COND_V(!(accessor_type == GLTFAccessor::TYPE_VEC3 || accessor_type == GLTFAccessor::TYPE_VEC4), ret); int vec_len = 3; - if (accessor_type == TYPE_VEC4) { + if (accessor_type == GLTFAccessor::TYPE_VEC4) { vec_len = 4; } |