Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java3D: Texture is not applied to OBJ model properly

Started by p_ooya Oct 8, 2011 at 6:21 AM 0 replies 1.6k views
Original Post
p_ooya
p_ooya
Hello everyone. Hope this is the right place for this question.
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:

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?
Ectara
Ectara

Hello everyone. Hope this is the right place for this question.
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:

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?


It sounds as if the texture coordinates are left uninitialized.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.