From d17bdb64859060b04026ca81b13af56f5194f9bd Mon Sep 17 00:00:00 2001 From: Nehon Date: Sat, 6 Sep 2014 20:55:35 +0200 Subject: [PATCH] BatchNode and GeometryBatchFactory now can handle normalized buffers. Also added a check in BatchNode that was present in GeometryBatchFactory --- jme3-core/src/main/java/com/jme3/scene/BatchNode.java | 9 +++++++++ .../java/jme3tools/optimize/GeometryBatchFactory.java | 3 +++ 2 files changed, 12 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java index f838d1fbc..1b8ccc009 100644 --- a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java @@ -478,6 +478,7 @@ public class BatchNode extends GeometryGroupNode implements Savable { private void mergeGeometries(Mesh outMesh, List geometries) { int[] compsForBuf = new int[VertexBuffer.Type.values().length]; VertexBuffer.Format[] formatForBuf = new VertexBuffer.Format[compsForBuf.length]; + boolean[] normForBuf = new boolean[VertexBuffer.Type.values().length]; int totalVerts = 0; int totalTris = 0; @@ -516,8 +517,15 @@ public class BatchNode extends GeometryGroupNode implements Savable { } for (VertexBuffer vb : geom.getMesh().getBufferList().getArray()) { + int currentCompsForBuf = compsForBuf[vb.getBufferType().ordinal()]; + if (vb.getBufferType() != VertexBuffer.Type.Index && currentCompsForBuf != 0 && currentCompsForBuf != vb.getNumComponents()) { + throw new UnsupportedOperationException("The geometry " + geom + " buffer " + vb.getBufferType() + + " has different number of components than the rest of the meshes " + + "(this: " + vb.getNumComponents() + ", expected: " + currentCompsForBuf + ")"); + } compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); + normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized(); } maxWeights = Math.max(maxWeights, geom.getMesh().getMaxNumWeights()); @@ -555,6 +563,7 @@ public class BatchNode extends GeometryGroupNode implements Savable { VertexBuffer vb = new VertexBuffer(VertexBuffer.Type.values()[i]); vb.setupData(VertexBuffer.Usage.Dynamic, compsForBuf[i], formatForBuf[i], data); + vb.setNormalized(normForBuf[i]); outMesh.setBuffer(vb); } diff --git a/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java b/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java index fa5747cf7..a7668dc56 100644 --- a/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java +++ b/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java @@ -96,6 +96,7 @@ public class GeometryBatchFactory { public static void mergeGeometries(Collection geometries, Mesh outMesh) { int[] compsForBuf = new int[VertexBuffer.Type.values().length]; Format[] formatForBuf = new Format[compsForBuf.length]; + boolean[] normForBuf = new boolean[VertexBuffer.Type.values().length]; int totalVerts = 0; int totalTris = 0; @@ -140,6 +141,7 @@ public class GeometryBatchFactory { } compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); + normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized(); } maxWeights = Math.max(maxWeights, geom.getMesh().getMaxNumWeights()); @@ -177,6 +179,7 @@ public class GeometryBatchFactory { VertexBuffer vb = new VertexBuffer(Type.values()[i]); vb.setupData(Usage.Static, compsForBuf[i], formatForBuf[i], data); + vb.setNormalized(normForBuf[i]); outMesh.setBuffer(vb); }