c++ – Reading fbx file – Can’t interpret received vertex data
I’ve successfuly read vertex data from a fbx file.
PLANE :
Pos :
vec3(-1.000000, -1.000000, 0.000000) vec3(1.000000, -1.000000, 0.000000) vec3(-1.000000, 1.000000, 0.000000) vec3(1.000000, 1.000000, 0.000000)
UV :
vec2(0.000000, 1.000000) vec2(1.000000, 0.000000) vec2(0.000000, 0.000000) vec2(1.000000, 1.000000)
Normal :
vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000)
Indices :
0 1 3 -3
UVIndices :
0 1 2 3
Edges :
2 1 3 0
TRIANGULATED PLANE :
Pos :
vec3(-1.000000, -1.000000, 0.000000) vec3(1.000000, -1.000000, 0.000000) vec3(-1.000000, 1.000000, 0.000000) vec3(1.000000, 1.000000, 0.000000)
UV :
vec2(1.000000, 0.000000) vec2(0.000000, 0.000000) vec2(0.000000, 1.000000) vec2(1.000000, 1.000000)
Normal :
vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000) vec3(0.000000, 0.000000, 1.000000)
Indices :
1 2 -1 1 3 -3
UVIndices :
0 1 2 3 4
Edges :
0 2 1 0 3 2
For each negative indices abs(index) – 1
I can’t see a logical connection between indices and UV or Normal vectors. And the UVIndices
doesn’t help either. In the more complex 3D models vertex position data can’t catch up with the texture coordinates data. Since the connected vertices can be separated in the texture coordinates. UVIndices seems to be just increasing consequently. However I observed that the UVIndices is trying to catch up with the normal vector’s size. For example… There are 4000 normal vectors in a vector. UVIndices is skipping some values by 3 or 4 to reach the 4000 at the end.
Even if I match the uv values with normal vectors using UVIndices there is no way matching them with the vertex position data.
And there is a normal vector for each vertex in face. Even if the vertex repeats itself.
Plane with one face : 4 vertices : 4 normal vectors (1 * 4)
Triangulated plane with 2 faces : 4 vertices : 6 normal vectors (2 * 3)
The question is that how should I interpret these values. The indices is only trying to explain the position data.
Let’s say there is 1000 vertex position, 2000 vertex texture coord, 4000 normal vectors. There is no possible way to create one vertex array out of these values.
struct Vertex {
glm::vec3 Position;
glm::vec2 TexCoord;
glm::vec3 Normal;
};
std::vector<glm::vec3> positions; //Contains vertex position data retrieved from the fbx file
std::vector<glm::vec3> normals; //Contains normal vectors retrieved from the fbx file
std::vector<glm::vec2> uvs; //Contains texture coordinates retrieved from the fbx file
std::vector<int> polygonVertexIndices; //Contains the indices retrieved from the fbx file
std::vector<int> uvIndices; //Contains the UV indices retrieved from the fbx file
std::vector<int> edges; //Contains the edges retrieved from the fbx file
std::vector<Vertex> meshVertices; // Destination vertices vector
std::vector<unsigned int> meshIndices; // Destination indices vector
for (size_t i = 0; i < positions.size(); i++)
{
Vertex vert;
vert.Position = positions[i];
vert.TexCoord; //Can't give a value
vert.Normal; //Can't give a value
//Everything is fine besides not being able to give a value to the texture coordinate & the normal vector variables..
meshVertices.push_back(vert);
}
for (size_t i = 0; i < polygonVertexIndices.size(); i++)
{
if(polygonVertexIndices[i] < 0)
meshIndices.push_back(abs(polygonVertexIndices[i] - 1));
else
meshIndices.push_back(polygonVertexIndices[i]);
}
I can render the 3D model pitch black (since the texture coordinates are always (glm::vec2(0))) using the meshVertices & the mesh indices.
Update 1 :
Could it be that the received data is not correct?
Update 2 :
What I’m exactly reading regarding the vertex data:
Objects
Geometry
-▲ ( 1 ) ( L )
-Plane☺Geometry ( 15 ) ( S )
-Mesh ( 4 ) ( S )
Properties70
GeometryVersion
-| ( 1 ) ( I )
Vertices
-┐┐More... ( 96 ) ( d )
PolygonVertexIndex
-☺♥² ( 16 ) ( i )
Edges
-☺☻♥ ( 16 ) ( i )
LayerElementNormal
- ( 1 ) ( I )
Version
-e ( 1 ) ( I )
Name
- ( 0 ) ( S )
MappingInformationType
-ByPolygonVertex ( 15 ) ( S )
ReferenceInformationType
-Direct ( 6 ) ( S )
Normals
-More... ( 96 ) ( d )
LayerElementUV
- ( 1 ) ( I )
Version
-e ( 1 ) ( I )
Name
-UVMap ( 5 ) ( S )
MappingInformationType
-ByPolygonVertex ( 15 ) ( S )
ReferenceInformationType
-IndexToDirect ( 13 ) ( S )
UV
-?More... ( 64 ) ( d )
UVIndex
-☻☺♥ ( 16 ) ( i )
Layer
- ( 1 ) ( I )
Version
-d ( 1 ) ( I )
LayerElement
Type
-LayerElementNormal ( 18 ) ( S )
TypedIndex
- ( 1 ) ( I )
LayerElement
Type
-LayerElementUV ( 14 ) ( S )
TypedIndex
- ( 1 ) ( I )
Model
-M ( 1 ) ( L )
-Plane☺Model ( 12 ) ( S )
-Mesh ( 4 ) ( S )
Version
-× ( 1 ) ( I )
Properties70
P
-Lcl Rotation ( 12 ) ( S )
-Lcl Rotation ( 12 ) ( S )
- ( 0 ) ( S )
-A ( 1 ) ( S )
-Ğ ( 1 ) ( D )
- ( 1 ) ( D )
- ( 1 ) ( D )
P
-Lcl Scaling ( 11 ) ( S )
-Lcl Scaling ( 11 ) ( S )
- ( 0 ) ( S )
-A ( 1 ) ( S )
-d ( 1 ) ( D )
-d ( 1 ) ( D )
-d ( 1 ) ( D )
P
-DefaultAttributeIndex ( 21 ) ( S )
-int ( 3 ) ( S )
-Integer ( 7 ) ( S )
- ( 0 ) ( S )
- ( 1 ) ( I )
P
-InheritType ( 11 ) ( S )
-enum ( 4 ) ( S )
- ( 0 ) ( S )
- ( 0 ) ( S )
-☺ ( 1 ) ( I )
MultiLayer
- ( 1 ) ( I )
MultiTake
- ( 1 ) ( I )
Shading
-☺ ( 1 ) ( C )
Culling
-CullingOff ( 10 ) ( S )
Connections
C
-OO ( 2 ) ( S )
-M ( 1 ) ( L )
- ( 1 ) ( L )
C
-OO ( 2 ) ( S )
-▲ ( 1 ) ( L )
-M ( 1 ) ( L )
Takes
Current
- ( 0 ) ( S )
Read more here: Source link