Author Topic: Loading an ASC file  (Read 2103 times)

Offline MarcoBelotti

  • byte
  • *
  • Posts: 2
    • View Profile
Loading an ASC file
« on: March 06, 2015, 09:22:14 am »
Hi guys, I'm pretty new to the JPCT world and I'm starting a project on DTMs (digital terrain models). Basically what you get is an ASC file with a matrix of coordinates representing the elevation of that point. I saw that JPCT had a function to load these files, so I  tried to write a program, but I can't load thev 3D model
The code is

Code: [Select]
import java.io.ByteArrayInputStream;
import java.io.InputStream;

import com.threed.jpct.*;

import javax.naming.Context;
import javax.swing.*;

public class prova {

private World world;
private FrameBuffer buffer;
private Object3D map;
private JFrame frame;

public static void main(String[] args) throws Exception {
new prova().loop();
}

public prova() throws Exception {

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

world = new World();
world.setAmbientLight(0, 255, 0);

    TextureManager texMan=TextureManager.getInstance();


    Texture rocks=new Texture("rocks.jpg");
    texMan.addTexture("rocks", rocks);
   
map=Loader.loadASC("411140_20_WGS.ASC", 400, false);      
    map.setTexture("rocks");
world.addObject(map);

    map.enableLazyTransformations();
    map.build();
    SimpleVector pos=map.getCenter();
    pos.scalarMul(-1f);
    map.translate(pos);
    map.rotateX((float)-Math.PI/2f);
    map.translateMesh();
    map.rotateMesh();
        map.setTranslationMatrix(new Matrix());
        map.setRotationMatrix(new Matrix());
    map.createTriangleStrips(2);


world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(map.getTransformedCenter());
}

public void loop() throws Exception
{
buffer = new FrameBuffer(1024, 860, FrameBuffer.SAMPLINGMODE_NORMAL);

while (frame.isShowing()) {
map.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);
}
}

Note that my code can have many errors, beacuse I'm still learning. Anyone knows why it doesn't work?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading an ASC file
« Reply #1 on: March 06, 2015, 09:49:18 am »
jPCT loads ASC, which is an old text-based variant of the 3ds format. It doesn't mean that it can load every ASCII-based (i.e. text based) format in existence. In your case, i think that ASC != ASC...so you would have to write a loader for your format yourself.

Offline MarcoBelotti

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Loading an ASC file
« Reply #2 on: March 06, 2015, 09:57:22 am »
So what kind of ASC files does JPCT support?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading an ASC file
« Reply #3 on: March 06, 2015, 11:04:08 am »
As said, it supports ASC, which is an old export format of 3ds.