Author Topic: how to load the model  (Read 4711 times)

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
how to load the model
« on: November 02, 2011, 07:58:22 am »
I want to create a sphere with texture coordinates, so I download the terra.asc. I load the file, and when I start it , it stop unexpectedly. I try many times, but it still doesn't work, can any one help me?
Code: [Select]
try {
model = Loader.loadASC(new FileInputStream("/assets/terra.asc"), 4, true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

model.setTexture("texture");
model.strip();
model.build();
world.addObject(model);
by the way, is there something wrong with the following code, I load the model using that fist, but when I use this function , the program will stop unexpectedly, thank you.
Code: [Select]
public InputStream loadf(String fileName)
{

AssetManager am=getResources().getAssets();
try{
return am.open(fileName,AssetManager.ACCESS_STREAMING);

}
catch(IOException e){
return null;

}
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: how to load the model
« Reply #1 on: November 02, 2011, 10:08:54 am »
stop unexpectedly says nothing and it's impossible to find a problem only with that information. You have to look in the ddms log output to see the actual exception.

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: how to load the model
« Reply #2 on: November 02, 2011, 03:42:36 pm »
Yes, I find that it says out of memory, so I load .obj files and md2 file, they work perfectly. Somehow, later I load the terra.asc, it work fine. I am not sure what happened, but I still have some question:
1. when I load the obj file and call setTexture(), but there is no texture on the object ,so the obj file doesn't contain texture coordinates , is that right?
2.when I load the md2 file and call setTexture(), the texture wrap the object perfectly, so the md2  file contains the texture coordinates, and if I want to create a object with texture, I just load the model, and set the texture using the picture, am I right?
3.when I load the obj terra.asc, it should work perfectly, but when I call setTexture(),the sphere's texture is not what I expected, I attach the picture. It isn't the result of the demon "earth". Is the texture coordinates different? Can you explain for me? Thank you!

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: how to load the model
« Reply #3 on: November 02, 2011, 09:58:08 pm »
1.) Yes. No all OBJ-files come with proper texture coordinates, but that's not a limitation of the format. OBJ itself can contain texture coordinates. Just not all models do.
2.) Yes
3.) IIRC, terra.asc has proper texture coordinates for a sperical texture, i.e. if you take for example this image and rescale it to 512*256 or something, it should look fine: http://celestia.h-schmidt.net/earth-vt/unshaded1024.jpg

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: how to load the model
« Reply #4 on: November 03, 2011, 05:16:03 pm »
Sorry about my late reply. Your picture works fine on the sphere. Then I try to understand your " the coordinates is proper for special texture", but I can't understand it. I tried a small picture , it doesn't wrap the shpere completly, when I try a bigger one it overlay some part. What confuse me is that the texture is an array, and the texture coordinates is the relative coordinate. It just point out what part of the texture will be applied in the vertex( there is always a part of the texture will be). If that is true why I have to rescale the texture to a special size? And is there any difference between the pictures of different size? Thank you!

Offline acfabro

  • byte
  • *
  • Posts: 2
    • View Profile
Re: how to load the model
« Reply #5 on: April 24, 2012, 12:58:59 pm »
3.) IIRC, terra.asc has proper texture coordinates for a sperical texture, i.e. if you take for example this image and rescale it to 512*256 or something, it should look fine: http://celestia.h-schmidt.net/earth-vt/unshaded1024.jpg

Loading terra.asc and applying a 512x256 texture worked for me, thanks! However, when I try rotateY() and rotateX() on the Object3D object, the center seems off -- what I mean to say is it looks like it is rotating around an axis which is not in the center of the sphere. When I used Primitives.getSphere() to generate the sphere, the rotation seems fine. Do you have any recommendations?

TIA
« Last Edit: April 24, 2012, 01:01:52 pm by acfabro »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: how to load the model
« Reply #6 on: April 24, 2012, 05:02:08 pm »
The center is calculated when calling build() based on the objects geometry. That's not always what you want. Try to set the rotation pivot after calling build() to 0,0,0.

Offline acfabro

  • byte
  • *
  • Posts: 2
    • View Profile
Re: how to load the model
« Reply #7 on: April 27, 2012, 06:15:03 pm »
Thanks Egon, i did that, but something entirely different happened -- the model appeared to revolve around an orbit.

Actually I solved my problem, I just to align the camera to the object then looked at it.

Code: [Select]
cam = world.getCamera();
cam.setPosition(sphere.getTransformedCenter().x, sphere.getTransformedCenter().y, -5);
cam.lookAt(sphere.getTransformedCenter());

I'm using the JPCT-AE Hello World code but changed the part where I load terra.asc in place of Primitives.getCube().

So I'm assuming when the model from terra.asc was loaded, it's center wasn't at 0,0,0 which is why I had to align the camera first. Is that correct?

I really appreciate this, I've just started to learn to use this stuff.