diff --git a/src/lib.rs b/src/lib.rs index 0077a47..ffeb065 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ use bevy::app::{App, Plugin, Update}; // Importing Fj-core functionalities use fj_core::algorithms::triangulate::Triangulate; -use fj_core::objects::{Solid}; +use fj_core::objects::{Sketch, Solid}; use fj_core::storage::Handle as FjHandle; // Importing Fj-interop mesh @@ -28,10 +28,10 @@ use fj_interop::mesh::Mesh as FjMesh; // Importing Fj-math and other standard functionalities -use fj_math::{Aabb, Point, Scalar, Vector}; +use fj_math::{Aabb, Line, Point, Scalar, Vector}; use std::ops::Deref; use bevy::math::Vec3; -use fj_core::geometry::GlobalPath; +use fj_core::geometry::{GlobalPath, SurfacePath}; use rand::Rng; trait ToVec3 { @@ -60,6 +60,7 @@ struct FjSolidWrapper{ pub struct FjMeshWrapper { pub mesh: FjMesh>, pub handle: FjHandle, + pub sketch: Sketch, } #[derive(Component)] @@ -161,12 +162,70 @@ fn update_fj_model_system( } } +fn render_line(mut commands: &mut Commands, + fj_model: &FjMeshWrapper, + mut meshes: &mut ResMut>, + mut materials: &mut ResMut>, + line: Line<2>) { + + let origin = line.origin().to_xyz(); + let direction = line.direction().to_xyz(); + let opposite_corner = Vec3::new( + origin.x.into_f32() + direction.x.into_f32() + 0.01, + origin.y.into_f32() + direction.y.into_f32() + 0.01, + origin.z.into_f32() + direction.z.into_f32() + 0.01, + ); + let mut rng = rand::thread_rng(); + let red: f32 = rng.gen_range(0.0..1.0); + let green: f32 = rng.gen_range(0.0..1.0); + let blue: f32 = rng.gen_range(0.0..1.0); + commands.spawn(( // line on base of sweep + PbrBundle { + mesh: meshes.add(Mesh::from(shape::Box::from_corners(opposite_corner.into(), origin.to_vec3()))), + material: materials.add(Color::rgb(red, green, blue).into()), + transform: Transform::from_xyz(0.0, 0.0, 0.0), + ..default() + }, + // RaycastPickTarget::default(), // <- Needed for the raycast backend. + // PickableBundle::default() // <- This one too + )); + commands.spawn(( // vertex + PbrBundle { + mesh: meshes.add(Mesh::from(shape::Cube { size: 0.025 })), + material: materials.add(Color::rgb(1.0, 1.0, 1.0).into()), + transform: Transform::from_xyz(origin.to_xyz().x.into_f32(), origin.to_xyz().y.into_f32(), origin.to_xyz().z.into_f32()), + ..default() + }, + // RaycastPickTarget::default(), // <- Needed for the raycast backend. + // PickableBundle::default() // <- This one too + )); + +} + fn add_debug_info_to_entity(mut commands: &mut Commands, fj_model: &FjMeshWrapper, mut meshes: &mut ResMut>, mut materials: &mut ResMut> ) { + for region in fj_model.sketch.regions(){ + for cycle in region.all_cycles(){ + for half_edge in cycle.half_edges(){ + match half_edge.path(){ + SurfacePath::Circle(x) => {} + SurfacePath::Line(x) => { + render_line(commands, fj_model, meshes, materials, x) + } + } + // 1d point + half_edge.boundary().inner[0].coords; + half_edge.boundary().inner[1].coords; + } + } + } + + + for shell in fj_model.handle.shells() { println!("{:?}. shell", shell); for face in shell.faces() {