A tool for subdividing a complex 2d shape into triangles.
C++ C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
pictures
src
.gitignore
README.md

README.md

ofxTrianglular

Easy to subdivide a complex 2d shape to triangles.

Support OSX(Xcode 6.0) Windows(Visual Studio 2012), and Linux(QtCreator, Ubuntu, Thanks for icq4ever).

Based on Jonathan Richard Shewchuk's triangle library


How to bulid

  • Based on OpenFrameworks, only need ofxTriangular, no other dependencies

  • To bulid example you need to include ofxUI and ofxXmlSettings in projectGenerator or added manually.

  • Replace the defalut project's ofApp.cpp + ofApp.h + main.cpp


Screenshots

OSX

image

Windows

image

Linux

screenshot_Linux

(Thanks for icq4ever)


Getting Started

Simplest way to init ofxTriangular.

// set a boundary made by ofPolyline
ofPolyline polyline

triangular.setBoundary(polyline);

If your 2d shape include some holes in it.

// set a hole made by ofPolyline

// one ofxHole connect one point inside it.
ofxHole hole;
vector<ofxHole> holes;

// only if point(x, y) was inside the hole that you want to add.
if(holeline.inside(x, y))
{
    hole.set(holeline, ofPoint(x, y));
    holes.push_back(hole);
}

triangular.setHoles(holes);

Subdivide complex 2d shape to triangles.

// generate the triangle collections

triangles = triangular.triangulate();

If you want to render the triangle that ofxTriangular generated.

// loop all of it if needed
for(int i=0; i<triangles.size(); i++)
{
   triangles[i].draw();
}

Shortage

  • The Option Tesselation was enabled, but the effect of it was not obvious.(unless you set the option tesselation 0 compared with 600)

  • Don't support advanced features like iteration, constraint. etc(haven't open the API yet).

  • Under some certain circumstances, Debug is much easier to crash than the Release.

Extreme Cases

Only in some exreme cases (complex nested boundary) that ofxTriangular runs on Windows was easier to crash than the OSX.

OSX

image

image

Windows

image

image


Author

   int 官某某 = Bingo;

   char[] 个人博客 = "http://bentleyblanks.github.io";