GLUtesselator已经被Google Maps的Brendan Kenny移植到了Javascript。 这是libtess.js在Github上的链接。 Vladimir Agafonkin(leaflet.js,Mapbox)最近开发了earcut.js,目前它是“最快和最小的JavaScript多边形三角剖分库,适用于您的WebGL应用程序”。 这是earcut.js在Github上的链接。
我遇到了同样的问题(在使用HTML Canvas和Box2D形状时),尝试使用Three.js的三角剖分函数,但对我来说使用这个非常好的库要容易得多:https://code.google.com/p/poly2tri/ JS实现在那里,并且完美地为我工作:https://code.google.com/p/poly2tri/source/browse/?repo=javascript#hg%2Fsrc
有几个库可以做到这一点。您使用的库也取决于数据的质量。某些库会在数据中存在重复点、自相交多边形或其他不一致性时崩溃。 poly2tri: https://github.com/r3mi/poly2tri.js earcut: https://github.com/mapbox/earcut libtess: https://github.com/brendankenny/libtess.js/