If you think the Android project min3d listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.min3d;
/*www.java2s.com*/import android.graphics.Bitmap;
import com.min3d.lib.Shared;
import com.min3d.lib.Utils;
import com.min3d.lib.core.Object3dContainer;
import com.min3d.lib.core.RendererActivity;
import com.min3d.lib.objectPrimitives.Sphere;
import com.min3d.lib.vos.Light;
import com.min3d.lib.vos.TextureVo;
/**
* Shows how objects can be assigned textures dynamically.
*
* Also demonstrates how the same "textureId" can be assigned to multiple objects
* (rather than, say, needing to create two instances of a texture
* for two separate objects)
*/publicclass ExampleAssigningTexturesDynamically extends RendererActivity
{
Object3dContainer _object1;
Object3dContainer _object2;
TextureVo _jupiterTexture;
TextureVo _earthTexture;
TextureVo _moonTexture;
int _count;
publicvoid initScene()
{
scene.lights().add(new Light());
// Add three textures to TextureManager
Bitmap b;
b = Utils.makeBitmapFromResourceId(R.drawable.jupiter);
Shared.textureManager().addTextureId(b, "jupiter", false);
b.recycle();
b = Utils.makeBitmapFromResourceId(R.drawable.earth);
Shared.textureManager().addTextureId(b, "earth", false);
b.recycle();
b = Utils.makeBitmapFromResourceId(R.drawable.moon);
Shared.textureManager().addTextureId(b, "moon", false);
b.recycle();
// Create three TextureVo's
_jupiterTexture = new TextureVo("jupiter");
_earthTexture = new TextureVo("earth");
_moonTexture = new TextureVo("moon");
_object1 = new Sphere(0.8f, 15, 10);
_object1.position().y = 0.9f;
scene.addChild(_object1);
_object2 = new Sphere(0.8f, 15, 10);
_object2.position().y = -0.9f;
scene.addChild(_object2);
_count = 0;
}
@Override
publicvoid updateScene()
{
_count++;
// Assign a different texture to the two objects
// every second or so
if (_count % 240 == 0) {
_object1.textures().clear(); // ie, no texture
_object2.textures().clear();
}
elseif (_count % 240 == 60) {
_object1.textures().addReplace(_jupiterTexture);
_object2.textures().addReplace(_jupiterTexture);
}
elseif (_count % 240 == 120) {
_object1.textures().addReplace(_earthTexture);
_object2.textures().addReplace(_earthTexture);
}
elseif (_count % 240 == 180) {
_object1.textures().addReplace(_moonTexture);
_object2.textures().addReplace(_moonTexture);
}
_object1.rotation().y +=1;
_object2.rotation().y -=1;
}
}