MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / load_model

Method load_model

framework/gltf_loader.cpp:1097–1321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1095}
1096
1097std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage_buffer, VkBufferUsageFlags additional_buffer_usage_flags)
1098{
1099 PROFILE_SCOPE("Process Model");
1100
1101 auto submesh = std::make_unique<sg::SubMesh>();
1102
1103 std::vector<vkb::core::BufferC> transient_buffers;
1104
1105 auto &queue = device.get_queue_by_flags(VK_QUEUE_GRAPHICS_BIT, 0);
1106
1107 auto command_buffer = device.get_command_pool().request_command_buffer();
1108
1109 command_buffer->begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
1110
1111 assert(index < model.meshes.size());
1112 auto &gltf_mesh = model.meshes[index];
1113
1114 assert(!gltf_mesh.primitives.empty());
1115 auto &gltf_primitive = gltf_mesh.primitives[0];
1116
1117 std::vector<Vertex> vertex_data;
1118 std::vector<AlignedVertex> aligned_vertex_data;
1119
1120 const float *pos = nullptr;
1121 const float *normals = nullptr;
1122 const float *uvs = nullptr;
1123 const uint16_t *joints = nullptr;
1124 const float *weights = nullptr;
1125 const float *colors = nullptr;
1126 uint32_t color_component_count{4};
1127
1128 // Position attribute is required
1129 auto &accessor = model.accessors[gltf_primitive.attributes.find("POSITION")->second];
1130 size_t vertex_count = accessor.count;
1131 auto &buffer_view = model.bufferViews[accessor.bufferView];
1132 pos = reinterpret_cast<const float *>(&(model.buffers[buffer_view.buffer].data[accessor.byteOffset + buffer_view.byteOffset]));
1133
1134 submesh->vertices_count = static_cast<uint32_t>(vertex_count);
1135
1136 if (gltf_primitive.attributes.find("NORMAL") != gltf_primitive.attributes.end())
1137 {
1138 accessor = model.accessors[gltf_primitive.attributes.find("NORMAL")->second];
1139 buffer_view = model.bufferViews[accessor.bufferView];
1140 normals = reinterpret_cast<const float *>(&(model.buffers[buffer_view.buffer].data[accessor.byteOffset + buffer_view.byteOffset]));
1141 }
1142
1143 if (gltf_primitive.attributes.find("TEXCOORD_0") != gltf_primitive.attributes.end())
1144 {
1145 accessor = model.accessors[gltf_primitive.attributes.find("TEXCOORD_0")->second];
1146 buffer_view = model.bufferViews[accessor.bufferView];
1147 uvs = reinterpret_cast<const float *>(&(model.buffers[buffer_view.buffer].data[accessor.byteOffset + buffer_view.byteOffset]));
1148 }
1149
1150 if (gltf_primitive.attributes.find("COLOR_0") != gltf_primitive.attributes.end())
1151 {
1152 accessor = model.accessors[gltf_primitive.attributes.find("COLOR_0")->second];
1153 buffer_view = model.bufferViews[accessor.bufferView];
1154 colors = reinterpret_cast<const float *>(&(model.buffers[buffer_view.buffer].data[accessor.byteOffset + buffer_view.byteOffset]));

Callers

nothing calls this directly

Calls 15

to_u32Function · 0.85
get_attribute_sizeFunction · 0.85
get_attribute_formatFunction · 0.85
get_attribute_dataFunction · 0.85
prepare_meshletsFunction · 0.85
sizeMethod · 0.80
emptyMethod · 0.80
endMethod · 0.80
waitMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected