NURBS Sharp
NURBS Sharp is a small, dependency-free NURBS (Non-Uniform Rational B-Spline) library for .NET. It provides data structures, evaluators, topology operators, I/O and tessellation utilities implemented using only the .NET standard library.
Table of Contents
Features
- Generation and evaluation of NURBS curves, surfaces
- Topology operators: degree elevation/reduction, knot insertion/removal/refinement, join/split
- Generation capabilities: interpolation, least squares approximation, primitive shapes
- Intersection calculations: Ray-Box, Ray-Mesh, Curve-Curve, Curve-Surface, Surface-Surface, Surface-Plane
- IO helpers:
- Mesh only: OBJ/STL export, simple BMP export
- NURBS only: IGES import/export (Point, Curve, Surface entities supported)
- Tessellation utilities for curves and surfaces
- Targets: .NET 8 and .NET Standard 2.1
Limitations
- Viewer: This library does not include a 3D model viewer. To inspect model details, a 3D rendering library or file export is required.
- NURBS Surface:
TrimSurfaceis not yet implemented. - Knot Vector: Currently, only "Clamped" knot vectors are supported (multiplicity = degree + 1).
- IGES Support:
- Import: Only supports Entity Type 126 (Rational B-spline curve), and 128 (Rational B-spline surface).
- Export: Only supports Point and NURBS entities. Mesh export is not supported.
- Mesh Export (OBJ/STL): Only supports Mesh objects. Direct export from NURBS is not supported (tessellation required).
- Intersection Calculations:
- The current state may be unstable due to its dependence on initial conditions.
Installation
Install via NuGet:
dotnet add package NurbsSharp
Or add the package reference to your project file.
Quick Start
Basic usage (C#):
using NurbsSharp.Core;
using NurbsSharp.Geometry;
using NurbsSharp.Tesselation;
using NurbsSharp.IO;
// Create a NURBS surface and evaluate a point
int degreeU = 3, degreeV = 3;
var knotsU = new double[] {0,0,0,0,1,1,1,1};
var knotsV = new double[] {0,0,0,0,1,1,1,1};
var kvU = new KnotVector(knotsU);
var kvV = new KnotVector(knotsV);
// Build control points (u x v grid)
ControlPoint[][] controlPoints = new ControlPoint[4][];
controlPoints[0] = new ControlPoint[] {
new ControlPoint(0.0, 0.0, 0.0, 1),
new ControlPoint(1.0, 0.0, 1.0, 1),
new ControlPoint(2.0, 0.0, 3.0, 1),
new ControlPoint(3.0, 0.0, 3.0, 1)
};
// ... Create Control Points ...
var surface = new NurbsSurface(degreeU, degreeV, kvU, kvV, controlPoints);
var point = surface.GetPos(0.5, 0.5);
Console.WriteLine(point);
Examples
tessellate a surface and export to STL:
int divideN = 20;
var mesh = SurfaceTessellator.Tessellate(surface, divideN, divideN);
using (var fs = new FileStream("test_output.stl", FileMode.Create, FileAccess.Write))
{
await STLExporter.ExportAsync(mesh, fs);
}
Examples Project: https://github.com/nyarurato/NurbsSharpSample
Github Wiki: https://github.com/nyarurato/NurbsSharp/wiki/Samples
Documentation
API Docs: https://nyarurato.github.io/NurbsSharp/
Development
Clone the repo and build locally:
dotnet restore
dotnet build -c Debug
Run unit tests:
dotnet test -c Debug
Project layout highlights:
src/Core— numeric helpers and core types (BoundingBox,Ray,KnotVector,LinAlg, etc.)src/Geometry—NurbsCurve,NurbsSurface,NurbsVolume,Mesh, etc.src/Evaluation— evaluators (curve/surface/volume)src/Operation— topology operators (degree, knot, join, split, surface operators)src/Generation— interpolation, least squares approximation, primitive shape generationsrc/Intersection— intersection calculations (Ray-Box, Ray-Mesh, Curve-Curve, Curve-Surface, BVH structures)src/IO—OBJExporter,STLExporter,BMPExporter, IGES import/exportsrc/Tesselation— tessellation (curve/surface)
Contributing
Contributions are welcome. Typical workflow:
- Fork the repository
- Create a branch with a descriptive name
- Add tests for new behavior where appropriate
- Open a pull request against
master
License
MIT License