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

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