Skip to content

Commit

Permalink
Move some code from main/mod.rs into a dedicated rendering::utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
MeFisto94 committed Jan 25, 2025
1 parent 8b690c2 commit 9963ab4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/game/map_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::rendering::asset_graph::resolver::Resolver;
use crate::rendering::common::coordinate_systems;
use crate::rendering::common::special_types::TerrainTextureLayerRend3;
use crate::rendering::importer::adt_importer::ADTImporter;
use crate::{transform_for_doodad_ref, transform_for_wmo_ref};
use crate::rendering::utils::{transform_for_doodad_ref, transform_for_wmo_ref};

pub struct MapManager {
runtime: Runtime,
Expand Down
48 changes: 1 addition & 47 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ use crate::game::application::GameApplication;
use crate::io::mpq::loader::MPQLoader;
use crate::settings::{CliArgs, OperationMode};
use clap::Parser;
use glam::{Affine3A, EulerRot, Quat, Vec3};
use glam::{EulerRot, Quat, Vec3};
use image_blp::BlpImage;
use image_blp::convert::blp_to_image;
use image_blp::parser::parse_blp_with_externals;
use mpq::Archive;
use rendering::common::coordinate_systems::TILE_SIZE;
use sargerust_files::adt::types::SMDoodadDef;
use sargerust_files::wdt::types::SMMapObjDef;
use std::sync::Arc;
use wow_world_messages::wrath::Vector3d;

Expand Down Expand Up @@ -71,49 +68,6 @@ fn main() {
app.run(operation_mode);
}

fn transform_for_doodad_ref(dad_ref: &SMDoodadDef) -> Affine3A {
let scale = Vec3::new(
dad_ref.scale as f32 / 1024.0,
dad_ref.scale as f32 / 1024.0,
dad_ref.scale as f32 / 1024.0,
);
let rotation = Quat::from_euler(
EulerRot::ZYX,
(dad_ref.rotation.y + 90.0).to_radians(),
(dad_ref.rotation.x + 0.0).to_radians(),
(dad_ref.rotation.z + 0.0).to_radians(),
);
// MDDFS (TODO: MODF) uses a completely different coordinate system, so we need to fix up things.

// 32*TILE_SIZE because the map is 64 TS wide, and so we're placing ourselfs into the mid.
let translation = Vec3::new(
32.0 * TILE_SIZE - dad_ref.position.x,
-(32.0 * TILE_SIZE - dad_ref.position.z),
dad_ref.position.y,
);
Affine3A::from_scale_rotation_translation(scale, rotation, translation)
}

fn transform_for_wmo_ref(wmo_ref: &SMMapObjDef) -> Affine3A {
// cfg[feature = "legion")] // Apparently, this scale is only valid starting legion, before it is padding (and probably 0)
// let scale = Vec3::new(wmo_ref.scale as f32 / 1024.0, wmo_ref.scale as f32 / 1024.0, wmo_ref.scale as f32 / 1024.0);
let scale = Vec3::new(1.0, 1.0, 1.0);
let rotation = Quat::from_euler(
EulerRot::ZYX,
(wmo_ref.rot.y + 0.5 * 180.0).to_radians(),
(wmo_ref.rot.x).to_radians(),
(wmo_ref.rot.z + 0.0).to_radians(),
);

// 32*TILE_SIZE because the map is 64 TS wide, and so we're placing ourselfs into the mid.
let translation = Vec3::new(
32.0 * TILE_SIZE - wmo_ref.pos.x,
-(32.0 * TILE_SIZE - wmo_ref.pos.z),
wmo_ref.pos.y,
);
Affine3A::from_scale_rotation_translation(scale, rotation, translation)
}

#[allow(unused)]
fn debug_dump_file(archive: &mut Archive, file: &str) {
let buf = io::mpq::loader::read_mpq_file_into_owned(archive, file).unwrap();
Expand Down
21 changes: 1 addition & 20 deletions src/rendering/mod.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
use std::ops::Deref;

use image_blp::BlpImage;
use image_blp::convert::blp_to_image;

pub mod application;
pub mod asset_graph;
pub mod common;
pub mod importer;
pub mod loader;
pub mod rend3_backend;

fn create_texture_rgba8(blp: &BlpImage, mipmap_level: usize) -> rend3::types::Texture {
let image = blp_to_image(blp, mipmap_level).expect("decode");
let image_dims = glam::UVec2::new(image.width(), image.height());
let image_data = image.into_rgba8();

rend3::types::Texture {
label: None,
data: image_data.into_raw(),
format: rend3::types::TextureFormat::Rgba8UnormSrgb,
size: image_dims,
mip_count: rend3::types::MipmapCount::ONE,
mip_source: rend3::types::MipmapSource::Uploaded,
}
}
pub mod utils;
2 changes: 1 addition & 1 deletion src/rendering/rend3_backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rend3_routine::pbr::{AlbedoComponent, PbrMaterial, Transparency};

use crate::rendering::common::types::TransparencyType::{Blend, Cutout, Opaque};
use crate::rendering::common::types::{AlbedoType, Material, Mesh, MeshWithLod, VertexBuffers};
use crate::rendering::create_texture_rgba8;
use crate::rendering::utils::create_texture_rgba8;

pub mod gpu_loaders;
pub mod material;
Expand Down
65 changes: 65 additions & 0 deletions src/rendering/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::rendering::common::coordinate_systems::TILE_SIZE;
use glam::{Affine3A, EulerRot, Quat, Vec3};
use image_blp::BlpImage;
use image_blp::convert::blp_to_image;
use sargerust_files::adt::types::SMDoodadDef;
use sargerust_files::wdt::types::SMMapObjDef;

pub fn create_texture_rgba8(blp: &BlpImage, mipmap_level: usize) -> rend3::types::Texture {
let image = blp_to_image(blp, mipmap_level).expect("decode");
let image_dims = glam::UVec2::new(image.width(), image.height());
let image_data = image.into_rgba8();

rend3::types::Texture {
label: None,
data: image_data.into_raw(),
format: rend3::types::TextureFormat::Rgba8UnormSrgb,
size: image_dims,
mip_count: rend3::types::MipmapCount::ONE,
mip_source: rend3::types::MipmapSource::Uploaded,
}
}

// TODO: this is probably even too specific for here and belongs somewhere in loaders/graph modules.
pub fn transform_for_doodad_ref(dad_ref: &SMDoodadDef) -> Affine3A {
let scale = Vec3::new(
dad_ref.scale as f32 / 1024.0,
dad_ref.scale as f32 / 1024.0,
dad_ref.scale as f32 / 1024.0,
);
let rotation = Quat::from_euler(
EulerRot::ZYX,
(dad_ref.rotation.y + 90.0).to_radians(),
(dad_ref.rotation.x + 0.0).to_radians(),
(dad_ref.rotation.z + 0.0).to_radians(),
);
// MDDFS (TODO: MODF) uses a completely different coordinate system, so we need to fix up things.

// 32*TILE_SIZE because the map is 64 TS wide, and so we're placing ourselfs into the mid.
let translation = Vec3::new(
32.0 * TILE_SIZE - dad_ref.position.x,
-(32.0 * TILE_SIZE - dad_ref.position.z),
dad_ref.position.y,
);
Affine3A::from_scale_rotation_translation(scale, rotation, translation)
}

pub fn transform_for_wmo_ref(wmo_ref: &SMMapObjDef) -> Affine3A {
// cfg[feature = "legion")] // Apparently, this scale is only valid starting legion, before it is padding (and probably 0)
// let scale = Vec3::new(wmo_ref.scale as f32 / 1024.0, wmo_ref.scale as f32 / 1024.0, wmo_ref.scale as f32 / 1024.0);
let scale = Vec3::new(1.0, 1.0, 1.0);
let rotation = Quat::from_euler(
EulerRot::ZYX,
(wmo_ref.rot.y + 0.5 * 180.0).to_radians(),
(wmo_ref.rot.x).to_radians(),
(wmo_ref.rot.z + 0.0).to_radians(),
);

// 32*TILE_SIZE because the map is 64 TS wide, and so we're placing ourselfs into the mid.
let translation = Vec3::new(
32.0 * TILE_SIZE - wmo_ref.pos.x,
-(32.0 * TILE_SIZE - wmo_ref.pos.z),
wmo_ref.pos.y,
);
Affine3A::from_scale_rotation_translation(scale, rotation, translation)
}

0 comments on commit 9963ab4

Please sign in to comment.