How to get a polygon from a Triangulated Face in Three.js?

喜你入骨 提交于 2019-12-11 04:26:19

问题


I looked up around the Net if this someone had the same problem. I'm working with three.js. I have a 3DObject, which may contain holes. The faces are triangulated. Let say I want to see it from above: my objective is to get a Polygon which represents the perimeter of the top face.(that means for me, no more triangulated faces but only 1 Polygon). My approach till now was the following: I used the Three.js function "EdgesGeometry" over a shape geometry to get a collection of unsorted lines which, connected with a self-written function, build a closed Polygon. The Problem begins with holes. Because after I use the "EdgesGeometry" function, I don't know if lines are the outer lines of a polygon or the inner lines around the hole. So I have a couple of question:

  • How can I know if a ShapeGeometry made of triangulated shapes contains a hole? (nice to know but it does not solve the problem)
  • Is there a function which transforms a Triangulatedshape (ShapeGeometry) in a Polygon with or without holes? (of course, they would be a different structure or definition)
  • May I have taken the wrong way to get to my objective?

My ideal result would look like this:

  • a collection of sorted segments which describe the perimeter of the polygon and 0 to n collections of sorted segments which describe the holes.
  • a collection of sorted points which describes the perimeter of the polygon and 0 to n collections of sorted points which describe the holes.

All these questions are referred to a three.js environment.

I hope my question is clear enough.

Thank you for your attention. Have a good day.

P.S. I have considered to use point-in-poly algorithms after my function in case of holes, but I think it is not performant and complexity (O notation) would raise.

来源:https://stackoverflow.com/questions/48169143/how-to-get-a-polygon-from-a-triangulated-face-in-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!