Skip to content

Commit

Permalink
CLEANUP: Use mesh::find_geometric_center instead of the main.rs one
Browse files Browse the repository at this point in the history
  • Loading branch information
magicaldave committed Oct 16, 2024
1 parent 75a7fe1 commit 43fc462
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/brush_ni_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use shalrath;
use shambler::{brush::BrushId, face::FaceId, Vector2 as SV2, Vector3 as SV3};
use tes3::nif::{NiTriShape, NiTriShapeData};

use crate::{find_geometric_center, map_data::MapData, surfaces};
use crate::{map_data::MapData, surfaces, Mesh};

pub struct BrushNiNode {
pub vis_shape: NiTriShape,
Expand Down Expand Up @@ -184,7 +184,7 @@ impl BrushNiNode {

fn collect(&mut self) {
if self.vis_verts.len() > 0 {
self.distance_from_origin = find_geometric_center(&self.vis_verts)
self.distance_from_origin = Mesh::find_geometric_center(&self.vis_verts)
}

Self::to_nif_format(&mut self.vis_data, &self.vis_verts, &self.vis_tris);
Expand Down
19 changes: 2 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ fn main() {
None => {}
}

let mesh_distance: SV3 = find_geometric_center(&mesh.node_distances) * (*scale_mode as f32);
let mesh_distance: SV3 =
Mesh::find_geometric_center(&mesh.node_distances) * (*scale_mode as f32);
mesh.final_distance = mesh_distance;
mesh.mangle = match get_prop("mangle", &prop_map) {
mangle if mangle.is_empty() => *get_rotation(&"0 0 0".to_string()),
Expand Down Expand Up @@ -291,22 +292,6 @@ fn get_rotation(str: &String) -> Box<[f32; 3]> {
Box::new([array[2], array[0], array[1]])
}

fn find_geometric_center(vertices: &Vec<SV3>) -> SV3 {
// Calculate the sum of each dimension using fold
let (sum_x, sum_y, sum_z) = vertices.iter().fold((0.0, 0.0, 0.0), |acc, v| {
(acc.0 + v.x, acc.1 + v.y, acc.2 + v.z)
});

// Calculate the average position in each dimension
let num_vertices = vertices.len() as f32;
let center_x = sum_x / num_vertices;
let center_y = sum_y / num_vertices;
let center_z = sum_z / num_vertices;

// Return the geometric center as a new Vertex
SV3::new(center_x, center_y, center_z)
}

/// Should probably make some specific struct for handling ESP objects
fn create_header_if_missing(plugin: &mut Plugin) {
match plugin.objects_of_type::<Header>().count() {
Expand Down

0 comments on commit 43fc462

Please sign in to comment.