3DS Loader from Xith Toolkit problem

I have a problem with Xith3D toolkit, the 3DS loader part.

    I want to load a model created with Wings3D and with a BMP or JPG texture ( they both won't load ).
    
    My texture is created with the Gimp.
    
    I launch my test program with the following command, under Linux :
    java -classpath../libs/xith3d.jar:./xith-3ds.jar:./ TDSTest2
    
    Here is the program output :
    `Available 0: GLCapabilities[DoubleBuffered: true, Stereo: false, HardwareAccelerated: true,DepthBits: 24, StencilBits: 8, Red: 8, Green: 8, Blue: 8, Alpha: 0,Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16 ] MS:false 0 Score: 132
    Available 1: GLCapabilities[DoubleBuffered: true, Stereo: false, HardwareAccelerated: true,DepthBits: 24, StencilBits: 8, Red: 8, Green: 8, Blue: 8, Alpha: 0,Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16 ] MS:false 0 Score: 132

[…]
Available 23: GLCapabilities[DoubleBuffered: false, Stereo: false, HardwareAccelerated: true,DepthBits: 0, StencilBits: 0, Red: 8, Green: 8, Blue: 8, Alpha: 8, RedAccum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16 ] MS:false 0 Score: 1944
Chosen index: 0
Chosen capabilities:
GLCapabilities [DoubleBuffered:true, Stereo: false, HardwareAccelerated: true, DepthBits: 24,StencilBits: 8, Red: 8, Green: 8, Blue: 8, Alpha: 0, Red Accum: 16,Green Accum: 16, Blue Accum: 16, Alpha Accum: 16 ] MS: false 0
Load took: 0.073 seconds
Init GL isnet.java.games.jogl.impl.x11.X11GLImpl
OpenGL Renderer = GeForce2MX/AGP/SSE/3DNOW!
OpenGL Version = 1.5.1 NVIDIA61.06
OpenGL Vendor = NVIDIA Corporation
OpenGL Extensions =GL_ARB_imaging GL_ARB_multitexture GL_ARB_point_parameters
[…]
GL_SUN_slice_accum`

    After that, i have a black window on my Linux desktop with nothingdisplayed on it.
    
    I tried the same model without textures : it's all right.
    
    The texture is in the right directory and the program find it,otherwise it would display the message "texture not found".

Here’s the source code ( nothing very interesting ) :

import com.xith3d.scenegraph.VirtualUniverse;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.DirectionalLight;
import com.xith3d.scenegraph.AmbientLight;
import com.xith3d.scenegraph.TransformGroup;
import com.xith3d.scenegraph.Transform3D;

import com.xith3d.render.RenderOptions;
import com.xith3d.render.Option;
import com.xith3d.render.CanvasPeer;
import com.xith3d.render.RenderPeer;
import com.xith3d.render.jogl.RenderPeerImpl;

import javax.vecmath.Vector3f;
import javax.vecmath.Color3f;
import java.util.ArrayList;

import org.newdawn.xith3d.threeds.TDSLoader;
import org.newdawn.xith3d.threeds.model.TDSModel;

/**
 * A test for OBJ files
 *
 * @author Kevin Glass
 */
public class TDSTest2 implements Runnable {
    private View view;
    private double lightAngle;
    private double modelAngle;
    private float anim = 0.0f;
    private DirectionalLight light;
    private TransformGroup tg = new TransformGroup();
    private TDSModel model;
    
    public TDSTest2() {
      VirtualUniverse universe = new VirtualUniverse();
        view = new View();            
        view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
        universe.addView(view);
        Locale locale = new Locale();
        universe.addLocale(locale);
        
        view.setBackClipDistance(500.0f);
        
        // setup view        
        view.getTransform().lookAt(
            new Vector3f( 20, 10, 0),  // location of eye (cubes)
            new Vector3f( 0, 10, 0),     // center of view (cubes)
            new Vector3f( 0, 1, 0));    // vector pointing up
        
        RenderPeer rp = new RenderPeerImpl();
        CanvasPeer cp = rp.makeCanvas(null, 800, 600, 32, false);
        Canvas3D canvas = new Canvas3D();
        canvas.set3DPeer(cp);
        view.addCanvas3D(canvas);
        
        RenderOptions options = new RenderOptions();
        options.setOption(Option.USE_SHADOWS,true);
        options.setOption(Option.USE_LIGHTING,true);
        
        cp.setRenderOptions(options);
        
        BranchGroup root = new BranchGroup();
        locale.addBranchGraph(root);
        
        Color3f ambientColor = new Color3f(0.5f, 0.5f, 0.5f);
      AmbientLight ambientLightNode = new AmbientLight(ambientColor);
      root.addChild(ambientLightNode);
        
        light = new DirectionalLight(true,new Color3f(1f,1f,1f),new Vector3f(0,0,1));
        root.addChild(light);
        
        TDSLoader.setDebug(false);
        
        try {
            long start = System.currentTimeMillis();
            //model = new TDSLoader().load("model/character.3ds",true);
            //model = new TDSLoader().load("model/cube_set/cube_rotation.3ds");
            //model = new TDSLoader().load("model/jeep/jeep1.3ds",true);
            //model = new TDSLoader().load("angel/angel.3ds",true);
            //model = new TDSLoader().load("angel/chalice.3ds",true);
            //model.setShowBounds(true,true);
          model = new TDSLoader().load("model/WA/William.3ds",true);
            //tg.addChild(model);
            
            //model = new TDSLoader().load("model_set/redbox_max.3DS",true);
            //model = new TDSLoader().load("jeep2/jeep.3ds",true);
            //model = new TDSLoader().load("jeep2/scale.3ds",true);
            //model = new TDSLoader().load("others/Tube.3ds",true);
            //model = new TDSLoader().load("samples/Kugel.3ds",true);
            //model = new TDSLoader().load("samples/building09.3ds",true);
            //model = new TDSLoader().load("scaleanim/output.3ds",true);
            System.out.println("Load took: "+((System.currentTimeMillis() - start) / 1000.0)+" seconds");
            
            tg.addChild(model);
            //model.setShowBounds(true,true);
            root.addChild(tg);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        new Thread(this).start();
    }
    
          
    public void run() {
        int count = 0;
        while (true) {
            try { Thread.sleep(10); } catch (Exception e) {};
         
            view.renderOnce();
            lightAngle -= 0.01;
            Vector3f dir = new Vector3f((float) -Math.cos(lightAngle),0,(float) Math.sin(lightAngle));            
            //light.setDirection(dir);
            
            modelAngle += 0.01;
            Transform3D yrot = new Transform3D();
            yrot.rotY((float) modelAngle);
            Transform3D xrot = new Transform3D();
            //xrot.rotX((float) modelAngle);
            //xrot.rotX((float) -Math.PI/2);
            yrot.mul(xrot);
            tg.setTransform(yrot);
            
            /*anim += 0.005f;
            if (anim > 1) {
                anim = 0;
            }
            model.setTime(anim);*/
            
            count++;
        }
    }
    
    public static void main(String argv[]) {        
        new TDSTest2();
    }
}

is your model and texture in a .jar?

if u want the models off the file system try this:


public static TDSModel loadBuilding(String bFileName) {
    try {
      TDSLoader tload = new TDSLoader();
      tload.setDebug(false);
      File f = new File(bFileName);
      TDSModel model = tload.load(f.getParent() + "\\", new FileInputStream(f), true);
      return(model);
    } catch (Exception ex) {
      ex.printStackTrace();
      return(null);
    }
  }

hope that helps?

Are the material settings on the model setup. What colour for instance is the model? How bright is the material? etc…

Incidently, do the packaged models work for you, e.g. the jeep?

Kev

My model and texture aren’t in a .jar archive. They are in the directory model/WA.

I don’t really understant the piece of code posted by aNt. If it for load models and textures in a .jar archive ?

I can send you the 3DS file, if you want.

The jeep model is running correctly. A curious thing is that if I load the model in Wings3D, when it import the texture, it says :
Corrupt JPEG data: 15 extraneous bytes before marker 0xee
Is it because my texture model isn’t corrupted that it won’t load ? ??? So strange !

I will try to apply the texture jeep1.jpg on my model and see what the 3DS loader do.

The model’s color is white and the texture William.jpg is covering the entire model.

I forgot to say that the texture jeep1.jpg is loaded correctly by Wings3D even it’s corrupted.

my code is for loading from a directory not a .jar. the
code in Kevs demo works with .jar’s (handy later in the
game).

make sure your textures are of sizes 128128, 512512, 1024*1024 etc…

u can send me over your model- i can try it in my loader
tests [see your messages]. i dont use Wing3D mind-
more of a Maya dude.

Haven’t had a chance to try this yet, will do very soon (i.e. now ;))

Kev

aNt,

your code is running correctly with the jeep model but not with my model.

I think I will change for MD2 models.

Is it a good idea to use MD2 models for characters AND other objects like the earth surface, trees, rocks, and so…

Character models yes, static models no…

Could you send me the non-textured model, the textured model appears to have no triangle-mesh information in it (no chunk 0x4000)

In addition, if you want to change for static models, how about ascii 3ds or OBJ?

Kev

OK, I send you the non-textured model.

Why should’nt I use MD2 format for static models ? it’s not a problem to have just one frame in the model ?

Anybody knows if there is a good modeler/animator for Linux that edit MD2 models ?

Is it possible to texture a model in the OBJ format ?

You’ll get a bit overhead with MD2 for single frame model. No real hardship its just not what they were designed for…

OBJ - texture, yep.

Kev

Okay. Thanks everybody for all your answers.