Jump to content
  • Advertisement
Sign in to follow this  
p_ooya

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

This topic is 2624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:

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?

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!