BatchNode not accounting for transformations in cloned spatials

Thought I would post this here for @nehon or @Momoko_Fan to take a peek at before I start digging into it tomorrow.

It appears that BatchNode does not account for transformations of cloned spatials. If you clone a spatial and batch it with the clonee, then they bother will share the same translation/rotation etc. I have attached this test case here. Just comment out batch.batch() to see how it looks before batching brings them together.



[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 TestBatchNode extends SimpleApplication {



public static void main(String[] args) {



TestBatchNode app = new TestBatchNode();

app.start();

}

BatchNode batch;



@Override

public void simpleInitApp() {

timer = new NanoTimer();

batch = new BatchNode(“theBatchNode”);



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

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

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

cube.setMaterial(mat);



Node parent = new Node(“parent”);



TangentBinormalGenerator.generate(cube);



cube.setLocalTranslation(0, 0, 0);

parent.attachChild(cube);



Spatial cubeClone1 = cube.clone();

cubeClone1.setLocalTranslation(0,2,0);

cubeClone1.setLocalScale(0.5f, 0.5f, 0.5f);

parent.attachChild(cubeClone1);

Spatial cubeClone2 = cube.clone();

cubeClone2.setLocalTranslation(2,0,0);

cubeClone2.setLocalScale(0.2f, 0.2f, 0.2f);

parent.attachChild(cubeClone2);



batch.attachChild(parent);



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);

}

Node n;

Geometry cube;

float time = 0;

DirectionalLight dl;

@Override

public void simpleUpdate(float tpf) {

time += tpf;

dl.setDirection(cam.getDirection());

}

}[/java]

mhhh strange…What happens if you attach the cubes directly to the batchNode instead of having the “parent” Node?

same thing

mhhh actually the problem comes from the material…and also batchNode

if for cloning you use cube.clone(false); (which means “don’t clone the material”) it works…



So there are 2 issues : the material.isEquals fails and it should not, and the transform of the geometries are not applied to the batches…if they are not batched…this one’s gonna be tricky.

@Sploreg it should be fixed now

3 Likes

sweet, it works well now Remy, thanks!