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?
Create 3D Box with "on-the-fly"-textures
Re: Create 3D Box with "on-the-fly"-textures
Hi i am also new here
this code creates the cube and sets the texture you want
take a look at tutorial 4 Movement it has good examples
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
Re: Create 3D Box with "on-the-fly"-textures
Awesome, thanks! 
I'll have a look at the tutorial.
I'll have a look at the tutorial.
Re: Create 3D Box with "on-the-fly"-textures
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?
Re: Create 3D Box with "on-the-fly"-textures
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.
- 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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Create 3D Box with "on-the-fly"-textures
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 )
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 )
Re: Create 3D Box with "on-the-fly"-textures
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).
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm