private void Update() { for (int i = 0; i < animData.poseBase.Length; i++) { animationTransformData poseresult = new animationTransformData(); animationTransformData dataPose0 = new animationTransformData(); animationTransformData dataPose1 = new animationTransformData(); KeyFrame key0 = animData.poseBase[i].keyFrames[keyframe0]; KeyFrame key1 = animData.poseBase[i].keyFrames[keyframe1]; dataPose0.setTransformIndividual(key0.keyPosition, Quaternion.Euler(key0.keyRotation), new Vector3(1, 1, 1)); dataPose1.setTransformIndividual(key1.keyPosition, Quaternion.Euler(key1.keyRotation), new Vector3(1, 1, 1)); switch (blendMode) { case testBlendMode.LERP: poseresult = blendStatic.lerp(dataPose0, dataPose1, parameter0, usingQuaternion); break; case testBlendMode.ADD: poseresult = blendStatic.add(dataPose0, dataPose1, usingQuaternion); break; case testBlendMode.SCALE: poseresult = blendStatic.scale(new identity(), dataPose0, parameter0, usingQuaternion); break; case testBlendMode.AVERAGE: poseresult = blendStatic.average(new identity(), dataPose0, dataPose1, parameter0, parameter1, usingQuaternion); break; } int parentIndex = animData.poseBase[i].parentNodeIndex; Vector3 localPosition = animData.poseBase[i].getLocalPosition(); Vector3 localRotation = animData.poseBase[i].getLocalRotationEuler(); //find delta change from localpose Matrix4x4 deltaMatrix = Matrix4x4.TRS(localPosition + poseresult.localPosition, Quaternion.Euler(localRotation + poseresult.localRotation.eulerAngles), new Vector4(1, 1, 1, 1)); if (parentIndex == -1) { //is root animData.poseBase[i].currentTransform = deltaMatrix; } else { //current transform = take the parent index current transform and multiply with delta matrix animData.poseBase[i].currentTransform = animData.poseBase[parentIndex].currentTransform * deltaMatrix; } animData.poseBase[i].updateNewPosition(gameObjectData.getObject(i)); } }
//binds the objects in the object hierarchy to a pose, either current or base void setPose(bool boundToCurrent) { for (int jointID = 0; jointID < animData.poseBase.Length; jointID++) { animationTransformData tData = new animationTransformData(0); if (boundToCurrent) { KeyFrame currentKey = animData.poseBase[jointID].keyFrames[currentKeyFrame]; tData.setTransformIndividual(currentKey.keyPosition, currentKey.keyQRotation, currentKey.scale); } ForwardKinematics.setData(gameObjectHierarchy, animData, tData, jointID); } }
void blendAnimation() { bool usingQuaternion = true; for (int i = 0; i < currentAnim.poseBase.Length; i++) { animationTransformData poseresult = new animationTransformData(); animationTransformData dataPose0 = new animationTransformData(); animationTransformData dataPose1 = new animationTransformData(); KeyFrame key0 = prevAnim.poseBase[i].keyFrames[currentFrame]; KeyFrame key1 = currentAnim.poseBase[i].keyFrames[currentFrame]; dataPose0.setTransformIndividual(key0.keyPosition, Quaternion.Euler(key0.keyRotation), new Vector3(1, 1, 1)); dataPose1.setTransformIndividual(key1.keyPosition, Quaternion.Euler(key1.keyRotation), new Vector3(1, 1, 1)); poseresult = blendStatic.lerp(dataPose0, dataPose1, transitionParameter, usingQuaternion); int parentIndex = currentAnim.poseBase[i].parentNodeIndex; Vector3 localPosition = currentAnim.poseBase[i].getLocalPosition(); Vector3 localRotation = currentAnim.poseBase[i].getLocalRotationEuler(); //find delta change from localpose Matrix4x4 deltaMatrix = Matrix4x4.TRS(localPosition + poseresult.localPosition, Quaternion.Euler(localRotation + poseresult.localRotation.eulerAngles), new Vector4(1, 1, 1, 1)); if (parentIndex == -1) { //is root currentAnim.poseBase[i].currentTransform = deltaMatrix; } else { //current transform = take the parent index current transform and multiply with delta matrix currentAnim.poseBase[i].currentTransform = currentAnim.poseBase[parentIndex].currentTransform * deltaMatrix; } currentAnim.poseBase[i].updateNewPosition(objectHierarchy.getObject(i)); } }