My texture is loaded but 3d model is still black why ?

Started by alper, November 13, 2014, 04:26:37 PM

Previous topic - Next topic

alper

public ImageTargetsRenderer(ImageTargets activity) {
this.mActivity = activity;

world = new World();
world.setAmbientLight(50,50,50);

sun = new Light(world);
sun.setIntensity(255, 255, 255);

// Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.hearse)), 64, 64));
//        TextureManager.getInstance().addTexture("texture", texture);

Config.maxPolysVisible = 1000;
Config.farPlane = 4000;
Config.collideOffset = 500;
Config.glTrilinear = true;

Bitmap textureImage = BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.hearse));
Texture texture = new Texture(textureImage);
        TextureManager.getInstance().addTexture("texture", texture);
       
        if(texture != null)
        {
        Log.i("Texture load", "texture is loaded");
        }

float scaleSize = 1;
try {

carModel = Object3D.mergeAll(Loader.loadOBJ(mActivity.getResources().getAssets().open("hearse.obj"),
mActivity.getResources().getAssets().open("hearse.obj.mtl"),scaleSize));

// carModel = Object3D.mergeAll(Loader.load3DS(mActivity.getResources().getAssets().open("stealth.3ds"), scaleSize));

} catch (IOException e) {
Toast errorToast2 = Toast.makeText(mActivity.getApplicationContext(), "3d model is not loaded", Toast.LENGTH_LONG);
errorToast2.show();
e.printStackTrace();
}
carModel.calcTextureWrap();
carModel.setTexture("texture");
carModel.setLighting(Object3D.LIGHTING_ALL_ENABLED);
carModel.setEnvmapped(true);
carModel.strip();
carModel.build();

world.addObject(carModel);

cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.setFOV(1.5f);

SimpleVector sv = new SimpleVector();
sv.set(carModel.getTransformedCenter());
sv.y += 100;
sv.z += 100;

sun.setPosition(sv);

MemoryHelper.compact();
}


My 3d model is appearing its okay, but full of surface is black. I have true width and height .jpg texture file, and i have no error in code. However model is good but its black and i didnt find the solution. Please help me.

EgonOlsen

#1
The code seems to be more or less a direct copy of the HelloWorld example, which means that it includes some stuff that isn't needed in this context. First, remove the call to setEnvMapped(). If your model has proper texture coordinates, you don't need it. It's not properly working on Android anyway. Second, try to get rid of the scale/convert calls when loading the texture. The example uses them to convert the icon bitmap. If your texture is already 64*64 (or some others power if two), you don't need all that. Just load the file as it is.
If it's still black, maybe your model has no proper texture coordinates.

alper

First, thank you. I will try your advice and again write here. And, yes you're right it's a little bit changed Helloworld example. I have 256*256 .jpg. Also, i already deleted and tried setEnvMapped() method it's same...

EgonOlsen

Make sure that your model has texture coordinates. If you are unsure, just upload it, so we can check it.

alper

I did changes you suggested. Here is the code :

public ImageTargetsRenderer(ImageTargets activity) {
this.mActivity = activity;

world = new World();
world.setAmbientLight(50,50,50);

sun = new Light(world);
sun.setIntensity(255, 255, 255);

// Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.hearse)), 64, 64));
//        TextureManager.getInstance().addTexture("texture", texture);

Config.maxPolysVisible = 1000;
Config.farPlane = 4000;
Config.collideOffset = 500;
Config.glTrilinear = true;

Drawable textureImage = mActivity.getResources().getDrawable(R.drawable.hearse);
Texture texture = new Texture(textureImage);
texture.setClamping(true); // I try with it and without it, its same
        TextureManager.getInstance().addTexture("texture", texture);
       
        if(texture != null)
        {
        Log.i("Texture load", "texture is loaded");
        }

float scaleSize = 1;
try {

carModel = Object3D.mergeAll(Loader.loadOBJ(mActivity.getResources().getAssets().open("hearse.obj"),
mActivity.getResources().getAssets().open("hearse.obj.mtl"),scaleSize));

// carModel = Object3D.mergeAll(Loader.load3DS(mActivity.getResources().getAssets().open("hearse.3ds"), scaleSize));

} catch (IOException e) {
Toast errorToast2 = Toast.makeText(mActivity.getApplicationContext(), "3d model is not loaded", Toast.LENGTH_LONG);
errorToast2.show();
e.printStackTrace();
}
carModel.calcTextureWrap();
carModel.setTexture("texture");
carModel.setLighting(Object3D.LIGHTING_ALL_ENABLED);
carModel.strip();
carModel.build();

world.addObject(carModel);

cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.setFOV(1.5f);

SimpleVector sv = new SimpleVector();
sv.set(carModel.getTransformedCenter());
sv.y += 100;
sv.z += 100;

sun.setPosition(sv);

MemoryHelper.compact();
}


It's probably texture coordinates is okay. I deleted setEnvMapped() method (default is false). And my texture is loading properly (Drawable, and texture constructor has drawable variable). Also, I have no error in code and logcat. However my model is still black. I upload my model and texture. If you want, If it helps, i can upload a picture of modal in my phone...

NOTE: I convert hearse.3ds to .mtl, .obj file format, because when ı load .3ds model it will appear upright on the screen

naldo

Quote from: alper on November 14, 2014, 09:23:52 AM

It's probably texture coordinates is okay. I deleted setEnvMapped() method (default is false). And my texture is loading properly (Drawable, and texture constructor has drawable variable). Also, I have no error in code and logcat. However my model is still black. I upload my model and texture. If you want, If it helps, i can upload a picture of modal in my phone...

NOTE: I convert hearse.3ds to .mtl, .obj file format, because when ı load .3ds model it will appear upright on the screen

Yep i already tested it (.3ds) and the model looks fine with the texture.
I think you could remove the "calcTextureWrap()" call in your code.

EgonOlsen

Quote from: naldo on November 14, 2014, 09:50:55 AM
I think you could remove the "calcTextureWrap()" call in your code.
Yes, naldo is right. Remove that call! I haven't noticed it ealier. It's used by the example to create some texture coordinates. You must not call it for models that provide them.

alper

Thanks to you brother. Its solved.
Now, One little question. Model is just a little bit shaking. How do I solve this ?

EgonOlsen


alper

When texture and model is loaded, model is vibrating just a little bit. Also, I have planned onTouchEvent and Animation ( I guess i can do that ). So, I think that it will be a problem vibrating model. May be, it is not problem, but i dont know now.

EgonOlsen

Honestly, i've no idea what you mean by 'vibrating'. If you don't apply any transformations to it, it can't do anything. If you do, they are obviously flawed. Is the code in onDrawFrame() still a copy of the HelloWorld example? If it is, then vibrations indicate that some touch events happen. If that is the case without you touching anything, your touch screen might be flawed.

alper

Now it is done i did good. Model is more stable not shaking. Thank you brother. Screen is not flowed, it was my mistake. Again thank you. "Where do I start doing onTouchEvent" is my new question :)