Giter Site home page Giter Site logo

geri-borbas / unity.library.eppz.geometry Goto Github PK

View Code? Open in Web Editor NEW
310.0 17.0 57.0 4.85 MB

2D Geometry for Unity. Suited for everyday polygon hassle. Polygon clipping, polygon winding direction, polygon area, polygon centroid, centroid of multiple polygons, line intersection, point-line distance, segment intersection, polygon-point containment, polygon triangulation, polygon Voronoi diagram, polygon offset, polygon outline, polygon buffer, polygon union, polygon substraction, polygon boolean operations, and more. It is a polygon fest.

License: Other

C# 98.64% ShaderLab 1.36%
polygon segment unity centroid intersection accuracy scene geometry buffering clipping clipper triangulation voronoi voronoi-diagram intersect intersection-point distance-calculation

unity.library.eppz.geometry's Introduction

eppz! Geometry

part of Unity.Library.eppz

๐Ÿ“ 2D geometry for Unity. Suited for everyday polygon hassle.

Polygon clipping, polygon winding direction, polygon area, polygon centroid, centroid of multiple polygons, line intersection, point-line distance, segment intersection, polygon-point containment, polygon triangulation, polygon Voronoi diagram, polygon offset, polygon outline, polygon buffer, polygon union, polygon substraction, polygon boolean operations, and more.

Unity.Library.eppz.Geometry.Model.Poygon.Mesh.Triangulation

The library is being used in production. However, it comes with the disclaimed liability and warranty of MIT License.

Examples

If you prefer to read example code immediately, you can find example scenes in Scenes folder.

Model classes

  • Vertex.cs
    • Basically a Vector2 point, but is aware of the polygon context it resides (neighbours, segments, edges, polygon, bisector, normal).
  • Segment.cs
    • Segment of two Vector2 point. Carries out basic geometry features (point distance, point containment, segment intersection).
  • Edge.cs
    • Edge of two Vertex in a polygon (a special Segment subclass). Likewise vertices, this model is also aware of the polygon context it resides (neighbours, segments, edges, polygon, perpendicular, normal).
  • Polygon.cs
    • The role player, it really embodies mostly every feature of this library. Basically a polygon made of vertices.
    • Can be created with point array, transforms, Source.Polygon components. Further polygons can be embedded into recursively. Vertices, edges, polygons can be enumerated (recursively).
    • Area, winding direction, centroid are being calculated. Also carries the basic geometry features (point containment, line-, segment-, polygon intersection and more).
    • Using library modules, it implements polygon offset (outline), union polygon (polygon clipping), basic mesh triangulation. It implements conversion to both Clipper and Triangle.NET, so you can implement further integration with those (awesome) libraries.

Most of the basic 2D geometry algorithm collection is implemented in this static base class. You can (mostly) use them with Unity Vector2 types directly, so (almost entirely) without the model classes introduced above.

Modules

