Broken BatchNode

This is mostly for @nehon, sorry to ruin your weekend :slight_smile:



Batch node doesn’t seem to batch objects when you load them and their materials from the asset manager. Here is a test case showing that the object count is at 20 whether you batch the spatials or not (they are just the simple Sign Post model). You can try adding the sign posts in one by one and see the count increase. But adding in hard-coded boxes does get them batched.

This is using the latest version from svn.



[java]package jme3test.batching;



import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

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.shape.Box;

import com.jme3.system.NanoTimer;

import com.jme3.util.TangentBinormalGenerator;



public class TestBatchNode2 extends SimpleApplication {



BatchNode batch;

Node n;

Geometry cube;

Geometry cube2;

float time = 0;

DirectionalLight dl;



public static void main(String[] args) {

TestBatchNode2 app = new TestBatchNode2();

app.start();

}



@Override

public void simpleInitApp() {

timer = new NanoTimer();

batch = new BatchNode(“theBatchNode”);



Box boxshape4 = new Box(Vector3f.ZERO, 1f, 1f, 1f );

cube = new Geometry(“cube1”, boxshape4);

Material mat = assetManager.loadMaterial(“Textures/Terrain/Pond/Pond.j3m”);

cube.setMaterial(mat);

cube.setLocalTranslation(3, 0, 0);



Box box = new Box(Vector3f.ZERO, 1f, 1f, 1f);

cube2 = new Geometry(“cube2”, box);

cube2.setMaterial(mat);

cube2.setLocalTranslation(0, 3, 0);



TangentBinormalGenerator.generate(cube);

TangentBinormalGenerator.generate(cube2);



Spatial mesh1 = (Node) assetManager.loadModel(“Models/Sign Post/Sign Post.mesh.xml”);

mesh1.setMaterial(assetManager.loadMaterial(“Models/Sign Post/Sign Post.j3m”));

mesh1.setLocalTranslation(10, 0, 0);

TangentBinormalGenerator.generate(mesh1);

Spatial mesh2 = (Node) assetManager.loadModel(“Models/Sign Post/Sign Post.mesh.xml”);

mesh2.setMaterial(assetManager.loadMaterial(“Models/Sign Post/Sign Post.j3m”));

mesh2.setLocalTranslation(10, 0, 10);

TangentBinormalGenerator.generate(mesh2);

Spatial mesh3 = (Node) assetManager.loadModel(“Models/Sign Post/Sign Post.mesh.xml”);

mesh3.setMaterial(assetManager.loadMaterial(“Models/Sign Post/Sign Post.j3m”));

mesh3.setLocalTranslation(0, 0, 10);

TangentBinormalGenerator.generate(mesh3);

Spatial mesh4 = (Node) assetManager.loadModel(“Models/Sign Post/Sign Post.mesh.xml”);

mesh4.setMaterial(assetManager.loadMaterial(“Models/Sign Post/Sign Post.j3m”));

mesh4.setLocalTranslation(0, -5, 10);

TangentBinormalGenerator.generate(mesh4);

Spatial mesh5 = (Node) assetManager.loadModel(“Models/Sign Post/Sign Post.mesh.xml”);

mesh5.setMaterial(assetManager.loadMaterial(“Models/Sign Post/Sign Post.j3m”));

mesh5.setLocalTranslation(0, 5, 10);

TangentBinormalGenerator.generate(mesh5);



// add all the spatials to a node, then batch that node

n = new Node(“aNode”);

n.attachChild(cube);

n.attachChild(cube2);

n.attachChild(mesh1);

n.attachChild(mesh2);

n.attachChild(mesh3);

n.attachChild(mesh4);

n.attachChild(mesh5);



// unbatched

//rootNode.attachChild(n);



// batched

batch.attachChild(n);

batch.batch();

rootNode.attachChild(batch);



dl=new DirectionalLight();

dl.setColor(ColorRGBA.White.mult(2));

dl.setDirection(new Vector3f(1, -1, -1));

rootNode.addLight(dl);

flyCam.setMoveSpeed(10);

getCamera().setLocation(new Vector3f(0f, 0f, 30f));

}

}

[/java]

3 Likes

It’s fixed in last SVN.

Thanks for the testcase! made it easy :wink:

1 Like