public static bool TheWinnerIsAtTheSameLocation( int currentClipIndex, int currentGroupIndex, float currentClipTime, float currentClipLength, NewClipInfoToPlay info, float maxClipDeltaTime, bool isLooping ) { if (currentClipIndex != info.clipIndex || currentGroupIndex != info.groupIndex) { return(false); } float clipDeltaLoop = currentClipTime + currentClipLength - (float)info.localTime; if (isLooping && clipDeltaLoop < maxClipDeltaTime) { return(true); } float clipDeltaTime = math.abs((float)(currentClipTime - info.localTime)); if (clipDeltaTime > maxClipDeltaTime) { return(false); } return(true); }
private void ImpactFinding() { NewClipInfoToPlay output = new NewClipInfoToPlay(-1, 0, -1, float.MaxValue); int poseStep = currentPose.Length; int frameCount = framesInfo.Length; float currentCost; for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { float contactCost = contactPoints[frameIndex].CalculateCost(currentContactPoints[0], contactCostType); int boneIndex = frameIndex * poseStep; float poseCost = 0f; for (int i = 0; i < poseStep; i++) { poseCost += currentPose[i].CalculateCost(bonesData[boneIndex], poseCostType); boneIndex++; } currentCost = poseCost * poseWeight + contactCost * contactWeight; if (currentCost < output.bestCost) { output.Set( framesInfo[frameIndex].clipIndex, framesInfo[frameIndex].localTime, currentCost ); } } infos[0] = output; }
public void Execute() { NewClipInfoToPlay output = new NewClipInfoToPlay(-1, 0, -1, float.MaxValue); int trajectoryStep = currentTrajectory.Length; int poseStep = currentPose.Length; int frameCount = framesInfo.Length; int currentClipIndex; float currentCost; for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { currentClipIndex = framesInfo[frameIndex].clipIndex; if ( framesInfo[frameIndex].localTime <whereWeCanFindingPos[currentClipIndex].x || framesInfo[frameIndex].localTime> whereWeCanFindingPos[currentClipIndex].y ) { continue; } currentCost = 0; float trajectoryCost = 0f; int tpIndex = frameIndex * trajectoryStep; for (int i = 0; i < trajectoryStep; i++) { trajectoryCost += currentTrajectory[i].CalculateCost(trajectoryPoints[tpIndex], trajectoryCostType); tpIndex++; } trajectoryCost *= trajectoryWeight; float poseCost = 0; int boneIndex = frameIndex * poseStep; for (int i = 0; i < poseStep; i++) { poseCost += currentPose[i].CalculateCost(bonesData[boneIndex], poseCostType); boneIndex++; } poseCost *= poseWeight; currentCost = trajectoryCost + poseCost; if (currentCost < output.bestCost) { output.Set( framesInfo[frameIndex].clipIndex, framesInfo[frameIndex].localTime, currentCost ); } } infos[0] = output; }
// Switch State features public LogicMotionMatchingLayer( MotionMatchingPlayableGraph mmAnimator, MotionMatchingLayer layer, Transform gameObject ) { this.transform = gameObject; passIK = layer.passIK; this.playableGraph = mmAnimator; currentBlendedStates = new List <int>(); this.layer = layer; logicStates = new List <LogicState>(); currentWeights = new List <float>(); bestPoseInfo = new NewClipInfoToPlay(-1, -1, -1, -1); }
public void Execute() { NewClipInfoToPlay output = new NewClipInfoToPlay(-1, currentGroupIndex, -1, float.MaxValue); int trajectoryStep = currentTrajectory.Length; int poseStep = currentPose.Length; int frameCount = framesInfo.Length; float currentCost; float trajectoryCost; float poseCost; float costWeight; for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { bool notSkipCheckingFrame = true; for (int i = 0; i < currentPlayingClips.Length; i++) { if (currentPlayingClips[i].groupIndex == currentGroupIndex && currentPlayingClips[i].clipIndex == framesInfo[frameIndex].clipIndex && currentPlayingClips[i].notFindInYourself) { notSkipCheckingFrame = false; break; } } if (notSkipCheckingFrame && framesInfo[frameIndex].sections.GetSection(sectionsIndexes[framesInfo[frameIndex].clipIndex])) { trajectoryCost = 0; poseCost = 0; costWeight = 1f; for (int i = 0; i < sectionDependecies.Length; i++) { if (framesInfo[frameIndex].sections.GetSection(sectionDependecies[i].sectionIndex)) { costWeight *= sectionDependecies[i].sectionWeight; } } int tpIndex = frameIndex * trajectoryStep; for (int i = 0; i < trajectoryStep; i++) { trajectoryCost += currentTrajectory[i].CalculateCost(trajectoryPoints[tpIndex], trajectoryCostType); tpIndex++; } int boneIndex = frameIndex * poseStep; for (int i = 0; i < poseStep; i++) { poseCost += currentPose[i].CalculateCost(bonesData[boneIndex], poseCostType); boneIndex++; } currentCost = costWeight * (poseWeight * poseCost + trajectoryWeight * trajectoryCost); if (currentCost < output.bestCost) { output.Set( framesInfo[frameIndex].clipIndex, framesInfo[frameIndex].localTime, currentCost ); } } } infos[0] = output; }
public void Execute() { NewClipInfoToPlay output = new NewClipInfoToPlay(-1, 0, -1, float.MaxValue); int poseStep = currentPose.Length; int frameCount = framesInfo.Length; int currentClipIndex; int contactPointIndex; int trajectoryStep = currentTrajectory.Length; float currentCost; for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { currentClipIndex = framesInfo[frameIndex].clipIndex; if ( framesInfo[frameIndex].localTime <whereWeCanFindingPos[currentClipIndex].x || framesInfo[frameIndex].localTime> whereWeCanFindingPos[currentClipIndex].y ) { continue; } currentCost = 0; float contactCost = 0f; int lastContactsIndex; switch (cntactMovmentType) { case ContactStateMovemetType.StartContact: contactPointIndex = frameIndex * (middleContactsCount + 1); for (int i = 0; i <= middleContactsCount; i++) { contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[i], contactCostType); contactPointIndex++; } break; case ContactStateMovemetType.ContactLand: contactPointIndex = frameIndex * (middleContactsCount + 1); for (int i = 1; i < middleContactsCount; i++) { contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[i], contactCostType); contactPointIndex++; } lastContactsIndex = currentContactPoints.Length - 1; contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[lastContactsIndex], contactCostType); break; case ContactStateMovemetType.StartContactLand: contactPointIndex = frameIndex * (middleContactsCount + 2); for (int i = 0; i <= middleContactsCount; i++) { contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[i], contactCostType); contactPointIndex++; } lastContactsIndex = currentContactPoints.Length - 1; contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[lastContactsIndex], contactCostType); break; case ContactStateMovemetType.Contact: contactPointIndex = frameIndex * middleContactsCount; for (int i = 1; i < middleContactsCount; i++) { contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[i], contactCostType); contactPointIndex++; } break; case ContactStateMovemetType.StartLand: contactPointIndex = frameIndex * 2; contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[0], contactCostType); contactPointIndex++; lastContactsIndex = currentContactPoints.Length - 1; contactCost += contactPoints[contactPointIndex].CalculateCost(currentContactPoints[lastContactsIndex], contactCostType); break; } int tpIndex = frameIndex * trajectoryStep; float trajectoryCost = 0f; for (int i = 0; i < trajectoryStep; i++) { trajectoryCost += currentTrajectory[i].CalculateCost(trajectoryPoints[tpIndex], trajectoryCostType); tpIndex++; } int boneIndex = frameIndex * poseStep; float poseCost = 0f; for (int i = 0; i < poseStep; i++) { poseCost += currentPose[i].CalculateCost(bonesData[boneIndex], poseCostType); boneIndex++; } currentCost = contactCost * contactWeight + trajectoryCost * trajectoryWeight + poseCost * poseWeight; if (currentCost < output.bestCost) { output.Set( framesInfo[frameIndex].clipIndex, framesInfo[frameIndex].localTime, currentCost ); } } infos[0] = output; }