8 releases

new 0.1.7 May 1, 2024
0.1.6 May 1, 2024
0.1.5 Apr 30, 2024

#329 in Game dev

Download history 423/week @ 2024-04-18 164/week @ 2024-04-25

587 downloads per month
Used in bevy_curvo

MIT license

110KB
2.5K SLoC

Curvo

License Crates.io Docs Test

Curvo is a NURBS curve / surface modeling library for Rust.

Visualization on bevy Visualization on Bevy

This library enables not only the creation of NURBS curves from control points, knot vectors, and weights associated with each control point, but also supports generating curves that precisely pass through the given control points and creating periodic curves. Additionally, it allows for the construction of NURBS surfaces through operations such as extruding and lofting based on NURBS curves as inputs.

The modeling operations for NURBS surfaces supported by this library currently include (or are planned to include) the following:

  • Extrude
  • Loft
  • Sweep
  • Revolve
Sweep a profile curve along a rail curve to create a surface

I also plan to implement features for finding the nearest points on surfaces (already implemented for curves), as well as dividing them based on arc lengths.

Find closest point on the NURBS curve

Usage

// Create a set of points to interpolate
let points = vec![
    Point3::new(-1.0, -1.0, 0.),
    Point3::new(1.0, -1.0, 0.),
    Point3::new(1.0, 1.0, 0.),
    Point3::new(-1.0, 1.0, 0.),
    Point3::new(-1.0, 2.0, 0.),
    Point3::new(1.0, 2.5, 0.),
];

// Create a NURBS curve that interpolates the given points with degree 3
// You can also specify the precision of the curve by generic type (f32 or f64)
let interpolated = NurbsCurve3D::<f64>::try_interpolate(&points, 3, None, None).unwrap();

// NURBS curve & surface can be transformed by nalgebra's matrix
let rotation = Rotation3::from_axis_angle(&Vector3::z_axis(), FRAC_PI_2);
let translation = Translation3::new(0., 0., 3.);
let transform_matrix = translation * rotation; // nalgebra::Isometry3

// Transform the curve by the given matrix (nalgebra::Isometry3 into nalgebra::Matrix4)
let offsetted = interpolated.transformed(&transform_matrix.into());

// Create a NURBS surface by lofting two NURBS curves
let lofted = NurbsSurface::try_loft(
  &[interpolated, offsetted],
  Some(3), // degree of v direction
).unwrap();

// Tessellate the surface in adaptive manner about curvature for efficient rendering
let option = AdaptiveTessellationOptions {
    norm_tolerance: 1e-4,
    ..Default::default()
};
let tessellation = lofted.tessellate(Some(option));

Dependencies

  • nalgebra: this library heavily relies on nalgebra, a linear algebra library, to perform its computations.

References

Dependencies

~6–50MB
~818K SLoC