For clipping, offsetting, triangulating the library use these brilliant third party C# libraries below.

  • Clipper

    • Polygon and line clipping and offsetting library (C++, C#, Delphi) by Angus Johnson. See standalone project repository Clipper for details.
  • Triangle.NET

    • Triangle.NET generates 2D (constrained) Delaunay triangulations and high-quality meshes of point sets or planar straight line graphs. It is a C# port by Christian Woltering of Jonathan Shewchuk's Triangle software. See standalone project repository Triangle.NET for details.

Naming

The library uses namespaces heavily. I like to name things as they are. An edge in this library called Edge, a polygon is called Polygon. If it is a polygon model, it resides the Model namespace (EPPZ.Geometry.Model actually). Whether it is a source component for polygon, it resides in the Source namespace. It becomes nicely readable, as you declare polygons like Model.Polygon, or reference polygon sources as Source.Polygon.

In addition, every class is namespaced in the folder it resides. If you look at a folder name, you can tell that classes are namespaced to the same as the folder name.

Add-ons

  • ClipperAddOns

    • Mainly Polygon extensions for easy conversion between eppz! Geometry and Clipper. It has a method to convert from generic Vector2[] array. Clipper works with integers. So conversion involves a scale up (and a scale down), thus you'll need to pass a scale value to Clipper. (for example eppz! Geometry internals use 10e+5f by default).
      • Polygon PolygonFromClipperPaths(Paths paths, float scale)
      • Polygon PolygonFromClipperPath(Path path, float scale)
      • Paths ClipperPaths(this Polygon this_, float scale)
      • Path ClipperPath(this Polygon this_, float scale)
      • Vector2[] PointsFromClipperPath(Path path, float scale)
  • TriangleNetAddOns

    • Bridges the gap between library Model.Polygon objects and Triangle.NET models (meshes, voronoi diagrams).
      • TriangleNet.Geometry.Polygon TriangleNetPolygon(this Polygon this_)
      • Rect Bounds(this TriangleNet.Voronoi.Legacy.SimpleVoronoi this_)
      • Paths ClipperPathsFromVoronoiRegions(List<TriangleNet.Voronoi.Legacy.VoronoiRegion> voronoiRegions, float scale = 1.0f)
      • Vector2 VectorFromPoint(TriangleNet.Geometry.Point point)
      • Vector2[] PointsFromVertices(ICollection<TriangleNet.Geometry.Point> vertices)
  • UnityEngineAddOns

    • Contains a single Model.Polygon (yet enormously useful) extension that triangulates the corresponding polygon, and hooks up the result into a UnityEngine.MeshFilter component. This is the core functionality embedded into Source.Mesh component (see example scene Polygon triangulation for more).
      • UnityEngine.Mesh Mesh(this EPPZ.Geometry.Model.Polygon this_, string name = "")
      • UnityEngine.Mesh Mesh(this EPPZ.Geometry.Model.Polygon this_, TriangulatorType triangulator, string name = "")
      • UnityEngine.Mesh Mesh(this EPPZ.Geometry.Model.Polygon this_, Color color, TriangulatorType triangulator, string name = "")

License

Licensed under the MIT License.

unity.library.eppz.geometry's People

Contributors

geri-borbas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity.library.eppz.geometry's Issues

Erro when add package from git URL

Hi Borbas,

Thanks for the amazing polygon operations! I am a green hand on unity. I would love to try this great library EPPZ. But it seems that directly download the [Unity.Library.eppz-master.zip] or add the depository by URL at unity package manager is not working. I keep getting this erro(picture). Is that because I do not have the MIT licence?

image

Thanks agian and looking forward to your reply!

Kind regards,
Qim

Singleton LineRendererCamera Not Initialised โ€” Unity 2019.3

Trying this library out as it looks very helpful! But I'm hitting an error when running all the example scenes.

NullReferenceException: Object reference not set to an instance of an object EPPZ.Lines.LineRendererCamera.AddDirectRenderer (EPPZ.Lines.DirectLineRenderer renderer) (at Assets/22. Assets โ€” 3rd Party/Unity.Library.eppz/Unity.Library.eppz.Lines/LineRendererCamera.cs:51) EPPZ.Lines.DirectLineRenderer.Awake () (at Assets/22. Assets โ€” 3rd Party/Unity.Library.eppz/Unity.Library.eppz.Lines/DirectLineRenderer.cs:32)

This seems to be some failure to initialise the singleton?

To get the library working I also added Unity.Library.eppz.Lines and the required define symbol. And I thought the singleton issue might be related to the missing execution order utility, so I also added Unity.Library.eppz.Utils, but this did not correct the above error.

Unity 2019.3.7f1
macOS 10.15.5

Polygon subtraction

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

Thanks!

Sort vertices clockwise

I have irregular vertices and i want to sort them CW or CCW. What is the generalized method to do it. Any suggestions please?

Missing dependencies

Error I am getting after importing your library.

Assets/Plugins/eppz!/Geometry/Scenes/Controllers/Controller_1.cs(33,10): error CS0246: The type or namespace name `SegmentLineRenderer' could not be found. Are you missing an assembly reference?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.