First of all I thought it was a bug in BatchNode, as I was getting a buffer overflow error using simple Quads, but as I debugged it to:
Line 467 of BatchNode
[java]totalVerts += geom.getVertexCount();[/java]
and wondered why my totalVerts was actually getting smaller each loop, I knew the error must be somewhere else. Then I tracked it down to Mesh.deepClone():
[java]
clone.vertCount = -1;
clone.elementCount = -1;
[/java]
Here’s the diff for Mesh.java:
[java]# This patch file was generated by NetBeans IDE
It uses platform neutral UTF-8 encoding and \n newlines.
— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -240,8 +240,8 @@
}
clone.vertexArrayID = -1;
-
clone.vertCount = -1;
-
clone.elementCount = -1;
-
clone.vertCount = vertCount;
-
clone.elementCount = elementCount; // although this could change // if the bone weight/index buffers are modified[/java]
Here’s a testcase:
[java]
package com.wezgui;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.BatchNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.shape.Quad;
/**
*
-
@author Wesley
*/
public class TestDeepClone extends SimpleApplication {public static void main(String[] args) {
new TestDeepClone().start();
}@Override
public void simpleInitApp() {Quad q = new Quad(1, 1); Geometry g = new Geometry("q", q); Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); g.setMaterial(m); // Create a deepClone Mesh q1 = q.deepClone(); Geometry g1 = new Geometry("q", q1); g1.move(2, 0, 0); g1.setMaterial(m); BatchNode node = new BatchNode("batch"); node.attachChild(g); node.attachChild(g1); node.batch(); // <--- Fails here rootNode.attachChild(node);
}
}
[/java]
It may also fix the bizarre behavior seen here by @Kaizo (although I haven’t checked):
http://hub.jmonkeyengine.org/forum/topic/seams-appearing-in-terrain-after-deformation/#post-258164