Open Sajdkick opened 6 years ago
Hey, thanks for the good words! I'm all happy if people find this useful as well! Let me give you a more detailed answer below.
Awesome, thanks for the quick reply!
All i had to do was to change this:
clipper.Execute(ClipType.ctUnion, unionPaths);
Into:
clipper.Execute(ClipType.ctDifference, unionPaths);
So if you wanted a general function for doing all these kinds of operations you could change the function public Polygon UnionPolygon()
into public Polygon BooleanOperation(ClipType clipType)
Super simple, thanks again!
Boolean operations are done using Clipper, a great open source freeware library for clipping and offsetting lines and polygons.
So far I only incorporated union, but you can easily extend the library to make extension methods doing different types of clipping operations. See ClipType
for the actual Clipper documentation.
In this library, only ClipType.ctUnion
is implemented so far. See Polygon.cs#L626
.
You can nicely arrange the extensions into an extension class like below.
using System;
using UnityEngine;
namespace EPPZ.Geometry
{
public static class Polygon_Extensions
{
public Polygon IntersectionPolygon(this Polygon _this)
{ ... }
public Polygon DifferencePolygon(this Polygon _this)
{ ... }
public Polygon XORPolygon(this Polygon _this)
{ ... }
}
}
i can't open example scene in unity 2018.3.6. is there any thing to do before importing?
Great stuff you got here! Just one question, you mention in the description that you can perform subtraction. Is it possible to subtract one polygon from another as shown in the picture below? So far i have only managed to do an XOR.![image](https://user-images.githubusercontent.com/14965425/42725250-1ec87f60-8781-11e8-895e-5d7d502362e2.png)
Thanks!