-
Notifications
You must be signed in to change notification settings - Fork 42
Unity Extensions
Justin edited this page Mar 11, 2022
·
6 revisions
CGALDotNet is designed to be independent of any other project but since its written in C# Unity is a natural fit to work with.
A number of extension methods are provides in the CGALDotNetUnity project to help convert between Unity's objects and CGALDotNet objects.
Some examples are as follows.
//These extension methods need the numeric namespace.
using CGALDotNetGeometry.Numerics;
//Create a CGALDotNet point.
var point1 = new Point3d();
//Convert it to a unity vector.
var vector = point1.ToUnityVector3();
//And back to a CGALDotNet point.
var point2 = point1.ToCGALPoint3();
Similar methods can be found for arrays of points and vectors and some shapes like rays and boxes.
Methods to convert polygons to game objects can also be found.
//These extension methods need the polygon namespace.
using CGALDotNetGeometry.Polygons;
//Create a polygon.
var polygon = new Polygon2<EIK>(points);
//Convert polygon to a game object with a triangulated mesh of the polygon.
//Polygon points are 2D and will be converted to 3D for the mesh.
var mesh = polygon.ToUnityMesh("polygon", position, material);