Home | History | Annotate | Download | only in android
      1 
      2 /*
      3  * Android 2.2+ SimpleTextured test.
      4  *
      5  * created: Mon Nov  8 00:08:22 EST 2010
      6  */
      7 
      8 package jme3test.android;
      9 
     10 
     11 import com.jme3.app.SimpleApplication;
     12 import com.jme3.asset.TextureKey;
     13 import com.jme3.light.PointLight;
     14 import com.jme3.material.Material;
     15 import com.jme3.math.ColorRGBA;
     16 import com.jme3.math.Vector3f;
     17 import com.jme3.scene.Geometry;
     18 import com.jme3.scene.Mesh;
     19 import com.jme3.scene.Node;
     20 import com.jme3.scene.shape.Box;
     21 import com.jme3.scene.shape.Sphere;
     22 import com.jme3.texture.Texture;
     23 import com.jme3.util.TangentBinormalGenerator;
     24 
     25 
     26 public class SimpleTexturedTest extends SimpleApplication {
     27 
     28 	private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(SimpleTexturedTest.class.getName());
     29 
     30 
     31 	private Node spheresContainer = new Node("spheres-container");
     32 
     33 
     34 	private boolean lightingEnabled = true;
     35 	private boolean texturedEnabled = true;
     36 	private boolean spheres = true;
     37 
     38 	@Override
     39 	public void simpleInitApp() {
     40 
     41 	    //flyCam.setRotationSpeed(0.01f);
     42 
     43 
     44 		Mesh shapeSphere = null;
     45 		Mesh shapeBox = null;
     46 
     47 
     48 		shapeSphere = new Sphere(16, 16, .5f);
     49 		shapeBox = new Box(Vector3f.ZERO, 0.3f, 0.3f, 0.3f);
     50 
     51 
     52 	//	ModelConverter.optimize(geom);
     53 
     54 		Texture texture = assetManager.loadTexture(new TextureKey("Interface/Logo/Monkey.jpg"));
     55 		Texture textureMonkey = assetManager.loadTexture(new TextureKey("Interface/Logo/Monkey.jpg"));
     56 
     57 		Material material = null;
     58 		Material materialMonkey = null;
     59 
     60 		if (texturedEnabled) {
     61 			if (lightingEnabled) {
     62 				material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
     63 				material.setBoolean("VertexLighting", true);
     64 				material.setFloat("Shininess", 127);
     65 				material.setBoolean("LowQuality", true);
     66 				material.setTexture("DiffuseMap", texture);
     67 
     68 				materialMonkey = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
     69 				materialMonkey.setBoolean("VertexLighting", true);
     70 				materialMonkey.setFloat("Shininess", 127);
     71 				materialMonkey.setBoolean("LowQuality", true);
     72 				materialMonkey.setTexture("DiffuseMap", textureMonkey);
     73 
     74 			} else {
     75 				material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
     76 				material.setTexture("ColorMap", texture);
     77 
     78 				materialMonkey = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
     79 				materialMonkey.setTexture("ColorMap", textureMonkey);
     80 			}
     81 		} else {
     82 			material = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
     83 			material.setColor("Color", ColorRGBA.Red);
     84 			materialMonkey = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
     85 			materialMonkey.setColor("Color", ColorRGBA.Red);
     86 		}
     87 
     88 		TangentBinormalGenerator.generate(shapeSphere);
     89 		TangentBinormalGenerator.generate(shapeBox);
     90 
     91 		int iFlipper = 0;
     92 		for (int y = -1; y < 2; y++) {
     93 			for (int x = -1; x < 2; x++){
     94 				Geometry geomClone = null;
     95 
     96 				//iFlipper++;
     97 				if (iFlipper % 2 == 0)
     98 				{
     99 					geomClone = new Geometry("geometry-" + y + "-" + x, shapeBox);
    100 				}
    101 				else
    102 				{
    103 					geomClone = new Geometry("geometry-" + y + "-" + x, shapeSphere);
    104 				}
    105 				if (iFlipper % 3 == 0)
    106 				{
    107 					geomClone.setMaterial(materialMonkey);
    108 				}
    109 				else
    110 				{
    111 					geomClone.setMaterial(material);
    112 				}
    113 				geomClone.setLocalTranslation(x, y, 0);
    114 
    115 //				Transform t = geom.getLocalTransform().clone();
    116 //				Transform t2 = geomClone.getLocalTransform().clone();
    117 //				t.combineWithParent(t2);
    118 //				geomClone.setLocalTransform(t);
    119 
    120 				spheresContainer.attachChild(geomClone);
    121 			}
    122 		}
    123 
    124 		spheresContainer.setLocalTranslation(new Vector3f(0, 0, -4f));
    125 		spheresContainer.setLocalScale(2.0f);
    126 
    127 		rootNode.attachChild(spheresContainer);
    128 
    129 		PointLight pointLight = new PointLight();
    130 
    131 		pointLight.setColor(new ColorRGBA(0.7f, 0.7f, 1.0f, 1.0f));
    132 
    133 		pointLight.setPosition(new Vector3f(0f, 0f, 0f));
    134 		pointLight.setRadius(8);
    135 
    136 		rootNode.addLight(pointLight);
    137 	}
    138 
    139 	@Override
    140 	public void simpleUpdate(float tpf) {
    141 
    142 		// secondCounter has been removed from SimpleApplication
    143                 //if (secondCounter == 0)
    144 		//	logger.info("Frames per second: " + timer.getFrameRate());
    145 
    146 		spheresContainer.rotate(0.2f * tpf, 0.4f * tpf, 0.8f * tpf);
    147 	}
    148 
    149 }
    150 
    151