Exemplo n.º 1
0
        private void CalculateAnimationsSequences(
            PreparingDataPlayableGraph graph,
            string saveFolder,
            List <Transform> bonesMask
            )
        {
            foreach (AnimationsSequence seq in creator.sequences)
            {
                if (!seq.IsValid())
                {
                    continue;
                }

                MotionMatchingData newCreatedAsset = MotionDataCalculator.CalculateAnimationSequenceData(
                    seq.name,
                    seq,
                    creator.gameObjectTransform.gameObject,
                    graph,
                    bonesMask,
                    creator.bonesWeights,
                    creator.posesPerSecond,
                    true,
                    creator.gameObjectTransform,
                    creator.trajectoryStepTimes,
                    seq.blendToYourself,
                    seq.findInYourself
                    );
                string             path        = saveFolder.Substring(Application.dataPath.Length - 6) + "/" + newCreatedAsset.name + ".asset";
                MotionMatchingData loadedAsset = (MotionMatchingData)AssetDatabase.LoadAssetAtPath(path, typeof(MotionMatchingData));

                float startTime = 0f;
                float endTime   = 0f;
                float delta     = 0.1f;
                for (int i = 0; i < seq.findPoseInClip.Count; i++)
                {
                    endTime += (seq.neededInfo[i].y - seq.neededInfo[i].x);
                    if (!seq.findPoseInClip[i])
                    {
                        float startB = startTime;
                        float endB   = endTime;
                        if (i == seq.findPoseInClip.Count - 1)
                        {
                            if (seq.findPoseInClip[0])
                            {
                                endB = endTime - delta;
                            }
                            if (seq.findPoseInClip[i - 1])
                            {
                                startB = startTime + delta;
                            }
                        }
                        else if (i == 0)
                        {
                            if (seq.findPoseInClip[i + 1])
                            {
                                endB = endTime - delta;
                            }
                            if (seq.findPoseInClip[seq.findPoseInClip.Count - 1])
                            {
                                startB = startTime + delta;
                            }
                        }
                        else
                        {
                            if (seq.findPoseInClip[i + 1])
                            {
                                endB = endTime - delta;
                            }
                            if (seq.findPoseInClip[i - 1])
                            {
                                startB = startTime + delta;
                            }
                        }

                        newCreatedAsset.neverChecking.timeIntervals.Add(new Vector2(startB, endB));
                    }
                    startTime = endTime;
                }

                if (loadedAsset == null)
                {
                    AssetDatabase.CreateAsset(newCreatedAsset, path);
                    //AssetDatabase.SaveAssets();
                }
                else
                {
                    loadedAsset.UpdateFromOther(newCreatedAsset, newCreatedAsset.name);

                    if (loadedAsset.contactPoints != null)
                    {
                        if (loadedAsset.contactPoints.Count > 0)
                        {
                            MotionDataCalculator.CalculateContactPoints(
                                loadedAsset,
                                loadedAsset.contactPoints.ToArray(),
                                graph,
                                creator.gameObjectTransform.gameObject
                                );
                        }
                    }

                    EditorUtility.SetDirty(loadedAsset);
                    //AssetDatabase.SaveAssets();
                }
            }

            Debug.Log("Calculation of sequences completed!");
        }
Exemplo n.º 2
0
        private void CalculateNormalClips(
            PreparingDataPlayableGraph graph,
            string saveFolder,
            List <Transform> bonesMask
            )
        {
            foreach (AnimationClip clip in creator.clips)
            {
                if (clip != null)
                {
                    MotionMatchingData newCreatedAsset = MotionDataCalculator.CalculateNormalData(
                        creator.gameObjectTransform.gameObject,
                        graph,
                        clip,
                        bonesMask,
                        creator.bonesWeights,
                        creator.posesPerSecond,
                        clip.isLooping,
                        creator.gameObjectTransform,
                        creator.trajectoryStepTimes,
                        creator.blendToYourself,
                        creator.findInYourself
                        );
                    string             path        = saveFolder.Substring(Application.dataPath.Length - 6) + "/" + newCreatedAsset.name + ".asset";
                    MotionMatchingData loadedAsset = (MotionMatchingData)AssetDatabase.LoadAssetAtPath(path, typeof(MotionMatchingData));

                    if (creator.cutTimeFromStart > 0f)
                    {
                        newCreatedAsset.neverChecking.timeIntervals.Add(
                            new float2(
                                0f,
                                math.clamp(creator.cutTimeFromStart, 0f, newCreatedAsset.animationLength)
                                ));
                    }

                    if (creator.cutTimeToEnd > 0f)
                    {
                        newCreatedAsset.neverChecking.timeIntervals.Add(
                            new float2(
                                math.clamp(newCreatedAsset.animationLength - creator.cutTimeToEnd, 0f, newCreatedAsset.animationLength),
                                newCreatedAsset.animationLength
                                ));
                    }

                    if (loadedAsset == null)
                    {
                        AssetDatabase.CreateAsset(newCreatedAsset, path);
                    }
                    else
                    {
                        loadedAsset.UpdateFromOther(newCreatedAsset, newCreatedAsset.name);

                        if (loadedAsset.contactPoints != null)
                        {
                            if (loadedAsset.contactPoints.Count > 0)
                            {
                                MotionDataCalculator.CalculateContactPoints(
                                    loadedAsset,
                                    loadedAsset.contactPoints.ToArray(),
                                    graph,
                                    creator.gameObjectTransform.gameObject
                                    );
                            }
                        }


                        EditorUtility.SetDirty(loadedAsset);
                        //AssetDatabase.SaveAssets();
                    }
                }
                else
                {
                    Debug.Log("Element is null");
                }
            }
            Debug.Log("Calculation of normal clips completed!");
        }
Exemplo n.º 3
0
        private void CalculateBlendTrees(
            PreparingDataPlayableGraph graph,
            string saveFolder,
            List <Transform> bonesMask
            )
        {
            foreach (BlendTreeInfo info in creator.blendTrees)
            {
                if (!info.IsValid())
                {
                    continue;
                }
                if (info.useSpaces && info.clips.Count == 2)
                {
                    for (int spaces = 1; spaces <= info.spaces; spaces++)
                    {
                        float currentFactor = (float)spaces / (info.spaces + 1);

                        float[] clipsWeights = new float[info.clips.Count];

                        clipsWeights[0] = currentFactor;
                        clipsWeights[1] = 1f - currentFactor;
                        //Debug.Log(clipsWeights[0]);
                        //Debug.Log(clipsWeights[1]);

                        MotionMatchingData dataToSave = MotionDataCalculator.CalculateBlendTreeData(
                            info.name + currentFactor.ToString(),
                            creator.gameObjectTransform.gameObject,
                            graph,
                            info.clips.ToArray(),
                            bonesMask,
                            creator.bonesWeights,
                            creator.gameObjectTransform,
                            creator.trajectoryStepTimes,
                            clipsWeights,
                            creator.posesPerSecond,
                            false,
                            info.blendToYourself,
                            info.findInYourself
                            );

                        string path = saveFolder.Substring(Application.dataPath.Length - 6) + "/" + dataToSave.name + ".asset";

                        MotionMatchingData loadedAsset = (MotionMatchingData)AssetDatabase.LoadAssetAtPath(path, typeof(MotionMatchingData));

                        if (loadedAsset == null)
                        {
                            AssetDatabase.CreateAsset(dataToSave, path);
                            //AssetDatabase.SaveAssets();
                        }
                        else
                        {
                            loadedAsset.UpdateFromOther(dataToSave, dataToSave.name);

                            if (loadedAsset.contactPoints != null)
                            {
                                if (loadedAsset.contactPoints.Count > 0)
                                {
                                    MotionDataCalculator.CalculateContactPoints(
                                        loadedAsset,
                                        loadedAsset.contactPoints.ToArray(),
                                        graph,
                                        creator.gameObjectTransform.gameObject
                                        );
                                }
                            }

                            EditorUtility.SetDirty(loadedAsset);
                            //AssetDatabase.SaveAssets();
                        }
                    }
                }
                else
                {
                    MotionMatchingData dataToSave = MotionDataCalculator.CalculateBlendTreeData(
                        info.name,
                        creator.gameObjectTransform.gameObject,
                        graph,
                        info.clips.ToArray(),
                        bonesMask,
                        creator.bonesWeights,
                        creator.gameObjectTransform,
                        creator.trajectoryStepTimes,
                        info.clipsWeights.ToArray(),
                        creator.posesPerSecond,
                        false,
                        info.blendToYourself,
                        info.findInYourself
                        );

                    string path = saveFolder.Substring(Application.dataPath.Length - 6) + "/" + dataToSave.name + ".asset";

                    MotionMatchingData loadedAsset = (MotionMatchingData)AssetDatabase.LoadAssetAtPath(path, typeof(MotionMatchingData));
                    if (loadedAsset == null)
                    {
                        AssetDatabase.CreateAsset(dataToSave, path);
                        //AssetDatabase.SaveAssets();
                    }
                    else
                    {
                        loadedAsset.UpdateFromOther(dataToSave, dataToSave.name);
                        EditorUtility.SetDirty(loadedAsset);
                        //AssetDatabase.SaveAssets();
                    }
                }
            }
            Debug.Log("Calculation of Blend trees completed!");
        }
        private void ContactsButtonOptions()
        {
            GUILayout.Space(5);

            switch (editedData.contactsType)
            {
            case ContactStateType.NormalContacts:
                if (GUILayout.Button("Sort contacts", GUIResources.Button_MD()) && editedData != null)
                {
                    editedData.contactPoints.Sort();
                }

                if (GUILayout.Button("Calculate Contacts", GUIResources.Button_MD()) && editedData != null && gameObject != null)
                {
                    if (gameObject == null)
                    {
                        Debug.LogWarning("Game object in MM Data Editor is NULL!");
                        return;
                    }
                    else
                    {
                        editedData.contactPoints.Sort();

                        MotionDataCalculator.CalculateContactPoints(
                            editedData,
                            editedData.contactPoints.ToArray(),
                            this.playableGraph,
                            this.gameObject
                            );

                        playableGraph.Initialize(gameObject);
                        playableGraph.CreateAnimationDataPlayables(editedData, currentAnimaionTime);
                    }
                }
                break;

            case ContactStateType.Impacts:
                if (GUILayout.Button("Sort impacts", GUIResources.Button_MD()) && editedData != null)
                {
                    editedData.contactPoints.Sort();
                }

                if (GUILayout.Button("Calculate Impacts", GUIResources.Button_MD()) && editedData != null && gameObject != null)
                {
                    if (gameObject == null)
                    {
                        Debug.LogWarning("Game object in MM Data Editor is NULL!");
                        return;
                    }
                    else
                    {
                        editedData.contactPoints.Sort();

                        MotionDataCalculator.CalculateImpactPoints(
                            editedData,
                            editedData.contactPoints.ToArray(),
                            this.playableGraph,
                            this.gameObject
                            );

                        playableGraph.Initialize(gameObject);
                        playableGraph.CreateAnimationDataPlayables(editedData, currentAnimaionTime);
                    }
                }
                break;
            }
        }