Skip to content

weianweigan/fidget-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fidget C#

C# bindings for the Fidget implicit modeling library.

Fidget is a library of infrastructure and algorithms for implicit surfaces, powered by bytecode evaluation and JIT compilation. This package provides .NET bindings via the C API (fidget-capi).

Installation

dotnet add package Fidget

The NuGet package includes native binaries for:

  • win-x64
  • linux-x64
  • osx-x64
  • osx-arm64

The correct native library for your platform is automatically copied to the output directory at build time.

Quick Start

using Fidget;

// Create a context for building math expressions
using var ctx = new Context();
var x = ctx.X;
var y = ctx.Y;
var z = ctx.Z;

// Build a sphere SDF: sqrt(x² + y² + z²) - 1.0
var r2 = ctx.Add(ctx.Add(ctx.Square(x), ctx.Square(y)), ctx.Square(z));
var sphere = ctx.Sub(ctx.Sqrt(r2), ctx.Constant(1.0));

// Compile into a shape
using var shape = new Shape(ctx, sphere);

// Evaluate at a point
using var tape = shape.CreatePointTape();
using var eval = new PointEvaluator();
float value = eval.Evaluate(tape, 0.5f, 0.0f, 0.0f);
Console.WriteLine(value); // negative = inside, positive = outside

// Generate a mesh
using var mesh = new Mesh(shape, depth: 8);
Console.WriteLine($"Triangles: {mesh.TriangleCount}");

Documentation

Comprehensive documentation is available in English and Chinese:

Chapter EN ZH
Introduction to Implicit Modeling en zh
Getting Started en zh
Context & Node API Reference en zh
Building Implicit Shapes en zh
Evaluation & Debugging en zh
Mesh Generation en zh
2D Rendering en zh
Advanced Examples en zh

Building from Source

# Clone with submodules
git clone --recurse-submodules https://github.com/weianweigan/fidget-csharp.git
cd fidget-csharp

# Build and test
./build.sh

Or step by step:

# 1. Build the Rust native library
cd fidget-capi
cargo build --release

# 2. Build and test the C# project
cd ..
dotnet test Fidget.slnx -c Release

License

This project is licensed under the Mozilla Public License 2.0, matching the upstream Fidget project.

About

csharp binding of fidget

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors