0

I'm importing an FBX model as an XNA model object, and reading through the vertexbuffer to get a hold of the triangles, indices, UVs, and put it into my custom model class. The problem is that the buffer only holds data on each triangle, not the quads they once were in 3dsmax.

I need to retain the quad structure to use the mesh as I want. The following points are different ways I believe I can achieve this, but I would need some help to get it done.

  1. One method I've tried is simply create quads in the order that the triangles appear. This works great for primitives which have the correct vertex/triangle order where each triangle of a quad comes after another, but edited meshes have an obstructed order which breaks the flow. If someone knows a method on how to rearrange vertex/triangle order before export this would still work.

  2. Is there any way to read off the FBX file (preferebly after it's loaded as a Model object, to avoid rewriting a seperate model pipeline) which triangles are connected as quads?

  3. The 'coding' approach. Given a list of vertices/indices, order them up accordingly so that the quad structure becomes evident. 3dsmax has a 'quadrify' button that works quite well, but can't figure out a straightforward way of doing it. edit; For this approach, what I mean is, what is an optimal way to look at an unordered structure of triangles to find the best "quad" version of the mesh, similarly to the 'quadrify' in 3dsmax tools.

jsmars
  • 1,640
  • 5
  • 21
  • 33

1 Answers1

1

It is possible to recover quad information using pure indexing information - for example, take the case of two quads decomposed into 4 triangles.

1       2       3
+-------+-------+
|\      |\      |
|  \    |  \    |
|    \  |    \  |
|      \|      \|
+-------+-------+
4       5       6

Now, your triangles are (assuming a clockwise winding order)

A=(1, 5, 4) B=(1, 2, 5) C=(2, 6, 5) D=(2, 3, 6)

The edges of your triangles are

A=(1-5, 5-4, 4-1) B=(1-2, 2-5, 5-1) C=(2-6, 6-5, 5-2) D=(2-3, 3-6, 6-2)

Now it's easy to see which triangles share an edge

  • A and B share exactly 1 edge 1-5 (because it is the same as 5-1)
  • B and C share 2-5
  • C and D share 2-6

Based on this information, we could quad-ify it as

  • 1 quad = (1, 2, 6, 5) + 2 triangles (1, 5, 4) and (2, 3, 6)

or

  • 2 quads (1, 2, 5, 4) and (2, 3, 6, 5)

A brute force method would be to determine all quad-ifications and choose the one that left the least number of degenerate triangles. If you're starting with perfect quad-based meshes, this should be zero.

Also, note that this method only examines and modifies index data. The total number of vertices or their values are left untouched.

Ani
  • 10,826
  • 3
  • 27
  • 46
  • What about a mesh which has thousands of triangles with more or less random vertex order and triangle order? and even if the quads are on a grid which they usually aren't on complex models, they may also have mixed triangulation. – jsmars Jun 24 '13 at 21:05
  • The same idea will work, it will only be a lot more computation. To reduce the amount of tests, you can use a spatial partitioning scheme like an octree. The only case this will not work is when your mesh does not share vertices - but replicates them to form triangles, even across triangles with shared edges. – Ani Jun 25 '13 at 14:37
  • It doesn't matter where the vertices are (on a grid or otherwise). Note that I am dealing with vertex indexing only in the above solution. – Ani Jun 25 '13 at 18:19
  • I still don't understand the key concept in this. I already have read off all shared edges and verts, the trouble is finding the correct two triangles which should form a quad. When the vertices and indices are mixed up, it will not know which neighboring triangle to choose to quad with to retain a correct quad structure. For instance, if you create a "geosphere" in 3dsmax, there are no edges and no apparent quad structure, how can I code a system which choses the correct neighboring triangle so that all triangles are accounted for? (And preferebly exactly the same quad strucutre as in 3dsmax) – jsmars Jun 25 '13 at 21:40
  • For meshes that don't start as quads - you will be unable to reconstruct a quad-based mesh correctly. This is INEVITABLE. And a geosphere is not quad based. If you think about it, you will realize that only sets (of 4) of coplanar points correctly be a quad. I guess at this point I need to ask : What are you doing that needs quads from a mesh constructed as triangles? – Ani Jun 29 '13 at 15:46
  • In such cases, you will need to perform the reduction like mesh simplification, using face normals to determine if two triangles can be collapsed into a quad. Of course, this changes the topology of the mesh. This is what "Quadrify" does and brings me back to - what do you need to do with it. – Ani Jun 29 '13 at 15:49
  • Yes a geosphere is not created as quads, but can easily be converted into quads for further use. I'm looking to create a quadtree LOD structure from a high triangle count model. Any model of say an animal or human can be built mainly as quads which are subdivided multiple times, and I'd like to build a way to display and cycle through different detail levels similarly to what Mudbox or ZBrush would do, so I need a valid quad structure of the model. I will look into creating a method based on face normals, that could work! – jsmars Jun 29 '13 at 22:29