1/*
2 * To change this template, choose Tools | Templates and open the template in
3 * the editor.
4 */
5package jme3test.batching;
6
7
8import com.jme3.app.SimpleApplication;
9import com.jme3.light.DirectionalLight;
10import com.jme3.material.Material;
11import com.jme3.math.ColorRGBA;
12import com.jme3.math.FastMath;
13import com.jme3.math.Quaternion;
14import com.jme3.math.Vector3f;
15import com.jme3.scene.BatchNode;
16import com.jme3.scene.Geometry;
17import com.jme3.scene.Node;
18import com.jme3.scene.shape.Box;
19import com.jme3.system.NanoTimer;
20import com.jme3.util.TangentBinormalGenerator;
21
22/**
23 *
24 * @author Nehon
25 */
26public class TestBatchNode extends SimpleApplication {
27
28    public static void main(String[] args) {
29
30        TestBatchNode app = new TestBatchNode();
31        app.start();
32    }
33    BatchNode batch;
34
35    @Override
36    public void simpleInitApp() {
37        timer = new NanoTimer();
38        batch = new BatchNode("theBatchNode");
39
40        /**
41         * A cube with a color "bleeding" through transparent texture. Uses
42         * Texture from jme3-test-data library!
43         */
44        Box boxshape4 = new Box(Vector3f.ZERO, 1f, 1f, 1f );
45        cube = new Geometry("cube1", boxshape4);
46        Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
47        cube.setMaterial(mat);
48//        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
49//        mat.setColor("Diffuse", ColorRGBA.Blue);
50//        mat.setBoolean("UseMaterialColors", true);
51        /**
52         * A cube with a color "bleeding" through transparent texture. Uses
53         * Texture from jme3-test-data library!
54         */
55        Box box = new Box(Vector3f.ZERO, 1f, 1f, 1f);
56        cube2 = new Geometry("cube2", box);
57        cube2.setMaterial(mat);
58
59        TangentBinormalGenerator.generate(cube);
60        TangentBinormalGenerator.generate(cube2);
61
62
63         n = new Node("aNode");
64       // n.attachChild(cube2);
65        batch.attachChild(cube);
66        batch.attachChild(cube2);
67      //  batch.setMaterial(mat);
68        batch.batch();
69        rootNode.attachChild(batch);
70        cube.setLocalTranslation(3, 0, 0);
71        cube2.setLocalTranslation(0, 3, 0);
72
73
74        dl=new DirectionalLight();
75        dl.setColor(ColorRGBA.White.mult(2));
76        dl.setDirection(new Vector3f(1, -1, -1));
77        rootNode.addLight(dl);
78        flyCam.setMoveSpeed(10);
79    }
80    Node n;
81    Geometry cube;
82    Geometry cube2;
83    float time = 0;
84    DirectionalLight dl;
85    @Override
86    public void simpleUpdate(float tpf) {
87        time += tpf;
88        dl.setDirection(cam.getDirection());
89        cube2.setLocalTranslation(FastMath.sin(-time)*3, FastMath.cos(time)*3, 0);
90        cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
91        cube2.setLocalScale(Math.max(FastMath.sin(time),0.5f));
92
93        batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
94
95    }
96//
97}
98