Usage of different texturesin different faces and Live texture changing

Hi, I’m quite new at jME, been using Java3D for a while now, but had some good truble with it’s way of rendering things. So, I decided to try out something new, without the need to workaround. :slight_smile: So, I’m looking for some advices.

My basic need is that I got 2d models I want to put as textures on a plane (A “plane” in here would be a box with one of the axis at 0 size, with the back culled). In order to make animations on such planes, I must replace the textures during the gameplay. Already tried swapping different textures in a separated thread, but didn’t worked out. And now I’m quite lost with how to do it.

Thanks to the help, this is now solved, by calling updateRenderState() on the boxes. :slight_smile:

Also, about swing objects, should I just simply add them on the root node, or another object should be created in order to do the on-screen interface? Didn’t tried this yet, just curious.

Edit: Tried TestjMEDesktop and found out what I needed to start. This part is solved.

And finishing, how can I put different textures on each face of, let’s say, a box? Is there a method for, or I must create my own Plane-based object and implement the textures in it?

Thanks in advance,


So, anybody? I was successful building a custom 6-side-independent box, but I'm quite sure it's not the best way around to do it. Also, how to change a texture of an object while it's live? just switching the TextureState of it for the new one won't work… :frowning:

i think your 6 side independent Box is the way to go, there are a few other posts about this topic somewhere in the forum.

Changing the textureState of one side of the box and calling updateRenderstate() should work to change the Texture.

Core-Dump beat me to it…

You could either use the six-quad box approach, or you could do it with texture coordinates. When you change textures be sure you're updating all the necessary states, like updateRenderState() and so on…

The texture changing worked! Thanks a lot!

Just need to try further the texture mapping. :slight_smile:

And that's kinda of a problem… I couldn't find anything about a 3D-shape texture mapping on the wiki. Could anybody give me a tip?

That is not really specific to jME. I would suggest searching online or finding a tutorial related to a modelling tool you use. Or even read the NeHe tutorials on OpenGL, that should give you a good foundation.

If you already understand this stuff, then your probably talking about setting/changing the texture coordinates. I don’t know of a specific example in jME to refer you to. Perhaps someone else does?

Tried using the 6-boxes once again, and graphically speaking, it worked! But, once I put more boxes together, it became a mess and really really slow at leading the graphs. I used this as code:

Box[] boxes = new Box[6];
    float[] cent = new float[3];
    float radius = 2f;
    boxes[0] = new Box("Box 0",new Vector3f(cent[0], cent[1]+radius, cent[2]), radius, 0, radius);
    boxes[1] = new Box("Box 1",new Vector3f(cent[0], cent[1]-radius, cent[2]), radius, 0, radius);
    boxes[2] = new Box("Box 2",new Vector3f(cent[0]+radius, cent[1], cent[2]), 0, radius, radius);
    boxes[3] = new Box("Box 3",new Vector3f(cent[0]-radius, cent[1], cent[2]), 0, radius, radius);
    boxes[4] = new Box("Box 4",new Vector3f(cent[0], cent[1], cent[2]+radius), radius, radius, 0);
    boxes[5] = new Box("Box 5",new Vector3f(cent[0], cent[1], cent[2]-radius), radius, radius, 0);
    for (x=0;x<6;x++){
        boxes[x].setModelBound(new BoundingBox());
        if (x==0)
            u = textures.getURL("ground_grass");
        else if (x==1)
            u = textures.getURL("wall_cliffbody");
            u = textures.getURL("wall_clifftop");
        ts = display.getRenderer().createTextureState();

nymon said:

That is not really specific to jME. I would suggest searching online or finding a tutorial related to a modelling tool you use. Or even read the NeHe tutorials on OpenGL, that should give you a good foundation.

Still, I look for better ways to do it. Read those openGL tutorials, but I still haven't figured out a way to do it decently. Could someone please give me an example of texture mapping on a box in jme?

Try researching UV Texture mapping. I found this blog post which will explain the concepts to you, it even has a 3D applet running to show how it looks. Neat!