www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Nemetz on June 16, 2011, 03:48:59 pm

Title: Cube Texture Problems
Post by: Nemetz 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!
      
Title: Re: Cube Texture Promblems
Post by: Nemetz 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)
Title: Re: Cube Texture Problems
Post by: Alexey on June 16, 2011, 05:13:44 pm
You can use UV mapping
Title: Re: Cube Texture Problems
Post by: Nemetz on June 16, 2011, 07:32:35 pm
You can use UV mapping
Can you make a little example?
Title: Re: Cube Texture Problems
Post by: Thomas. 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
Title: Re: Cube Texture Problems
Post by: 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 (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.
Title: Re: Cube Texture Problems
Post by: Nemetz 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 (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);
Title: Re: Cube Texture Problems
Post by: 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?
Title: Re: Cube Texture Problems
Post by: Nemetz 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?
Title: Re: Cube Texture Problems
Post by: Nemetz 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?
Title: Re: Cube Texture Problems
Post by: EgonOlsen 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.
Title: Re: Cube Texture Problems
Post by: Nemetz 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.

Title: Re: Cube Texture Problems
Post by: Nemetz 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?
Title: Re: Cube Texture Problems
Post by: 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) (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.
Title: Re: Cube Texture Problems
Post by: Nemetz 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) (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.
Title: Re: Cube Texture Problems
Post by: Nemetz on June 29, 2011, 11:38:02 am
Hi 2 all!
In rendering i made this one:
Code: [Select]
box.setTexture("transp");
box.setTransparency(500);
box.setShadingMode(Object3D.SHADING_FAKED_FLAT);
box.align(cam);
box.strip();
box.build();
Where texture is a transparency texture only with a border.
Fron and left side looks god, but i don't see back side of box, i mean i don't see border there.
(http://tt4a.ru/image-1531_4E0AF33D.jpg)
Is it a bug or i made something wrong?

Title: Re: Cube Texture Problems
Post by: EgonOlsen on June 29, 2011, 12:25:14 pm
It's not a bug and you haven't done something wrong. It's by design and it's called backface culling. You can disable it by using Object3D.setCulling(...);
Title: Re: Cube Texture Problems
Post by: Nemetz on June 29, 2011, 02:40:06 pm
Thank you for your help!