Author Topic: View a simple .3ds model  (Read 2431 times)

Offline Pascal

  • byte
  • *
  • Posts: 6
    • View Profile
View a simple .3ds model
« on: October 17, 2012, 02:44:42 pm »
Hello,
i just tested the HelloWorld Applet and it works well. But when I want to change the Object3D "box" from the given Primitives.getBox(...) to a 3D-model (commented Line below it), after compiling and opening the .html file, there is still the green Box shown and not my 3D-model. Also when I change the Primitives.getBox() to .getCube(15) there is still the green Box from the beginning and no Cube.

Why does this happen?

Thanks for your help,
Pascal

Code: [Select]
private Object3D box;

    private FrameBuffer buffer = null;
    private World world = null;

    private boolean alive = true;
    private boolean initialized = false;

    @Override
    // Initialize all components of the applet
    public void init()
    {

        world = new World();  // create a new world
        World.setDefaultThread( Thread.currentThread() );

        // Add some light to the scene
        world.setAmbientLight(0, 255, 0);


        // create a new buffer to draw on:
        buffer = new FrameBuffer( getWidth(), getHeight(),
                                  FrameBuffer.SAMPLINGMODE_NORMAL );

// the lines iīm talking about
//**************************************************       
       
        // Create the box:
        box = Primitives.getBox(13f, 2f);
//      box = Loader.load3DS("D:/Temp/Tele.3ds",1)[0];
        box.build();

//**************************************************   

        // add the box our world:
        world.addObject( box );

        // set the camera's position:
        world.getCamera().setPosition( 50, -50, -5 );

        // Look at the box:
        world.getCamera().lookAt( box.getTransformedCenter() );

        // Finished initializing.  Now it is safe to paint.
        initialized = true;

        // Start the main "Game Loop":
        new Thread( this ).start();
    }

    // Main Game Loop:
    @Override
    public void run()
    {
        while( alive )
        {
            // Have the box rotate:
            box.rotateY( 0.01f );

            // Tell the applet to repaint itself:
            this.repaint();

            // Sleep for a bit:
            try
            {
                Thread.sleep( 10 );
            }
            catch( Exception e )
            {}
        }
    }

    // Draw the scene:
    @Override
    public void paint( Graphics g )
    {
        // Make sure jPCT is finished initializing:
        if( !initialized )
            return;

        buffer.clear();   // erase the previous frame

        // render the world onto the buffer:
        world.renderScene( buffer );
        world.draw( buffer );
        buffer.update();

        buffer.display( g, 0, 0 );
    }

    // End the main game loop:
    @Override
    public void destroy()
    {
    alive = false;
    }
}

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: View a simple .3ds model
« Reply #1 on: October 17, 2012, 02:53:11 pm »
It's probably a cache issue. Clear your cache. If you're using Firefox, good luck with that (Firefox's cache is a nightmare).

Offline Pascal

  • byte
  • *
  • Posts: 6
    • View Profile
Re: View a simple .3ds model
« Reply #2 on: October 17, 2012, 03:20:16 pm »
Thanks, an other browser and the Cube works. But importing my .3ds model still doesnīt work (the Applet loads and then there is only an empty window) and there is no Error-Message...

It is a free .3ds model that I have. Isnīt it so easy to show it in the applet as i thought? Or whatīs going wrong?

The model I used: http://artist-3d.com/free_3d_models/dnm/model_disp.php?uid=2719&count=count

Iīm new in 3d-programming and experiment a little bit to get to know how it works

Best Regards,
Pascal

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: View a simple .3ds model
« Reply #3 on: October 17, 2012, 08:22:09 pm »
The problem here is most likely that each model has different properties. Some have a large scale, some are very small. Some are located around the origin, some are way off. Chances are that your model is there, but you are just not looking at it. Try to mode the camera further away (i.e. -50 or -100 instead of -5 for the z value) and see if that helps. If it doesn't, play around with scale factor in the loading method (currently 1 in your code). Increase it to 10 or 100. Also make sure that the first array index that you are using actually contains the whole mesh (i.e. the array returned by the loader has a size of 1). If it isn't, better do something like

Code: [Select]
box = Object3D.mergeAll(Loader.load3DS("D:/Temp/Tele.3ds",1));