libs/render/src/eu/render/compiledmesh.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "eu/render/compiledmesh.h" | ||
| 2 | |||
| 3 | #include "world.h" | ||
| 4 | #include "eu/core/mesh.h" | ||
| 5 | |||
| 6 | namespace eu::render | ||
| 7 | { | ||
| 8 | ✗ | CompiledMesh compile_mesh(DEBUG_LABEL_ARG_MANY const core::Mesh& mesh, const core::CompiledGeomVertexAttributes& geom_layout) | |
| 9 | { | ||
| 10 | ✗ | CompiledMesh ret; | |
| 11 | |||
| 12 | ✗ | for (const auto& meshes : mesh.meshes) | |
| 13 | { | ||
| 14 | ✗ | CompiledTransformedMesh trans{ | |
| 15 | ✗ | .name = meshes.name, | |
| 16 | .transform = meshes.transform, | ||
| 17 | .geoms = {} | ||
| 18 | ✗ | }; | |
| 19 | ✗ | for (const auto& geom : meshes.geoms) | |
| 20 | { | ||
| 21 | ✗ | auto compiled = compile_geom(USE_DEBUG_LABEL_MANY(debug_label) geom.geom, geom_layout); | |
| 22 | ✗ | trans.geoms.emplace_back(compiled); | |
| 23 | ✗ | } | |
| 24 | ✗ | ret.meshes.emplace_back(trans); | |
| 25 | ✗ | } | |
| 26 | |||
| 27 | ✗ | return ret; | |
| 28 | ✗ | } | |
| 29 | |||
| 30 | ✗ | void MeshInWorld::add_to_world(CompiledMesh* m, World* world, std::shared_ptr<Material> mat) | |
| 31 | { | ||
| 32 | ✗ | ASSERT(compiled_mesh == nullptr); | |
| 33 | ✗ | compiled_mesh = m; | |
| 34 | |||
| 35 | ✗ | for (const auto& mesh : m->meshes) | |
| 36 | { | ||
| 37 | ✗ | TransformedMeshInWorld trans; | |
| 38 | ✗ | for (const auto& geom: mesh.geoms) | |
| 39 | { | ||
| 40 | ✗ | auto instanced = make_mesh_instance(geom.geom, mat); | |
| 41 | ✗ | world->meshes.emplace_back(instanced); | |
| 42 | ✗ | trans.geoms.emplace_back(instanced); | |
| 43 | ✗ | } | |
| 44 | ✗ | meshes.emplace_back(trans); | |
| 45 | ✗ | } | |
| 46 | ✗ | } | |
| 47 | |||
| 48 | ✗ | void MeshInWorld::set_transform(const m4& trans) | |
| 49 | { | ||
| 50 | ✗ | for (std::size_t mesh_index = 0; mesh_index < meshes.size(); mesh_index += 1) | |
| 51 | { | ||
| 52 | ✗ | for (std::size_t geom_index = 0; geom_index < meshes[mesh_index].geoms.size(); geom_index += 1) | |
| 53 | { | ||
| 54 | ✗ | meshes[mesh_index].geoms[geom_index]->transform = trans * compiled_mesh->meshes[mesh_index].transform; | |
| 55 | } | ||
| 56 | } | ||
| 57 | ✗ | } | |
| 58 | |||
| 59 | } | ||
| 60 |