master
mitchellhansen 9 months ago
parent 6dc8e2a47f
commit 78222ad55a

@ -52,7 +52,7 @@ impl ToVec3 for fj_math::Vector<3> {
#[derive(Component)] #[derive(Component)]
struct FjSolidWrapper{ struct FjSolidWrapper {
handle: fj_core::storage::Handle<Solid>, handle: fj_core::storage::Handle<Solid>,
} }
@ -148,26 +148,24 @@ fn update_fj_model_system(
for (entity, solid) in &query { for (entity, solid) in &query {
let bevy_mesh = convert_mesh(&solid.mesh); let bevy_mesh = convert_mesh(&solid.mesh);
commands.entity(entity).insert( commands.entity(entity).insert(
( (
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(bevy_mesh.clone())), mesh: meshes.add(Mesh::from(bevy_mesh.clone())),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.0, 0.0), transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default() ..default()
}, },
FjConvertedFlag FjConvertedFlag
));
));
add_debug_info_to_entity(&mut commands, solid, &mut meshes, &mut materials); add_debug_info_to_entity(&mut commands, solid, &mut meshes, &mut materials);
} }
} }
fn render_line(mut commands: &mut Commands, fn render_line<const T: usize>(mut commands: &mut Commands,
fj_model: &FjMeshWrapper, fj_model: &FjMeshWrapper,
mut meshes: &mut ResMut<Assets<Mesh>>, mut meshes: &mut ResMut<Assets<Mesh>>,
mut materials: &mut ResMut<Assets<StandardMaterial>>, mut materials: &mut ResMut<Assets<StandardMaterial>>,
line: Line<2>) { line: Line<T>) {
let origin = line.origin().to_xyz(); let origin = line.origin().to_xyz();
let direction = line.direction().to_xyz(); let direction = line.direction().to_xyz();
let opposite_corner = Vec3::new( let opposite_corner = Vec3::new(
@ -199,23 +197,21 @@ fn render_line(mut commands: &mut Commands,
// RaycastPickTarget::default(), // <- Needed for the raycast backend. // RaycastPickTarget::default(), // <- Needed for the raycast backend.
// PickableBundle::default() // <- This one too // PickableBundle::default() // <- This one too
)); ));
} }
fn add_debug_info_to_entity(mut commands: &mut Commands, fn add_debug_info_to_entity(mut commands: &mut Commands,
fj_model: &FjMeshWrapper, fj_model: &FjMeshWrapper,
mut meshes: &mut ResMut<Assets<Mesh>>, mut meshes: &mut ResMut<Assets<Mesh>>,
mut materials: &mut ResMut<Assets<StandardMaterial>> mut materials: &mut ResMut<Assets<StandardMaterial>>,
) { ) {
for region in fj_model.sketch.regions() {
for region in fj_model.sketch.regions(){ for cycle in region.all_cycles() {
for cycle in region.all_cycles(){ for half_edge in cycle.half_edges() {
for half_edge in cycle.half_edges(){ match half_edge.path() {
match half_edge.path(){ SurfacePath::Circle(x) => {}
SurfacePath::Circle(x) => {} SurfacePath::Line(x) => {
SurfacePath::Line(x) => { render_line(commands, fj_model, meshes, materials, x)
render_line(commands, fj_model, meshes, materials, x) }
}
} }
// 1d point // 1d point
half_edge.boundary().inner[0].coords; half_edge.boundary().inner[0].coords;
@ -225,7 +221,6 @@ fn add_debug_info_to_entity(mut commands: &mut Commands,
} }
for shell in fj_model.handle.shells() { for shell in fj_model.handle.shells() {
println!("{:?}. shell", shell); println!("{:?}. shell", shell);
for face in shell.faces() { for face in shell.faces() {
@ -238,6 +233,8 @@ fn add_debug_info_to_entity(mut commands: &mut Commands,
x.aabb(); x.aabb();
} }
GlobalPath::Line(x) => { GlobalPath::Line(x) => {
render_line(commands, fj_model, meshes, materials, x);
let origin = x.origin(); let origin = x.origin();
let direction = x.direction(); let direction = x.direction();
let opposite_corner = Vec3::new( let opposite_corner = Vec3::new(
@ -249,16 +246,6 @@ fn add_debug_info_to_entity(mut commands: &mut Commands,
let red: f32 = rng.gen_range(0.0..1.0); let red: f32 = rng.gen_range(0.0..1.0);
let green: 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); 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(( // line on top of sweep, just offset by the sweep vector commands.spawn(( // line on top of sweep, just offset by the sweep vector
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::from_corners(opposite_corner.into(), origin.to_vec3()))), mesh: meshes.add(Mesh::from(shape::Box::from_corners(opposite_corner.into(), origin.to_vec3()))),
@ -279,16 +266,6 @@ fn add_debug_info_to_entity(mut commands: &mut Commands,
// RaycastPickTarget::default(), // <- Needed for the raycast backend. // RaycastPickTarget::default(), // <- Needed for the raycast backend.
// PickableBundle::default() // <- This one too // 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
));
commands.spawn(( // swept vertex commands.spawn(( // swept vertex
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.025 })), mesh: meshes.add(Mesh::from(shape::Cube { size: 0.025 })),
@ -307,7 +284,7 @@ fn add_debug_info_to_entity(mut commands: &mut Commands,
// I want to insert a component when dragging starts, that contains // I want to insert a component when dragging starts, that contains
// data about the exact ray hit location. // data about the exact ray hit location.
// On::<Pointer<DragStart>>::run(run), // On::<Pointer<DragStart>>::run(run),
// On::<Pointer<DragStart>>::target_insert(DragCaster::default()), // On::<Pointer<DragStart>>::target_insert(DragCaster::default()),
// On::<Pointer<Drag>>::target_component_mut::<DragCaster>(|drag, mut caster| { // On::<Pointer<Drag>>::target_component_mut::<DragCaster>(|drag, mut caster| {
// caster.hit_location = drag.hit.position.unwrap(); // caster.hit_location = drag.hit.position.unwrap();
// //

Loading…
Cancel
Save