Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - mallikpavan

Pages: [1]
1
Support / 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;
}
}

2
Support / How to attach multiple textures to single .3ds file
« on: March 13, 2015, 07:44:15 am »
Hi

   I tried to load a house.3ds file using JPCT-AE. i have multiple texture files to add. Below is the way how i am attaching the textures.


house= load3DSModel(
            mActivity.getResources().openRawResource(R.raw.cottagen131214),
            0.5f);

      TextureManager.getInstance().addTexture(
            "003.jpg",
            new Texture(
                  BitmapHelper.rescale(BitmapHelper.convert(mActivity
                        .getResources().getDrawable(R.drawable.c003)),
                        128, 128)));

      TextureManager.getInstance().addTexture(
            "009.jpg",
            new Texture(
                  BitmapHelper.rescale(BitmapHelper.convert(mActivity
                        .getResources().getDrawable(R.drawable.c009)),
                        128, 128)));

      TextureManager.getInstance().addTexture(
            "119.jpg",
            new Texture(
                  BitmapHelper.rescale(BitmapHelper.convert(mActivity
                        .getResources().getDrawable(R.drawable.c119)),
                        128, 128)));

      TextureManager.getInstance().addTexture(
            "221 roof gray.jpg",
            new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity
                  .getResources().getDrawable(R.drawable.c221roofgray)),
                  128, 128)));

      TextureManager.getInstance().addTexture(
            "Doski113.jpg",
            new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity
                  .getResources().getDrawable(R.drawable.doski113)), 128,
                  128)));

      TextureManager.getInstance().addTexture(
            "old3.jpg",
            new Texture(
                  BitmapHelper.rescale(BitmapHelper.convert(mActivity
                        .getResources().getDrawable(R.drawable.old3)),
                        128, 128)));

      TextureManager.getInstance().addTexture(
            "OLDMETAL.jpg",
            new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity
                  .getResources().getDrawable(R.drawable.oldmetal)), 128,
                  128)));

      TextureManager.getInstance().addTexture(
            "stone_paving_01.jpg",
            new Texture(BitmapHelper.rescale(BitmapHelper
                  .convert(mActivity.getResources().getDrawable(
                        R.drawable.stone_paving_01)), 128, 128)));

It seems not working. Please help me to apply the multiple textures to my .3ds model. thanks in advance.

Pages: [1]