[4.4] GLTF: Fix nasty bug with incorrect buffer indices
This commit is contained in:
@ -194,10 +194,6 @@ Error GLTFDocument::_serialize(Ref<GLTFState> p_state) {
|
||||
return Error::FAILED;
|
||||
}
|
||||
|
||||
for (GLTFBufferViewIndex i = 0; i < p_state->buffer_views.size(); i++) {
|
||||
p_state->buffer_views.write[i]->buffer = 0;
|
||||
}
|
||||
|
||||
/* STEP SERIALIZE BUFFER VIEWS */
|
||||
err = _encode_buffer_views(p_state);
|
||||
if (err != OK) {
|
||||
@ -1120,14 +1116,21 @@ String GLTFDocument::_get_component_type_name(const GLTFAccessor::GLTFComponentT
|
||||
return "<Error>";
|
||||
}
|
||||
|
||||
Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_src, const int p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type, const GLTFAccessor::GLTFComponentType 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_accessor_into_buffer_view(Ref<GLTFState> p_state, const double *p_src, const int64_t p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type, const GLTFAccessor::GLTFComponentType p_component_type, const bool p_normalized, const int64_t p_byte_offset, const bool p_for_vertex, GLTFBufferViewIndex &r_buffer_view, const bool p_for_vertex_indices) {
|
||||
const int component_count = COMPONENT_COUNT_FOR_ACCESSOR_TYPE[p_accessor_type];
|
||||
const int component_size = _get_component_type_size(p_component_type);
|
||||
ERR_FAIL_COND_V(component_size == 0, FAILED);
|
||||
// The byte offset of an accessor MUST be a multiple of the accessor's component size.
|
||||
// See 3.6.2.4: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#data-alignment
|
||||
int64_t offset = p_byte_offset;
|
||||
if (p_byte_offset % component_size != 0) {
|
||||
offset += component_size - (p_byte_offset % component_size);
|
||||
}
|
||||
|
||||
int skip_every = 0;
|
||||
int skip_bytes = 0;
|
||||
//special case of alignments, as described in spec
|
||||
int64_t skip_every = 0;
|
||||
int64_t skip_bytes = 0;
|
||||
// Accessors of matrix type have data stored in column-major order. The start of each column MUST be aligned to 4-byte boundaries.
|
||||
// See 3.6.2.4: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#data-alignment
|
||||
switch (p_component_type) {
|
||||
case GLTFAccessor::COMPONENT_TYPE_SIGNED_BYTE:
|
||||
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE: {
|
||||
@ -1144,7 +1147,7 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
|
||||
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_SHORT: {
|
||||
if (p_accessor_type == GLTFAccessor::TYPE_MAT3) {
|
||||
skip_every = 6;
|
||||
skip_bytes = 4;
|
||||
skip_bytes = 2;
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
@ -1153,8 +1156,10 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
|
||||
|
||||
Ref<GLTFBufferView> bv;
|
||||
bv.instantiate();
|
||||
const uint32_t offset = bv->byte_offset = p_byte_offset;
|
||||
Vector<uint8_t> &gltf_buffer = p_state->buffers.write[0];
|
||||
const GLTFBufferIndex buffer0 = 0;
|
||||
bv->buffer = buffer0;
|
||||
bv->byte_offset = offset;
|
||||
Vector<uint8_t> &gltf_buffer = p_state->buffers.write[buffer0];
|
||||
|
||||
int stride = component_count * component_size;
|
||||
if (p_for_vertex && stride % 4) {
|
||||
@ -1180,232 +1185,232 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
|
||||
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "glTF: Failed to encode buffer view, component type not set.");
|
||||
}
|
||||
case GLTFAccessor::COMPONENT_TYPE_SIGNED_BYTE: {
|
||||
Vector<int8_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<int8_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
if (p_normalized) {
|
||||
buffer.write[dst_i] = d * 128.0;
|
||||
encoded_data.write[dst_i] = d * 128.0;
|
||||
} else {
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
}
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(int8_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(int8_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE: {
|
||||
Vector<uint8_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<uint8_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
if (p_normalized) {
|
||||
buffer.write[dst_i] = d * 255.0;
|
||||
encoded_data.write[dst_i] = d * 255.0;
|
||||
} else {
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
}
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
gltf_buffer.append_array(buffer);
|
||||
const size_t buffer_size = buffer.size() * sizeof(uint8_t);
|
||||
gltf_buffer.append_array(encoded_data);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(uint8_t);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_SIGNED_SHORT: {
|
||||
Vector<int16_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<int16_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
if (p_normalized) {
|
||||
buffer.write[dst_i] = d * 32768.0;
|
||||
encoded_data.write[dst_i] = d * 32768.0;
|
||||
} else {
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
}
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(int16_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(int16_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_SHORT: {
|
||||
Vector<uint16_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<uint16_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
if (p_normalized) {
|
||||
buffer.write[dst_i] = d * 65535.0;
|
||||
encoded_data.write[dst_i] = d * 65535.0;
|
||||
} else {
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
}
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(uint16_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(uint16_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_SIGNED_INT: {
|
||||
Vector<int32_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<int32_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(int32_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(int32_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_INT: {
|
||||
Vector<uint32_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<uint32_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(uint32_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(uint32_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT: {
|
||||
Vector<float> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<float> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(float);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(float);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_DOUBLE_FLOAT: {
|
||||
Vector<double> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<double> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
double d = *p_src;
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(double);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(double);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_HALF_FLOAT: {
|
||||
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "glTF: Half float not supported yet.");
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_SIGNED_LONG: {
|
||||
Vector<int64_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<int64_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
// FIXME: This can result in precision loss because int64_t can store some values that double can't.
|
||||
double d = *p_src;
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(int64_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(int64_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_LONG: {
|
||||
Vector<uint64_t> buffer;
|
||||
buffer.resize(p_count * component_count);
|
||||
int32_t dst_i = 0;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
for (int j = 0; j < component_count; j++) {
|
||||
Vector<uint64_t> encoded_data;
|
||||
encoded_data.resize(p_count * component_count);
|
||||
int64_t dst_i = 0;
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
for (int64_t j = 0; j < component_count; j++) {
|
||||
if (skip_every && j > 0 && (j % skip_every) == 0) {
|
||||
dst_i += skip_bytes;
|
||||
}
|
||||
// FIXME: This can result in precision loss because int64_t can store some values that double can't.
|
||||
double d = *p_src;
|
||||
buffer.write[dst_i] = d;
|
||||
encoded_data.write[dst_i] = d;
|
||||
p_src++;
|
||||
dst_i++;
|
||||
}
|
||||
}
|
||||
const int64_t old_size = gltf_buffer.size();
|
||||
const size_t buffer_size = buffer.size() * sizeof(uint64_t);
|
||||
const size_t buffer_size = encoded_data.size() * sizeof(uint64_t);
|
||||
gltf_buffer.resize(old_size + buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
|
||||
memcpy(gltf_buffer.ptrw() + old_size, encoded_data.ptrw(), buffer_size);
|
||||
bv->byte_length = buffer_size;
|
||||
} break;
|
||||
}
|
||||
@ -1417,7 +1422,7 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
|
||||
gltf_buffer.push_back(0);
|
||||
}
|
||||
|
||||
r_accessor = bv->buffer = p_state->buffer_views.size();
|
||||
r_buffer_view = p_state->buffer_views.size();
|
||||
p_state->buffer_views.push_back(bv);
|
||||
return OK;
|
||||
}
|
||||
@ -1434,6 +1439,12 @@ Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> p_state, double *p_dst, c
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX_V(bv->buffer, p_state->buffers.size(), ERR_PARSE_ERROR);
|
||||
if (bv->byte_offset % p_component_size != 0) {
|
||||
WARN_PRINT("glTF: Buffer view byte offset is not a multiple of accessor component size. This file is invalid per the glTF specification and will not load correctly in some glTF viewers, but Godot will try to load it anyway.");
|
||||
}
|
||||
if (p_byte_offset % p_component_size != 0) {
|
||||
WARN_PRINT("glTF: Accessor byte offset is not a multiple of accessor component size. This file is invalid per the glTF specification and will not load correctly in some glTF viewers, but Godot will try to load it anyway.");
|
||||
}
|
||||
|
||||
const uint32_t offset = bv->byte_offset + p_byte_offset;
|
||||
Vector<uint8_t> buffer = p_state->buffers[bv->buffer]; //copy on write, so no performance hit
|
||||
@ -1693,7 +1704,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state,
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i, p_for_vertex_indices);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i, p_for_vertex_indices);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -1802,7 +1813,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> p_state,
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -1855,7 +1866,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> p_state
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -1922,7 +1933,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> p_sta
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -1973,7 +1984,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> p_stat
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -2026,7 +2037,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> p
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -2101,7 +2112,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_stat
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -2151,7 +2162,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> p_state,
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -2245,11 +2256,11 @@ GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p
|
||||
} else {
|
||||
sparse_accessor->sparse_indices_component_type = GLTFAccessor::COMPONENT_TYPE_UNSIGNED_SHORT;
|
||||
}
|
||||
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) {
|
||||
if (_encode_accessor_into_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.
|
||||
if (_encode_buffer_view(p_state, changed_values.ptr(), changed_indices.size(), sparse_accessor->accessor_type, sparse_accessor->component_type, sparse_accessor->normalized, sparse_accessor->sparse_values_byte_offset, false, buffer_view_i_values) != OK) {
|
||||
if (_encode_accessor_into_buffer_view(p_state, changed_values.ptr(), changed_indices.size(), sparse_accessor->accessor_type, sparse_accessor->component_type, sparse_accessor->normalized, sparse_accessor->sparse_values_byte_offset, false, buffer_view_i_values) != OK) {
|
||||
return -1;
|
||||
}
|
||||
sparse_accessor->sparse_indices_buffer_view = buffer_view_i_indices;
|
||||
@ -2258,7 +2269,7 @@ GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p
|
||||
} else if (changed_indices.size() > 0) {
|
||||
GLTFBufferIndex buffer_view_i;
|
||||
sparse_accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, sparse_accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, sparse_accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -2332,7 +2343,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> p_state
|
||||
accessor->accessor_type = accessor_type;
|
||||
accessor->component_type = component_type;
|
||||
accessor->byte_offset = 0;
|
||||
Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, attribs.ptr(), p_attribs.size(), accessor_type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -2772,7 +2783,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_variant(Ref<GLTFState> p_sta
|
||||
p_state->buffers.push_back(Vector<uint8_t>());
|
||||
}
|
||||
const int64_t buffer_size = p_state->buffers[buffer_view_index].size();
|
||||
Error err = _encode_buffer_view(p_state, encoded_attribs.ptr(), p_attribs.size(), p_accessor_type, p_component_type, false, buffer_size, false, buffer_view_index);
|
||||
Error err = _encode_accessor_into_buffer_view(p_state, encoded_attribs.ptr(), p_attribs.size(), p_accessor_type, p_component_type, false, buffer_size, false, buffer_view_index);
|
||||
if (err != OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -274,11 +274,11 @@ private:
|
||||
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> p_state,
|
||||
const Vector<Transform3D> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
Error _encode_buffer_view(Ref<GLTFState> p_state, const double *p_src,
|
||||
const int p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type,
|
||||
Error _encode_accessor_into_buffer_view(Ref<GLTFState> p_state, const double *p_src,
|
||||
const int64_t p_count, const GLTFAccessor::GLTFAccessorType p_accessor_type,
|
||||
const GLTFAccessor::GLTFComponentType p_component_type, const bool p_normalized,
|
||||
const int p_byte_offset, const bool p_for_vertex,
|
||||
GLTFBufferViewIndex &r_accessor, const bool p_for_indices = false);
|
||||
const int64_t p_byte_offset, const bool p_for_vertex,
|
||||
GLTFBufferViewIndex &r_buffer_view, const bool p_for_indices = false);
|
||||
|
||||
Error _encode_accessors(Ref<GLTFState> p_state);
|
||||
Error _encode_buffer_views(Ref<GLTFState> p_state);
|
||||
|
||||
Reference in New Issue
Block a user