Files
ViewDesignEngine/dotnet/VdeSharp/MeshData.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

105 lines
3.2 KiB
C#

namespace VdeSharp;
/// <summary>
/// Mesh data structure representing a triangulated surface.
/// Contains vertices and triangle indices.
/// </summary>
public class MeshData : IDisposable
{
/// <summary>3D vertex positions (x,y,z triplets)</summary>
public double[] Vertices { get; private set; }
/// <summary>Triangle indices, 3 per face</summary>
public int[] Indices { get; private set; }
/// <summary>Axis-aligned bounding box min (x,y,z)</summary>
public (double X, double Y, double Z) BoundsMin { get; private set; }
/// <summary>Axis-aligned bounding box max (x,y,z)</summary>
public (double X, double Y, double Z) BoundsMax { get; private set; }
/// <summary>Native mesh handle (opaque).</summary>
internal nint _handle;
private bool _ownsHandle;
/// <summary>
/// Wraps an existing native mesh handle. Caller sets ownership.
/// </summary>
internal MeshData(nint handle, bool ownsHandle = true)
{
_handle = handle;
_ownsHandle = ownsHandle;
Vertices = Array.Empty<double>();
Indices = Array.Empty<int>();
}
/// <summary>
/// Creates a MeshData from raw vertex and index arrays.
/// </summary>
public MeshData(double[] vertices, int[] indices)
{
Vertices = vertices;
Indices = indices;
_handle = nint.Zero;
_ownsHandle = false;
}
/// <summary>
/// Extracts mesh data from the native handle into managed arrays.
/// Call this after receiving a mesh from native code.
/// </summary>
public unsafe void ExtractFromNative()
{
if (_handle == nint.Zero) return;
nuint numVerts = NativeMethods.vde_mesh_num_vertices(_handle);
nuint numFaces = NativeMethods.vde_mesh_num_faces(_handle);
Vertices = new double[(int)numVerts * 3];
Indices = new int[(int)numFaces * 3];
for (nuint i = 0; i < numVerts; i++)
{
NativeMethods.vde_mesh_get_vertex(_handle, i,
out Vertices[(int)i * 3],
out Vertices[(int)i * 3 + 1],
out Vertices[(int)i * 3 + 2]);
}
for (nuint i = 0; i < numFaces; i++)
{
int* facePtr;
int count = NativeMethods.vde_mesh_get_face(_handle, i, &facePtr);
if (count >= 3)
{
Indices[(int)i * 3] = facePtr[0];
Indices[(int)i * 3 + 1] = facePtr[1];
Indices[(int)i * 3 + 2] = facePtr[2];
}
NativeMethods.vde_free_buffer(facePtr);
}
// Bounds
NativeMethods.vde_mesh_get_bounds(_handle,
out double mx, out double my, out double mz,
out double Mx, out double My, out double Mz);
BoundsMin = (mx, my, mz);
BoundsMax = (Mx, My, Mz);
}
/// <summary>Number of vertices</summary>
public int VertexCount => Vertices.Length / 3;
/// <summary>Number of triangles</summary>
public int TriangleCount => Indices.Length / 3;
public void Dispose()
{
if (_ownsHandle && _handle != nint.Zero)
{
NativeMethods.vde_mesh_free(_handle);
_handle = nint.Zero;
}
}
}