MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _encode_buffer_glb

Method _encode_buffer_glb

modules/gltf/gltf_document.cpp:741–778  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

739}
740
741Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path) {
742 print_verbose("glTF: Total buffers: " + itos(p_state->buffers.size()));
743
744 if (p_state->buffers.is_empty()) {
745 return OK;
746 }
747 Array buffers;
748 if (!p_state->buffers.is_empty()) {
749 Vector<uint8_t> buffer_data = p_state->buffers[0];
750 Dictionary gltf_buffer;
751
752 gltf_buffer["byteLength"] = buffer_data.size();
753 buffers.push_back(gltf_buffer);
754 }
755
756 for (GLTFBufferIndex i = 1; i < p_state->buffers.size(); i++) {
757 Vector<uint8_t> buffer_data = p_state->buffers[i];
758 Dictionary gltf_buffer;
759 String filename = p_path.get_basename().get_file() + itos(i) + ".bin";
760 String path = p_path.get_base_dir() + "/" + filename;
761 Error err;
762 Ref<FileAccess> file = FileAccess::open(path, FileAccess::WRITE, &err);
763 if (file.is_null()) {
764 return err;
765 }
766 if (buffer_data.is_empty()) {
767 return OK;
768 }
769 file->create(FileAccess::ACCESS_RESOURCES);
770 file->store_buffer(buffer_data.ptr(), buffer_data.size());
771 gltf_buffer["uri"] = filename;
772 gltf_buffer["byteLength"] = buffer_data.size();
773 buffers.push_back(gltf_buffer);
774 }
775 p_state->json["buffers"] = buffers;
776
777 return OK;
778}
779
780Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path) {
781 print_verbose("glTF: Total buffers: " + itos(p_state->buffers.size()));

Callers

nothing calls this directly

Calls 11

itosFunction · 0.85
get_basenameMethod · 0.80
get_base_dirMethod · 0.80
sizeMethod · 0.65
is_emptyMethod · 0.45
push_backMethod · 0.45
get_fileMethod · 0.45
is_nullMethod · 0.45
createMethod · 0.45
store_bufferMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected