Hello!
I'm trying to set an texture on to a Shape3D but the picture always
appear upside down. Like a painting hanging upside down, (not faceing
the wall, hope you understand).
I have tried to change the textureCordinates but nothing happens, this
is the code:
1) The Shape3D
import java.applet.*;
import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.event.*;
import java.util.Enumeration;
public class TextureGround extends Shape3D
{
float x = 2;
float y = 4;
float z = 2;
float posX = 0;
float posY = 0;
float posZ = 0;
int type = 0;
public TextureGround(float x, float y, float z, Point3f point3f,
String imageName, Applet applet)
{
this.x = x;
this.y = y;
this.z = z;
posX = point3f.x;
posY = point3f.y;
posZ = point3f.z;
QuadArray quadArray = new QuadArray(4,
GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
//Point3f point3f = new Point3f(posX, posY, posZ);
quadArray.setCoordinate(0, point3f);
point3f.set(posX, posY, posZ - z);
quadArray.setCoordinate(1, point3f);
point3f.set(posX + x, posY, posZ - z);
quadArray.setCoordinate(2, point3f);
point3f.set(posX + x, posY, posZ);
quadArray.setCoordinate(3, point3f);
Point2f point2f = new Point2f(0.0f, 1.0f);
quadArray.setTextureCoordinate(0, point2f);
point2f.set(0.0f, 0.0f);
quadArray.setTextureCoordinate(1, point2f);
point2f.set(1.0f, 0.0f);
quadArray.setTextureCoordinate(2, point2f);
point2f.set(1.0f, 1.0f);
quadArray.setTextureCoordinate(3, point2f);
setAppearance(new TextureAppearance(imageName, applet));
setGeometry(quadArray);
}
}
2) The TextureAppearance
import java.applet.*;
import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.image.TextureLoader;
public class TextureAppearance extends Appearance
{
public TextureAppearance(String imageName, Applet applet)
{
TextureLoader textureLoader = new
TextureLoader(imageName, applet);
ImageComponent2D imageComponent2D =
textureLoader.getImage();
Texture2D texture2D = new Texture2D(Texture.BASE_LEVEL,
Texture.RGBA, imageComponent2D.getWidth(),
imageComponent2D.getHeight());
texture2D.setImage(0, imageComponent2D);
setTexture(texture2D);
PolygonAttributes polygonAttributes = new
PolygonAttributes();
polygonAttributes.setCullFace(PolygonAttributes.CULL_NONE);
setPolygonAttributes(polygonAttributes);
}
}
3) I test this with:
branchGroup.addChild(addShape3DAt(new Point3f(0.0f, 0.0f, 0.0f),
"images/coastline_north_west.gif"));
public Shape3D addShape3DAt(Point3f point3f, String fileName)
{
TextureGround textureGround = new TextureGround(20.0f, 0.0f,
20.0f, point3f, fileName, this);
return textureGround;
}
I can't understand why it always appear hanging upsidedown, so if
someone understands please let me know!
Best Regards
Fredrik Andersson
==========================================================================To
unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".