SamuelRe.CSG.Sharp 1.0.0

dotnet add package SamuelRe.CSG.Sharp --version 1.0.0                
NuGet\Install-Package SamuelRe.CSG.Sharp -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SamuelRe.CSG.Sharp" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SamuelRe.CSG.Sharp --version 1.0.0                
#r "nuget: SamuelRe.CSG.Sharp, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SamuelRe.CSG.Sharp as a Cake Addin
#addin nuget:?package=SamuelRe.CSG.Sharp&version=1.0.0

// Install SamuelRe.CSG.Sharp as a Cake Tool
#tool nuget:?package=SamuelRe.CSG.Sharp&version=1.0.0                

CSG.Sharp

alternate text is missing from this package README image alternate text is missing from this package README image

This is a .Net8.0 port/fork of the PSneijders CSG.Sharp library. The original library was written in .Net-Framework and was not published to NuGet. This is a slimmed down version with some bugfixes and extensions.

OG Readme:

Constructive solid geometry on meshes using BSP trees in C#

alt tag

Constructive Solid Geometry (CSG) is a modeling technique that uses Boolean operations like union and intersection to combine 3D solids. This library implements CSG operations on meshes elegantly and concisely using BSP trees, and is meant to serve as an easily understandable implementation of the algorithm. All edge cases involving overlapping coplanar polygons in both solids are correctly handled.

Example usage:

    var cube = Cube.Create();
    var sphere = Sphere.Create(radius: 1.3);
    var polygons = cube.Subtract(sphere).ToPolygons();

Implementation Details

All CSG operations are implemented in terms of two functions, clipTo() and invert(), which remove parts of a BSP tree inside another BSP tree and swap solid and empty space, respectively. To find the union of a and b, we want to remove everything in a inside b and everything in b inside a, then combine polygons from a and b into one solid:

    a.ClipTo(b);
    b.ClipTo(a);
    a.Build(b.AllPolygons());

The only tricky part is handling overlapping coplanar polygons in both trees. The code above keeps both copies, but we need to keep them in one tree and remove them in the other tree. To remove them from b we can clip the inverse of b against a. The code for union now looks like this:

    a.ClipTo(b);
    b.ClipTo(a);
    b.Invert();
    b.ClipTo(a);
    b.Invert();
    a.Build(b.AllPolygons());

Subtraction and intersection naturally follow from set operations. If union is A | B, subtraction is A - B = ~(~A | B) and intersection is A & B = ~(~A | ~B) where ~ is the complement operator.

TODOs

  • Complete porting of csg.js

Recent Changes

See CHANGES.txt

Committers

Parts are take from the wonderful library https://evanw.github.io/csg.js/

License

MIT license

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 116 8/23/2024