/** * Remove the inverse-kinematics target for the specified bone. * * @param bone which bone has the target (not null, modified) */ 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++; } }
/** * Remove the inverse-kinematics target for the specified bone. * * @param bone which bone has the target (not null, modified) */ 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++; } }
/** * Creates a skeleton from a bone list. * The root bones are found automatically. * <p> * Note that using this constructor will cause the bones in the list * to have their bind pose recomputed based on their local transforms. * * @param boneList The list of bones to manage by this Skeleton */ public Skeleton(Bone[] boneList) { this.boneList = boneList; List<Bone> rootBoneList = new ArrayList<>(); for (int i = boneList.length - 1; i >= 0; i--) { Bone b = boneList[i]; if (b.getParent() == null) { rootBoneList.add(b); } } rootBones = rootBoneList.toArray(new Bone[rootBoneList.size()]); createSkinningMatrices(); for (int i = rootBones.length - 1; i >= 0; i--) { Bone rootBone = rootBones[i]; rootBone.update(); rootBone.setBindingPose(); } }
/** * Ensure that user control is enabled for any bones used by inverse * kinematics and disabled for any other bones. */ public void applyUserControl() { for (Bone bone : skeleton.getRoots()) { RagdollUtils.setUserControl(bone, false); } if (ikTargets.isEmpty()) { setKinematicMode(); } else { Iterator iterator = ikTargets.keySet().iterator(); TempVars vars = TempVars.get(); while (iterator.hasNext()) { Bone bone = (Bone) iterator.next(); while (bone.getParent() != null) { Quaternion tmpRot1 = vars.quat1; Vector3f position = vars.vect1; matchPhysicObjectToBone(boneLinks.get(bone.getName()), position, tmpRot1); bone.setUserControl(true); bone = bone.getParent(); } } vars.release(); } }
/** * Add a target for inverse kinematics. * * @param bone which bone the IK applies to (not null) * @param worldPos the world coordinates of the goal (not null) * @param chainLength number of bones in the chain * @return a new instance (not null, already added to ikTargets) */ 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; }
/** * Ensure that user control is enabled for any bones used by inverse * kinematics and disabled for any other bones. */ public void applyUserControl() { for (Bone bone : skeleton.getRoots()) { RagdollUtils.setUserControl(bone, false); } if (ikTargets.isEmpty()) { setKinematicMode(); } else { Iterator iterator = ikTargets.keySet().iterator(); TempVars vars = TempVars.get(); while (iterator.hasNext()) { Bone bone = (Bone) iterator.next(); while (bone.getParent() != null) { Quaternion tmpRot1 = vars.quat1; Vector3f position = vars.vect1; matchPhysicObjectToBone(boneLinks.get(bone.getName()), position, tmpRot1); bone.setUserControl(true); bone = bone.getParent(); } } vars.release(); } }
/** * Add a target for inverse kinematics. * * @param bone which bone the IK applies to (not null) * @param worldPos the world coordinates of the goal (not null) * @param chainLength number of bones in the chain * @return a new instance (not null, already added to ikTargets) */ 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; }
@Override public boolean isTrackToBeChanged() { // location limit does not work on bones who are connected to their parent return trackToBeChanged && !(this.getOwner() instanceof Bone && ((Bone) this.getOwner()).getParent() != null && blenderContext.getBoneContext(ownerOMA).is(BoneContext.CONNECTED_TO_PARENT)); }
@Override public boolean isTrackToBeChanged() { // location copy does not work on bones who are connected to their parent return trackToBeChanged && !(this.getOwner() instanceof Bone && ((Bone) this.getOwner()).getParent() != null && blenderContext.getBoneContext(ownerOMA).is(BoneContext.CONNECTED_TO_PARENT)); }
public BonesChain(Bone bone, boolean useTail, int bonesAffected, Collection<Long> alteredOmas, BlenderContext blenderContext) { if (bone != null) { ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); if (!useTail) { bone = bone.getParent(); } while (bone != null && (bonesAffected <= 0 || this.size() < bonesAffected)) { BoneContext boneContext = blenderContext.getBoneContext(bone); this.add(boneContext); alteredOmas.add(boneContext.getBoneOma()); Transform transform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), Space.CONSTRAINT_SPACE_WORLD); localBonesMatrices.add(new DTransform(transform).toMatrix()); bone = bone.getParent(); } if(localBonesMatrices.size() > 0) { // making the matrices describe the local transformation Matrix parentWorldMatrix = localBonesMatrices.get(localBonesMatrices.size() - 1); for(int i=localBonesMatrices.size() - 2;i>=0;--i) { SimpleMatrix m = parentWorldMatrix.invert().mult(localBonesMatrices.get(i)); parentWorldMatrix = localBonesMatrices.get(i); localBonesMatrices.set(i, new Matrix(m)); } } } }
/** * Generate physics shapes and bone links for the skeleton. * * @param model the spatial with the model's SkeletonControl (not null) */ protected void scanSpatial(Spatial model) { AnimControl animControl = model.getControl(AnimControl.class); Map<Integer, List<Float>> pointsMap = null; if (weightThreshold == -1.0f) { pointsMap = RagdollUtils.buildPointMap(model); } skeleton = animControl.getSkeleton(); skeleton.resetAndUpdate(); for (int i = 0; i < skeleton.getRoots().length; i++) { Bone childBone = skeleton.getRoots()[i]; if (childBone.getParent() == null) { logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton); boneRecursion(model, childBone, baseRigidBody, 1, pointsMap); } } }
/** * Generate physics shapes and bone links for the skeleton. * * @param model the spatial with the model's SkeletonControl (not null) */ protected void scanSpatial(Spatial model) { AnimControl animControl = model.getControl(AnimControl.class); Map<Integer, List<Float>> pointsMap = null; if (weightThreshold == -1.0f) { pointsMap = RagdollUtils.buildPointMap(model); } skeleton = animControl.getSkeleton(); skeleton.resetAndUpdate(); for (int i = 0; i < skeleton.getRoots().length; i++) { Bone childBone = skeleton.getRoots()[i]; if (childBone.getParent() == null) { logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton); boneRecursion(model, childBone, baseRigidBody, 1, pointsMap); } } }
if (link.bone.getParent() == null) {
if (link.bone.getParent() == null) {
@Override public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) { if (this.getOwner() instanceof Bone && ((Bone) this.getOwner()).getParent() != null && blenderContext.getBoneContext(ownerOMA).is(BoneContext.CONNECTED_TO_PARENT)) {