-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add an example for intersection plane #249
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It would be great to figure out some better lighting so that the diamond’s shape doesn’t look completely flat.
fn mquad_mesh_from_points(trimesh: &(Vec<Point3<Real>>, Vec<[u32; 3]>), camera_pos: Vec3) -> Mesh { | ||
let (points, indices) = trimesh; | ||
// Transform the parry mesh into a mquad Mesh | ||
let (mquad_points, mquad_indices) = ( | ||
points | ||
.iter() | ||
.map(|p| Vertex { | ||
position: mquad_from_na(*p), | ||
uv: Vec2::new(p.x, p.y), | ||
color: DARKGRAY, | ||
}) | ||
.collect(), | ||
indices.iter().flatten().map(|v| *v as u16).collect(), | ||
); | ||
|
||
// Macroquad doesn´t support adding normals to vertices, so we'll bake a color into these vertices. | ||
// See https://github.com/not-fl3/macroquad/issues/321. | ||
|
||
// Compute the normal of each vertex, making them unique | ||
let vertices: Vec<Vertex> = mquad_compute_normals(&mquad_points, &mquad_indices, camera_pos); | ||
// Regenerate the index for each vertex. | ||
let indices: Vec<u16> = (0..vertices.len() * 3) | ||
.into_iter() | ||
.map(|i| i as u16) | ||
.collect(); | ||
let mesh = Mesh { | ||
vertices, | ||
indices, | ||
texture: None, | ||
}; | ||
mesh | ||
} | ||
|
||
fn mquad_compute_normals(points: &Vec<Vertex>, indices: &Vec<u16>, cam_pos: Vec3) -> Vec<Vertex> { | ||
let mut vertices: Vec<Vertex> = Vec::<Vertex>::new(); | ||
for indices in indices.chunks(3) { | ||
let v0 = &points[indices[0] as usize]; | ||
let v1 = &points[indices[1] as usize]; | ||
let v2 = &points[indices[2] as usize]; | ||
let normal = (v0.position - v2.position) | ||
.cross(v1.position - v2.position) | ||
.normalize(); | ||
let brightness_mod = 0.2 + (0.8 / 2.) * (normal.dot(cam_pos) + 1.); | ||
|
||
for &i in indices.iter() { | ||
let mut color = points[i as usize].color; | ||
color.r *= brightness_mod; | ||
color.g *= brightness_mod; | ||
color.b *= brightness_mod; | ||
|
||
vertices.push(Vertex { | ||
position: points[i as usize].position, | ||
uv: Vec2::ZERO, | ||
color: color, | ||
}); | ||
} | ||
} | ||
vertices | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this is lengthy, but unfortunately there's not much way around it (see not-fl3/macroquad#321); it would be good to settle on a "common" library for all examples, but as it's the first 3d example this might be ok to keep it here, and we'll move it out with the next example, probably #250
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
|
||
#[macroquad::main("parry3d::query::PlaneIntersection")] | ||
async fn main() { | ||
let trimesh = Cuboid::new(Vector3::new(1.0, 1.0, 1.0)).to_trimesh(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let trimesh = Cuboid::new(Vector3::new(1.0, 1.0, 1.0)).to_trimesh(); | |
let trimesh = Cuboid::new(Vector3::repeat(1.0)).to_trimesh(); |
|
||
// Get the intersection polyline. | ||
let intersection_result = trimesh.intersection_with_local_plane( | ||
&UnitVector3::new_normalize(Vector3::<Real>::new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the type parameter annotation really necessary?
&UnitVector3::new_normalize(Vector3::<Real>::new( | |
&UnitVector3::new_normalize(Vector3::new( |
Interesting CI failure. Hopefully now that |
intersection_with_local_plane
#248Screencast.from.08-05-2024.06.05.14.PM.webm