Texture on a custom node

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
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Texture on a custom node

Post by BillyCallahan »

Hello (again),

Here's my problem: I created a custom node (with the code of the third tutorial), my custom node is beam wood (at least the shape).
I tried to put a texture on it but it's scaling it not repeating it, so instead of having my beam that looks like wood : I get a brown beam (all brown).
So far I found out that:
I can't set a repeated texture to an ISceneNode, I have to create an IMeshNode to set my texture to every meshBuffer.
Does it mean I have change all my code ? I spent so much time on it...

I also found this:

Code: Select all

 
scene::IAnimatedMesh *room = scenegraph->getMesh("room.3ds");
scene::IMeshSceneNode *Nroom = scenegraph->addMeshSceneNode(room->getMesh(0));
 
Nroom->setMaterialFlag(video::EMF_LIGHTING, true);
 
scenegraph->getMeshManipulator()->makePlanarTextureMapping(room->getMesh(0), 0.04f);
 
Nroom->setMaterialTexture( 0, driver->getTexture("rockwall.bmp") );
But it needs a mesh...

Thank you,
Billy.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Re: Texture on a custom node

Post by sudi »

you need uv coordinates on your custom mesh
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Re: Texture on a custom node

Post by kornwaretm »

yes uv coordinate required. check the S3DVertex constructor parameters, you should find the u and v coordinate. u for horizontal and v for vertical in texture space. 0,0 for upper top, and 1,1 for lower bottom. for tiling you can use bigger number basically 0.0 , 0.0 and 2.0, 2.0 will repeat the texture twice or you will have 4 tiles.
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Texture on a custom node

Post by BillyCallahan »

Hola !

Okay thanks for your answers, you saved me :)
I 'm trying to draw a parallelepiped rectangle (8 vertex) but I don't know exactly which coordinates I've to set...
I set 0.0/2.0 everywhere but of course it's not working.
I saw this : http://irrlicht.sourceforge.net/forum/v ... p?p=219161 but still...can't figure out how it works.
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Texture on a custom node

Post by BillyCallahan »

Up :)

EDIT: After about 100 tests...I can draw my parallelepiped rectangle with three faces textured because these are the faces already defined into the vertice tab.
It means I'd need 14 vertex to textured all faces, right ?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Texture on a custom node

Post by CuteAlien »

The way it works is - left top point in your texture has uv 0,0 and right-bottom point in your textures has 1,1. All other points on your textures have uv's in between.
So for each vertex you have to think about which point on the texture should be at that vertex. And use corresponding values between 0 and 1.

When you use values outside the 0-1 range it depends on the E_TEXTURE_CLAMP setting you use. You can set that in SMaterial for each TextureLayer with TextureWrapU and TextureWrapV. You have the following options: http://irrlicht.sourceforge.net/docu/na ... f84b39811f
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Texture on a custom node

Post by BillyCallahan »

Okay thank you for E_CLAMP :)

About the rest, I already got it. But somehow, I can't understand why there's still some faces left un-textured...
Here's a quick draw, the numbers are the vertex I defined and the '?' those I didn't (even there are the same).

Image


And here's what I get...

Image

Image

Don't mind the the thin black line, that's the axis :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Texture on a custom node

Post by CuteAlien »

Please show the code you use to set the uv's.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Texture on a custom node

Post by BillyCallahan »

Hello,

It finally works out !
I ended up defining 14 vertex to set a different texture for each faces :)

Thank you man :)
Post Reply