diff --git a/engine/src/core/com/jme3/scene/Mesh.java b/engine/src/core/com/jme3/scene/Mesh.java index 46893614a..5f178ed8e 100644 --- a/engine/src/core/com/jme3/scene/Mesh.java +++ b/engine/src/core/com/jme3/scene/Mesh.java @@ -353,6 +353,27 @@ public class Mesh implements Savable, Cloneable { */ public void prepareForAnim(boolean forSoftwareAnim){ if (forSoftwareAnim) { + // convert indices to ubytes on the heap + VertexBuffer indices = getBuffer(Type.BoneIndex); + if (!indices.getData().hasArray()) { + ByteBuffer originalIndex = (ByteBuffer) indices.getData(); + ByteBuffer arrayIndex = ByteBuffer.allocate(originalIndex.capacity()); + originalIndex.clear(); + arrayIndex.put(originalIndex); + indices.updateData(arrayIndex); + } + indices.setUsage(Usage.CpuOnly); + + // convert weights on the heap + VertexBuffer weights = getBuffer(Type.BoneWeight); + if (!weights.getData().hasArray()) { + FloatBuffer originalWeight = (FloatBuffer) weights.getData(); + FloatBuffer arrayWeight = FloatBuffer.allocate(originalWeight.capacity()); + originalWeight.clear(); + arrayWeight.put(originalWeight); + weights.updateData(arrayWeight); + } + weights.setUsage(Usage.CpuOnly); // position, normal, and tanget buffers to be in "Stream" mode VertexBuffer positions = getBuffer(Type.Position); VertexBuffer normals = getBuffer(Type.Normal); @@ -1305,18 +1326,32 @@ public class Mesh implements Savable, Cloneable { out.write(modeStart, "modeStart", null); out.write(pointSize, "pointSize", 1f); - if(isAnimated()){ - VertexBuffer vb = getBuffer(Type.HWBoneIndex); - if(vb!=null){ + //Removing HW skinning buffers to not save them + VertexBuffer hwBoneIndex = null; + VertexBuffer hwBoneWeight = null; + if (isAnimated()) { + hwBoneIndex = getBuffer(Type.HWBoneIndex); + if (hwBoneIndex != null) { buffers.remove(Type.HWBoneIndex.ordinal()); } - vb = getBuffer(Type.HWBoneWeight); - if(vb!=null){ + hwBoneWeight = getBuffer(Type.HWBoneWeight); + if (hwBoneWeight != null) { buffers.remove(Type.HWBoneWeight.ordinal()); } } - + out.writeIntSavableMap(buffers, "buffers", null); + + //restoring Hw skinning buffers. + if (isAnimated()) { + if (hwBoneIndex != null) { + buffers.put(hwBoneIndex.getBufferType().ordinal(), hwBoneIndex); + } + if (hwBoneWeight != null) { + buffers.put(hwBoneWeight.getBufferType().ordinal(), hwBoneWeight); + } + } + out.write(lodLevels, "lodLevels", null); }