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
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)-
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