BatchNode : fixed bounding issue
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9755 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
6c2dcc472d
commit
c31c7a406b
engine/src
@ -122,7 +122,7 @@ public class BatchNode extends Node implements Savable {
|
||||
|
||||
for (Batch batch : batches.getArray()) {
|
||||
if (batch.needMeshUpdate) {
|
||||
batch.geometry.getMesh().updateBound();
|
||||
batch.geometry.updateModelBound();
|
||||
batch.geometry.updateWorldBound();
|
||||
batch.needMeshUpdate = false;
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
*/
|
||||
package jme3test.batching;
|
||||
|
||||
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.bounding.BoundingBox;
|
||||
import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
@ -15,6 +15,8 @@ import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.BatchNode;
|
||||
import com.jme3.scene.Geometry;
|
||||
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.system.NanoTimer;
|
||||
import com.jme3.util.TangentBinormalGenerator;
|
||||
@ -31,12 +33,24 @@ public class TestBatchNode extends SimpleApplication {
|
||||
app.start();
|
||||
}
|
||||
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
|
||||
public void simpleInitApp() {
|
||||
timer = new NanoTimer();
|
||||
batch = new BatchNode("theBatchNode");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A cube with a color "bleeding" through transparent texture. Uses
|
||||
* Texture from jme3-test-data library!
|
||||
@ -63,14 +77,22 @@ public class TestBatchNode extends SimpleApplication {
|
||||
n = new Node("aNode");
|
||||
// n.attachChild(cube2);
|
||||
batch.attachChild(cube);
|
||||
batch.attachChild(cube2);
|
||||
// batch.attachChild(cube2);
|
||||
// batch.setMaterial(mat);
|
||||
batch.batch();
|
||||
rootNode.attachChild(batch);
|
||||
cube.setLocalTranslation(3, 0, 0);
|
||||
cube2.setLocalTranslation(0, 3, 0);
|
||||
cube2.setLocalTranslation(0, 20, 0);
|
||||
|
||||
|
||||
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.setDirection(new Vector3f(1, -1, -1));
|
||||
@ -82,16 +104,45 @@ public class TestBatchNode extends SimpleApplication {
|
||||
Geometry cube2;
|
||||
float time = 0;
|
||||
DirectionalLight dl;
|
||||
boolean done = false;
|
||||
|
||||
@Override
|
||||
public void simpleUpdate(float tpf) {
|
||||
if (!done) {
|
||||
done = true;
|
||||
batch.attachChild(cube2);
|
||||
batch.batch();
|
||||
}
|
||||
updateBoindPoints(points);
|
||||
frustum.update(points);
|
||||
time += tpf;
|
||||
dl.setDirection(cam.getDirection());
|
||||
cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0);
|
||||
cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user