Adrian Lopez

05-06-2006, 05:34 PM

I've been thinking of a way to split a LW mesh into groups of connected polygons that share the same properties (textures, UV groups, etc.). So far the best I've been able to come up with is the following procedure:

1. Create a list of polygon-vertex pairs. For every pair, this table contains the polygon's ID, the position of the vertex within that polygon's list of vertices, the desired values for each vertex (Position, Texture, UV values, etc), and a reserved column for use in step 3:

(Polygon ID) (Vertex Order) (Polygon/Vertex Values) (reserved)

2. Sort above table by polygon/vertex values and use that to create a list of unique polygon/vertex values:

(Unique Polygon/Vertex Values)

3. To each polygon-vertex pair in the table created in step 1, add an index into the list of unique vertex values:

(Polygon ID) (Vertex Order) (Vertex Values) (UPVV Index)

4. Sort the above table by Polygon ID and Vertex Order.

5. Create a table of polygons and their "colors". Each "color" is actually a single integer value that identifies a polygon as part of a group. All polygons are initially assigned a color of 0:

(Polygon ID) ("Color")

6. Create a table that maps vertices to polygons. This is used to find all polygons that share a particular vertex.

(Vertex) (Polygon)

7. Iterating through the vertex/polygon table created in step 6, assign a color to every polygon that shares that vertex. If any of these polygons has previously been assigned a color, the polygons surrounding the vertex are colored according to the lowest of these colors. Otherwise, the polygons are assigned a unique color.

8. Iterating through the vertex/polygon table, each polygon surrounding a particular vertex is colored according to the lowest of the polygons' colors.

9. Repeat steps 8-9 until no more polygons have been recolored.

10. Output a list of polygons sorted according to "color".

Any comments or suggestions?

1. Create a list of polygon-vertex pairs. For every pair, this table contains the polygon's ID, the position of the vertex within that polygon's list of vertices, the desired values for each vertex (Position, Texture, UV values, etc), and a reserved column for use in step 3:

(Polygon ID) (Vertex Order) (Polygon/Vertex Values) (reserved)

2. Sort above table by polygon/vertex values and use that to create a list of unique polygon/vertex values:

(Unique Polygon/Vertex Values)

3. To each polygon-vertex pair in the table created in step 1, add an index into the list of unique vertex values:

(Polygon ID) (Vertex Order) (Vertex Values) (UPVV Index)

4. Sort the above table by Polygon ID and Vertex Order.

5. Create a table of polygons and their "colors". Each "color" is actually a single integer value that identifies a polygon as part of a group. All polygons are initially assigned a color of 0:

(Polygon ID) ("Color")

6. Create a table that maps vertices to polygons. This is used to find all polygons that share a particular vertex.

(Vertex) (Polygon)

7. Iterating through the vertex/polygon table created in step 6, assign a color to every polygon that shares that vertex. If any of these polygons has previously been assigned a color, the polygons surrounding the vertex are colored according to the lowest of these colors. Otherwise, the polygons are assigned a unique color.

8. Iterating through the vertex/polygon table, each polygon surrounding a particular vertex is colored according to the lowest of the polygons' colors.

9. Repeat steps 8-9 until no more polygons have been recolored.

10. Output a list of polygons sorted according to "color".

Any comments or suggestions?