Hello everyone.
I'm relatively new to java3d and I'm having a problem. I want to assign a texture (an image) to an obj 3d model. The problem is, when I run the code the 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. Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Shape3D torus=null; Scene t1 = getSceneFromFile("Some local path\torus.obj"); \\Grabbing the model from the scene BranchGroup branchGroup = t1.getSceneGroup(); torus = (Shape3D) branchGroup.getChild(0); \\loading the image, generating the texture and making the appearance 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); |
How to solve this issue?