Преглед изворни кода

Hadrware skinning buffers are now not saved along the other buffers in a j3o file.
They are created when loading the model.
This was causing issue when loading j3o files saved before the change

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10658 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

rem..om пре 12 година
родитељ
комит
68fa1b7084

+ 5 - 8
engine/src/core/com/jme3/animation/SkeletonControl.java

@@ -122,7 +122,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
             m.setInt("NumberOfBones", numBones);
         }
         for (Mesh mesh : targets) {
-            if (isMeshAnimated(mesh)) {
+            if (mesh.isAnimated()) {
                 mesh.prepareForAnim(false);
             }
         }
@@ -135,7 +135,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
             }
         }
         for (Mesh mesh : targets) {
-            if (isMeshAnimated(mesh)) {
+            if (mesh.isAnimated()) {
                 mesh.prepareForAnim(true);
             }
         }
@@ -216,9 +216,6 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
         this.targets = new SafeArrayList<Mesh>(Mesh.class, Arrays.asList(targets));
     }
 
-    private boolean isMeshAnimated(Mesh mesh) {
-        return mesh.getBuffer(Type.BindPosePosition) != null;
-    }
 
     private void findTargets(Node node) {
         Mesh sharedMesh = null;        
@@ -232,7 +229,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
 
                 if (childSharedMesh != null) {
                     // Don’t bother with non-animated shared meshes
-                    if (isMeshAnimated(childSharedMesh)) {
+                    if (childSharedMesh.isAnimated()) {
                         // child is using shared mesh,
                         // so animate the shared mesh but ignore child
                         if (sharedMesh == null) {
@@ -244,7 +241,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
                     }
                 } else {
                     Mesh mesh = geom.getMesh();
-                    if (isMeshAnimated(mesh)) {
+                    if (mesh.isAnimated()) {
                         targets.add(mesh);
                         materials.add(geom.getMaterial());
                     }
@@ -333,7 +330,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
     //only do this for software updates
     void resetToBind() {
         for (Mesh mesh : targets) {
-            if (isMeshAnimated(mesh)) {
+            if (mesh.isAnimated()) {
                 Buffer bwBuff = mesh.getBuffer(Type.BoneWeight).getData();
                 Buffer biBuff = mesh.getBuffer(Type.BoneIndex).getData();
                 if (!biBuff.hasArray() || !bwBuff.hasArray()) {

+ 26 - 0
engine/src/core/com/jme3/scene/Mesh.java

@@ -1279,6 +1279,11 @@ public class Mesh implements Savable, Cloneable {
     public SafeArrayList<VertexBuffer> getBufferList(){
         return buffersList;
     }
+    
+    public boolean isAnimated() {
+        return getBuffer(Type.BindPosePosition) != null;
+    }
+
 
     public void write(JmeExporter ex) throws IOException {
         OutputCapsule out = ex.getCapsule(this);
@@ -1299,6 +1304,17 @@ public class Mesh implements Savable, Cloneable {
         out.write(elementLengths, "elementLengths", null);
         out.write(modeStart, "modeStart", null);
         out.write(pointSize, "pointSize", 1f);
+        
+        if(isAnimated()){
+            VertexBuffer vb = getBuffer(Type.HWBoneIndex);
+            if(vb!=null){
+                buffers.remove(Type.HWBoneIndex.ordinal());
+            }
+            vb = getBuffer(Type.HWBoneWeight);
+            if(vb!=null){
+                buffers.remove(Type.HWBoneWeight.ordinal());
+            }
+        }
 
         out.writeIntSavableMap(buffers, "buffers", null);
         out.write(lodLevels, "lodLevels", null);
@@ -1324,6 +1340,16 @@ public class Mesh implements Savable, Cloneable {
             buffersList.add(entry.getValue());
         }
         
+        //creating hw animation buffers empty so that they are put in the cache
+        if(isAnimated()){
+            VertexBuffer hwBoneIndex = new VertexBuffer(Type.HWBoneIndex);
+            hwBoneIndex.setUsage(Usage.CpuOnly);
+            setBuffer(hwBoneIndex);
+            VertexBuffer hwBoneWeight = new VertexBuffer(Type.HWBoneWeight);
+            hwBoneWeight.setUsage(Usage.CpuOnly);
+            setBuffer(hwBoneWeight);
+        }
+        
         Savable[] lodLevelsSavable = in.readSavableArray("lodLevels", null);
         if (lodLevelsSavable != null) {
             lodLevels = new VertexBuffer[lodLevelsSavable.length];