Author Topic: Problems with texture allignment on 3ds files  (Read 1950 times)

Offline dandee

  • byte
  • *
  • Posts: 7
    • View Profile
Problems with texture allignment on 3ds files
« on: March 03, 2011, 09:26:45 am »
Hello togehter,
after some days searching in this forum itīs time to post my first question.

I have following problem: I try do write a serializer for 3ds files. I am a bleeding beginner in things like jpct so please be patient. So the first thing I played with the examples. After playing a little bit around I designed my own 3ds files and textures. The current step I stuck is to correctly apply textures to my 3ds file. Somehow I canīt get it working to apply my textures like in blender.

I designed a 3d modell in my CAD applikation, exported it to vrml, imported it into blender, designed a simple texture an exported it to 3ds.


I have created following files:
3ds file: https://dandee2.homelinux.net/~daniel/temp/xprs3.3ds
Texture: https://dandee2.homelinux.net/~daniel/temp/xprs3.jpg

Adding the texture in Blender looks like:
https://dandee2.homelinux.net/~daniel/temp/BlenderPic.jpg


With a simple loadinbg program from the samples the results look like:
With option calctexturewrap: https://dandee2.homelinux.net/~daniel/temp/calcTextureWrap.jpg

Without this option:
https://dandee2.homelinux.net/~daniel/temp/withoutcalctexturewrap.jpg

Other samples from jpct site are looking good (for example rock.3ds plus texture) so i think it has something to do with my texture or my 3ds but I am not so familar with that and maybe someone sees the problem directly.

Thank you for you help. Best regards from Bochum.

My code:
Code: [Select]
import com.threed.jpct.*;
import java.io.InputStream;
import java.util.logging.Level;
import javax.swing.*;
/**
 *
 * @author dslawaticki
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    private World world;
    private FrameBuffer buffer;
    private Object3D box;
    private JFrame frame;

    public static void main(String[] args) {
        try {
            new Main().loop();
        } catch (Exception ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
            
    }
    public Main() throws Exception {

frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

world = new World();
world.setAmbientLight(200, 200, 200);

TextureManager.getInstance().addTexture("box", new Texture("D:\\Privat\\3DModelle\\xprs3.jpg"));
                System.out.println (TextureManager.getInstance().getTexture("box").getHeight());
                System.out.println (TextureManager.getInstance().getTexture("box").getWidth());

                box = loadModel("xprs3.3ds",1);
                box.setTexture("box");
                box.calcTextureWrap();
                box.recreateTextureCoords();

box.setEnvmapped(Object3D.ENVMAP_DISABLED);
    
world.addObject(box);

world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
              
}
        private Object3D loadModel(String filename, float scale) {
    InputStream in1 = getClass().getResourceAsStream(filename);
       Object3D[] model = Loader.load3DS(in1, scale);
       Object3D o3d = new Object3D(0);
       Object3D temp = null;
       for (int i = 0; i < model.length; i++) {
           temp = model[i];
           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;
   }

private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);

while (frame.isShowing()) {
//world.getCamera().setPosition(50, -50, -5);
                        box.rotateY(0.01f);
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.display(frame.getGraphics());
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}

}
« Last Edit: March 03, 2011, 01:06:46 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12089
    • View Profile
    • http://www.jpct.net
Re: Problems with texture allignment on 3ds files
« Reply #1 on: March 03, 2011, 02:10:10 pm »
Note: I've modified your post so that the code actually appears in code-tags. It's much more readable that way.

Now on to your problem: The model doesn't seem to have any uv-coordinates assigned. Maybe the exporter is faulty or you have to do something in Blender to make it actually export them or whatever...you can check this by doing:

Code: [Select]
PolygonManager pm = box.getPolygonManager();
for (int i = 0; i < pm.getMaxPolygonID(); i++) {
   for (int p = 0; p < 3; p++) {
      System.out.println(i + "/" + p + ": " + pm.getTextureUV(i, p));
   }
}

Remember that the call to calcTextureWarp() has to go away for this to be checked, because it will generate new texture coordinates. It's meant to be used only on objects that have none but should somehow show a texture...it almost never generates the coordinates one really wants. It's for quick prototyping only.

One last note: Move the call to build() out of the loop. It's not needed to call it over and over again.

Offline dandee

  • byte
  • *
  • Posts: 7
    • View Profile
Re: Problems with texture allignment on 3ds files
« Reply #2 on: March 03, 2011, 03:55:47 pm »
Thanks for editing.
Ok it looks like I have a blender problem. Maybe I should crawl some blender tuts.
Println says:
.....
1191/1: (0.0,1.0,0.0)
1191/2: (0.0,1.0,0.0)
1192/0: (0.0,1.0,0.0)
1192/1: (0.0,1.0,0.0)
1192/2: (0.0,1.0,0.0)
1193/0: (0.0,1.0,0.0)
1193/1: (0.0,1.0,0.0)
1193/2: (0.0,1.0,0.0)

For every line. Seems that there are no uv mappings... :-/

Offline dandee

  • byte
  • *
  • Posts: 7
    • View Profile
Re: Problems with texture allignment on 3ds files
« Reply #3 on: March 03, 2011, 04:08:51 pm »
Ok, I am sorry for that.
It was, as what you told. So a blender handling problem.  ::) I hat to add an material with texture to the blender model.

Thanks!  ;D