Loading multitexture object

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Loading multitexture object

Post by Auradrummer »

Hello All,

This is a very simple code that can be avoid a bunch of problems to you. It will allows you to load a mesh with more than one texture on it.

This is the function:

Code: Select all

SMesh* loadmesh (const c8* file, const c8* texes[])
{
	u32 i;
	IMesh* box = smgr->getMesh(file);
	SMesh* mesh = new SMesh();
	u32 meshbuffer=box->getMeshBufferCount();

	for (i=0; i < meshbuffer; i++)
	{
		IMeshBuffer* part0 = box->getMeshBuffer(i);
		mesh->addMeshBuffer(part0);
		mesh->MeshBuffers[i]->getMaterial().setTexture( 0, driver->getTexture(texes[i]) );
		printf("LWO Loader mutitexture: %s loaded \n",texes[i]);
	}
	return mesh;
This is the function call, that you'll place where you want to load your mesh.

Code: Select all

const c8* car=".../address and name of your mesh/...";
const c8* tex[n+1]; // number of textures of mesh plus 1
tex[1] = ".../address and name of your first texture/ ...";
tex[2] = ".../address and name of your second texture/ ...";
.
.
.
tex[n] = ".../address and name of your 'n' texture/...";

SMesh* box2;
box2 = loadmesh(car,tex);
Be aware, the texture indexes begin at 1.

That's it.
Last edited by Auradrummer on Mon Jun 02, 2008 1:35 pm, edited 1 time in total.
Professional Software Developer and Amateur Game Designer ;-)
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

that's a nicely written tutorial.

thank you.
Image
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Why don't you use the original mesh :?
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post by Auradrummer »

Thanks dlanglev :wink:

hybrid: I'm using LWO, and inside LWO the path to the texture aren't correct. This is because I'm programming under Linux, and my models have to be done under Windows.

And this code I posted open more possibilities. I think, for example, that if I try to load a reflection map in only one of these meshbuffers I'll can. I think I can even one of the meshbuffers wireframe.

This is possibilities, that I don't tested, but in my case is because the path of textures.
Professional Software Developer and Amateur Game Designer ;-)
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

But I think hybrid wants to know why you don't just do:

Code: Select all

for (i=0; i < meshbuffer; i++)
{ 
    box->getMeshBuffer(i)->getMaterial().setTexture( 0, driver->getTexture(texes[i]) ); 
}
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Moreover, the mesh loader should handle the problematic paths, not the user afterwards. The typical loading of textures in Irrlicht is as follows: First the full path, then the mesh's path, then the current working directory, some mesh types also have a scene manager attribute to set another path. The textures should be in one of these locations.
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post by Auradrummer »

BlindSide: I don't remember if I tried exactly what you posted, but I remember I tried to get Mesh Buffers from an IMesh and failed, and 'box' is an IMesh. So I converted to SMesh first, than generated the SceneNode.
But, this solution I found is that one I was capable to implement, due my inexperience in Irrlicht. I read the API trying to find anything better without success. This explains why I don't made anything easier. But I'll appreciate a lot if someone presents a better solution.

Hybrid: Loading LWO this don't works, at least here. When I load my object, Various log's appears. Among them there are some that says "c:\documents\texes ... \tex.jpg cannot load" (or something like this). This path is the one I used in Windows when I built the object. If I don't specify a new texture, the mesh will be drawn with the base color of the texture, as in Linux that path doesn't exists.
Professional Software Developer and Amateur Game Designer ;-)
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post by Auradrummer »

Really, my function is not able to load two meshes. I have to look into it. Hybrid, do you have some tip to me that can help me to make the natural loader function works? :mrgreen:
Professional Software Developer and Amateur Game Designer ;-)
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post by Auradrummer »

Really, hybrid, is fully working that feature. The problem is that I was placing texes and meshes in different places. If everything is in the same place, all works. I spent about four days to load those textures...... :|
..................................... BUT I STILL GOT A MEDAL OF BEST GOALKEEPER OF 1996 AMATEUR CHAMPIONSHIP :D
Professional Software Developer and Amateur Game Designer ;-)
Post Reply