Few textures were applied and few not.

Started by mallikpavan, March 18, 2015, 08:13:19 PM

Previous topic - Next topic

mallikpavan

Hi

       I tried to load a .3ds file into android by using our jpct-ae. i read the texture names from the file by using

String[] names_textures=Loader.readTextureNames3DS(mActivity.getResources().openRawResource(R.raw.house));

the above code returned me the list of texture files. i gave the same names while loading texture files but few of the textures only applied to the model object, rest of the textures were not. would you please tell me the reason why? Below is the my code.



package com.qualcomm.QCARSamples.ImageTargets;

import java.io.InputStream;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;
import android.util.DisplayMetrics;

import com.qualcomm.QCAR.QCAR;
import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;

/** The renderer class for the ImageTargets sample. */
public class ImageTargetsRenderer implements GLSurfaceView.Renderer {
public boolean mIsActive = false;

/** Reference to main activity **/
public ImageTargets mActivity;

private FrameBuffer fb;

private World world;

private float[] modelViewMat;

private Light sun;

private Object3D cube;
private Camera cam;

private float fov;

private float fovy;

/** Native function for initializing the renderer. */
public native void initRendering();

/** Native function to update the renderer. */
public native void updateRendering(int width, int height);

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

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

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

TextureManager.getInstance().addTexture(
"Siding16.jpg",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.siding16))));
TextureManager.getInstance().addTexture(
"LTCHER~3.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.ltcher3))));
TextureManager.getInstance().addTexture(
"LTHICK~4.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.lthick4))));
TextureManager.getInstance().addTexture(
"LAKEER~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.lakeer1))));
TextureManager.getInstance().addTexture(
"CHAIRR~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.chairr1))));
TextureManager.getInstance().addTexture(
"FAWNHA~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.fawnha1))));
TextureManager.getInstance().addTexture(
"AFRICA~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.africa1))));
TextureManager.getInstance().addTexture(
"518lmpw.jpg",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.c518lmpw))));
TextureManager.getInstance().addTexture(
"612cdw.jpg",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.c612cdw))));
TextureManager.getInstance().addTexture(
"MDCHER~3.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.mdcher3))));
TextureManager.getInstance().addTexture(
"STUCCO03.jpg",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.stucco03))));
TextureManager.getInstance().addTexture(
"Grass01.jpg",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.grass01))));
TextureManager.getInstance().addTexture(
"NAE62C~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.nae62c1))));
TextureManager.getInstance().addTexture(
"WOODFL~3.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.woodfl3))));
TextureManager.getInstance().addTexture(
"SH6ABB~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.sh6abb1))));
TextureManager.getInstance().addTexture(
"Plywood.jpg",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.plywood))));
TextureManager.getInstance().addTexture(
"VENTWH~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.ventwh1))));
TextureManager.getInstance().addTexture(
"MDMAPC~1.JPG",
new Texture(BitmapHelper.convert(mActivity.getResources()
.getDrawable(R.drawable.mdmapc1))));


cube = load3DSModel(
mActivity.getResources().openRawResource(R.raw.house), 0.01f);


cube.calcTextureWrapSpherical();

cube.strip();
cube.build();

world.addObject(cube);

cam = world.getCamera();

SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;

sun.setPosition(sv);

MemoryHelper.compact();
}

/** Called when the surface is created or recreated. */
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
DebugLog.LOGD("GLRenderer::onSurfaceCreated");

// Call native function to initialize rendering:
initRendering();

// Call Vuforia function to (re)initialize rendering after first use
// or after OpenGL ES context was lost (e.g. after onPause/onResume):
QCAR.onSurfaceCreated();
}

/** Called when the surface changed size. */
public void onSurfaceChanged(GL10 gl, int width, int height) {
DebugLog.LOGD(String.format("GLRenderer::onSurfaceChanged (%d, %d)",
width, height));

if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(width, height);
Config.viewportOffsetAffectsRenderTarget = true;

// Call native function to update rendering when render surface
// parameters have changed:
updateRendering(width, height);

// Call Vuforia function to handle render surface size changes:
QCAR.onSurfaceChanged(width, height);
}

/** The native render function. */
public native void renderFrame();

/** Called to draw the current frame. */
public void onDrawFrame(GL10 gl) {
if (!mIsActive)
return;

// Update render view (projection matrix and viewport) if needed:
mActivity.updateRenderView();

// Call our native function to render content
renderFrame();

updateCamera();

world.renderScene(fb);
world.draw(fb);
fb.display();
}

public void updateModelviewMatrix(float mat[]) {
modelViewMat = mat;
}

public void updateCamera() {
if (modelViewMat != null) {
float[] m = modelViewMat;

final SimpleVector camUp;
if (mActivity.isPortrait()) {
camUp = new SimpleVector(-m[0], -m[1], -m[2]);
} else {
camUp = new SimpleVector(-m[4], -m[5], -m[6]);
}

final SimpleVector camDirection = new SimpleVector(m[8], m[9],
m[10]);
final SimpleVector camPosition = new SimpleVector(m[12], m[13],
m[14]);

cam.setOrientation(camDirection, camUp);
cam.setPosition(camPosition);

cam.setFOV(fov);
cam.setYFOV(fovy);
}
}

public void setVideoSize(int videoWidth, int videoHeight) {

DisplayMetrics displaymetrics = new DisplayMetrics();
mActivity.getWindowManager().getDefaultDisplay()
.getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;

int widestVideo = videoWidth > videoHeight ? videoWidth : videoHeight;
int widestScreen = width > height ? width : height;

float diff = (widestVideo - widestScreen) / 2;

Config.viewportOffsetY = diff / widestScreen;
}

public void setFov(float fov) {
this.fov = fov;
}

public void setFovy(float fovy) {
this.fovy = fovy;
}

private Object3D load3DSModel(InputStream is, float scale) {
Object3D[] model = Loader.load3DS(is, scale);
Object3D o3d = new Object3D(0);
Object3D temp = null;
for (int i = 0; i < model.length; i++) {
temp = model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateX((float) (+.5 * Math.PI));
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
}
return o3d;
}
}


EgonOlsen

Don't do this:


cube.calcTextureWrapSpherical();


It's part of the example to generate some texture coordinates. If the model already has some, it's not needed and actually hurts.

mallikpavan

Hi EgonOlsen

Thanks for the reply. I removed cube.calcTextureWrapSpherical(); But it's not working for me. would you please provide me any sample source code which contains .3ds file displaying with multiple textures?

I tried to display the below .3ds model.

http://www.shareaec.com/v/22436/browse/5/3D-Model/Stone-Front-Home


Only few of the textures are applying to this model few were not like gross & top.

Thanks in advance.

EgonOlsen

Your code looks fine to me as long as these are really the actual texture names. Can you post the log output from loading this model, please?

mallikpavan

Hi EgonOlsen

        Please find the attached log.zip file.

EgonOlsen

If there would be some textures that the loader can't find in the TextureManager, a message like 'Texture named...added to TextureManager!' would appear. This isn't the case, so that's not the issue. Your textures seems to be fine by itself. So either your file just doesn't contain texture names for the missing parts (might be an exporter issue) or the texture are applied but the uv-mapping isn't right. I loaded the model in DeepExploration and while it shows textures on all parts, uv-mapping of the roof and some other parts of the house is wrong there as well.
Do you have a screen shot? Maybe we are talking about different things here when we say that "textures aren't applied".

mallikpavan

Hi EgonOlsen

     I attached the screen shot of my model. in the image, black area should be green color gross but it is showing as black color.

EgonOlsen

Are you sure that this is a missing texture and not just a lighting issue. The image is very dark, it's hard to see anything. Have you tried to increase the ambient color?

mallikpavan

Hi EgonOlsen

             thanks alot for your patience and quick response. I didn't increase any ambient colors in my code. i am just fallowing the same code which i attached to our previous conversation (i.e March 18, 2015, 08:13:19 pm). If you don't mine would you please share me the source code what you have tried?

EgonOlsen

Just add or modify a call to world.setAmbient(255, 255, 255).

mallikpavan

Hi EgonOlsen

       Finally i am able to set the textures to my model by removing below code.

        world.setAmbientLight(20, 20, 20);
        sun.setIntensity(250, 250, 250);

           
             Thank you so much for you support and response.   :) :) :) :) :) :) :) :) :) :)