use of com.jme3.animation.Bone in project jmonkeyengine by jMonkeyEngine.
the class ArmatureModifier method apply.
@Override
public void apply(Node node, BlenderContext blenderContext) {
if (invalid) {
LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName());
}
if (modifying) {
TemporalMesh temporalMesh = this.getTemporalMesh(node);
if (temporalMesh != null) {
LOGGER.log(Level.FINE, "Applying armature modifier to: {0}", temporalMesh);
LOGGER.fine("Creating map between bone name and its index.");
for (int i = 0; i < skeleton.getBoneCount(); ++i) {
Bone bone = skeleton.getBone(i);
temporalMesh.addBoneIndex(bone.getName(), i);
}
temporalMesh.applyAfterMeshCreate(this);
} else {
LOGGER.log(Level.WARNING, "Cannot find temporal mesh for node: {0}. The modifier will NOT be applied!", node);
}
}
}
use of com.jme3.animation.Bone in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method setIKTarget.
public Vector3f setIKTarget(Bone bone, Vector3f worldPos, int chainLength) {
Vector3f target = worldPos.subtract(targetModel.getWorldTranslation());
ikTargets.put(bone.getName(), target);
ikChainDepth.put(bone.getName(), chainLength);
int i = 0;
while (i < chainLength + 2 && bone.getParent() != null) {
if (!bone.hasUserControl()) {
bone.setUserControl(true);
}
bone = bone.getParent();
i++;
}
// setIKMode();
return target;
}
use of com.jme3.animation.Bone in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method ikUpdate.
private void ikUpdate(float tpf) {
TempVars vars = TempVars.get();
Quaternion tmpRot1 = vars.quat1;
Quaternion[] tmpRot2 = new Quaternion[] { vars.quat2, new Quaternion() };
Iterator<String> it = ikTargets.keySet().iterator();
float distance;
Bone bone;
String boneName;
while (it.hasNext()) {
boneName = it.next();
bone = (Bone) boneLinks.get(boneName).bone;
if (!bone.hasUserControl()) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
continue;
}
distance = bone.getModelSpacePosition().distance(ikTargets.get(boneName));
if (distance < IKThreshold) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "Distance is close enough");
continue;
}
int depth = 0;
int maxDepth = ikChainDepth.get(bone.getName());
updateBone(boneLinks.get(bone.getName()), tpf * (float) FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
Vector3f position = vars.vect1;
for (PhysicsBoneLink link : boneLinks.values()) {
matchPhysicObjectToBone(link, position, tmpRot1);
}
}
vars.release();
}
use of com.jme3.animation.Bone in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method removeIKTarget.
public void removeIKTarget(Bone bone) {
int depth = ikChainDepth.remove(bone.getName());
int i = 0;
while (i < depth + 2 && bone.getParent() != null) {
if (bone.hasUserControl()) {
// matchPhysicObjectToBone(boneLinks.get(bone.getName()), position, tmpRot1);
bone.setUserControl(false);
}
bone = bone.getParent();
i++;
}
}
use of com.jme3.animation.Bone in project jmonkeyengine by jMonkeyEngine.
the class TestOgreComplexAnim method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
Bone b = control.getSkeleton().getBone("spinehigh");
Bone b2 = control.getSkeleton().getBone("uparm.left");
angle += tpf * rate;
if (angle > FastMath.HALF_PI / 2f) {
angle = FastMath.HALF_PI / 2f;
rate = -1;
} else if (angle < -FastMath.HALF_PI / 2f) {
angle = -FastMath.HALF_PI / 2f;
rate = 1;
}
Quaternion q = new Quaternion();
q.fromAngles(0, angle, 0);
b.setUserControl(true);
b.setUserTransforms(Vector3f.ZERO, q, Vector3f.UNIT_XYZ);
b2.setUserControl(true);
b2.setUserTransforms(Vector3f.ZERO, Quaternion.IDENTITY, new Vector3f(1 + angle, 1 + angle, 1 + angle));
}
Aggregations