how to load the model

Started by luozi, November 02, 2011, 07:58:22 AM

Previous topic - Next topic

luozi

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?
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.public InputStream loadf(String fileName)
{

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

}
catch(IOException e){
return null;

}
}

EgonOlsen

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.

luozi

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]

EgonOlsen

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

luozi

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!

acfabro

#5
Quote from: EgonOlsen on November 02, 2011, 09:58:08 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

EgonOlsen

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.

acfabro

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.


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.