Trying to texture a model

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Uberbot
Posts: 31
Joined: Thu Dec 13, 2007 4:07 am

Trying to texture a model

Post by Uberbot »

Hi all,

I'm trying to apply a texture to a mesh.

I created a house model in Blender and exported it to .obj format. Then I downloaded a brick.jpg texture.

Now I want to make the walls of my house look like... brick. But I also want to eventually apply a different texture to the floor and roof.

Here is what I'm doing:
//############################################
scene::IMeshSceneNode* node;
scene::IAnimatedMesh* house;

house = smgr->getMesh("./house_Scene.obj");
node = smgr->addMeshSceneNode(house);
node->setMaterialTexture(0,driver->getTexture("graph/brick.jpg"));
//############################################

What I end up with is a completely grey house. I was able to apply a .jpg texture to a boxnode, so I believe my lighting is correct.

I do NOT want to UV map this building, as it is fairly complex.

What am I missing?

Here is a rendering of my Blender model:
Image[/img]
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Trying to texture a model

Post by Acki »

Uberbot wrote:Here is what I'm doing:
//############################################
scene::IMeshSceneNode* node;
scene::IAnimatedMesh* house;

house = smgr->getMesh("./house_Scene.obj");
node = smgr->addMeshSceneNode(house);
node->setMaterialTexture(0,driver->getTexture("graph/brick.jpg"));
//############################################

What I end up with is a completely grey house. I was able to apply a .jpg texture to a boxnode, so I believe my lighting is correct.

I do NOT want to UV map this building, as it is fairly complex.

What am I missing?
the problem is that with setMaterialTexture you apply the texture to all mesh buffers and this is not what you want !!! ;)

the easiest way is to apply the textures in blender...
I think UV mapping is not naccessary there, just apply the textures to the parts they belong to...

or you can create a mesh for each part that uses a different texture (not recomended though)...

or you can use my IrrExtensions, there I extended the setMaterialTexture function so you're able to apply a texture to any mesh buffer you want to... :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Uberbot
Posts: 31
Joined: Thu Dec 13, 2007 4:07 am

Post by Uberbot »

the problem is that with setMaterialTexture you apply the texture to all mesh buffers and this is not what you want !!! Wink
No, it sure isn't.
the easiest way is to apply the textures in blender...
But, as you can see from the attached screenshot, I HAVE applied the texture in blender...
I think UV mapping is not naccessary there, just apply the textures to the parts they belong to...

or you can create a mesh for each part that uses a different texture (not recomended though)...

or you can use my IrrExtensions, there I extended the setMaterialTexture function so you're able to apply a texture to any mesh buffer you want to... Laughing
Ya, UV mapping is overkill and quite complicated in this case. I really want this model to export in once piece, so separate meshes is not recommended, as you mention.

Finally, I'm hoping to be able to do this in standard Irrlicht, without any extensions. Though your extensions look interesting....

Any ideas as to what I'm doing wrong?
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Post by Catprog »

What you need to do is to get each mesh buffer (each one is a different texture). I am assuming you have multiple textures in the mesh and not one big texture.

Try something like this. (I think)

Code: Select all

int bufferCount =  house->getMeshBufferCount ();

IMeshBuffer* buffer = house->getMeshBuffer(1);

video::SMaterial mat =	buffer ->getMaterial ();

