using Jobberwocky.GeometryAlgorithms.Source.Core; using Jobberwocky.GeometryAlgorithms.Source.Algorithms.Triangulation2D; using Jobberwocky.GeometryAlgorithms.Source.Algorithms.Triangulation3D; using UnityEngine; using System; using Jobberwocky.GeometryAlgorithms.Source.Parameters; namespace Jobberwocky.GeometryAlgorithms.Source.API { public class TriangulationAPI : ThreadingAPI { /// /// Creates a 2D triangulation of the given input points + parameters. /// The points input should not include the boundary and holes points. /// /// /// Geometry public static Geometry Triangulate2DRaw(Triangulation2DParameters parameters) { var triWrapper2D = new Triangulation2DWrapper(); return triWrapper2D.Triangulate2D(parameters); } /// /// Creates a 2D triangulation of the given input points + parameters. /// The points input should not include the boundary and holes points. /// /// /// Triangulated Unity mesh public Mesh Triangulate2D(Triangulation2DParameters parameters) { // Create triangulation Geometry geometry = Triangulate2DRaw(parameters); return geometry.ToUnityMesh(); } /// /// Creates a 2D triangulation using threading /// /// /// public void Triangulate2DAsync(Action callback, Triangulation2DParameters parameters = null) { StartWorker((IParameters param, Action callbackResult) => { var triWrapper = new Triangulation2DWrapper(); var geometry = triWrapper.Triangulate2D((Triangulation2DParameters)param); return new ThreadingResult(callbackResult, geometry); }, parameters, callback); } /// /// Creates a 3D triangulation of the given input points. /// Note that this method assumes that the 3D shape is convex and without holes. /// This means that concave shapes are triangulated to a convex shape and holes are removed. /// /// /// Unity mesh public Mesh Triangulate3D(Triangulation3DParameters parameters) { var geometry = Triangulate3DRaw(parameters); return geometry.ToUnityMesh(); } /// /// Creates a 3D triangulation of the given input points. /// Note that this method assumes that the 3D shape is convex and without holes. /// This means that concave shapes are triangulated to a convex shape and holes are removed. /// /// /// Geometry public Geometry Triangulate3DRaw(Triangulation3DParameters parameters) { var triWrapper3D = new Triangulation3DWrapper(); return triWrapper3D.Triangulate3D(parameters); } /// /// Creates a 3D convex triangulation using threading /// /// /// /// public void Triangulation3DThreading(Action callback, Triangulation3DParameters parameters) { StartWorker( (IParameters param, Action callbackResult) => { var triWrapper = new Triangulation3DWrapper(); var geometry = triWrapper.Triangulate3D(parameters); return new ThreadingResult(callbackResult, geometry); }, parameters, callback); } } }