Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,7 @@ pub fn sun_acos(x: f64) -> f64 {
let w = r(z) * s + c;
2.0 * (df + w)
}

pub fn lerp(a: f64, b: f64, t: f64) -> f64 {
a * (1.0 - t) + b * t
}
34 changes: 34 additions & 0 deletions src/constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,40 @@ impl MeshBool {
}
}

///Constructs a geodesic sphere of a given radius.
///
///@param radius Radius of the sphere. Must be positive.
///@param circularSegments Number of segments along its
///diameter. This number will always be rounded up to the nearest factor of
///four, as this sphere is constructed by refining an octahedron. This means
///there are a circle of vertices on all three of the axis planes. Default is
///calculated by the static Defaults.
pub fn sphere(radius: f64, circular_segments: i32) -> Self {
if radius <= 0.0 {
return Self::invalid();
}
let n: i32 = if circular_segments > 0 {
(circular_segments + 3) / 4
} else {
(Quality::get_circular_segments(radius) / 4) as i32
};
let mut meshbool_impl = MeshBoolImpl::from_shape(Shape::Octahedron, Matrix3x4::identity());
meshbool_impl.subdivide(|_, _, _| n - 1, false);
meshbool_impl.vert_pos.iter_mut().for_each(|v| {
*v = Vector3::from(core::f64::consts::FRAC_PI_2 * (Vector3::repeat(1.0) - v.coords))
.into();
v.iter_mut().for_each(|i| *i = i.cos());
*v = (radius * Vector3::from(v.coords.normalize())).into();
if v.x.is_nan() {
*v = Vector3::repeat(0.0).into();
}
});
meshbool_impl.finish();
// Ignore preceding octahedron.
meshbool_impl.initialize_original(false);
return Self::from(meshbool_impl);
}

///Constructs a manifold from a set of polygons by extruding them along the
///Z-axis.
///Note that high twistDegrees with small nDivisions may cause
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ mod parallel;
mod polygon;
mod properties;
mod shared;
mod smoothing;
mod sort;
mod subdivision;
mod tree2d;
mod tri_dis;
mod utils;
Expand Down
13 changes: 13 additions & 0 deletions src/meshboolimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ use std::f64;
use std::mem;
use std::sync::atomic::{AtomicI32, AtomicUsize, Ordering as AtomicOrdering};

#[derive(Clone)]
pub struct BaryIndices {
pub tri: i32,
pub start4: i32,
pub end4: i32,
}

impl BaryIndices {
pub fn new(tri: i32, start4: i32, end4: i32) -> Self {
Self { tri, start4, end4 }
}
}

#[derive(Copy, Clone)]
#[allow(unused)]
pub enum Shape {
Expand Down
11 changes: 11 additions & 0 deletions src/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ where
}
}

pub fn exclusive_scan_iter<IO>(input: impl Iterator<Item = IO>, output: &mut [IO], init: IO)
where
IO: Copy + AddAssign,
{
let mut acc = init;
for (idx, i) in input.enumerate() {
output[idx] = acc;
acc += i;
}
}

///Copy values in the input range `[first, last)` to the output range
///starting from `d_first` that satisfies the predicate `pred`,
///i.e. `pred(x) == true`, and returns `d_first + n` where `n` is the number of
Expand Down
70 changes: 68 additions & 2 deletions src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::AABB;
use crate::utils::{K_PRECISION, mat3, next3_usize};
use core::f64;
use nalgebra::{Matrix2x3, Matrix3, Matrix3x4, Point3, Vector3};
use nalgebra::{Matrix2x3, Matrix3, Matrix3x4, Point3, Vector3, Vector4};
use std::ops::MulAssign;

#[inline]
Expand Down Expand Up @@ -134,7 +134,19 @@ impl Halfedge {
}
}

#[derive(Copy, Clone, Debug)]
#[derive(Default, Clone)]
pub struct Barycentric {
pub tri: i32,
pub uvw: Vector4<f64>,
}

impl Barycentric {
pub fn new(tri: i32, uvw: Vector4<f64>) -> Self {
Self { tri, uvw }
}
}

#[derive(Default, Copy, Clone, Debug)]
pub struct TriRef {
/// The unique ID of the mesh instance of this triangle. If .meshID and .tri
/// match for two triangles, then they are coplanar and came from the same
Expand All @@ -157,3 +169,57 @@ impl TriRef {
&& self.face_id == other.face_id
}
}

///This is a temporary edge structure which only stores edges forward and
///references the halfedge it was created from.
#[derive(Default, Clone)]
pub struct TmpEdge {
pub first: i32,
pub second: i32,
pub halfedge_idx: i32,
}

impl TmpEdge {
fn new(start: i32, end: i32, idx: i32) -> Self {
Self {
first: start.min(end),
second: start.max(end),
halfedge_idx: idx,
}
}
}

// impl Ord for TmpEdge {
// // bool operator<(const TmpEdge& other) const {
// // }
// fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// if self.first == other.first {
// self.second.cmp(&other.second)
// } else {
// self.first.cmp(&other.first)
// }
// }
// }

#[inline]
pub fn create_tmp_edges(halfedge: &[Halfedge]) -> Vec<TmpEdge> {
let edges: Vec<TmpEdge>;
edges = (0..halfedge.len())
.into_iter()
.map(|idx| {
let half = &halfedge[idx];
TmpEdge::new(
half.start_vert,
half.end_vert,
if half.is_forward() { idx as i32 } else { -1 },
)
})
.collect();

let edges: Vec<TmpEdge> = edges
.into_iter()
.filter(|edge| !(edge.halfedge_idx < 0))
.collect();
debug_assert_eq!(edges.len(), halfedge.len() / 2, "Not oriented!");
return edges;
}
10 changes: 10 additions & 0 deletions src/smoothing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::meshboolimpl::MeshBoolImpl;

impl MeshBoolImpl {
pub fn is_marked_inside_quad(&self, _halfedge: i32) -> bool {
// if !self.halfedge_tangent.is_empty() {
// return self.halfedge_tangent[halfedge as usize].w < 0;
// }
return false;
}
}
Loading