parent
06f8a00549
commit
9df4449f49
@ -0,0 +1,12 @@ |
||||
package com.jme3.anim; |
||||
|
||||
/** |
||||
* Created by Nehon |
||||
* An AnimationMask is defining a subset of elements on which an animation will be applied. |
||||
* Most used implementation is the ArmatureMask that defines a subset of joints in an Armature. |
||||
*/ |
||||
public interface AnimationMask { |
||||
|
||||
boolean contains(Object target); |
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.jme3.anim; |
||||
|
||||
import java.util.BitSet; |
||||
|
||||
public class ArmatureMask implements AnimationMask { |
||||
|
||||
private BitSet affectedJoints = new BitSet(); |
||||
|
||||
@Override |
||||
public boolean contains(Object target) { |
||||
return affectedJoints.get(((Joint) target).getId()); |
||||
} |
||||
|
||||
public static ArmatureMask createMask(Armature armature, String fromJoint) { |
||||
ArmatureMask mask = new ArmatureMask(); |
||||
mask.addFromJoint(armature, fromJoint); |
||||
return mask; |
||||
} |
||||
|
||||
public static ArmatureMask createMask(Armature armature, String... joints) { |
||||
ArmatureMask mask = new ArmatureMask(); |
||||
mask.addBones(armature, joints); |
||||
for (String joint : joints) { |
||||
mask.affectedJoints.set(armature.getJoint(joint).getId()); |
||||
} |
||||
return mask; |
||||
} |
||||
|
||||
/** |
||||
* Add joints to be influenced by this animation mask. |
||||
*/ |
||||
public void addBones(Armature armature, String... jointNames) { |
||||
for (String jointName : jointNames) { |
||||
Joint joint = findJoint(armature, jointName); |
||||
affectedJoints.set(joint.getId()); |
||||
} |
||||
} |
||||
|
||||
private Joint findJoint(Armature armature, String jointName) { |
||||
Joint joint = armature.getJoint(jointName); |
||||
if (joint == null) { |
||||
throw new IllegalArgumentException("Cannot find joint " + jointName); |
||||
} |
||||
return joint; |
||||
} |
||||
|
||||
/** |
||||
* Add a joint and all its sub armature joints to be influenced by this animation mask. |
||||
*/ |
||||
public void addFromJoint(Armature armature, String jointName) { |
||||
Joint joint = findJoint(armature, jointName); |
||||
recurseAddJoint(joint); |
||||
} |
||||
|
||||
private void recurseAddJoint(Joint joint) { |
||||
affectedJoints.set(joint.getId()); |
||||
for (Joint j : joint.getChildren()) { |
||||
recurseAddJoint(j); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue