浏览代码

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

rem..om 12 年之前
父节点
当前提交
a67786c58e
共有 1 个文件被更改,包括 41 次插入6 次删除
  1. 41 6
      engine/src/core/com/jme3/scene/Mesh.java

+ 41 - 6
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);
     }