First off, here’s my setup :
private Geometry meshInstance;
private Geometry referenceMeshInstance;
public static void main(String[] args) {
FlatShadingMain app = new FlatShadingMain();
app.start();
}
private Mesh createMesh() {
return new Box(1, 1, 1);
}
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10f);
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", ColorRGBA.Blue);
material.getAdditionalRenderState().setWireframe(true);
material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
Mesh mesh = createMesh();
mesh.clearBuffer(Type.TexCoord);
mesh.clearBuffer(Type.Color);
FlatShadedNormalCalculator.computeNormals(mesh, true);
meshInstance = new Geometry("meshInstance", mesh);
meshInstance.setMaterial(material);
Mesh referenceMesh = createMesh();
referenceMesh.clearBuffer(Type.TexCoord);
referenceMesh.clearBuffer(Type.Normal);
referenceMesh.clearBuffer(Type.Index);
referenceMesh.clearBuffer(Type.Color);
referenceMeshInstance = new Geometry("referenceMeshInstance", referenceMesh);
referenceMeshInstance.setLocalTranslation(-3, 0, 0);
referenceMeshInstance.setMaterial(material);
rootNode.attachChild(meshInstance);
rootNode.attachChild(referenceMeshInstance);
}
@Override
public void simpleUpdate(float tpf) {
meshInstance.rotate(0, FastMath.PI * tpf, 0);
}
Notice that I have a reference mesh and that both share a material that disables face culling.
If I try to update a vertex buffer of type position with a new float buffer, the mesh (actually the created geometry) doesn’t appear on the screen, even if the float buffer is a “fake” deep clone of the previous one. Please keep in mind that I also cleared the normals.
FloatBuffer positionFloatBuffer = (FloatBuffer) positionVertexBuffer.getData();
FloatBuffer positionNewFloatBuffer = FloatBuffer.allocate(positionFloatBuffer.limit());
positionFloatBuffer.rewind();
for (int i = 0; i < positionFloatBuffer.limit(); ++i)
positionNewFloatBuffer.put(positionFloatBuffer.get());
mesh.clearBuffer(Type.Index);
positionVertexBuffer.updateData(positionNewFloatBuffer);
// positionVertexBuffer.updateData(BufferUtils.clone(positionFloatBuffer)); This works
mesh.updateCounts();
mesh.updateBound();
What could I be doing wrong?
Thanks in advance