Author Topic: Cube Texture Problems  (Read 11224 times)

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Cube Texture Problems
« on: June 16, 2011, 03:48:59 pm »
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!
      
« Last Edit: June 16, 2011, 04:57:33 pm by Nemetz »

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Promblems
« Reply #1 on: June 16, 2011, 03:55:00 pm »
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)

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: Cube Texture Problems
« Reply #2 on: June 16, 2011, 05:13:44 pm »
You can use UV mapping

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #3 on: June 16, 2011, 07:32:35 pm »
You can use UV mapping
Can you make a little example?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Cube Texture Problems
« Reply #4 on: June 16, 2011, 07:52:11 pm »
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
« Last Edit: June 16, 2011, 07:55:26 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Cube Texture Problems
« Reply #5 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.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #6 on: June 16, 2011, 08:53:19 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);
« Last Edit: June 16, 2011, 09:31:01 pm by Nemetz »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Cube Texture Problems
« Reply #7 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?

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #8 on: June 16, 2011, 11:28:41 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?
« Last Edit: June 17, 2011, 07:47:26 am by Nemetz »

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #9 on: June 17, 2011, 09:00:17 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Cube Texture Problems
« Reply #10 on: June 17, 2011, 09:25:55 am »
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.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #11 on: June 17, 2011, 09:33:14 am »
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.

« Last Edit: June 17, 2011, 09:45:27 am by Nemetz »

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #12 on: June 18, 2011, 08:41:38 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Cube Texture Problems
« Reply #13 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.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Cube Texture Problems
« Reply #14 on: June 18, 2011, 11:28:09 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.