From b681c372cf696f453a2c4f293b74618849259844 Mon Sep 17 00:00:00 2001 From: mattatz Date: Fri, 20 Dec 2024 22:29:02 +0900 Subject: [PATCH 1/5] Upgrade bevy_normal_material to 0.7.1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65bada8..00ad394 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -989,9 +989,9 @@ dependencies = [ [[package]] name = "bevy_normal_material" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66367f2b77afe4d0fa2537b21aeee0fdf11d62a5f2133d61acb4cc7166326d13" +checksum = "dd0173d0ad6a6561e33ff19184661e82e843b44dd53210bcc34e27f1daa46205" dependencies = [ "bevy", ] diff --git a/Cargo.toml b/Cargo.toml index 63510be..ecb455e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ bevy = { version = "0.15.0", optional = true } bevy_egui = { version = "0.31.1", optional = true } bevy-inspector-egui = { version = "0.28.0", optional = true } bevy_infinite_grid = { version = "0.14.0", optional = true } -bevy_normal_material = { version = "0.7.0", optional = true } +bevy_normal_material = { version = "0.7.1", optional = true } bevy_panorbit_camera = { version = "0.21.1", optional = true } bevy_points = { version = "0.7.0", optional = true } argmin = "0.10.0" From e2fcde55b774993cec7dc630bdff7d7a8e27bc97 Mon Sep 17 00:00:00 2001 From: mattatz Date: Fri, 20 Dec 2024 22:38:47 +0900 Subject: [PATCH 2/5] Invert face index in surface tessellation. --- src/surface/nurbs_surface.rs | 4 ++-- src/tessellation/surface_tessellation.rs | 29 +++++++++--------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/surface/nurbs_surface.rs b/src/surface/nurbs_surface.rs index 53bce9b..e3214fb 100644 --- a/src/surface/nurbs_surface.rs +++ b/src/surface/nurbs_surface.rs @@ -376,8 +376,8 @@ where let ioff = iu * (divs_v + 1); (0..divs_v).flat_map(move |iv| { [ - [ioff + iv, ioff + iv + 1, ioff + iv + divs_v + 2], - [ioff + iv, ioff + iv + divs_v + 2, ioff + iv + divs_v + 1], + [ioff + iv, ioff + iv + divs_v + 2, ioff + iv + 1], + [ioff + iv, ioff + iv + divs_v + 1, ioff + iv + divs_v + 2], ] }) }) diff --git a/src/tessellation/surface_tessellation.rs b/src/tessellation/surface_tessellation.rs index 513819d..a4664dd 100644 --- a/src/tessellation/surface_tessellation.rs +++ b/src/tessellation/surface_tessellation.rs @@ -84,26 +84,19 @@ where match uvs.len() { 4 => { - self.faces.push([ids[0], ids[3], ids[1]]); - self.faces.push([ids[3], ids[2], ids[1]]); + self.faces.push([ids[0], ids[1], ids[3]]); + self.faces.push([ids[3], ids[1], ids[2]]); } 5 => { let il = ids.len(); - self.faces.push([ - ids[split_id], - ids[(split_id + 2) % il], - ids[(split_id + 1) % il], - ]); - self.faces.push([ - ids[(split_id + 4) % il], - ids[(split_id + 3) % il], - ids[split_id], - ]); - self.faces.push([ - ids[split_id], - ids[(split_id + 3) % il], - ids[(split_id + 2) % il], - ]); + let a = ids[split_id]; + let b = ids[(split_id + 1) % il]; + let c = ids[(split_id + 2) % il]; + let d = ids[(split_id + 3) % il]; + let e = ids[(split_id + 4) % il]; + self.faces.push([a, b, c]); + self.faces.push([a, d, e]); + self.faces.push([a, c, d]); } n => { let center = node.center(surface); @@ -115,7 +108,7 @@ where let mut j = n - 1; let mut i = 0; while i < n { - self.faces.push([center_index, ids[i], ids[j]]); + self.faces.push([center_index, ids[j], ids[i]]); j = i; i += 1; } From f2f6fc41b4735e7387dcc3128f014a6d4bfe24e7 Mon Sep 17 00:00:00 2001 From: mattatz Date: Fri, 20 Dec 2024 22:50:35 +0900 Subject: [PATCH 3/5] WIP. --- examples/closest_point_on_surface.rs | 8 ++++---- examples/intersect_surface_curve.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/closest_point_on_surface.rs b/examples/closest_point_on_surface.rs index 487f28b..0f28912 100644 --- a/examples/closest_point_on_surface.rs +++ b/examples/closest_point_on_surface.rs @@ -96,7 +96,7 @@ fn setup( ); let vertices = tess.points().iter().map(|pt| (*pt).into()).collect(); - let normals = tess.normals().iter().map(|n| (-n).into()).collect(); + let normals = tess.normals().iter().map(|n| (*n).into()).collect(); let uvs = tess.uvs().iter().map(|uv| (*uv).into()).collect(); let indices = tess .faces() @@ -137,9 +137,9 @@ fn setup( (0..N) .map(|j| { let x = i as f64 - hn; - let z = (rng.gen::() - 0.5) * 2.; - let y = j as f64 - hn; - Point4::new(x, z, y, 1.) + let y = (rng.gen::() - 0.5) * 2.; + let z = (j as f64) - hn; + Point4::new(x, y, z, 1.) }) .collect_vec() }) diff --git a/examples/intersect_surface_curve.rs b/examples/intersect_surface_curve.rs index 6ad135f..d709ddb 100644 --- a/examples/intersect_surface_curve.rs +++ b/examples/intersect_surface_curve.rs @@ -11,7 +11,7 @@ use bevy_normal_material::{plugin::NormalMaterialPlugin, prelude::NormalMaterial use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; use bevy_points::{plugin::PointsPlugin, prelude::PointsMaterial}; use itertools::Itertools; -use misc::surface_2_mesh; +use misc::{surface_2_mesh, surface_2_regular_mesh}; use nalgebra::{Matrix4, Point3, Point4, Vector3}; use curvo::prelude::*; @@ -76,7 +76,7 @@ fn setup( .map(|j| { let x = i as f64 - hn; let y = (rng.gen::() - 0.5) * 2.; - let z = j as f64 - hn; + let z = (j as f64) - hn; Point4::new(x, y, z, 1.) }) .collect_vec() @@ -86,6 +86,7 @@ fn setup( commands.spawn(( Mesh3d(meshes.add(surface_2_mesh(&surface, None))), + // Mesh3d(meshes.add(surface_2_regular_mesh(&surface, 64, 64))), MeshMaterial3d(normal_materials.add(NormalMaterial { opacity: 0.35, cull_mode: None, @@ -201,7 +202,6 @@ fn setup( z_axis_color: Color::BLACK, ..Default::default() }, - transform: Transform::from_rotation(Quat::from_rotation_x(FRAC_PI_2)), ..Default::default() }); } From 0bfe96d7197932a826a670df1ffacd57cd7a6442 Mon Sep 17 00:00:00 2001 From: mattatz Date: Fri, 20 Dec 2024 22:51:10 +0900 Subject: [PATCH 4/5] fmt. --- examples/intersect_surface_curve.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/intersect_surface_curve.rs b/examples/intersect_surface_curve.rs index d709ddb..f616700 100644 --- a/examples/intersect_surface_curve.rs +++ b/examples/intersect_surface_curve.rs @@ -1,5 +1,3 @@ -use std::f32::consts::FRAC_PI_2; - use bevy::{ color::palettes::css::TOMATO, prelude::*, @@ -11,7 +9,7 @@ use bevy_normal_material::{plugin::NormalMaterialPlugin, prelude::NormalMaterial use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; use bevy_points::{plugin::PointsPlugin, prelude::PointsMaterial}; use itertools::Itertools; -use misc::{surface_2_mesh, surface_2_regular_mesh}; +use misc::surface_2_mesh; use nalgebra::{Matrix4, Point3, Point4, Vector3}; use curvo::prelude::*; From a40623b0e93220ebeef88db51681c6bb5818f102 Mon Sep 17 00:00:00 2001 From: mattatz Date: Fri, 20 Dec 2024 22:51:25 +0900 Subject: [PATCH 5/5] Upgrade version to 0.1.42 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00ad394..f6b9931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1966,7 +1966,7 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" [[package]] name = "curvo" -version = "0.1.41" +version = "0.1.42" dependencies = [ "anyhow", "approx", diff --git a/Cargo.toml b/Cargo.toml index ecb455e..500489b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "curvo" -version = "0.1.41" +version = "0.1.42" authors = ["Masatatsu Nakamura