Create 3D Box with "on-the-fly"-textures

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
b0wter
Posts: 4
Joined: Mon Oct 14, 2013 4:26 pm

Create 3D Box with "on-the-fly"-textures

Post by b0wter »

I am new to the Irrlicht engine and I need to create a bunch of cubes and texture them. Usually I would create models for the boxes in a 3d editor and texture them there but I need to be able to assign the textures the moment I create the box.
Until now, I have no idea on how to achieve this. I've taken a look at the "render-to-texture" tutorial but it seems unnecessary complex to handle such a task. Are there any better ways?
tothex
Posts: 5
Joined: Tue Sep 24, 2013 5:38 pm

Re: Create 3D Box with "on-the-fly"-textures

Post by tothex »

Hi i am also new here
this code creates the cube and sets the texture you want

Code: Select all

 
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
 
IMeshSceneNode *meshnode = smgr->addCubeSceneNode(10,0,1,vector3df(5,100,25),vector3df(0,0,0),vector3df(5,5,5)); //create the cube
ITexture* texture= driver->getTexture("C:\\irrlicht-1.8\\media\\wall.jpg"); //create  texture
ITexture* texture2= driver->getTexture("C:\\irrlicht-1.8\\media\\water.jpg"); //create  texture
meshnode->setMaterialTexture(0,texture);  //set the texture
 
take a look at tutorial 4 Movement it has good examples
b0wter
Posts: 4
Joined: Mon Oct 14, 2013 4:26 pm

Re: Create 3D Box with "on-the-fly"-textures

Post by b0wter »

Awesome, thanks! :)
I'll have a look at the tutorial.
b0wter
Posts: 4
Joined: Mon Oct 14, 2013 4:26 pm

Re: Create 3D Box with "on-the-fly"-textures

Post by b0wter »

Do you also know if there is the possibility to display different textures on the different sides of the cube? Maybe I can use different layers of textures with different texture mappings?
CuteAlien
Admin
Posts: 10012
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Create 3D Box with "on-the-fly"-textures

Post by CuteAlien »

2 choices:
- Using independent meshbuffers for each side of the cube. Then you can just set the materials for each one on it's own.
- Using one huge texture with everything you want to display in it. Then you can set the uv-coordinates of the corners to the corresponding parts of the texture.
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
b0wter
Posts: 4
Joined: Mon Oct 14, 2013 4:26 pm

Re: Create 3D Box with "on-the-fly"-textures

Post by b0wter »

Thanks for the Info!
Putting all texture into a really large one is no problem so I will probably stick to that solution. I guess I will just need to shift the texture with setTextureTranslate(...)?
( http://www.irrlicht3d.org/wiki/index.ph ... dMaterials )
CuteAlien
Admin
Posts: 10012
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Create 3D Box with "on-the-fly"-textures

Post by CuteAlien »

Hm, no - because then the whole texture is shifted which I think wouldn't help you. What you want to do in that case is set the uv-coordinates for each vertex. And I really hope the default cube has 24 vertices and the sides don't share them or this will not work (then you have to create your own cube where that is the case).

You get the vertices from the meshbuffer (which you get from the mesh, which you get from the node). The result of getVertices () can be casted to the vertex type you are using. So for type EVT_STANDARD you would cast to irr::video::S3DVertex. UV coordinates in there are called TCoords: http://irrlicht.sourceforge.net/docu/st ... ertex.html
And they describe the position of that vertex on your texture in coordinates from 0-1 (0,0 would be left-top, 1,1 right-bottom).
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
Post Reply