Author Topic: Unexpected Texture rendering.  (Read 1990 times)

Offline mat1

  • byte
  • *
  • Posts: 2
    • View Profile
Unexpected Texture rendering.
« on: October 05, 2013, 01:12:16 pm »
Hello,

   I am trying to add a texture to a sphere (PlanetTexture1.png attached) but I find that it is  rendered a plain green as in the screenshot (Screenshot.png also attached). Here is the code I am using:

Texture Manager:
    planet1Texture = new Texture(assetManager.open("PlanetTexture1.png"));
    TextureManager.getInstance().addTexture("PlanetTexture1.png", planet1Texture);

The model object:   
     planet1 = Primitives.getSphere(5.0f);
    SimpleVector planetPos = new SimpleVector();
    planetPos.set(25, 0, 30);
    planet1.setOrigin(planetPos);
    planet1.setTexture(ti1);
    planet1.build();
    planet1.strip();
    world.addObject(planet1);
 
Add texture to model:
TextureInfo ti1 = new TextureInfo(TextureManager.getInstance().getTextureID("PlanetTexture1.png"));

What do I need to add to get that texture rendered as I would see it in the png file?

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Unexpected Texture rendering.
« Reply #1 on: October 05, 2013, 01:18:17 pm »
That doesn't work because (as the docs state) objects created by the Primitives class have no texture coordinates. Search the forum and you should be able to find a link to a download with a sphere object that has some if that helps.

Offline mat1

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Unexpected Texture rendering.
« Reply #2 on: October 05, 2013, 05:12:31 pm »
Thanks for your help, in case any one else comes up against this problem, here is the code I am using:

planet1Texture = new Texture(assetManager.open("PlanetTexture1.png"));
TextureManager.getInstance().addTexture("Planet", planet1Texture);

.....

 InputStream inputStrm1 = null;
 try {
       inputStrm1 = assetManager.open("Planet.3ds");
   }catch

.....

planet1 = loadModel(inputStrm1, 5.0f);
planet1.setTexture("Planet");
planet1.build();
planet1.strip();
world.addObject(planet1);

.....

public Object3D loadModel(InputStream filename, float scale) {
        Object3D[] model = Loader.load3DS(filename, scale);
        Object3D o3d = new Object3D(0);
        Object3D temp = null;
        for (int i = 0; i < model.length; i++) {
            temp = model;
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setRotationMatrix(new Matrix());
            o3d = Object3D.mergeObjects(o3d, temp);
            o3d.build();
        }
        return o3d;
    }

The result is attached.

[attachment deleted by admin]