Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 p_ooya   Members   -  Reputation: 100

Like
0Likes
Like

Posted 08 October 2011 - 12:21 AM

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?

Sponsor:

#2 Ectara   Crossbones+   -  Reputation: 2827

Like
0Likes
Like

Posted 12 October 2011 - 09:41 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS