Exactly how the question says , how does the vertex properties like vertex stride and the data stored in the mesh part decided based on the format of a model and how would i determine that and then decide which vertexdeclaration to be used properly

For ex - a .obj model might or might not have vt data , vn data based on which it may have a different data in the meshpart . How would i go about deciding which vertex declaration to use to properly decode the data in that mesh's vertex buffer


1 Answer 1


What I do in cases like this is just use the same vertex declaration but just set the missing elements to zero.

I use assimp for all my mesh importing so it will be a bit different but I just check like this:

  Dim hasTexCoords As Boolean = mesh.HasTextureCoords(0)
  Dim hasColors As Boolean = mesh.HasVertexColors(0)
  Dim hasNormals As Boolean = mesh.HasNormals
  Dim hasTangents As Boolean = mesh.Tangents IsNot Nothing
  Dim hasBitangents As Boolean = mesh.BiTangents IsNot Nothing
  Dim hasBW As Boolean = mesh.Bones IsNot Nothing

        Dim Verts As New List(Of PCTNTBNSkinned_ImportType)
                For i As Integer = 0 To mesh.VertexCount - 1
                    Dim Vertex As New PCTNTBNSkinned_ImportType
                    Vertex.Position = FromVector(mesh.Vertices(i))
                    If hasColors Then
                        Vertex.Color = FromColor(mesh.VertexColorChannels(0)(i))
                    End If
                    If hasNormals Then
                        Vertex.Normal = FromVector(mesh.Normals(i))
                    End If
                    If hasTangents Then
                        Vertex.Tangent = FromVector(mesh.Tangents(i))
                    End If
                    If hasBitangents Then
                        Vertex.BiNormal = FromVector(mesh.BiTangents(i))
                    End If
                    If hasTexCoords Then
                        Vertex.TexCoord = New Vector2(mesh.TextureCoordinateChannels(0)(i).X, mesh.TextureCoordinateChannels(0)(i).Y)
                    End If

that way if my shader needs an element its there and I can just add another processing step to my mesh importing to add the missing data.

You end up with a bit of waist if the shader u are using doesn't need all that vertex data u are sending but at lest it gets u up and running.

90% of my meshes use the same shader so for me its not an issue


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .