Browse Source

Fixed cloning to not confuse the hardware skinning safety check
that attempts to protect users from shared materials.

Paul Speed 9 years ago
parent
commit
80f4e04935
1 changed files with 17 additions and 1 deletions
  1. 17 1
      jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java

+ 17 - 1
jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java

@@ -409,7 +409,23 @@ public class SkeletonControl extends AbstractControl implements Cloneable, JmeCl
         // Not automatic set cloning yet
         Set<Material> newMaterials = new HashSet<Material>();
         for( Material m : this.materials ) {
-            newMaterials.add(cloner.clone(m));
+            Material mClone = cloner.clone(m);
+            newMaterials.add(mClone);
+            if( mClone != m ) {
+                // Material was really cloned so clear the bone matrices in case
+                // this is hardware skinned.  This allows a local version to be
+                // used and will be reset on the material.  Really this just avoids
+                // the 'safety' check in controlRenderHardware().  Right now material
+                // doesn't clone itself with the cloner (and doesn't clone its parameters)
+                // else this would be unnecessary.
+                MatParam boneMatrices = mClone.getParam("BoneMatrices");
+                
+                // ...because for some strange reason you can't clear a non-existant 
+                // parameter.
+                if( boneMatrices != null ) {                    
+                    mClone.clearParam("BoneMatrices");
+                }
+            }
         }
         this.materials = newMaterials;
     }