public static MotionMatchingData CalculateBlendTreeData( string name, GameObject go, PreparingDataPlayableGraph graph, AnimationClip[] clips, List <Transform> bonesMask, List <Vector2> bonesWeights, Transform root, List <float> trajectoryStepTimes, float[] weightsForClips, int sampling, bool loop, bool blendToYourself, bool findInYourself ) { if (!graph.IsValid()) { graph.Initialize(go); } go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; #region need floats float frameTime = 1f / (float)sampling; int numberOfFrames = Mathf.FloorToInt(clips[0].length / frameTime) + 1; #endregion float weightSum = 0f; for (int i = 0; i < weightsForClips.Length; i++) { weightSum += weightsForClips[i]; } for (int i = 0; i < weightsForClips.Length; i++) { weightsForClips[i] = weightsForClips[i] / weightSum; } MotionMatchingData data = new MotionMatchingData( clips, weightsForClips, sampling, name, loop, clips[0].length, findInYourself, blendToYourself, AnimationDataType.BlendTree ); FrameData frameBuffer; BoneData boneBuffer; PoseData poseBuffor; Trajectory trajectoryBuffor; NeedValueToCalculateData[] previewBoneData = new NeedValueToCalculateData[bonesMask.Count]; NeedValueToCalculateData[] nextBoneData = new NeedValueToCalculateData[bonesMask.Count]; for (int i = 0; i < clips.Length; i++) { graph.AddClipPlayable(clips[i]); graph.SetMixerInputTime(i, 0f); graph.SetMixerInputWeight(i, weightsForClips[i]); } graph.Evaluate(frameTime); int frameIndex = 0; float currentCheckingTime = 0f; // FramesCalculation for (; frameIndex < numberOfFrames; frameIndex++) { for (int i = 0; i < bonesMask.Count; i++) { previewBoneData[i] = GetValuesFromTransform(bonesMask[i], root); } graph.Evaluate(frameTime); currentCheckingTime = frameIndex * frameTime; for (int i = 0; i < bonesMask.Count; i++) { nextBoneData[i] = GetValuesFromTransform(bonesMask[i], root); } poseBuffor = new PoseData(bonesMask.Count); for (int i = 0; i < bonesMask.Count; i++) { float2 boneWeight = bonesWeights[i]; float3 velocity = BoneData.CalculateVelocity(previewBoneData[i].position, nextBoneData[i].position, frameTime); float3 localPosition = previewBoneData[i].position; quaternion orientation = previewBoneData[i].rotation; boneBuffer = new BoneData(localPosition, velocity); poseBuffor.SetBone(boneBuffer, i); } trajectoryBuffor = new Trajectory(trajectoryStepTimes.Count); frameBuffer = new FrameData( frameIndex, currentCheckingTime, trajectoryBuffor, poseBuffor, new FrameSections(true) ); data.AddFrame(frameBuffer); } // Trajectory calculations float clipGlobalStart; Vector2 clipStartAndStop; float recordingClipTime; if (trajectoryStepTimes[0] < 0) { clipGlobalStart = trajectoryStepTimes[0]; clipStartAndStop = new Vector2(-clipGlobalStart, -clipGlobalStart + clips[0].length); } else { clipGlobalStart = 0; clipStartAndStop = new Vector2(0, clips[0].length); } if (trajectoryStepTimes[trajectoryStepTimes.Count - 1] > 0) { recordingClipTime = clipStartAndStop.y + trajectoryStepTimes[trajectoryStepTimes.Count - 1] + 0.1f; } else { recordingClipTime = clipStartAndStop.y + 0.1f; } int samplesPerSecond = 100; float deltaTime = 1f / (float)samplesPerSecond; int dataCount = Mathf.CeilToInt(recordingClipTime / deltaTime); NeedValueToCalculateData[] recordData = new NeedValueToCalculateData[dataCount]; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; for (int i = 0; i < graph.GetMixerInputCount(); i++) { graph.SetMixerInputTimeInPlace(i, clipGlobalStart); } recordData[0] = new NeedValueToCalculateData( go.transform.position, go.transform.forward, go.transform.rotation ); for (int i = 0; i < dataCount; i++) { graph.Evaluate(deltaTime); recordData[i] = new NeedValueToCalculateData( go.transform.position, go.transform.forward, go.transform.rotation ); } //clearing graph from all animations graph.ClearMainMixerInput(); MotionDataCalculator.CalculateTrajectoryPointsFromRecordData( data, recordData, recordingClipTime, deltaTime, clipStartAndStop, trajectoryStepTimes ); data.usedFrameCount = data.numberOfFrames; data.trajectoryPointsTimes = new List <float>(); for (int i = 0; i < trajectoryStepTimes.Count; i++) { data.trajectoryPointsTimes.Add(trajectoryStepTimes[i]); } return(data); }