GeoSharPlus is a C++/C# interoperability library for geometry data exchange. It uses FlatBuffers to move geometry between managed (.NET) and native (C++) code on Windows and macOS. Rhino and Grasshopper were the first target. This repository is a template: click "Use this template" and add your own C++ functions.
Click "Use this template" on GitHub to create your own repository.
git clone https://github.com/YOUR_USERNAME/YOUR_PROJECT.git
cd YOUR_PROJECT
# Set VCPKG_ROOT to your vcpkg checkout. The CMake presets read it.
# macOS / Linux shell:
export VCPKG_ROOT=/path/to/vcpkg
# Windows PowerShell:
# $env:VCPKG_ROOT = "C:\path\to\vcpkg"
# Build the C++ library
cd GeoSharPlusCPP
# macOS
cmake --preset macos-default
cmake --build --preset macos-release
# Windows (use a Visual Studio Developer shell, so that Ninja finds the MSVC compiler)
cmake --preset windows-default
cmake --build --preset windows-release
# Build the C# library
cd ../GeoSharPlusNET
dotnet buildThe macos-default preset uses the arm64-osx vcpkg triplet (Apple Silicon). The windows-default preset uses x64-windows. The first configure step downloads and builds the vcpkg dependencies, so it takes some time.
See the Extension Guide below.
The demo projects GSPdemoConsole and GSPdemoGH build and run on Windows and macOS. See How the Native Library Reaches the Demos.
GeoSharPlus/
βββ GeoSharPlusCPP/ # C++ Native Library
β βββ CMakeLists.txt # β οΈ UPSTREAM - Build configuration
β βββ CMakePresets.json # β οΈ UPSTREAM - Build presets (windows-*, macos-*)
β βββ vcpkg.json # β οΈ UPSTREAM - Pinned dependencies
β βββ include/GeoSharPlusCPP/
β β βββ Core/ # β οΈ UPSTREAM - Core types & macros (Macro.h, MathTypes.h, Geometry.h)
β β βββ Serialization/ # β οΈ UPSTREAM - FlatBuffers serialization (Serializer.h)
β β βββ Extensions/ # β
YOUR CODE HERE (ExampleExtensions.h)
β βββ src/
β β βββ Core/ # β οΈ UPSTREAM - Core implementations
β β βββ Serialization/ # β οΈ UPSTREAM - Serialization implementations
β β βββ Extensions/ # β
YOUR CODE HERE (ExampleExtensions.cpp)
β βββ schema/
β βββ *.fbs # β οΈ UPSTREAM - Core FlatBuffer schemas
β βββ extensions/ # β
YOUR SCHEMAS HERE
β
βββ GeoSharPlusNET/ # C# Wrapper Library
β βββ Core/ # β οΈ UPSTREAM - Core utilities
β β βββ MarshalHelper.cs # Memory marshaling helpers
β β βββ Platform.cs # OS detection, library paths
β β βββ Serializer.cs # FlatBuffers serialization for GSP types
β βββ Geometry/ # β οΈ UPSTREAM - Platform-independent geometry types
β β βββ Vec2.cs # 2D point/vector
β β βββ Vec3.cs # 3D point/vector
β β βββ Mesh.cs # Mesh with vertices and faces
β β βββ IGeometryAdapter.cs # Interface for CAD platform adapters
β βββ Adapters/ # CAD Platform Adapters
β β βββ Rhino/ # β οΈ UPSTREAM - Rhino adapter
β β βββ RhinoAdapter.cs # Converts Rhino types β GSP types
β βββ Extensions/ # β
YOUR CODE HERE
β β βββ _README.md # Detailed extension guide
β β βββ ExampleExtensions.cs # Example: Point/Mesh roundtrip
β βββ RuntimeInit.cs # β οΈ UPSTREAM - Platform initialization
β βββ Wrapper.cs # β οΈ UPSTREAM - High-level API for Rhino types
β
βββ GeoSharPlusNET.Tests/ # xUnit tests for Core and Geometry (no Rhino needed)
βββ generated/ # β οΈ UPSTREAM - Generated FlatBuffers code (tracked)
β βββ GSP_FB/
β βββ cpp/ # *_generated.h
β βββ csharp/ # *_generated.cs
βββ cppPrebuild/ # Build output: native library (created by CMake, not tracked)
βββ GSPdemoGH/ # Example Grasshopper Plugin
βββ GSPdemoConsole/ # Example Console App
βββ GSP.DEMO.sln # Solution for the demos
βββ scripts/
β βββ sync-upstream.ps1 # Update from template
βββ UPSTREAM_FILES.md # List of upstream files
The library uses a layered architecture with platform-independent core types:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application (Grasshopper Plugin, Console App, etc.) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GSP.Extensions (Your custom C++βC# bridge functions) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GSP.Adapters (CAD-specific: Rhino, AutoCAD, etc.) β
β Converts CAD types β GSP.Geometry types β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GSP.Geometry (Platform-independent: Vec3, Mesh, etc.) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GSP.Core (Serializer, MarshalHelper, Platform detection) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GeoSharPlusCPP.dll / libGeoSharPlusCPP.dylib (C++ Native) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key Concepts:
- GSP.Geometry: Platform-independent types (
Vec3,Vec2,Mesh) that don't depend on any CAD software - GSP.Adapters: Convert between CAD-specific types (e.g.,
Rhino.Geometry.Point3d) and GSP types - GSP.Core: Serialization and memory management utilities
- GSP.Extensions: Your custom C++ functions with C# bindings
π‘ For a detailed step-by-step guide with more examples, see
GeoSharPlusNET/Extensions/_README.md
Create a new file in GeoSharPlusCPP/include/GeoSharPlusCPP/Extensions/:
// MyFunctions.h
#pragma once
#include <cstdint>
#include "GeoSharPlusCPP/Core/Macro.h"
extern "C" {
GSP_API bool GSP_CALL my_compute_something(
const uint8_t* inBuffer,
int inSize,
uint8_t** outBuffer,
int* outSize);
} // extern "C"Create a new file in GeoSharPlusCPP/src/Extensions/:
// MyFunctions.cpp
#include "GeoSharPlusCPP/Extensions/MyFunctions.h"
#include "GeoSharPlusCPP/Core/MathTypes.h"
#include "GeoSharPlusCPP/Serialization/Serializer.h"
namespace GS = GeoSharPlusCPP::Serialization;
extern "C" {
GSP_API bool GSP_CALL my_compute_something(
const uint8_t* inBuffer,
int inSize,
uint8_t** outBuffer,
int* outSize) {
// Your implementation using IGL, Eigen, etc.
return true;
}
} // extern "C"Create a new file in GeoSharPlusNET/Extensions/:
// MyFunctionsBridge.cs
using System.Runtime.InteropServices;
namespace GSP.Extensions {
public static class MyFunctionsBridge {
private const string WinLibName = @"GeoSharPlusCPP.dll";
private const string MacLibName = @"libGeoSharPlusCPP.dylib";
[DllImport(WinLibName, EntryPoint = "my_compute_something",
CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool MyComputeSomethingWin(
byte[] inBuffer, int inSize, out IntPtr outBuffer, out int outSize);
[DllImport(MacLibName, EntryPoint = "my_compute_something",
CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool MyComputeSomethingMac(
byte[] inBuffer, int inSize, out IntPtr outBuffer, out int outSize);
public static bool MyComputeSomething(
byte[] inBuffer, int inSize, out IntPtr outBuffer, out int outSize) {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return MyComputeSomethingWin(inBuffer, inSize, out outBuffer, out outSize);
else
return MyComputeSomethingMac(inBuffer, inSize, out outBuffer, out outSize);
}
}
}
β οΈ A C++boolhas 1 byte. The default .NET marshalling reads a 4-byte Win32BOOL. Add[return: MarshalAs(UnmanagedType.I1)]to everyDllImportthat returnsbool.
For cleaner API usage, create a wrapper that handles serialization:
// MyFunctionsUtils.cs
using GSP.Core;
using GSP.Geometry;
namespace GSP.Extensions {
public static class MyFunctionsUtils {
/// <summary>
/// Process points using your custom C++ algorithm.
/// Works with platform-independent GSP.Geometry.Vec3 types.
/// </summary>
public static Vec3[]? ProcessPoints(Vec3[] points) {
// Serialize input
var buffer = Serializer.Serialize(points);
// Call native function
if (!MyFunctionsBridge.MyComputeSomething(buffer, buffer.Length,
out IntPtr outPtr, out int outSize))
return null;
// Marshal and deserialize result
var resultBuffer = MarshalHelper.CopyAndFree(outPtr, outSize);
return Serializer.DeserializeVec3Array(resultBuffer);
}
/// <summary>
/// Process Rhino points using your custom C++ algorithm.
/// Convenience overload for Rhino users.
/// </summary>
public static Rhino.Geometry.Point3d[]? ProcessPoints(Rhino.Geometry.Point3d[] points) {
var adapter = GSP.Adapters.Rhino.RhinoAdapter.Instance;
var gspPoints = adapter.PointsToGSP(points);
var result = ProcessPoints(gspPoints);
return result != null ? adapter.PointsFromGSP(result) : null;
}
}
}# Rebuild C++ (use windows-release on Windows)
cd GeoSharPlusCPP
cmake --build --preset macos-release
# Rebuild C#
cd ../GeoSharPlusNET
dotnet buildIf you add a new C++ source file, run the configure preset again (cmake --preset macos-default or cmake --preset windows-default) before you build.
The demo projects do not call PowerShell scripts. MSBuild targets in the .csproj files copy the native library to the build output.
- The CMake post-build step writes the native library into
cppPrebuild/at the repository root:GeoSharPlusCPP.dllon Windows andlibGeoSharPlusCPP.dylibon macOS. - The MSBuild targets in
GSPdemoGHandGSPdemoConsolecopy that file fromcppPrebuild/to the output folder of the demo. - The demos run on Windows and macOS.
Build the C++ library first. If cppPrebuild/ is empty, the demo build has no native library to copy.
If you use the project in your own solution, copy the same MSBuild targets from the demo .csproj files.
When the GeoSharPlus template gets updates, you can sync them:
# First time: add upstream remote
git remote add upstream https://github.com/xarthurx/GeoSharPlus.git
# Sync updates
.\scripts\sync-upstream.ps1This updates all upstream files that are listed in UPSTREAM_FILES.md. It does not change your Extensions folders. The script compares your current HEAD with upstream/main.
The library is designed to support multiple CAD platforms through the adapter pattern. To add support for a new CAD platform:
Create a new folder in GeoSharPlusNET/Adapters/ (e.g., AutoCAD/):
// GeoSharPlusNET/Adapters/AutoCAD/AutoCADAdapter.cs
using Autodesk.AutoCAD.Geometry;
using GSP.Geometry;
namespace GSP.Adapters.AutoCAD {
public class AutoCADAdapter : IGeometryAdapter<Point3d, Autodesk.AutoCAD.DatabaseServices.Mesh> {
public static AutoCADAdapter Instance { get; } = new();
public Vec3 PointToGSP(Point3d point) => new(point.X, point.Y, point.Z);
public Point3d PointFromGSP(Vec3 point) => new(point.X, point.Y, point.Z);
// Implement other interface methods...
}
}var adapter = AutoCADAdapter.Instance;
var gspPoints = adapter.PointsToGSP(autocadPoints);
var result = MyUtils.ProcessPoints(gspPoints);
var autocadResult = adapter.PointsFromGSP(result);We welcome contributions for adapters to other CAD platforms!
- CMake 3.21+
- Ninja (the CMake presets use it)
- vcpkg with the
VCPKG_ROOTenvironment variable set - Visual Studio 2022 or later with the C++ workload (Windows), or Xcode command line tools / Clang (macOS)
- .NET 8.0 SDK
- Rhino 8 (only for Grasshopper development)
vcpkg installs these packages from GeoSharPlusCPP/vcpkg.json. The builtin-baseline pins all ports to vcpkg release 2026.10.16:
| Package | Version |
|---|---|
| Eigen3 | 5.0.1 |
| libigl | 2.6.0 |
| FlatBuffers | 25.2.10 |
β οΈ FlatBuffers version rule: the vcpkgflatbuffersversion and theGoogle.FlatBuffersNuGet version must be equal. Theflatccompiler writes a version check into the generated C++ and C# code, so a different version breaks the build. Anoverridesentry invcpkg.jsonholds FlatBuffers at 25.2.10, because 25.2.10 is the newestGoogle.FlatBuffersNuGet version. If you change one version, change the other.
- BeingAliveLanguage - A Grasshopper plugin to create computational diagrams for living systems
- IG-Mesh - A one-stop solution for mesh processing in Grasshopper (for Rhino)
MIT License - See LICENSE for details.
