Page 1 of 1

Texture on a custom node

Posted: Fri Jun 26, 2015 12:22 pm
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.

Re: Texture on a custom node

Posted: Fri Jun 26, 2015 8:50 pm
by sudi
you need uv coordinates on your custom mesh

Re: Texture on a custom node

Posted: Sun Jun 28, 2015 2:52 pm
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.

Re: Texture on a custom node

Posted: Mon Jun 29, 2015 7:00 am
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.

Re: Texture on a custom node

Posted: Tue Jun 30, 2015 1:45 pm
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 ?

Re: Texture on a custom node

Posted: Tue Jun 30, 2015 2:21 pm
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

Re: Texture on a custom node

Posted: Tue Jun 30, 2015 2:34 pm
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 :)

Re: Texture on a custom node

Posted: Tue Jun 30, 2015 3:06 pm
by CuteAlien
Please show the code you use to set the uv's.

Re: Texture on a custom node

Posted: Tue Jun 30, 2015 3:23 pm
by BillyCallahan
Hello,

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

Thank you man :)