Hi again!
i wrote an application that load obj from exported file from maya and render it with directx11 , i succeeded to load the obj file but my problem is in render function.
if i render the mesh ( in this case an cube ) without indices i see the vertices of the mesh ( i use D3D11_PRIMITIVE_TOPOLOGY_POINTLIST) , but if i render using indices i get extra vertex in the middle of the mesh that did not exist in obj file at all !!
the render view
[attachment=6145:Capture.JPG]
i will post the part of the code that create the vertex and index buffers
this function is to load obj file ;
CL_Mesh
main.cpp
main.cpp
any help !!
load obj from maya into dx11 problem !
thats because obj files assume arrays start with "1", unlike c++ where arrays start with "0". For example, in an obj file, the index list might start with this triangle:
1,2,3
but in c++ when you store the vertices, the first triangle would actually look like this:
0,1,2
so you need to subtract 1 from every index in the index list when loading in the obj file
also, make sure that the obj file you are loading defines it's index list as TRIANGLES and not polygons such as squares, since a lot of the time obj exporters will not check that and give you a list of polygons instead of triangles. If that is the case, you can check in your code to see if there is more than 3 vertices per polygon, and if there is, just make another triangle with the next vertex, last vertex of previous triangle, and first vertex of the entire polygon.
for example, and obj file index list might look like this:
1,2,3,4
notice how its a square. you can change it so its like this:
1,2,3
1,3,4
and you could do it for polygons with more sides like this for an example:
1,2,3,4,5,6
to
1,2,3
1,3,4
1,4,5
1,5,6
so that ever vertex after the first three creates a new triangle.
(btw, in case this could possibly be of use to you http://braynzarsoft.mezoka.com/index.php?p=D3D11OBJMODEL)
1,2,3
but in c++ when you store the vertices, the first triangle would actually look like this:
0,1,2
so you need to subtract 1 from every index in the index list when loading in the obj file
also, make sure that the obj file you are loading defines it's index list as TRIANGLES and not polygons such as squares, since a lot of the time obj exporters will not check that and give you a list of polygons instead of triangles. If that is the case, you can check in your code to see if there is more than 3 vertices per polygon, and if there is, just make another triangle with the next vertex, last vertex of previous triangle, and first vertex of the entire polygon.
for example, and obj file index list might look like this:
1,2,3,4
notice how its a square. you can change it so its like this:
1,2,3
1,3,4
and you could do it for polygons with more sides like this for an example:
1,2,3,4,5,6
to
1,2,3
1,3,4
1,4,5
1,5,6
so that ever vertex after the first three creates a new triangle.
(btw, in case this could possibly be of use to you http://braynzarsoft.mezoka.com/index.php?p=D3D11OBJMODEL)
thats because obj files assume arrays start with "1", unlike c++ where arrays start with "0". For example, in an obj file, the index list might start with this triangle:
1,2,3
but in c++ when you store the vertices, the first triangle would actually look like this:
0,1,2
so you need to subtract 1 from every index in the index list when loading in the obj file
also, make sure that the obj file you are loading defines it's index list as TRIANGLES and not polygons such as squares, since a lot of the time obj exporters will not check that and give you a list of polygons instead of triangles. If that is the case, you can check in your code to see if there is more than 3 vertices per polygon, and if there is, just make another triangle with the next vertex, last vertex of previous triangle, and first vertex of the entire polygon.
for example, and obj file index list might look like this:
1,2,3,4
notice how its a square. you can change it so its like this:
1,2,3
1,3,4
and you could do it for polygons with more sides like this for an example:
1,2,3,4,5,6
to
1,2,3
1,3,4
1,4,5,
1,5,6
so that ever vertex after the first three creates a new triangle.
(btw, in case this could possibly be of use to you http://braynzarsoft....p=D3D11OBJMODEL)
thank you !! it's work now
but i have another problem
in general DXSDK tutorial each vertex have only one uv coordinate , but in the obj file i have more than uv for each vertex why ? how i do to render the texture without using mtl at all !?
thank you again !
I don't exactly understand your first question, but you should know that the number of vertex positions, texture coordinates, and normals are not the same. This prevents duplicates from being written to the file. The index list will say which positions, texture coords, and normals to use for each vertex.
You don't have to have a material to render a texture. you can just send whatever texture you want to the shader before you draw your geometry. This means you don't have to load the obj's mtl file
You don't have to have a material to render a texture. you can just send whatever texture you want to the shader before you draw your geometry. This means you don't have to load the obj's mtl file
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement