From f6ca843f0313d67ac8bb23cfdf967fb1429a56ca Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Tue, 29 Oct 2013 19:50:41 +0000 Subject: [PATCH] Fixed how Hardware BoneIndex and BoneWeight buffers are handled in extractVertexData when used for a shared mesh. All buffers are now properly initialized and data copied over if needed. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10855 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/scene/Mesh.java | 34 +++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/engine/src/core/com/jme3/scene/Mesh.java b/engine/src/core/com/jme3/scene/Mesh.java index 46a2f2e41..abfed0634 100644 --- a/engine/src/core/com/jme3/scene/Mesh.java +++ b/engine/src/core/com/jme3/scene/Mesh.java @@ -1166,28 +1166,30 @@ public class Mesh implements Savable, Cloneable { // Now, create the vertex buffers SafeArrayList oldVertexData = other.getBufferList(); for (VertexBuffer oldVb : oldVertexData) { - if (oldVb.getBufferType() == VertexBuffer.Type.Index - ||oldVb.getBufferType() == VertexBuffer.Type.HWBoneIndex - || oldVb.getBufferType() == VertexBuffer.Type.HWBoneWeight ) { + if (oldVb.getBufferType() == VertexBuffer.Type.Index) { // ignore the index buffer continue; } - // Create a new vertex buffer with similar configuration, but - // with the capacity of number of unique vertices - Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(), oldVb.getNumComponents(), newNumVerts); - VertexBuffer newVb = new VertexBuffer(oldVb.getBufferType()); newVb.setNormalized(oldVb.isNormalized()); - newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(), oldVb.getFormat(), buffer); - - // Copy the vertex data from the old buffer into the new buffer - for (int i = 0; i < newNumVerts; i++) { - int oldIndex = newIndicesToOldIndices.get(i); - - // Copy the vertex attribute from the old index - // to the new index - oldVb.copyElement(oldIndex, newVb, i); + //check for data before copying, some buffers are just empty shells + //for caching purpose (HW skinning buffers), and will be filled when + //needed + if(oldVb.getData()!=null){ + // Create a new vertex buffer with similar configuration, but + // with the capacity of number of unique vertices + Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(), oldVb.getNumComponents(), newNumVerts); + newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(), oldVb.getFormat(), buffer); + + // Copy the vertex data from the old buffer into the new buffer + for (int i = 0; i < newNumVerts; i++) { + int oldIndex = newIndicesToOldIndices.get(i); + + // Copy the vertex attribute from the old index + // to the new index + oldVb.copyElement(oldIndex, newVb, i); + } } // Set the buffer on the mesh