Loading Models With Assimp Directx 11

Started by
6 comments, last by ExErvus 7 years, 9 months ago

Are there any tutorials to load models with assimp in c++ directx 11?

I searched, could not find anything. Mostly opengl stuff.

thx

Advertisement

So far, i have:


Assimp::Importer importer;



    const aiScene * scene = importer.ReadFile("untitled.obj", aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);




Next steps?


std::vector<Vertex::Basic32> vertices(8);
	Assimp::Importer importer;



    const aiScene * scene = importer.ReadFile("untitled.obj", aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);

	aiMesh *mesh = scene->mMeshes[0]; 
	
   for(int i = 0;i<8;i++)
   {
	  
{
	
aiVector3D pos = mesh->mVertices[i];
 
vertices[i].Pos.x    =  pos.x;
vertices[i].Pos.y    =  pos.y;
vertices[i].Pos.z    =  pos.z;
	}
	

   }
   std::vector<UINT> indices;

 for (int i = 0; i < mesh->mNumFaces; i++) {
    const aiFace& Face = mesh->mFaces[i];
    if(Face.mNumIndices == 3) {
        indices.push_back(Face.mIndices[0]);
        indices.push_back(Face.mIndices[1]);
        indices.push_back(Face.mIndices[2]);

}

 }

My code now loads the cube and now need to load normal and texture....

I can pretty much load any model. But cant find code to load textures.??

There is no way to load texture via Assimp. Assimp will only hold the name of the texture for you. You must load those images with some other library, or write it yoursellf.

STB image library is a good start.

or seeing this is a DX11 app try DXTK which is a replacement for D3DX functions. It will load textures straight into SRVs so that you can use them in pixelshaders. https://directxtk.codeplex.com/

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

But what are these then.("mTextureCoords")


vec.x = mesh->mTextureCoords[0][i].x; 
vec.y = mesh->mTextureCoords[0][i].y;

I'm loading a .OBJ. So are these "mTextureCoords" are "vt" values?

I tested the mTextureCoords values in my debugger and they were different so just wondering.

Those are UV coordinates. I have never used Assimp, but have looked into its functionality. as imoogi already said, you will have to load the texture yourself using the texture path that Assimp gives you.

I can pretty much load any model. But cant find code to load textures.??

You shouldn't be trying to "find the code" to load a texture or for anything you want to accomplishing in programming. You should understand your tools, then use your accrued knowledge to put the pieces together yourself. It is usually boilerplate code that you will ever "need to find" which only sets you up, but does not accomplish your task. Read a book, take a class, LEARN to code, not copy/paste.

This topic is closed to new replies.

Advertisement