Cube Texture Problems

Started by Nemetz, June 16, 2011, 03:48:59 PM

Previous topic - Next topic

Nemetz

Hi!
I'm just started with your engine, and it's great.
But a have some problem.
Cant assign a texture for each face of cube. I have 8 png files 64x64.
How can i assign this?
If a doing it like in demo example in one file, they are wraping spherical, and it looks not so good)
Tried like this one:
cube.getPolygonManager().setPolygonTexture(iterator, TextureManager.getInstance().getTextureID("texture"));
It doesnt work also.
I downloaded Alien game, but i didn't find how testure setting at the wal.
Thanks a lot!
      

Nemetz

I think i need smth like skyBox, but with cube functionality, is it possible in jpct android engine?
it wold be great for having a constructor for cube like:
public SkyBox(java.lang.String left,
              java.lang.String front,
              java.lang.String right,
              java.lang.String back,
              java.lang.String up,
              java.lang.String down,
              float size)

Alexey


Nemetz


Thomas.

#4
on youtube are a lot of video tutorials about UVW mapping in 3ds max, blender,... this part you can do also in the jpct, but it is much complicated...
edit: I did not see whole video, but seem be good ... http://www.youtube.com/watch?v=9nbkTFOFiCI

EgonOlsen

A simple cube can also be done in code pretty easily. The objects generated by the Primitives class don't have any uv-mapping. See this thread: http://www.jpct.net/forum2/index.php/topic,393.0.html. It also contains some code at the end to create a cube with proper uv-mapping.

Nemetz

#6
Quote from: EgonOlsen on June 16, 2011, 08:06:30 PM
A simple cube can also be done in code pretty easily. The objects generated by the Primitives class don't have any uv-mapping. See this thread: http://www.jpct.net/forum2/index.php/topic,393.0.html. It also contains some code at the end to create a cube with proper uv-mapping.
So, with primitives i can't cover all cube by the different textures?
And what about size of object, for example i use Primitives.getCube(12), how can i use scale in this code?
Texture must be a triangle?
Object3D box=new Object3D(12);
   
    SimpleVector upperLeftFront=new SimpleVector(-1,-1,-1);
    SimpleVector upperRightFront=new SimpleVector(1,-1,-1);
    SimpleVector lowerLeftFront=new SimpleVector(-1,1,-1);
    SimpleVector lowerRightFront=new SimpleVector(1,1,-1);
   
    SimpleVector upperLeftBack = new SimpleVector( -1, -1, 1);
    SimpleVector upperRightBack = new SimpleVector(1, -1, 1);
    SimpleVector lowerLeftBack = new SimpleVector( -1, 1, 1);
    SimpleVector lowerRightBack = new SimpleVector(1, 1, 1);

EgonOlsen

You could, but it's worth the hassle. Objects created by the Primitives class are meant to be used as simple place holder objects to try things out. They are not meant to be used for "real" applications unless you can live with the fact that they have no textures assigned.

To scale in that code simply by using other values than -+1

"Texture must be a triangle?"...i don't get that question. What do you mean with that?

Nemetz

#8
Quote from: EgonOlsen on June 16, 2011, 09:47:32 PM
You could, but it's worth the hassle. Objects created by the Primitives class are meant to be used as simple place holder objects to try things out. They are not meant to be used for "real" applications unless you can live with the fact that they have no textures assigned.

To scale in that code simply by using other values than -+1

"Texture must be a triangle?"...i don't get that question. What do you mean with that?
Ok, i understood, what i can scale by use another values.
About texture, i mean what in this application will be a lot of cubes, and i'll need to apply it to cube by the air.
So, in code example, which you show me, i add faces, like triangles, and texture also must be triangle or square, for example 64x64?

Nemetz

So, i made it like this:
public class TextureBox extends Object3D{
   
   int size = 1;
   
