MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / RenderP3DFile

Function RenderP3DFile

engine/Poseidon/Graphics/Textures/ModelRenderer.cpp:332–391  ·  view source on GitHub ↗

Render P3D directly from Model mesh data, no ShapeAdapter/engine globals needed

Source from the content-addressed store, hash-verified

330
331// Render P3D directly from Model mesh data, no ShapeAdapter/engine globals needed
332RenderedModel RenderP3DFile(const std::string& path, int imgW, int imgH, const std::string& view, int lodIndex,
333 uint8_t bgR, uint8_t bgG, uint8_t bgB)
334{
335 RenderedModel result;
336 try
337 {
338 MRLog("DetectFormat");
339 auto info = P3DFormatDetector::DetectFormat(path);
340 MRLog(("sig=" + info.signature + " ok=" + (info.isSupported ? "y" : "n")).c_str());
341 if (!info.isSupported)
342 return result;
343
344 Poseidon::Model::Model model;
345 if (info.signature == "ODOL")
346 {
347 MRLog("ODOLLoader::load");
348 model = Poseidon::Asset::Formats::ODOLLoader::load(path);
349 }
350 else if (info.signature == "MLOD")
351 {
352 MRLog("MLODLoader::load");
353 model = Poseidon::Asset::Formats::MLODLoader::load(path);
354 }
355 else
356 {
357 return result;
358 }
359 MRLog("load done");
360
361 model.compile();
362 MRLog("compile done");
363
364 int nLods = static_cast<int>(model.lodLevels.size());
365 MRLog(("nLods=" + std::to_string(nLods)).c_str());
366 if (lodIndex >= nLods)
367 return result;
368
369 const auto& mesh = model.lodLevels[lodIndex].mesh;
370 int nv = static_cast<int>(mesh.vertices.size());
371 MRLog(("verts=" + std::to_string(nv) + " tris=" + std::to_string(mesh.triangles.size()) +
372 " quads=" + std::to_string(mesh.quads.size()))
373 .c_str());
374
375 auto edges = collectMeshEdges(mesh);
376 MRLog(("edges=" + std::to_string(edges.size())).c_str());
377
378 MeshVA va{&mesh};
379 result = renderWireframeT(va, edges, imgW, imgH, view, bgR, bgG, bgB);
380 MRLog("render done");
381 }
382 catch (const std::exception& e)
383 {
384 MRLog(("EXCEPTION: " + std::string(e.what())).c_str());
385 }
386 catch (...)
387 {
388 MRLog("EXCEPTION: unknown");
389 }

Callers 2

DecodeFileFunction · 0.85

Calls 6

MRLogFunction · 0.85
loadFunction · 0.85
collectMeshEdgesFunction · 0.85
renderWireframeTFunction · 0.85
compileMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected