|
|
@ -4,8 +4,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package jme3test.batching; |
|
|
|
package jme3test.batching; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.app.SimpleApplication; |
|
|
|
import com.jme3.app.SimpleApplication; |
|
|
|
|
|
|
|
import com.jme3.bounding.BoundingBox; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.material.Material; |
|
|
|
import com.jme3.material.Material; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
@ -15,6 +15,8 @@ import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.scene.BatchNode; |
|
|
|
import com.jme3.scene.BatchNode; |
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Node; |
|
|
|
import com.jme3.scene.Node; |
|
|
|
|
|
|
|
import com.jme3.scene.Spatial; |
|
|
|
|
|
|
|
import com.jme3.scene.debug.WireFrustum; |
|
|
|
import com.jme3.scene.shape.Box; |
|
|
|
import com.jme3.scene.shape.Box; |
|
|
|
import com.jme3.system.NanoTimer; |
|
|
|
import com.jme3.system.NanoTimer; |
|
|
|
import com.jme3.util.TangentBinormalGenerator; |
|
|
|
import com.jme3.util.TangentBinormalGenerator; |
|
|
@ -31,17 +33,29 @@ public class TestBatchNode extends SimpleApplication { |
|
|
|
app.start(); |
|
|
|
app.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
BatchNode batch; |
|
|
|
BatchNode batch; |
|
|
|
|
|
|
|
WireFrustum frustum; |
|
|
|
|
|
|
|
Geometry frustumMdl; |
|
|
|
|
|
|
|
private Vector3f[] points; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
points = new Vector3f[8]; |
|
|
|
|
|
|
|
for (int i = 0; i < points.length; i++) { |
|
|
|
|
|
|
|
points[i] = new Vector3f(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void simpleInitApp() { |
|
|
|
public void simpleInitApp() { |
|
|
|
timer = new NanoTimer(); |
|
|
|
timer = new NanoTimer(); |
|
|
|
batch = new BatchNode("theBatchNode"); |
|
|
|
batch = new BatchNode("theBatchNode"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A cube with a color "bleeding" through transparent texture. Uses |
|
|
|
* A cube with a color "bleeding" through transparent texture. Uses |
|
|
|
* Texture from jme3-test-data library! |
|
|
|
* Texture from jme3-test-data library! |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Box boxshape4 = new Box(Vector3f.ZERO, 1f, 1f, 1f ); |
|
|
|
Box boxshape4 = new Box(Vector3f.ZERO, 1f, 1f, 1f); |
|
|
|
cube = new Geometry("cube1", boxshape4); |
|
|
|
cube = new Geometry("cube1", boxshape4); |
|
|
|
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); |
|
|
|
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); |
|
|
|
cube.setMaterial(mat); |
|
|
|
cube.setMaterial(mat); |
|
|
@ -63,15 +77,23 @@ public class TestBatchNode extends SimpleApplication { |
|
|
|
n = new Node("aNode"); |
|
|
|
n = new Node("aNode"); |
|
|
|
// n.attachChild(cube2);
|
|
|
|
// n.attachChild(cube2);
|
|
|
|
batch.attachChild(cube); |
|
|
|
batch.attachChild(cube); |
|
|
|
batch.attachChild(cube2); |
|
|
|
// batch.attachChild(cube2);
|
|
|
|
// batch.setMaterial(mat);
|
|
|
|
// batch.setMaterial(mat);
|
|
|
|
batch.batch(); |
|
|
|
batch.batch(); |
|
|
|
rootNode.attachChild(batch); |
|
|
|
rootNode.attachChild(batch); |
|
|
|
cube.setLocalTranslation(3, 0, 0); |
|
|
|
cube.setLocalTranslation(3, 0, 0); |
|
|
|
cube2.setLocalTranslation(0, 3, 0); |
|
|
|
cube2.setLocalTranslation(0, 20, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dl=new DirectionalLight(); |
|
|
|
updateBoindPoints(points); |
|
|
|
|
|
|
|
frustum = new WireFrustum(points); |
|
|
|
|
|
|
|
frustumMdl = new Geometry("f", frustum); |
|
|
|
|
|
|
|
frustumMdl.setCullHint(Spatial.CullHint.Never); |
|
|
|
|
|
|
|
frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); |
|
|
|
|
|
|
|
frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true); |
|
|
|
|
|
|
|
frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red); |
|
|
|
|
|
|
|
rootNode.attachChild(frustumMdl); |
|
|
|
|
|
|
|
dl = new DirectionalLight(); |
|
|
|
dl.setColor(ColorRGBA.White.mult(2)); |
|
|
|
dl.setColor(ColorRGBA.White.mult(2)); |
|
|
|
dl.setDirection(new Vector3f(1, -1, -1)); |
|
|
|
dl.setDirection(new Vector3f(1, -1, -1)); |
|
|
|
rootNode.addLight(dl); |
|
|
|
rootNode.addLight(dl); |
|
|
@ -82,16 +104,45 @@ public class TestBatchNode extends SimpleApplication { |
|
|
|
Geometry cube2; |
|
|
|
Geometry cube2; |
|
|
|
float time = 0; |
|
|
|
float time = 0; |
|
|
|
DirectionalLight dl; |
|
|
|
DirectionalLight dl; |
|
|
|
|
|
|
|
boolean done = false; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void simpleUpdate(float tpf) { |
|
|
|
public void simpleUpdate(float tpf) { |
|
|
|
|
|
|
|
if (!done) { |
|
|
|
|
|
|
|
done = true; |
|
|
|
|
|
|
|
batch.attachChild(cube2); |
|
|
|
|
|
|
|
batch.batch(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateBoindPoints(points); |
|
|
|
|
|
|
|
frustum.update(points); |
|
|
|
time += tpf; |
|
|
|
time += tpf; |
|
|
|
dl.setDirection(cam.getDirection()); |
|
|
|
dl.setDirection(cam.getDirection()); |
|
|
|
cube2.setLocalTranslation(FastMath.sin(-time)*3, FastMath.cos(time)*3, 0); |
|
|
|
cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0); |
|
|
|
cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); |
|
|
|
cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); |
|
|
|
cube2.setLocalScale(Math.max(FastMath.sin(time),0.5f)); |
|
|
|
cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f)); |
|
|
|
|
|
|
|
|
|
|
|
batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); |
|
|
|
// batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateBoindPoints(Vector3f[] points) { |
|
|
|
|
|
|
|
BoundingBox bb = (BoundingBox) batch.getWorldBound(); |
|
|
|
|
|
|
|
float xe = bb.getXExtent(); |
|
|
|
|
|
|
|
float ye = bb.getYExtent(); |
|
|
|
|
|
|
|
float ze = bb.getZExtent(); |
|
|
|
|
|
|
|
float x = bb.getCenter().x; |
|
|
|
|
|
|
|
float y = bb.getCenter().y; |
|
|
|
|
|
|
|
float z = bb.getCenter().z; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
points[0].set(new Vector3f(x - xe, y - ye, z - ze)); |
|
|
|
|
|
|
|
points[1].set(new Vector3f(x - xe, y + ye, z - ze)); |
|
|
|
|
|
|
|
points[2].set(new Vector3f(x + xe, y + ye, z - ze)); |
|
|
|
|
|
|
|
points[3].set(new Vector3f(x + xe, y - ye, z - ze)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
points[4].set(new Vector3f(x + xe, y - ye, z + ze)); |
|
|
|
|
|
|
|
points[5].set(new Vector3f(x - xe, y - ye, z + ze)); |
|
|
|
|
|
|
|
points[6].set(new Vector3f(x - xe, y + ye, z + ze)); |
|
|
|
|
|
|
|
points[7].set(new Vector3f(x + xe, y + ye, z + ze)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|