use std::collections::HashMap; use kiss3d::nalgebra::{Point3, Vector3}; use crate::geometry::{ atom::{Polyhedron, PrimitiveAtom}, face::{Face, FaceType}, }; pub fn create_cube_atom() -> PrimitiveAtom { let cube = create_cube_polyhedron(); // Create 6 solid faces for the cube let mut face_types = HashMap::new(); let mut face_ids = vec![]; for face in &cube.faces { face_types.insert(face.clone().id(), FaceType::Solid); face_ids.push(face.clone().id()); } PrimitiveAtom { geometry: cube, faces: face_ids, face_types, } } pub fn create_cube_polyhedron() -> Polyhedron { // Unit cube vertices: 8 corners let vertices = vec![ Point3::new(0.0f32, 0.0, 0.0), // 0: origin Point3::new(1.0f32, 0.0, 0.0), // 1 Point3::new(1.0f32, 1.0, 0.0), // 2 Point3::new(0.0f32, 1.0, 0.0), // 3 Point3::new(0.0f32, 0.0, 1.0), // 4 Point3::new(1.0f32, 0.0, 1.0), // 5 Point3::new(1.0f32, 1.0, 1.0), // 6 Point3::new(0.0f32, 1.0, 1.0), // 7 ]; // 6 faces of the cube, each defined by 4 vertex indices let faces = vec![ // Bottom face (z=0), normal pointing down Face::from_type( FaceType::Solid, vec![0, 1, 2, 3], Vector3::new(0.0f32, 0.0, -1.0), ), // Top face (z=1), normal pointing up Face::from_type( FaceType::Solid, vec![4, 7, 6, 5], Vector3::new(0.0f32, 0.0, 1.0), ), // Front face (y=0), normal pointing forward Face::from_type( FaceType::Solid, vec![0, 4, 5, 1], Vector3::new(0.0f32, -1.0, 0.0), ), // Back face (y=1), normal pointing back Face::from_type( FaceType::Solid, vec![3, 2, 6, 7], Vector3::new(0.0f32, 1.0, 0.0), ), // Left face (x=0), normal pointing left Face::from_type( FaceType::Solid, vec![0, 3, 7, 4], Vector3::new(-1.0f32, 0.0, 0.0), ), // Right face (x=1), normal pointing right Face::from_type( FaceType::Solid, vec![1, 5, 6, 2], Vector3::new(1.0f32, 0.0, 0.0), ), ]; Polyhedron { vertices, faces } }