Hi,
When i try to render a basic obj file that i have imported with help of assimp. I cant see anything at all or just a random vertex., but i have no problem rendering objects that i have created from arrays or a more basic .obj importer. So Im starting to think that i have missed something basic here either in my assimp load function or some where else in the pipeline.
The random vertex that I see in some modules is starting to think that this is a index problem. But as i said im not sure.
This is how i define my input elelements.,
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
[source lang="cpp"] GraphicObject* Loader::LoadModel(wstring filename)
{
const struct aiScene* pScene = NULL;
char cFilename[MAX_PATH]="";
wcstombs(cFilename, filename.c_str(),sizeof(cFilename));
GraphicObject* obj = NULL;
pScene = aiImportFile(cFilename,
aiProcess_OptimizeMeshes |
aiProcess_ConvertToLeftHanded);
if (pScene->HasMeshes())
{
const aiMesh* pMesh = pScene->mMeshes[0];
UINT numVertices = pMesh->mNumVertices;
Vertex *vertices = new Vertex[numVertices];
for (UINT i=0;i< numVertices;i++)
{
vertices.pos = XMFLOAT3(pMesh->mVertices.x,pMesh->mVertices.y,pMesh->mVertices.z);
}
UINT numFaces = pMesh->mNumFaces;
UINT numIndices = numFaces*pMesh->mFaces[0].mNumIndices;
WORD *indices = new WORD[numIndices];
for(UINT i=0;i<numFaces;++i)
{
UINT numIndices = pMesh->mFaces.mNumIndices;
for (UINT n=0;n<numIndices;++n)
{
indices= (WORD)pMesh->mFaces.mIndices[n];
}
}
obj = LoadGeometry(_T("TEST"),vertices,indices,pMesh->mNumVertices,pMesh->mFaces->mNumIndices);
}[/source]
Can someone see if i do anything obviously wrong here?
Im not sure if im doing something wrong in just ASSIMP or its a combo DX11+ASSIMP, thats why i posted this here in the dx forum.
Problems importing mesh (assimp)
The loop variable 'i' is being incremented per face, but being used as the index to the indices array.
Thx beans222, I have now changed the loop to
[source lang="cpp"]TArray<WORD> indices;
for(UINT i=0;i<numFaces;++i)
{
UINT numIndices = pMesh->mFaces.mNumIndices;
for (UINT n=0;n<numIndices;n++)
{
indices.add((WORD)pMesh->mFaces.mIndices[n]);
}
}
[/source]
and also changed the vertex loop to use a TArray
[source lang="cpp"] TArray<Vertex> vertices;
for (UINT i=0;i< numVertices;i++)
{
Vertex vtex;
vtex.pos = XMFLOAT3(pMesh->mVertices.x,pMesh->mVertices.y,pMesh->mVertices.z);
vertices.add(vtex);
}[/source]
but it didnt solved my problem. Below is the data that the program parse, v is from the vertex array and i from indices
v 1.51758 , -1 , 1
v 1.51758 , -1 , -1
v -0.482425 , -1 , -1
v -0.482424 , -1 , 1
v 1.51758 , 1 , 0.999999
v -0.482424 , 1 , 1
v -0.482425 , 1 , -1
v 1.51758 , 1 , -1
v 1.51758 , -1 , 1
v 1.51758 , 1 , 0.999999
v 1.51758 , 1 , -1
v 1.51758 , -1 , -1
v 1.51758 , -1 , -1
v 1.51758 , 1 , -1
v -0.482425 , 1 , -1
v -0.482425 , -1 , -1
v -0.482425 , -1 , -1
v -0.482425 , 1 , -1
v -0.482424 , 1 , 1
v -0.482424 , -1 , 1
v 1.51758 , 1 , 0.999999
v 1.51758 , -1 , 1
v -0.482424 , -1 , 1
v -0.482424 , 1 , 1
i : 3
i : 2
i : 1
i : 0
i : 7
i : 6
i : 5
i : 4
i : 11
i : 10
i : 9
i : 8
i : 15
i : 14
i : 13
i : 12
i : 19
i : 18
i : 17
i : 16
i : 23
i : 22
i : 21
i : 20
Vetices : 24
Faces : 6
Indices size: 24
Size of indicies 16
and this is the data from the orginal file
v 1.517576 -1.000000 -1.000000
v 1.517576 -1.000000 1.000000
v -0.482425 -1.000000 1.000000
v -0.482424 -1.000000 -1.000000
v 1.517576 1.000000 -0.999999
v -0.482424 1.000000 -1.000000
v -0.482425 1.000000 1.000000
v 1.517575 1.000000 1.000001
s off
f 1 2 3 4
f 5 6 7 8
f 1 5 8 2
f 2 8 7 3
f 3 7 6 4
f 5 1 4 6
I have been working on this problem for a while now.. im pretty much stuck. My gut feeling is that I'm missing out on something very basic.
Anyone pls?
(I do recognize that the Directx/XNA forum might have been the wrong forum for this sorry.)
[source lang="cpp"]TArray<WORD> indices;
for(UINT i=0;i<numFaces;++i)
{
UINT numIndices = pMesh->mFaces.mNumIndices;
for (UINT n=0;n<numIndices;n++)
{
indices.add((WORD)pMesh->mFaces.mIndices[n]);
}
}
[/source]
and also changed the vertex loop to use a TArray
[source lang="cpp"] TArray<Vertex> vertices;
for (UINT i=0;i< numVertices;i++)
{
Vertex vtex;
vtex.pos = XMFLOAT3(pMesh->mVertices.x,pMesh->mVertices.y,pMesh->mVertices.z);
vertices.add(vtex);
}[/source]
but it didnt solved my problem. Below is the data that the program parse, v is from the vertex array and i from indices
v 1.51758 , -1 , 1
v 1.51758 , -1 , -1
v -0.482425 , -1 , -1
v -0.482424 , -1 , 1
v 1.51758 , 1 , 0.999999
v -0.482424 , 1 , 1
v -0.482425 , 1 , -1
v 1.51758 , 1 , -1
v 1.51758 , -1 , 1
v 1.51758 , 1 , 0.999999
v 1.51758 , 1 , -1
v 1.51758 , -1 , -1
v 1.51758 , -1 , -1
v 1.51758 , 1 , -1
v -0.482425 , 1 , -1
v -0.482425 , -1 , -1
v -0.482425 , -1 , -1
v -0.482425 , 1 , -1
v -0.482424 , 1 , 1
v -0.482424 , -1 , 1
v 1.51758 , 1 , 0.999999
v 1.51758 , -1 , 1
v -0.482424 , -1 , 1
v -0.482424 , 1 , 1
i : 3
i : 2
i : 1
i : 0
i : 7
i : 6
i : 5
i : 4
i : 11
i : 10
i : 9
i : 8
i : 15
i : 14
i : 13
i : 12
i : 19
i : 18
i : 17
i : 16
i : 23
i : 22
i : 21
i : 20
Vetices : 24
Faces : 6
Indices size: 24
Size of indicies 16
and this is the data from the orginal file
v 1.517576 -1.000000 -1.000000
v 1.517576 -1.000000 1.000000
v -0.482425 -1.000000 1.000000
v -0.482424 -1.000000 -1.000000
v 1.517576 1.000000 -0.999999
v -0.482424 1.000000 -1.000000
v -0.482425 1.000000 1.000000
v 1.517575 1.000000 1.000001
s off
f 1 2 3 4
f 5 6 7 8
f 1 5 8 2
f 2 8 7 3
f 3 7 6 4
f 5 1 4 6
I have been working on this problem for a while now.. im pretty much stuck. My gut feeling is that I'm missing out on something very basic.
Anyone pls?
(I do recognize that the Directx/XNA forum might have been the wrong forum for this sorry.)
Are you actually rendering quads? If not, you should have assimp make triangles (aiProcess_Triangulate). Also use aiProcess_JoinIdenticalVertices otherwise assimp will assume you don't want to be using an index buffer.
Hi, no your are right..Its triangles that im tryning to render. So i changed aiImportFile to pScene = aiImportFile(cFilename,
aiProcess_JoinIdenticalVertices|
aiProcess_Triangulate|
aiProcess_OptimizeMeshes|
aiProcess_ConvertToLeftHanded
);
First it didnt work, but now for some reason it started to work, maybe some lib wasn't correcly updated in the build process. Any how it works. the for you help beans222
aiProcess_JoinIdenticalVertices|
aiProcess_Triangulate|
aiProcess_OptimizeMeshes|
aiProcess_ConvertToLeftHanded
);
First it didnt work, but now for some reason it started to work, maybe some lib wasn't correcly updated in the build process. Any how it works. the for you help beans222
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement