Author Topic: Few textures were applied and few not.  (Read 910 times)

Offline mallikpavan

  • byte
  • *
  • Posts: 8
    • View Profile
Few textures were applied and few not.
« on: March 18, 2015, 08:13:19 pm »
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.


Code: [Select]
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;
}
}
« Last Edit: March 19, 2015, 10:06:20 am by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Few textures were applied and few not.
« Reply #1 on: March 19, 2015, 10:07:26 am »
Don't do this:

Code: [Select]
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.

Offline mallikpavan

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Few textures were applied and few not.
« Reply #2 on: March 20, 2015, 07:42:21 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Few textures were applied and few not.
« Reply #3 on: March 21, 2015, 09:28:39 am »
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?

Offline mallikpavan

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Few textures were applied and few not.
« Reply #4 on: March 22, 2015, 05:40:20 pm »
Hi EgonOlsen

        Please find the attached log.zip file.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Few textures were applied and few not.
« Reply #5 on: March 22, 2015, 08:20:50 pm »
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".

Offline mallikpavan

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Few textures were applied and few not.
« Reply #6 on: March 24, 2015, 07:39:01 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Few textures were applied and few not.
« Reply #7 on: March 24, 2015, 11:22:28 am »
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?

Offline mallikpavan

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Few textures were applied and few not.
« Reply #8 on: March 24, 2015, 11:52:36 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Few textures were applied and few not.
« Reply #9 on: March 24, 2015, 12:26:53 pm »
Just add or modify a call to world.setAmbient(255, 255, 255).

Offline mallikpavan

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Few textures were applied and few not.
« Reply #10 on: March 24, 2015, 12:42:50 pm »
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.   :) :) :) :) :) :) :) :) :) :)