Construct a MeshNetwork from all meshes in the currently loaded scene.
One MeshSlot per aiMesh, named from aiMesh::mName (or "mesh_N" if unnamed). Each slot's MeshWriterNode holds the extracted vertex and index data.
If resolver is provided, it is called with the raw diffuse path from each mesh's material. The returned VKImage is assigned to slot.diffuse_texture. Null resolver skips texture binding entirely.
156{
159 return nullptr;
160 }
161
162 auto net = std::make_shared<Nodes::Network::MeshNetwork>();
163 const aiScene* s =
m_impl->scene;
164
165 for (unsigned int i = 0; i < s->mNumMeshes; ++i) {
166 const aiMesh* ai_mesh = s->mMeshes[i];
167
168 std::string mesh_name(ai_mesh->mName.C_Str());
169 if (mesh_name.empty())
170 mesh_name = "mesh_" + std::to_string(i);
171
172 std::string mat_name;
173 if (s->mNumMaterials > 0 && ai_mesh->mMaterialIndex < s->mNumMaterials) {
174 aiString ai_mat;
175 s->mMaterials[ai_mesh->mMaterialIndex]->Get(AI_MATKEY_NAME, ai_mat);
176 mat_name = ai_mat.C_Str();
177 }
178
180 if (!mesh_data.is_valid()) {
182 "ModelReader::create_mesh_network: skipping invalid mesh '{}'", mesh_name);
183 continue;
184 }
185
186 const auto* vb = std::get_if<std::vector<uint8_t>>(&mesh_data.vertex_variant);
187 const auto* ib = std::get_if<std::vector<uint32_t>>(&mesh_data.index_variant);
188
189 if (!vb || !ib)
190 continue;
191
192 const size_t vertex_count = vb->size() / sizeof(Nodes::MeshVertex);
193 auto node = std::make_shared<Nodes::GpuSync::MeshWriterNode>(vertex_count);
194 node->set_mesh(
195 std::span<const Nodes::MeshVertex>(
196 reinterpret_cast<const Nodes::MeshVertex*>(vb->data()),
197 vertex_count),
198 std::span<const uint32_t>(ib->data(), ib->size()));
199
200 auto slot_idx = net->add_slot(mesh_name, node);
201
202 if (resolver) {
203 const auto raw = get_diffuse_path(mesh_data);
204 if (!raw.empty()) {
205 auto image = resolver(raw);
207 net->get_slot(slot_idx).diffuse_texture = std::move(
image);
208 } else {
210 "ModelReader::create_mesh_network: resolver returned null for '{}' (slot '{}')",
211 raw, mesh_name);
212 }
213 }
214 }
215 }
216
218 "ModelReader::create_mesh_network: {} slots", net->slot_count());
219
220 return net;
221}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::unique_ptr< Impl > m_impl
Kakshya::MeshData extract_single_mesh(const void *ai_mesh, const void *ai_scene, std::string_view mesh_name, std::string_view material_name) const
void set_error(std::string msg) const
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.