Files
ViewDesignEngine/dotnet/VdeSharp/SdfEngine.cs
T
茂之钳 5e2812a6f3
CI / Build & Test (push) Failing after 33s
CI / Release Build (push) Failing after 35s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
feat(v6.2): Blender addon + .NET/C# bindings + developer docs + plugin system
v6.2.1 — Blender Integration Addon:
- 5 files, 1,732 lines: __init__, operators (9 ops), panels (4 panels)
- preferences, vde_bridge (subprocess CLI bridge)
- Import/Export STEP, primitives, boolean, SDF→Mesh

v6.2.2 — .NET/C# Bindings (VdeSharp):
- 8 files: NativeMethods (50+ P/Invoke), BrepModel, MeshData, SdfEngine, Assembly
- C API extended with 20 new functions (STEP I/O, Boolean, SDF, Assembly)
- vde_capi rebuilt as SHARED library
- Example: import STEP → boolean → export

v6.2.3 — Developer Docs + Plugin System:
- 7 docs: architecture, contributing, API overview, building, testing, plugin-system
- plugin_system.h/.cpp: PluginInterface, PluginManager, dlopen/LoadLibrary
- README.md updated with v6 features
- Syntax-check passed (GCC 10.2.1, -Wall -Wextra -Wpedantic)
2026-07-26 22:24:40 +08:00

83 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace VdeSharp;
/// <summary>
/// Managed wrapper for VDE SDF (Signed Distance Function) modeling.
/// Provides an expression-tree based CSG modeling approach.
/// </summary>
public class SdfEngine : IDisposable
{
private readonly nint _ctx;
internal nint _handle;
private bool _disposed;
internal SdfEngine(nint ctx, nint handle)
{
_ctx = ctx;
_handle = handle;
}
/// <summary>Create a sphere SDF node.</summary>
public static SdfEngine Sphere(nint ctx, double radius)
{
nint hdl = NativeMethods.vde_sdf_sphere(ctx, radius);
return new SdfEngine(ctx, hdl);
}
/// <summary>Create a box SDF node with half-extents (hx, hy, hz).</summary>
public static SdfEngine Box(nint ctx, double hx, double hy, double hz)
{
nint hdl = NativeMethods.vde_sdf_box(ctx, hx, hy, hz);
return new SdfEngine(ctx, hdl);
}
/// <summary>Create a cylinder SDF node.</summary>
public static SdfEngine Cylinder(nint ctx, double radius, double height)
{
nint hdl = NativeMethods.vde_sdf_cylinder(ctx, radius, height);
return new SdfEngine(ctx, hdl);
}
/// <summary>CSG union: this other</summary>
public SdfEngine Union(SdfEngine other)
{
nint hdl = NativeMethods.vde_sdf_union(_ctx, _handle, other._handle);
return new SdfEngine(_ctx, hdl);
}
/// <summary>CSG intersection: this ∩ other</summary>
public SdfEngine Intersection(SdfEngine other)
{
nint hdl = NativeMethods.vde_sdf_intersection(_ctx, _handle, other._handle);
return new SdfEngine(_ctx, hdl);
}
/// <summary>CSG difference: this \ other</summary>
public SdfEngine Difference(SdfEngine other)
{
nint hdl = NativeMethods.vde_sdf_difference(_ctx, _handle, other._handle);
return new SdfEngine(_ctx, hdl);
}
/// <summary>
/// Convert the SDF tree to a triangle mesh using Marching Cubes.
/// </summary>
/// <param name="resolution">Grid resolution per axis (e.g., 64 for 64³ voxels)</param>
public MeshData ToMesh(int resolution = 64)
{
nint mh = NativeMethods.vde_sdf_to_mesh(_ctx, _handle, resolution);
var mesh = new MeshData(mh, ownsHandle: true);
mesh.ExtractFromNative();
return mesh;
}
public void Dispose()
{
if (!_disposed && _handle != nint.Zero)
{
NativeMethods.vde_sdf_free(_handle);
_handle = nint.Zero;
_disposed = true;
}
}
}