   public  TextureBox(int size){   
      
      super(size);
       SimpleVector upperLeftFront=new SimpleVector(-size,-size,-size);
       SimpleVector upperRightFront=new SimpleVector(size,-size,-size);
       SimpleVector lowerLeftFront=new SimpleVector(-size,size,-size);
       SimpleVector lowerRightFront=new SimpleVector(size,size,-size);
       
       SimpleVector upperLeftBack = new SimpleVector( -size, -size, size);
       SimpleVector upperRightBack = new SimpleVector(size, -size, size);
       SimpleVector lowerLeftBack = new SimpleVector( -size, size, size);
       SimpleVector lowerRightBack = new SimpleVector(size, size, size);
       
       // Front
       this.addTriangle(upperLeftFront,0,0, lowerLeftFront,0,size, upperRightFront,size,0);
       this.addTriangle(upperRightFront,size,0, lowerLeftFront,0,size, lowerRightFront,size,size);
       
       // Back
       this.addTriangle(upperLeftBack,0,0, upperRightBack,size,0, lowerLeftBack,0,size);
       this.addTriangle(upperRightBack,size,0, lowerRightBack,size,size, lowerLeftBack,0,size);
       
       // Upper
       this.addTriangle(upperLeftBack,0,0, upperLeftFront,0,size, upperRightBack,size,0);
       this.addTriangle(upperRightBack,size,0, upperLeftFront,0,size, upperRightFront,size,size);
       
       // Lower
       this.addTriangle(lowerLeftBack,0,0, lowerRightBack,size,0, lowerLeftFront,0,size);
       this.addTriangle(lowerRightBack,size,0, lowerRightFront,size,size, lowerLeftFront,0,size);
       
       // Left
       this.addTriangle(upperLeftFront,0,0, upperLeftBack,size,0, lowerLeftFront,0,size);
       this.addTriangle(upperLeftBack,size,0, lowerLeftBack,size,size, lowerLeftFront,0,size);
       
       // Right
       this.addTriangle(upperRightFront,0,0, lowerRightFront,0,size, upperRightBack,size,0);
       this.addTriangle(upperRightBack,size,0, lowerRightFront, 0,size, lowerRightBack,size,size);
       this.build();
   }

}



But when i'm use it like this:
cube = new TextureBox( 12);
cube.setTexture("texture");
I see 12x12 textures per face, and i cant understand why...
What should i do for see 1 texture per 1 face?

EgonOlsen

Maybe you should take one step back and read a little bit about vertices and uv-mapping to understand this better. You have changed the scaling of the cube by using size instead of +-1, but you've also changed the uv-mapping to tile a dozen times by applying that size to the uv-coordinates. Apply it to the SimpleVectors only and leave the 1s in the addTriangle()-method as they were.

Nemetz

#11
Yes, thank you, thats great. I understand.
At the back side of my cube textures look like in mirror, what should i need to change?
And i can use anly 1 texture for all faces? who can i make a texture for each face?
And also, can u give me an account to wiki.
Want to make some examples there, about you awesome engine.


Nemetz

So, help me, how i can draw a diffrent texture for ecah face?
And why back textures like a mirror? should i have a direction for back faces?

EgonOlsen

If you want different textures, use a method that supports this...like: http://www.jpct.net/doc/com/threed/jpct/Object3D.html#addTriangle(com.threed.jpct.SimpleVector, float, float, com.threed.jpct.SimpleVector, float, float, com.threed.jpct.SimpleVector, float, float, int)

If the texture isn't placed correctly, switch the texture coordinates for these faces. As said, i advise you to learn something about uv-mapping to understand what these 0s and 1s actually mean.

Nemetz

Quote from: EgonOlsen on June 18, 2011, 09:16:25 PM
If you want different textures, use a method that supports this...like: http://www.jpct.net/doc/com/threed/jpct/Object3D.html#addTriangle(com.threed.jpct.SimpleVector, float, float, com.threed.jpct.SimpleVector, float, float, com.threed.jpct.SimpleVector, float, float, int)

If the texture isn't placed correctly, switch the texture coordinates for these faces. As said, i advise you to learn something about uv-mapping to understand what these 0s and 1s actually mean.
Thank you!
Ok, will doanload some books and video.