textures loading
This commit is contained in:
@@ -11,16 +11,13 @@
|
||||
namespace {
|
||||
[[nodiscard]] auto load_scene_to_renderer(trb::render::renderer &renderer,
|
||||
trb::game::scene &scene) {
|
||||
const auto is_mesh_node = [](const auto &v) {
|
||||
return std::holds_alternative<trb::game::mesh_node>(v);
|
||||
const auto upload_mesh_node = [&](const auto &mesh) {
|
||||
return renderer.register_mesh(
|
||||
mesh,
|
||||
scene.textures[scene.materials[mesh.material_index].albedo_texture]);
|
||||
};
|
||||
|
||||
const auto upload_mesh_node = [&](const auto &v) {
|
||||
return renderer.register_mesh(std::get<trb::game::mesh_node>(v));
|
||||
};
|
||||
|
||||
return scene.nodes | std::views::filter(is_mesh_node) |
|
||||
std::views::transform(upload_mesh_node) |
|
||||
return scene.meshes | std::views::transform(upload_mesh_node) |
|
||||
std::ranges::to<std::vector<std::uint32_t>>();
|
||||
}
|
||||
|
||||
@@ -33,8 +30,7 @@ bounds_of(const trb::game::scene &scene) {
|
||||
return std::holds_alternative<trb::game::mesh_node>(v);
|
||||
};
|
||||
|
||||
for (const auto &v : scene.nodes | std::views::filter(is_mesh_node)) {
|
||||
const auto &mesh = std::get<trb::game::mesh_node>(v);
|
||||
for (const auto &mesh : scene.meshes) {
|
||||
for (const auto [position, normal, uv] : mesh.vertices) {
|
||||
min = glm::min(min, position);
|
||||
max = glm::max(max, position);
|
||||
@@ -51,22 +47,14 @@ struct level_view {
|
||||
[[nodiscard]] level_view calculate_camera_matrices(glm::vec3 min, glm::vec3 max,
|
||||
float aspectRatio,
|
||||
float zoom = 1.0f) {
|
||||
// 1. Calculate the X/Z center. We ignore the Y center per your requirement.
|
||||
glm::vec3 center =
|
||||
glm::vec3((min.x + max.x) * 0.5f, 0.0f, (min.z + max.z) * 0.5f);
|
||||
|
||||
// 2. Position the camera.
|
||||
// For 45 degrees in Y-up: we move 'distance' up (Y) and 'distance' back (Z).
|
||||
float distance = 100.0f;
|
||||
glm::vec3 cameraPos = center + glm::vec3(0.0f, distance, distance);
|
||||
|
||||
// 3. View Matrix
|
||||
// Up is (0, 1, 0). Camera looks at the X/Z center.
|
||||
glm::mat4 view = glm::lookAt(cameraPos, center, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// 4. Determine Ortho Bounds
|
||||
// We must check all corners because at 45 degrees, the Y-height
|
||||
// of objects affects their projected X/Y position on screen.
|
||||
glm::vec3 corners[8] = {{min.x, min.y, min.z}, {max.x, min.y, min.z},
|
||||
{min.x, max.y, min.z}, {max.x, max.y, min.z},
|
||||
{min.x, min.y, max.z}, {max.x, min.y, max.z},
|
||||
@@ -83,7 +71,6 @@ struct level_view {
|
||||
vMaxY = glm::max(vMaxY, vSpace.y);
|
||||
}
|
||||
|
||||
// 5. Apply Zoom and Aspect Ratio
|
||||
float width = (vMaxX - vMinX) / zoom;
|
||||
float height = (vMaxY - vMinY) / zoom;
|
||||
float midX = (vMinX + vMaxX) * 0.5f;
|
||||
|
||||
Reference in New Issue
Block a user