mat->setTexture(0,driver->getTexture("graph/brick.jpg"));
EDIT:Another thing you can do is to not set the material and it might use the ones in the file.(I think)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Uberbot wrote:But, as you can see from the attached screenshot, I HAVE applied the texture in blender...
yes, but as far as you use setMaterialTexture all textures are getting the same (the one you apply with it)... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you load a .obj file which does not provide UV coords (as it's probably in this case), all texcoords are (0,0). So when applying the texture, the object should get the color of the upper-left pixel of the texture, nothing more. Do the UV mapping and it will work, or try makePlanarTextureMapping.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

UV map isn't hard no matter how complex is your building.
use ultimate unwrap, you can attach multiple textures, and hide UV maps what aren't you doing at present.
Uberbot
Posts: 31
Joined: Thu Dec 13, 2007 4:07 am

Post by Uberbot »

Catprog wrote:What you need to do is to get each mesh buffer (each one is a different texture). I am assuming you have multiple textures in the mesh and not one big texture.

Try something like this. (I think)

Code: Select all

int bufferCount =  house->getMeshBufferCount ();

IMeshBuffer* buffer = house->getMeshBuffer(1);

video::SMaterial mat =	buffer ->getMaterial ();

mat->setTexture(0,driver->getTexture("graph/brick.jpg"));
EDIT:Another thing you can do is to not set the material and it might use the ones in the file.(I think)
OK, so this is what I've got so far:
============================
house = smgr->getMesh("./house.obj");

node = smgr->addMeshSceneNode(house);

int count = house->getMeshBufferCount();
scene::IMeshBuffer* buffer = house->getMeshBuffer(1);
video::SMaterial mat = buffer->getMaterial();
(&mat)->setTexture(0,driver->getTexture("graph/brick.jpg"));

//node->setMaterialFlag(EMF_LIGHTING, false);
//node->setMaterialTexture(0,driver->getTexture("graph/brick.jpg"));
============================

I've commented out the code that everyone said I didn't need. I had to take the address of the SMaterial mat in order to get access to the setTexture() function. Still, my house is grey.

It's been suggested that I use Ultimate Unwrap. But since I don't use Windows, I can't use this option.

I've seen some pretty amazing screenshots in this forum, so I know this is being done... a lot. What am I doing wrong that's making this so hard? I was under the impression that a lot of people were modeling with Blender for Irrlicht. If so, what are they doing differently?

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

Post by hybrid »

By copying the material you got from getMaterial() you lose the relation of the material with the mesh. By changing that new material you'll see absolutely no results. Instead, just store the pointer and use it instead of the adress of the object.
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

Hallow,

I usually just use this code and should work ok with no more processing

house = smgr->getMesh("./house_Scene.obj");
node = smgr->addMeshSceneNode(house);

just make sure the .mtl and all texture files are in the same folder as .obj
Uberbot
Posts: 31
Joined: Thu Dec 13, 2007 4:07 am

Post by Uberbot »

Allright, now I'm making progress....

At least now I have an error message on the console!

Here is the code:

======================
house = smgr->getMesh("./graph/house_Scene.obj");
node = smgr->addMeshSceneNode(house);
======================

Here is the error message I get on the console:
======================
Could not open file of texture: ./graph/House
Loaded mesh: ./graph/house_Scene.obj
======================

I've put the .tga, .mtl, and .obj files all in the ./graph directory, as you indicated.

I don't see the "House" file created. Where is this file supposed to come from and what format is it in?

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

Post by hybrid »

The "House" file is up to you, it seems to be mentioned in your .mtl file. However, Irrlicht doesn't seem to recognize the format, or the file simply has a different name. Just Edit the .mtl file to specify the correct filename.
Uberbot
Posts: 31
Joined: Thu Dec 13, 2007 4:07 am

Now I'm confused.

Post by Uberbot »

I was also expecting House to be mentioned in the .mtl file, but it's not.

Here is the contents of house.mtl
======================
# Blender3D MTL File: house.blend
# Material Count: 3
newmtl (null)
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.690196 0.219608 0.219608
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2


newmtl Material.001
Ns 92.156863
Ka 0.000000 0.000000 0.000000
Kd 0.258510 0.195765 0.195765
Ks 0.250000 0.250000 0.250000
Ni 1.000000
d 1.000000
illum 2


newmtl Material.003
Ns 92.156863
Ka 0.000000 0.000000 0.000000
Kd 0.396549 0.333804 0.333804
Ks 0.250000 0.250000 0.250000
Ni 1.000000
d 1.000000
illum 2
======================

So, I don't know where the error message came from, then.
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

Hello,

your exporter might have problem. I am using max and my .mtl looks something like below. as you will see, the texture file is specified in the mtl, in my case the jpg files

maybe a blender expert can help you

# Max2Mtl Version 4.0 Mar 10th, 2001
#
newmtl 01_-_Default
Ka 0.6 0.6 0.6
Kd 0.6 0.6 0.6
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
map_Kd txt1.jpg
#
newmtl 02_-_Default
Ka 0.6 0.6 0.6
Kd 0.6 0.6 0.6
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
map_Kd txt2.jpg
#
newmtl 07_-_Default
Ka 0.6 0.6 0.6
Kd 0.6 0.6 0.6
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
map_Kd wase.jpg
#
newmtl 03_-_Default
Ka 0.6 0.6 0.6
Kd 0.6 0.6 0.6
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
map_Kd txt3.jpg
#
# EOF
Post Reply