Texture problem for my 3D format loader

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Yusaku
Posts: 8
Joined: Sun Jun 10, 2007 3:43 am

Texture problem for my 3D format loader

Post by Yusaku »

I grabbed the code from MS3D file loader and tried to create my own format loader (It's from my 3Dmax export plugin, but since it's working fine in my file viewer, I'm quite sure it's not the problem of the file).

When I render this model in Irrlicht, the polygons are fine, but it's always black... I checked renderring code and my texture it's not NULL. Can you point out my mistakes within my file loader code? Thx a million...

(in step 1, I'd load information into ikkModel)

Code: Select all

	// 2. Convert to AnimatedMesh -------------------------

	if(ikkModel.nNumMat == 0)
	{
		// if there are no materials, add at least one buffer
		AnimatedMesh->createBuffer();
	}

	IKK_ASSERT(ikkModel.nNumMat == ikkModel.nNumTxtr);

	for (i=0; i<ikkModel.nNumMat; ++i)
	{
		scene::SSkinMeshBuffer *tmpBuffer = AnimatedMesh->createBuffer();

		tmpBuffer->Material.MaterialType = video::EMT_SOLID;

		// how to set these color values? we don't have these information in IkkModel yet... then I set all the values to default value of 3DMax
		tmpBuffer->Material.AmbientColor = video::SColorf(.2f, .2f, .2f, 1.f).toSColor();
		tmpBuffer->Material.DiffuseColor = video::SColorf(.8f, .8f, .8f, 1.f).toSColor();
		tmpBuffer->Material.EmissiveColor = video::SColorf(0.f, 0.f, 0.f, 1.f).toSColor();
		tmpBuffer->Material.SpecularColor = video::SColorf(0.f, 0.f, 0.f, 1.f).toSColor();
		tmpBuffer->Material.Shininess = 0;

		core::stringc TexturePath( ikkModel.pTxtr[ikkModel.pMat[i].nTxtrID].sName );
		if (TexturePath.trim()!="")
		{
			TexturePath=stripPathFromString(file->getFileName(),true) + stripPathFromString(TexturePath,false);
			tmpBuffer->Material.setTexture(0, Driver->getTexture(TexturePath.c_str()) );
		}

		core::stringc AlphamapPath="";				// no alpha map yet
		if (AlphamapPath.trim()!="")
		{
			AlphamapPath=stripPathFromString(file->getFileName(),true) + stripPathFromString(AlphamapPath,false);
			tmpBuffer->Material.setTexture(2, Driver->getTexture(AlphamapPath.c_str()) );
		}
	}

	// create vertices and indices, attach them to the joints.
	video::S3DVertex v;
	core::array<video::S3DVertex> *Vertices;
	core::array<u16> Indices;

	for (i=0; i<ikkModel.nNumMesh; ++i)
	{
		u32 nMatID = ikkModel.pMesh[i].nMatID;
		Vertices = &AnimatedMesh->getMeshBuffers()[nMatID]->Vertices_Standard;

		for (j = 0; j<ikkModel.pMesh[i].nNumVert; ++j)
		{
			v.TCoords.X = ikkModel.pMesh[i].pUV[j*2+0];
			v.TCoords.Y = ikkModel.pMesh[i].pUV[j*2+1];

			v.Normal.X = ikkModel.pMesh[i].pNor[j*3+0];
			v.Normal.Y = ikkModel.pMesh[i].pNor[j*3+1];
			v.Normal.Z = ikkModel.pMesh[i].pNor[j*3+2];

			IkkMat& ikkMat = ikkModel.pMat[ ikkModel.pMesh[i].nMatID ];
			v.Color.set(ikkMat.bColor[0], ikkMat.bColor[1], ikkMat.bColor[2], ikkMat.bColor[3]);

			v.Pos.X = ikkModel.pMesh[i].pPos[j*3+0];
			v.Pos.Y = ikkModel.pMesh[i].pPos[j*3+1];
			v.Pos.Z = ikkModel.pMesh[i].pPos[j*3+2];

			// check if we already have this vertex in our vertex array
			s32 index = -1;
			for (u32 iV = 0; iV < Vertices->size(); ++iV)
			{
				if (v == (*Vertices)[iV])
				{
					index = (s32)iV;
					break;
				}
			}

			if (index == -1)
			{
				index = Vertices->size();

				Vertices->push_back(v);
			}
			Indices.push_back(index);
		}


		// Add indices into IMeshBuffer
		core::array<u16>& indices = AnimatedMesh->getMeshBuffers()[nMatID]->Indices;
		for(j=0; j<ikkModel.pMesh[i].nNumIdx; ++j)
			indices.push_back(Indices[ ikkModel.pMesh[i].pIdx[j] ]);
	}

hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Lighting enabled without a light source? Wrong face orientation with backface culling disabled? Wrong/scaled normals? Can be so much which could be wrong here, I guess you have to debug some more on your own...
Post Reply