How to apply a texture in a specific face of cube

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.

How to apply a texture in a specific face of cube

Postby yuko » Mon Dec 10, 2007 12:01 pm

I want simply to apply a texture to one face of a CubeSceneNode, I followed the tutorial about custom scene nodes but I dont know how to apply the texture only to one face of the cube. help please!

Thanks in advance!
yuko
 
Posts: 6
Joined: Mon Apr 03, 2006 4:54 pm

Postby Cardinal4 » Mon Dec 10, 2007 3:35 pm

You could either UV map your own cube in a modeling program, or make a custom scene node with mesh buffers for each side of a face.

Here's two links where it's explained it better [in C++ though]:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24533
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3680
Sketches of a rambling mind
Still a long way on learning Irrlicht...
User avatar
Cardinal4
 
Posts: 97
Joined: Sun Jun 11, 2006 1:20 am
Location: SG

Postby yuko » Mon Dec 10, 2007 3:54 pm

thank you for answering. :)
I think the solution for my problem is the second option you talk about , because the texture to apply in the front face of the cube is choosed dynamically by user so generate UV coordenates from an external tool I think is not possible (maybe I am wrong...) :roll:
Now I will try to understand the example in the first thread you quoted...
yuko
 
Posts: 6
Joined: Mon Apr 03, 2006 4:54 pm

Postby yuko » Mon Dec 10, 2007 4:49 pm

I have tried the second option but It doesn't work and I don't know why...:

Code: Select all
           
String rutaTextura1 = @Principal.path + "Texturas/Suelos/baldosa.png";
            String rutaTextura2 = @Principal.path + "Texturas/Paredes/paredSuper.jpg";

            float cubeSize = 40.0f;
            IrrlichtNETCP.Color cubeColour = new IrrlichtNETCP.Color(255, 255, 255, 255);

            MeshBuffer buffer = new MeshBuffer(IrrlichtNETCP.VertexType.Standard);
            MeshBuffer buffer2 = new MeshBuffer(IrrlichtNETCP.VertexType.Standard);
            ushort[] u = { 0, 2, 1, 0, 3, 2 };
            ushort[] u2 = { 0, 11, 10, 0, 10, 7 };
             
            for (uint i = 0; i < 6; i++)
            {
                buffer.SetIndex(i, u[i]);
                buffer2.SetIndex(i, u2[i]);
            }

            // set material per buffer, use this or the one at the end of this code
            buffer.Material.Texture1 = this.device.VideoDriver.GetTexture(rutaTextura1);
            buffer2.Material.Texture1 = this.device.VideoDriver.GetTexture(rutaTextura2);


            buffer.SetVertex(0, new Vertex3D(new Vector3D(0, 0, 0), new Vector3D(-1, -1, -1), cubeColour, new Vector2D(0, 1)));
            buffer.SetVertex(1, new Vertex3D(new Vector3D(1, 0, 0), new Vector3D(1, -1, -1), cubeColour, new Vector2D(1, 1)));
            buffer.SetVertex(2, new Vertex3D(new Vector3D(1, 1, 0), new Vector3D(1, 1, -1), cubeColour, new Vector2D(1, 0)));
            buffer.SetVertex(3, new Vertex3D(new Vector3D(0, 1, 0), new Vector3D(-1, 1, -1), cubeColour, new Vector2D(0, 0)));
            buffer.SetVertex(4, new Vertex3D(new Vector3D(1, 0, 1), new Vector3D(1, -1, 1), cubeColour, new Vector2D(0, 1)));
            buffer.SetVertex(5, new Vertex3D(new Vector3D(1, 1, 1), new Vector3D(1, 1, 1), cubeColour, new Vector2D(0, 0)));

            buffer2.SetVertex(0, new Vertex3D(new Vector3D(0, 1, 1), new Vector3D(-1, 1, 1), cubeColour, new Vector2D(1, 0)));
            buffer2.SetVertex(1, new Vertex3D(new Vector3D(0, 0, 1), new Vector3D(-1, -1, 1), cubeColour, new Vector2D(1, 1)));
            buffer2.SetVertex(2, new Vertex3D(new Vector3D(0, 1, 1), new Vector3D(-1, 1, 1), cubeColour, new Vector2D(0, 1)));
            buffer2.SetVertex(3, new Vertex3D(new Vector3D(0, 1, 0), new Vector3D(-1, 1, -1), cubeColour, new Vector2D(1, 1)));
            buffer2.SetVertex(4, new Vertex3D(new Vector3D(1, 0, 1), new Vector3D(1, -1, 1), cubeColour, new Vector2D(1, 0)));
            buffer2.SetVertex(5, new Vertex3D(new Vector3D(1, 0, 0), new Vector3D(1, -1, -1), cubeColour, new Vector2D(0, 0)));

            Mesh cubeMesh = new Mesh();
            cubeMesh.AddMeshBuffer(buffer);
            cubeMesh.AddMeshBuffer(buffer2);

            SceneNode cubeSceneNode = this.device.SceneManager.AddMeshSceneNode(cubeMesh, null, -1);

            //Set material per scene node, material count should be the same as buffer count
            cubeSceneNode.GetMaterial(0).Texture1 = this.device.VideoDriver.GetTexture(rutaTextura1);
            cubeSceneNode.GetMaterial(1).Texture1 = this.device.VideoDriver.GetTexture(rutaTextura2);

            cubeSceneNode.Scale = new Vector3D(cubeSize, cubeSize, cubeSize);
            cubeSceneNode.SetMaterialFlag(MaterialFlag.Lighting, false);


In the scene the back face of the cube appears ok but the other face does not appear in a correct way, I suppose I have defined bad the vertex coordinates to render a cube. Someone can help me please??

Thanks
yuko
 
Posts: 6
Joined: Mon Apr 03, 2006 4:54 pm


Return to Irrlicht.NET

Who is online

Users browsing this forum: No registered users and 1 guest