1. Products
  2.   3D
  3.   .NET
  4.   Geometry3Sharp
 
  

C# .NET 3D Library for 2D/3D Geometric Computation 

Work with 3D Bitmap, Mesh Creation & Ray-Casting against the Mesh surface via Open Source .NET 3D APIs .

Geometry3Sharp is an open source pure C# library for working with geometric computations like 2D/3D Vector Math, Curves and Surfaces, Spatial Queries, and Implicit Surfaces. Geometry3Sharp is fully compatible with Unity. You need to set the G3_USING_UNITY scripting definition and after that, you will have transparent interop between g3 and Unity vector types

Geometry3Sharp library is developed by Gradientspace and is specifically designed to facilitate geometric computations in 3D space, offering a wide range of functionalities that cater to various applications such as computer-aided design (CAD), mesh processing, robotics, and more. At its core, Geometry3Sharp provides a rich set of data structures and algorithms to manipulate 3D geometric entities. These include points, vectors, lines, planes, meshes, and more complex constructs like Boolean operations, mesh simplification, and mesh subdivision.

The library supports several important features related to mesh creation and doing ray-casting against the mesh surface, Mesh simplification, Unity remeshing animations, generating 3D lattices, MarchingCubes, working with 3d Bitmaps, Fast Mesh, Surfacing Point Sets with Fast Winding Numbers and many more.

Previous Next

Getting Started with Geometry3Sharp

The easiest way to install Geometry3Sharp is by using NuGet. Please use the following command for a smooth installation.

Install Geometry3Sharp via NuGet

Install-Package geometry3Sharp -Version 1.0.324 

Mesh Construction via .NET Library

The open source library Geometry3Sharp provides functionality for Interactive Mesh creation using .NET. First of all, you need to construct a DMesh3 object from lists of vertex x/y/z coordinates. A new utility function is now provided which makes this construction very simple. Moreover, the NewVertexInfo type has provided extra constructors for other cases, such as vertex colors and UVs.

Construct 3D Meshes via C# .NET Library

using System;
using g3;

namespace Geometry3SharpExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a new empty DMesh3 object
            DMesh3 mesh = new DMesh3();

            // Add vertices
            int v1 = mesh.AppendVertex(new Vector3d(0, 0, 0));
            int v2 = mesh.AppendVertex(new Vector3d(1, 0, 0));
            int v3 = mesh.AppendVertex(new Vector3d(1, 1, 0));
            int v4 = mesh.AppendVertex(new Vector3d(0, 1, 0));

            // Add triangles
            mesh.AppendTriangle(v1, v2, v3);
            mesh.AppendTriangle(v1, v3, v4);

            // Perform mesh operations if needed (e.g., smoothing, subdivision, etc.)

            // Save the mesh to file
            string outputPath = "path/to/your/mesh.obj";
            StandardMeshWriter.WriteFile(outputPath, mesh, FileType.OBJ);

            Console.WriteLine("Mesh construction completed. Result saved to: " + outputPath);
        }
    }
}

Create Bitmap3Voxelization of a Mesh

Geometry3Sharp enables software developers to create Bitmap3 Voxelization of a mesh inside their own applications. There are several ways to create this Bitmap3voxelization of a mesh such as Voxelization with the mesh winding number, voxelization with Point-containment queries, creating a Minecraft-style surface mesh and more. The tutorials for the above are provided in the GitHub documentation section.

How to Perform Voxelization of a Mesh using C# .NET Geometry3Sharp Library

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using g3;
using g3.Intersection;

namespace Geometry3SharpExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load a mesh from file
            DMesh3 mesh = StandardMeshReader.ReadMesh("path/to/your/mesh.obj");

            // Set voxel size (the size of each voxel in world units)
            double voxelSize = 0.1;

            // Create a bitmap to store the voxelized result
            Bitmap voxelBitmap = new Bitmap(512, 512, PixelFormat.Format32bppArgb);

            // Create a VoxelGrid3f object for voxelization
            VoxelGrid3f voxelGrid = new VoxelGrid3f(voxelSize, voxelSize, voxelSize, mesh.GetBounds().Diagonal.Length);

            // Voxelize the mesh
            MeshToImplicit.MeshToImplicit mm = new MeshToImplicit.MeshToImplicit();
            mm.Implicit = new ImplicitMeshSignedDistanceGrid(mesh, voxelSize);
            mm.Implicit.Voxelization = voxelGrid;
            mm.Compute();

            // Generate the voxelized bitmap
            for (int y = 0; y < voxelBitmap.Height; y++)
            {
                for (int x = 0; x < voxelBitmap.Width; x++)
                {
                    Vector3d voxelPos = voxelGrid.GridToWorld(new Vector3i(x, y, 0));
                    float dist = voxelGrid.GetValueAt(voxelPos);
                    Color color = dist < 0 ? Color.Black : Color.White;
                    voxelBitmap.SetPixel(x, y, color);
                }
            }

            // Save the voxelized bitmap to file
            string outputPath = "path/to/your/voxelized_mesh.bmp";
            voxelBitmap.Save(outputPath, ImageFormat.Bmp);

            Console.WriteLine("Voxelization completed. Result saved to: " + outputPath);
        }
    }
}
 

3D Printer Control 

The Geometry3Sharp library allows developers to directly generate GCode for their 3D printer. you'll need the geometry3Sharp, gsGCode, and gsSlicer libraries. You will need the Settings object that is appropriate for your printer. You can easily customize the settings programmatically.

 English