Texture Problems !

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Texture Problems !

Davidave
Hey guys ! i have got a big problem with texturing a simple box. My texture seems to be stretched out over the surface!! i use an image for my texture which 128x128 pixel. Now i have read something about Quadarrays ! But i really dont understand what a quadarray IS or what it is doing!  Huh

it would be awesome if i show you my code and someone could help me to implement a quadarray!!! Smiley

this is my code

       Appearance wallApp = new Appearance();
   
       Texture mauer = new TextureLoader("mauer.jpg", frame).getTexture();
     
       //ground links
     
      TransformGroup tgLeft = new TransformGroup();
      Transform3D t3Left= new  Transform3D();
      Vector3f min = new Vector3f(-1.72f, -0.55f, -4f);
      t3Left.setTranslation(min);
      boxapp.setTexture(grass);
     
      Box left = new Box(1.5f,0.005f,6f,Box.GENERATE_TEXTURE_COORDS,wallapp);
      tgLeft.setTransform(t3Left);
      tgLeft.addChild(left);
      RootBg.addChild(tgLeft);


and this is an example i have found


 QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES
 | GeometryArray.TEXTURE_COORDINATE_2);
 Point3f p = new Point3f();
 p.set(-1.0f, 1.0f, 0.0f);
 plane.setCoordinate(0, p);
 p.set(-1.0f, -1.0f, 0.0f);
 plane.setCoordinate(1, p);
 p.set( 1.0f, -1.0f, 0.0f);
 plane.setCoordinate(2, p);
 p.set( 1.0f, 1.0f, 0.0f);
 plane.setCoordinate(3, p);
 Point2f q = new Point2f();
q.set(0.0f, 1.0f);
 plane.setTextureCoordinate(0, q);
 q.set(0.0f, 0.0f);
 plane.setTextureCoordinate(1, q);
 q.set(1.0f, 0.0f);
 plane.setTextureCoordinate(2, q);
q.set(1.0f, 1.0f);
 plane.setTextureCoordinate(3, q);


okay thats it! now i have to modify this quadarray?! what do I need ? the size of my Box(1.5f,0.005f,6f)?? the Coordinates of my box( -1.72f, -0.55f, -4f) ?? please help me =(

thanks in advance
david


ps. im only allowed to use java3d
Reply | Threaded
Open this post in threaded view
|

Re: Texture Problems !

jfpauly
I think I can help you for texturing your Box.
You have access to the different sides appearance with the  setAppearance method of primitives (box, cone,...):
example of code :
if (obj instanceof Box) {
            ((Box) obj).setAppearance(side, univers.currentApp);
        } else if (obj instanceof Cone) {
            ((Cone) obj).setAppearance(side, univers.currentApp);
        } else if (obj instanceof Cylinder) {
            ((Cylinder) obj).setAppearance(side, univers.currentApp);
        } else {
            Toolkit.getDefaultToolkit().beep();
            jLabel1.setText("Object should be a Cone, a Cylinder, or a Box");
        }
where side = Box.BACK (for instance)
and univers.currentApp = the appearance you want for this side
For you, if left is your Box instance you would code : left.setAppearance...
I hope this helps you
Regards
jfp
Reply | Threaded
Open this post in threaded view
|

Re: Texture Problems !

Davidave
hey thank i will try it =)