5e2812a6f3
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)
191 lines
10 KiB
C#
191 lines
10 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace VdeSharp;
|
|
|
|
/// <summary>
|
|
/// P/Invoke declarations for the VDE C API (libvde_capi.so / vde_capi.dll).
|
|
/// All native handles are represented as nint (IntPtr).
|
|
/// </summary>
|
|
internal static partial class NativeMethods
|
|
{
|
|
// ── Library name ──
|
|
private const string LibName = "vde_capi";
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Engine lifecycle
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_create();
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_destroy(nint ctx);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern IntPtr vde_version();
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern IntPtr vde_last_error(nint ctx);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Mesh I/O
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_load_mesh(nint ctx, string path);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern int vde_save_mesh(nint ctx, nint mesh, string path, string format);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Mesh query
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nuint vde_mesh_num_vertices(nint mesh);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nuint vde_mesh_num_faces(nint mesh);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_mesh_get_vertex(nint mesh, nuint idx,
|
|
out double x, out double y, out double z);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_mesh_get_bounds(nint mesh,
|
|
out double minX, out double minY, out double minZ,
|
|
out double maxX, out double maxY, out double maxZ);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_mesh_free(nint mesh);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Mesh processing
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_mesh_simplify(nint ctx, nint mesh, double targetRatio);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_mesh_smooth(nint ctx, nint mesh, int iterations);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_mesh_boolean(nint ctx, nint a, nint b, int op);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern unsafe int vde_mesh_get_face(nint mesh, nuint faceIdx, int** outIndices);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// B-Rep modeling
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_body_create_box(nint ctx, double w, double h, double d);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_body_create_cylinder(nint ctx, double r, double h, int segs);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_body_create_sphere(nint ctx, double r, int su, int sv);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_body_to_mesh(nint ctx, nint body, double deflection);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_body_free(nint body);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_body_clone(nint ctx, nint body);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// B-Rep STEP/IGES I/O
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern unsafe int vde_body_load_step(nint ctx, string path, nint** outBodies);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern unsafe int vde_body_load_iges(nint ctx, string path, nint** outBodies);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern int vde_body_save_step(nint ctx, nint[] bodies, int count, string path);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern int vde_body_save_iges(nint ctx, nint[] bodies, int count, string path);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// B-Rep Boolean
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_body_boolean(nint ctx, nint a, nint b, int op);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Body array lifetime
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern unsafe void vde_body_free_array(nint* bodies, int count);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Buffer lifetime
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern unsafe void vde_free_buffer(void* ptr);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// SDF
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_sphere(nint ctx, double r);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_box(nint ctx, double hx, double hy, double hz);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_cylinder(nint ctx, double r, double h);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_union(nint ctx, nint a, nint b);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_intersection(nint ctx, nint a, nint b);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_difference(nint ctx, nint a, nint b);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_sdf_to_mesh(nint ctx, nint sdf, int resolution);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_sdf_free(nint sdf);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Assembly
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern nint vde_assembly_create(nint ctx, string name);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern int vde_assembly_add_part(nint assembly, string name, nint body);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern int vde_assembly_part_count(nint assembly);
|
|
|
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
internal static extern void vde_assembly_free(nint assembly);
|
|
|
|
// ═══════════════════════════════════════════════════
|
|
// Helpers
|
|
// ═══════════════════════════════════════════════════
|
|
|
|
internal static string PtrToStringUTF8(IntPtr ptr)
|
|
{
|
|
if (ptr == IntPtr.Zero) return string.Empty;
|
|
return Marshal.PtrToStringUTF8(ptr) ?? string.Empty;
|
|
}
|
|
}
|