diff options
Diffstat (limited to 'engine/src/core/com/jme3/scene')
-rw-r--r-- | engine/src/core/com/jme3/scene/BatchNode.java | 13 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/Mesh.java | 153 |
2 files changed, 82 insertions, 84 deletions
diff --git a/engine/src/core/com/jme3/scene/BatchNode.java b/engine/src/core/com/jme3/scene/BatchNode.java index bc1b2cb..303de7a 100644 --- a/engine/src/core/com/jme3/scene/BatchNode.java +++ b/engine/src/core/com/jme3/scene/BatchNode.java @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -190,10 +191,10 @@ public class BatchNode extends Node implements Savable { } batches.clear(); } - - for (Material material : matMap.keySet()) { + for (Map.Entry<Material, List<Geometry>> entry : matMap.entrySet()) { Mesh m = new Mesh(); - List<Geometry> list = matMap.get(material); + Material material = entry.getKey(); + List<Geometry> list = entry.getValue(); nbGeoms += list.size(); if (!needsFullRebatch) { list.add(batches.get(material).geometry); @@ -408,9 +409,9 @@ public class BatchNode extends Node implements Savable { throw new UnsupportedOperationException(); } - for (Entry<VertexBuffer> entry : geom.getMesh().getBuffers()) { - compsForBuf[entry.getKey()] = entry.getValue().getNumComponents(); - formatForBuf[entry.getKey()] = entry.getValue().getFormat(); + for (VertexBuffer vb : geom.getMesh().getBufferList().getArray()) { + compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); + formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); } if (mode != null && mode != listMode) { diff --git a/engine/src/core/com/jme3/scene/Mesh.java b/engine/src/core/com/jme3/scene/Mesh.java index 6c587f2..036e525 100644 --- a/engine/src/core/com/jme3/scene/Mesh.java +++ b/engine/src/core/com/jme3/scene/Mesh.java @@ -43,7 +43,6 @@ import com.jme3.math.Matrix4f; import com.jme3.math.Triangle; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; -import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer.Format; import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Usage; @@ -55,8 +54,6 @@ import com.jme3.util.SafeArrayList; import java.io.IOException; import java.nio.*; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; /** * <code>Mesh</code> is used to store rendering data. @@ -237,9 +234,9 @@ public class Mesh implements Savable, Cloneable { clone.buffers = new IntMap<VertexBuffer>(); clone.buffersList = new SafeArrayList<VertexBuffer>(VertexBuffer.class); - for (Entry<VertexBuffer> ent : buffers){ - VertexBuffer bufClone = ent.getValue().clone(); - clone.buffers.put(ent.getKey(), bufClone); + for (VertexBuffer vb : buffersList.getArray()){ + VertexBuffer bufClone = vb.clone(); + clone.buffers.put(vb.getBufferType().ordinal(), bufClone); clone.buffersList.add(bufClone); } @@ -540,8 +537,8 @@ public class Mesh implements Savable, Cloneable { * for all {@link VertexBuffer vertex buffers} on this Mesh. */ public void setStatic() { - for (Entry<VertexBuffer> entry : buffers){ - entry.getValue().setUsage(Usage.Static); + for (VertexBuffer vb : buffersList.getArray()){ + vb.setUsage(Usage.Static); } } @@ -551,8 +548,8 @@ public class Mesh implements Savable, Cloneable { * for all {@link VertexBuffer vertex buffers} on this Mesh. */ public void setDynamic() { - for (Entry<VertexBuffer> entry : buffers){ - entry.getValue().setUsage(Usage.Dynamic); + for (VertexBuffer vb : buffersList.getArray()){ + vb.setUsage(Usage.Dynamic); } } @@ -562,8 +559,8 @@ public class Mesh implements Savable, Cloneable { * for all {@link VertexBuffer vertex buffers} on this Mesh. */ public void setStreamed(){ - for (Entry<VertexBuffer> entry : buffers){ - entry.getValue().setUsage(Usage.Stream); + for (VertexBuffer vb : buffersList.getArray()){ + vb.setUsage(Usage.Stream); } } @@ -572,11 +569,11 @@ public class Mesh implements Savable, Cloneable { * Some GPUs may prefer the data in this format, however it is a good idea * to <em>avoid</em> using this method as it disables some engine features. */ + @Deprecated public void setInterleaved(){ ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(); - for (Entry<VertexBuffer> entry : buffers){ - vbs.add(entry.getValue()); - } + vbs.addAll(buffersList); + // ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(buffers.values()); // index buffer not included when interleaving vbs.remove(getBuffer(Type.Index)); @@ -860,6 +857,65 @@ public class Mesh implements Savable, Cloneable { } /** + * Sets the {@link VertexBuffer} on the mesh. + * This will update the vertex/triangle counts if needed. + * + * @param vb The buffer to set + * @throws IllegalArgumentException If the buffer type is already set + */ + public void setBuffer(VertexBuffer vb){ + if (buffers.containsKey(vb.getBufferType().ordinal())) + throw new IllegalArgumentException("Buffer type already set: "+vb.getBufferType()); + + buffers.put(vb.getBufferType().ordinal(), vb); + buffersList.add(vb); + updateCounts(); + } + + /** + * Unsets the {@link VertexBuffer} set on this mesh + * with the given type. Does nothing if the vertex buffer type is not set + * initially. + * + * @param type The buffer type to remove + */ + public void clearBuffer(VertexBuffer.Type type){ + VertexBuffer vb = buffers.remove(type.ordinal()); + if (vb != null){ + buffersList.remove(vb); + updateCounts(); + } + } + + /** + * Creates a {@link VertexBuffer} for the mesh or modifies + * the existing one per the parameters given. + * + * @param type The type of the buffer + * @param components Number of components + * @param format Data format + * @param buf The buffer data + * + * @throws UnsupportedOperationException If the buffer already set is + * incompatible with the parameters given. + */ + public void setBuffer(Type type, int components, Format format, Buffer buf){ + VertexBuffer vb = buffers.get(type.ordinal()); + if (vb == null){ + vb = new VertexBuffer(type); + vb.setupData(Usage.Dynamic, components, format, buf); + setBuffer(vb); + }else{ + if (vb.getNumComponents() != components || vb.getFormat() != format){ + throw new UnsupportedOperationException("The buffer already set " + + "is incompatible with the given parameters"); + } + vb.updateData(buf); + updateCounts(); + } + } + + /** * Set a floating point {@link VertexBuffer} on the mesh. * * @param type The type of {@link VertexBuffer}, @@ -871,21 +927,7 @@ public class Mesh implements Savable, Cloneable { * @param buf The floating point data to contain */ public void setBuffer(Type type, int components, FloatBuffer buf) { -// VertexBuffer vb = buffers.get(type); - VertexBuffer vb = buffers.get(type.ordinal()); - if (vb == null){ - if (buf == null) - return; - - vb = new VertexBuffer(type); - vb.setupData(Usage.Dynamic, components, Format.Float, buf); -// buffers.put(type, vb); - buffers.put(type.ordinal(), vb); - buffersList.add(vb); - }else{ - vb.setupData(Usage.Dynamic, components, Format.Float, buf); - } - updateCounts(); + setBuffer(type, components, Format.Float, buf); } public void setBuffer(Type type, int components, float[] buf){ @@ -893,14 +935,7 @@ public class Mesh implements Savable, Cloneable { } public void setBuffer(Type type, int components, IntBuffer buf) { - VertexBuffer vb = buffers.get(type.ordinal()); - if (vb == null){ - vb = new VertexBuffer(type); - vb.setupData(Usage.Dynamic, components, Format.UnsignedInt, buf); - buffers.put(type.ordinal(), vb); - buffersList.add(vb); - updateCounts(); - } + setBuffer(type, components, Format.UnsignedInt, buf); } public void setBuffer(Type type, int components, int[] buf){ @@ -908,14 +943,7 @@ public class Mesh implements Savable, Cloneable { } public void setBuffer(Type type, int components, ShortBuffer buf) { - VertexBuffer vb = buffers.get(type.ordinal()); - if (vb == null){ - vb = new VertexBuffer(type); - vb.setupData(Usage.Dynamic, components, Format.UnsignedShort, buf); - buffers.put(type.ordinal(), vb); - buffersList.add(vb); - updateCounts(); - } + setBuffer(type, components, Format.UnsignedShort, buf); } public void setBuffer(Type type, int components, byte[] buf){ @@ -923,38 +951,7 @@ public class Mesh implements Savable, Cloneable { } public void setBuffer(Type type, int components, ByteBuffer buf) { - VertexBuffer vb = buffers.get(type.ordinal()); - if (vb == null){ - vb = new VertexBuffer(type); - vb.setupData(Usage.Dynamic, components, Format.UnsignedByte, buf); - buffers.put(type.ordinal(), vb); - buffersList.add(vb); - updateCounts(); - } - } - - public void setBuffer(VertexBuffer vb){ - if (buffers.containsKey(vb.getBufferType().ordinal())) - throw new IllegalArgumentException("Buffer type already set: "+vb.getBufferType()); - - buffers.put(vb.getBufferType().ordinal(), vb); - buffersList.add(vb); - updateCounts(); - } - - /** - * Clears or unsets the {@link VertexBuffer} set on this mesh - * with the given type. - * Does nothing if the vertex buffer type is not set initially - * - * @param type The type to remove - */ - public void clearBuffer(VertexBuffer.Type type){ - VertexBuffer vb = buffers.remove(type.ordinal()); - if (vb != null){ - buffersList.remove(vb); - updateCounts(); - } + setBuffer(type, components, Format.UnsignedByte, buf); } public void setBuffer(Type type, int components, short[] buf){ |