use core::f32; use bevy::{ color, image::{ImageAddressMode, ImageLoaderSettings, ImageSampler, ImageSamplerDescriptor}, prelude::*, render::view::screenshot::{save_to_disk, Screenshot} }; use bevy_copperfield::{ mesh::{ attributes::{AttributeKind, SelectionQueries, TraversalQueries}, face_ops, mesh_ops, vertex_ops, HalfEdgeId, HalfEdgeMesh, MeshPosition, StackVec, }, mesh_builders::HalfEdgeMeshBuilder, uvmesh::{Chart, ProjectionMethod}, }; use camera_controls::{capture_mouse, FlyingCamera}; use itertools::Itertools; use line_drawing::Bresenham; use slotmap::SecondaryMap; use smallvec::SmallVec; #[derive(Resource)] pub struct Charts { charts: Vec, } pub fn cuboid_tests() -> (Vec, HalfEdgeMesh) { let mut mesh = Cuboid::new(1.0, 1.0, 1.0).procgen(); let faces = mesh.face_keys().collect::>(); let face = faces[1]; face_ops::extrude(&mut mesh, face, 1.0); face_ops::extrude(&mut mesh, face, 1.0); let middle_face = mesh.goto(face).twin().next().face().unwrap(); face_ops::extrude(&mut mesh, middle_face, 1.0); mesh_ops::subdivide(&mut mesh); mesh_ops::subdivide(&mut mesh); mesh_ops::invert_normals(&mut mesh); // let charts = create_charts(&mut mesh); mesh.uv_projection = ProjectionMethod::Cube { center: Vec3 { x: 0.0, y: 1.0, z: 0.5, }, scale: Vec3 { x: 1.0, y: 3.0, z: 2.0, }, }; // mesh.uv_projection = ProjectionMethod::Sphere {center: Vec3{x:0.0, y:1.0, z:0.0}, radius: Vec3{x:1.0, y:1.5, z:1.0} }; // mesh.uv_projection = ProjectionMethod::LSCM; mesh.calculate_uvs(); (Vec::new(), mesh) } pub fn sample_mesh_tests() -> HalfEdgeMesh { let mut mesh = sample_mesh(); mesh.is_smooth = false; let v = mesh.vertex_keys().collect::>(); let face = vertex_ops::chamfer(&mut mesh, v[2], 0.25); face_ops::extrude(&mut mesh, face, 0.5); // mesh_ops::subdivide(&mut mesh); // mesh_ops::subdivide(&mut mesh); mesh } pub fn builder_tests() -> HalfEdgeMesh { let mut mesh = Circle::new(0.5).mesh().resolution(8).procgen(); mesh.is_smooth = false; let face = mesh.goto(Vec3::ZERO).twin().face().unwrap(); face_ops::transform( &mut mesh, face, Transform::from_translation(-0.5 * Vec3::Y) .with_rotation(Quat::from_rotation_x(-f32::consts::FRAC_PI_2)), ); face_ops::extrude(&mut mesh, face, 1.0); mesh } pub fn build_mesh() -> (Vec, HalfEdgeMesh) { cuboid_tests() // sample_mesh_tests() // builder_tests() } pub mod camera_controls { use core::f32; use bevy::{ input::mouse::{MouseMotion, MouseWheel}, prelude::*, window::{CursorGrabMode, PrimaryWindow}, }; #[derive(Component, Default)] pub struct FlyingCamera { pub pitch: f32, pub yaw: f32, } pub fn capture_mouse( mut q_windows: Query<&mut Window, With>, mut motion_events: ResMut>, ) { let mut primary_window = q_windows.single_mut(); primary_window.cursor_options.grab_mode = CursorGrabMode::Locked; primary_window.cursor_options.visible = false; motion_events.clear(); } pub fn player_controller( time: Res