Browse Source

BatchNode and GeometryBatchFactory now can handle normalized buffers.
Also added a check in BatchNode that was present in GeometryBatchFactory

Nehon 11 năm trước cách đây
mục cha
commit
d17bdb6485

+ 9 - 0
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<Geometry> 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);
         }
 

+ 3 - 0
jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java

@@ -96,6 +96,7 @@ public class GeometryBatchFactory {
     public static void mergeGeometries(Collection<Geometry> 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);
         }