Skip to content

Conversation

@ThierryBerger
Copy link
Contributor

@ThierryBerger ThierryBerger commented Jul 30, 2024

Screencast.from.08-05-2024.06.05.14.PM.webm

@ThierryBerger ThierryBerger requested a review from sebcrozet July 30, 2024 15:48
Copy link
Member

@sebcrozet sebcrozet left a 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.

Comment on lines +82 to +140
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
}
Copy link
Contributor Author

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

@ThierryBerger ThierryBerger requested a review from sebcrozet August 5, 2024 16:09
Copy link
Member

@sebcrozet sebcrozet left a 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(
Copy link
Member

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?

Suggested change
&UnitVector3::new_normalize(Vector3::<Real>::new(
&UnitVector3::new_normalize(Vector3::new(

@waywardmonkeys
Copy link
Contributor

Interesting CI failure. Hopefully now that xargo is gone, it'll work once you update past that. :)

@ThierryBerger ThierryBerger merged commit 72a0e8d into dimforge:master Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants