Is it possible to find an edge loop in run time?

Hi there, I am wanting to find edge loops on pipes in run time so that I could get the center, diameter, and circumference of a pipe.

I have limitations that don’t allow me to manually create paths or curves to define these pipes. I require a script that can be (preferably) executed in the editor.

What I want to do is create a point in the center of each edge loop along a pipe so that I can create a curve through the pipe. I know a lot of you will say do that while you create the pipes in your 3d program. Or create each one manually. However I have 6 different 3D models each with over 400 pipes or pipe segments and I would rather not spend the better part of this year making paths for each of these pipes.

Here is a video to give you all an idea of what I need a path through a pipe for… http://www.youtube.com/watch?v=tXGtzhEwFiQ

I noticed things like the ability to get an array of vertices in a mesh or a vertex count but nothing about how to find an edge loop. If I could find all vertices on an edge loop I could average them to find the center of the pipe.

It is easy to create a mesh based on a path/curve but creating a path/curve based on a mesh seems to be really hard. So, any ideas on where to start? I would obviously post my results for others as I am sure this could be very useful.

I would suggest writing a script to manually select the “start loop” of your pipe and the “direction” for the program to start building the path. Direction should be limited to a line perpendicular to the plane of the start loop.
Or you could manually position a box, and have your mesh-checking script use its positioning to -find- the startLoop and direction.

Once you somehow have a start loop and direction,
here’s some five-minute pseudocode:

currentLoop = startLoop
path = new Array()
path.Add( currentLoop.Center() )

while ( not end ) :
  nextLoop = new Array()
  foreach vertex in currentLoop :
    foreach triangle in mesh : 
      if vertex in triangle :
        foreach triangleVertex in triangle :
          if triangleVertex not in currentLoop :
            if Vector3.Angle( triangleVertex - vertex, currentDirection ) < 89 :
              if triangleVertex not in nextLoop :
                nextLoop.Add( triangleVertex );
          }
        }
      }
    }
  }
  if ( nextLoop.length == 0 ) 
    end = true
  else :

    currentDirection = Center( nextLoop ) - Center( currentLoop )
    nextPoint = Center( nextLoop )
  
    path.Add( nextPoint )
  }
}

I don’t know of a better way to get all triangles from a vertex; the brute force method above will probably be painfully slow.

The “angle < 89” above is just so we don’t find any edges backwards.

And here’s a link to the Mesh class, which has all those wonderful functions like GetTriangles and such.

This is all if your pipes are flat with no outcroppings or anything. If you have fixin’s, you’ll want to probably make sure the distance from vertex to currentCenter+direction is some amount.