Skip to content

Instantly share code, notes, and snippets.

@AndreaCatania

AndreaCatania/FBX_edges.md

Last active Jan 14, 2021
Embed
What would you like to do?
Explanation on how the edges are stored into the FBX.

FBX format - Unique Edges

How the edges are stored into FBX?

How to parse the edges from FBX?

Let's consider this geometry:

Objects:  {
	Geometry: 140696156120336, "Geometry::", "Mesh" {
		Vertices: *18 {
			a: -1,-1,0,1,-1,0,-1,1,0,1,1,0,-1.00631749629974,2.97582387924194,-0.0179548189043999,0.993682563304901,2.97582387924194,-0.0179548189043999
		} 
		PolygonVertexIndex: *8 {
			a: 0,1,3,-3,2,3,5,-5
		} 
		Edges: *7 {
			a: 0,1,2,3,5,6,7
		} 

Untitled22211

The edges (stored as an array of 7 integers) is a direct reference to the PolygonVertexIndex. You can take the vertex of an edge in this way:

int vertex_index = PolygonVertexIndex[Edges[0]];

The Edge array contains just the first vertex of each unique edge, the other vertex is the following vertex in the polygon, if the vertex is negative the first polygon vertex is its next. This mean that in our case we have the following edges:

// Polygon 1
int polygon0_edge_0[2] = {PolygonVertexIndex[Edges[0]], PolygonVertexIndex[Edges[0]+1]}; // Vertex 0 - 1
int polygon0_edge_1[2] = {PolygonVertexIndex[Edges[1]], PolygonVertexIndex[Edges[1]+1]}; // Vertex 1 - 3
int polygon0_edge_2[2] = {PolygonVertexIndex[Edges[2]], ~PolygonVertexIndex[Edges[2]+1]}; // Vertex 3 - 2
int polygon0_edge_3[2] = {~PolygonVertexIndex[Edges[3]], PolygonVertexIndex[0]}; // Vertex 2 - 0

// Polygon 2
int polygon1_edge_0[2] = {PolygonVertexIndex[Edges[4]], PolygonVertexIndex[Edges[4]+1]}; // Vertex 3 - 5
int polygon1_edge_1[2] = {PolygonVertexIndex[Edges[5]], ~PolygonVertexIndex[Edges[5]+1]}; // Vertex 5 - 4
int polygon1_edge_2[2] = {~PolygonVertexIndex[Edges[6]], PolygonVertexIndex[4]}; // Vertex 4 - 2

Note: You may have noticed the use of ~ in the code. It's used to reverse the integer and obtain the actual vertex ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment