Sign in to follow this  
p_ooya

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

Recommended Posts

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:

[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);
[/code]
How to solve this issue?

Share this post


Link to post
Share on other sites
[quote name='p_ooya' timestamp='1318054862' post='4870395']
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:

[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);
[/code]
How to solve this issue?
[/quote]

It sounds as if the texture coordinates are left uninitialized.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this