From a67786c58eed75eb878f6cc2d89c0a0e7e28b1d8 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sat, 22 Jun 2013 19:48:45 +0000 Subject: [PATCH] fixed issue when saving a mesh in hw skinning mode was not restoring the buffers. restored the code to enforce BoneIndex and BoneWeight to be in the heap for software anim because it was failing on android, until I find a proper solution git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10659 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/scene/Mesh.java | 47 +++++++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) 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); }