I load a 3d model of a torus (obj file) into my program, using these lines:
Shape3D torus=null;
Scene t1 = getSceneFromFile("Some local path\torus.obj");
Then I grab the model from the scene using this code:
BranchGroup branchGroup = t1.getSceneGroup();
torus = (Shape3D) branchGroup.getChild(0);
The following piece of code set an image as texture and then apply that texture to an Appearance object.
TextureLoader textureLoader=new TextureLoader("Another local path\myImage.jpg",null);
ImageComponent2D image=textureLoader.getImage();
Texture2D texture=new Texture2D(Texture.BASE_LEVEL,Texture.RGBA,image.getWidth(),image.getHeight());
texture.setImage(0, image);
Appearance app = new Appearance();
app.setTexture(texture);
torus.setAppearance(app);
When I run the code the torus model is loaded correctly but the texture is not assigned correctly. More accurately, the whole 3d model has a single color instead of an image as texture. Mentioned color, is the color of the pixel at bottom-left of the image.
What's the solution? Thanks in advance.