Get border edges of mesh - in winding order

后端 未结 3 1426
心在旅途
心在旅途 2021-02-12 22:04

I have a triangulated mesh. Assume it looks like an bumpy surface. I want to be able to find all edges that fall on the surrounding border of the mesh. (forget about inner verti

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-12 22:40

    Traversal Code (not efficient - needs to be tidied up, will get to that at some point) Please Note: I store each segment in the chain as 2 indices - rather than 1 as suggested by Darren. This is purely for my own implementation / rendering needs.

            // okay now lets sort the segments so that they make a chain.
    
            var sorted = new List();
            var visited = new Dictionary();
    
            var startIndex = edges[0];
            var nextIndex = edges[1];
    
            sorted.Add(startIndex);
            sorted.Add(nextIndex);
    
            visited[0] = true;
            visited[1] = true;
    
            while (nextIndex != startIndex)
            {
                for (int i = 0; i < edges.Count - 1; i += 2)
                {
                    var j = i + 1;
                    if (visited.ContainsKey(i) || visited.ContainsKey(j))
                        continue;
    
                    var iIndex = edges[i];
                    var jIndex = edges[j];
    
                    if (iIndex == nextIndex)
                    {
                        sorted.Add(nextIndex);
                        sorted.Add(jIndex);
                        nextIndex = jIndex;
                        visited[j] = true;
                        break;
                    }
                    else if (jIndex == nextIndex)
                    {
                        sorted.Add(nextIndex);
                        sorted.Add(iIndex);
                        nextIndex = iIndex;
                        visited[i] = true;
                        break;
                    }
                }
            }
    
            return sorted;
    

提交回复
热议问题