From 80f4e0493528d7689ea306d95b72b1de6f0ba576 Mon Sep 17 00:00:00 2001 From: Paul Speed Date: Tue, 5 Apr 2016 11:01:27 -0400 Subject: [PATCH] Fixed cloning to not confuse the hardware skinning safety check that attempts to protect users from shared materials. --- .../com/jme3/animation/SkeletonControl.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java b/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java index 4a69c2d7c..b753ad2cb 100644 --- a/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java +++ b/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 newMaterials = new HashSet(); 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; }