Author Topic: Help pls. Resources problem  (Read 1092 times)

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Help pls. Resources problem
« on: October 17, 2011, 11:04:56 pm »
Hello!
The question probably stupid and has the obvious solution, but I can not solve the problem.
I have two classes -
The main TamagochiActivity
And additional AnimationEn which I set up for animation.

But when I initialize the model he can not find the resources (textures, etc.)

I can as it is not properly set up a class ...
Main class TamagochiActivity
Code: [Select]
public class TamagochiActivity extends Activity {

// Used to handle pause and resume...
private static TamagochiActivity master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);
...
private AnimationEn teste=null;
...

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();

public MyRenderer() {

}


public void onSurfaceChanged(GL10 gl, int w, int h) {



if (fb != null) {
fb.dispose();

}
fb = new FrameBuffer(gl, w, h);



if (master == null) {

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

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




Resources res = getResources();

teste.Run();// Init myAnim animated model (Problem here)
world.addObject( teste.myAnim );// and add to world

world.buildAllObjects();
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());

SimpleVector sv = new SimpleVector();
SimpleVector sv2 = new SimpleVector();
sv.set(cube.getTransformedCenter());

sv2.set(test.getTransformedCenter());
sv2.y+=10;
sv2.x+=10;

sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = TamagochiActivity.this;
}
}
}
...

AnimationEn class (full)-


Code: [Select]
package com.demo.tamagochi;

import com.threed.jpct.Object3D;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.util.BitmapHelper;
import java.io.InputStream;

import android.app.Activity;
import android.content.res.Resources;



import com.threed.jpct.Animation;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
import com.threed.jpct.SimpleVector;


public class AnimationEn extends TamagochiActivity{
//private static AnimationEn master = null;
private float ind=0;
public Object3D myAnim=null;
//public Resources res;


public AnimationEn(){

}

public void Run(){
Resources res = getResources();//not work
//res.getR


Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(res.getDrawable(R.drawable.art)),128, 128));
TextureManager.getInstance().addTexture("texture", texture);




myAnim = loadModel( res.openRawResource(R.raw.cub1), 1.0f);

        Animation anim = new Animation(14);
        anim.setInterpolationMethod(Animation.LINEAR);
        anim.setCaching(false);
       
        anim.createSubSequence("idle");
        anim.addKeyFrame(myAnim.getMesh().cloneMesh(true));

        anim.createSubSequence("walk");
        anim.addKeyFrame(myAnim.getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub2), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub3), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub4), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub5), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub6), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub7), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub6), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub5), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub4), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub3), 1.0f).getMesh().cloneMesh(true));
        anim.addKeyFrame(loadModel(res.openRawResource(R.raw.cub2), 1.0f).getMesh().cloneMesh(true));
       
       
        myAnim.setAnimationSequence(anim);



        myAnim.setTexture("texture");

        //test.calcNormals();
        myAnim.build();

}


private Object3D loadModel(InputStream objStream, float scale) {
        Loader.setVertexOptimization(false);
        Object3D[] model = Loader.load3DS(objStream, 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.calcBoundingBox();
            o3d.calcNormals();
        }
       
        //o3d.build();
       
        return o3d;
    }
public void doAnim() {
{
ind += 0.05f;
if (ind > 1f) {
ind -= 1f;
}
}
myAnim.animate(ind,2);///,animateMe.getAnimationSequence().getSequence("standing-up"));
}


}



Please help, if its possible
« Last Edit: October 17, 2011, 11:07:48 pm by Zemalax »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Help pls. Resources problem
« Reply #1 on: October 18, 2011, 11:56:02 am »
Maybe the additional Activity has no access to the initial ones resources. Why si AnimationEn an Activity at all? Why not a simple class? Anyway, just feed the resources from the initial Activity to AnimationEn. Either in the constructor or in the method call or via some singleton ResourceProvider that will be initialized by the TamagochiActivity or something like that.

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Help pls. Resources problem
« Reply #2 on: October 18, 2011, 04:48:25 pm »
I solved the problem but probably incorrect, TamagochiActivity I made a static variable Resources. And AnimationEn now it works, but there was another tricky issue, why then in the TamagochiActivity now I can not get access to the resource. I'll have to actually try to use ResourceProvider

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Help pls. Resources problem
« Reply #3 on: October 18, 2011, 08:44:44 pm »
Just to clarify: ResourceProvider was a name that i made up. There is no such class (as far as i know) in the Android-SDK. You have to write it yourself.
« Last Edit: October 19, 2011, 06:45:04 am by EgonOlsen »

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Help pls. Resources problem
« Reply #4 on: October 18, 2011, 11:35:51 pm »
I know it) After reading the forums, people faced with this problem. And one solution I came. Just clean project O_o