Beispiel #1
0
        public static List <AnimationClip> ImportAnimationClips(ImporterContext ctx)
        {
            List <AnimationClip> animasionClips = new List <AnimationClip>();

            for (int i = 0; i < ctx.GLTF.animations.Count; ++i)
            {
                var clip = new AnimationClip();
                clip.ClearCurves();
                clip.legacy = true;
                clip.name   = ctx.GLTF.animations[i].name;
                if (string.IsNullOrEmpty(clip.name))
                {
                    clip.name = "legacy_" + i;
                }
                clip.wrapMode = WrapMode.Loop;

                var animation = ctx.GLTF.animations[i];
                if (string.IsNullOrEmpty(animation.name))
                {
                    animation.name = string.Format("animation:{0}", i);
                }

                animasionClips.Add(ImportAnimationClip(ctx, animation, ctx.GLTF.nodes[0]));
            }

            return(animasionClips);
        }
Beispiel #2
0
    /// <summary>
    /// 删除指定帧
    /// </summary>
    /// <param name="clip">动画剪辑</param>
    /// <param name="keyName">帧名</param>
    static void CompressKey(AnimationClip clip)
    {
        // 部分骨骼带位移
        // 部分动画不做减帧压缩
        // 动画压缩分类型:All,OnlyScale,None;All只包含Scale和Position
        EditorCurveBinding[] curves   = AnimationUtility.GetCurveBindings(clip);
        AnimationClip        tempClip = Object.Instantiate(clip);

        clip.ClearCurves();
        for (int j = 0; j < curves.Length; j++)
        {
            EditorCurveBinding curveBinding = curves[j];

            int    index    = curveBinding.path.LastIndexOf("/");
            string boneName = curveBinding.path.Substring(index + 1);
            if (!_excludeHash.Contains(boneName))
            {
                if (curveBinding.propertyName.Contains("Position") ||
                    curveBinding.propertyName.Contains("Scale"))
                {
                    continue;
                }
            }

            AnimationCurve curve = AnimationUtility.GetEditorCurve(tempClip, curveBinding);
            clip.SetCurve(curveBinding.path, curveBinding.type, curveBinding.propertyName, curve);
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            //animClip = anim.clip;

            animClip.ClearCurves();
            //animClip.ClearCurves ();
            //animator.GetCurrentAnimatorStateInfo(1).normalizedTime = 0.0f;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            AnimationCurve testCurve = new AnimationCurve();
            Keyframe       key1      = new Keyframe();
            Keyframe       key2      = new Keyframe();

            key1.time  = 0f;
            key1.value = 2;

            key2.time  = 2f;
            key2.value = 1;

            testCurve.AddKey(key1);
            testCurve.AddKey(key2);

            animClip.SetCurve("", typeof(Transform), "localPosition.y", testCurve);

            //anim.

            //animClip.
        }
    }
        private List <AnimationClip> ImportAnimationClips(glTF gltf, Axises invertAxis)
        {
            var animationClips = new List <AnimationClip>();

            for (var i = 0; i < gltf.animations.Count; ++i)
            {
                var clip = new AnimationClip();
                clip.ClearCurves();
                clip.legacy = true;
                clip.name   = gltf.animations[i].name;
                if (string.IsNullOrEmpty(clip.name))
                {
                    clip.name = $"legacy_{i}";
                }
                clip.wrapMode = WrapMode.Loop;

                var animation = gltf.animations[i];
                if (string.IsNullOrEmpty(animation.name))
                {
                    animation.name = $"animation:{i}";
                }

                animationClips.Add(AnimationImporterUtil.ConvertAnimationClip(gltf, animation, invertAxis.Create()));
            }

            return(animationClips);
        }
Beispiel #5
0
    // When the Animation get's manipulated, it need's to reset when the game restarts and here it recreate the beginning
    private void CreateElevateAnim()
    {
        float firstFloorKeyframeTime = 0.3f / 2.3f;

        _elevateClip.ClearCurves();
        AnimationCurve curve = AnimationCurve.Constant(0, firstFloorKeyframeTime * 2, 0);

        Keyframe firstKeyframe      = new Keyframe(0, 0);
        Keyframe firstFloorKeyframe = new Keyframe(firstFloorKeyframeTime, -0.3f);

        curve.AddKey(firstKeyframe);
        curve.AddKey(firstFloorKeyframe);

        _elevateClip.SetCurve("", typeof(Transform), "localPosition.y", curve);

        AnimationEvent firstWork = new AnimationEvent();

        firstWork.functionName = "Work";
        firstWork.time         = firstFloorKeyframeTime;
        firstWork.intParameter = 0;
        _elevateClip.AddEvent(firstWork);
        _workEvents.Add(firstWork);

        _storeCoins = new AnimationEvent();
        _storeCoins.functionName = "StoreCoins";
        _storeCoins.time         = firstFloorKeyframeTime * 2;
        _elevateClip.AddEvent(_storeCoins);
    }
Beispiel #6
0
        public void SaveToClip(AnimationClip clip, float fps = 60)
        {
            if (!recorder.isRecording)
            {
                clip.ClearCurves();
                clip.frameRate = fps;
                return;
            }

            // todo: use CurveFilterOptions in 2019
            recorder.SaveToClip(clip, fps);

            var rootCurves   = new AnimationCurve[7];
            var muscleCurves = new AnimationCurve[HumanTrait.MuscleCount];

            getProxyCurves(clip, rootCurves, muscleCurves);
            RemoveConstantCurves(clip);
            SetHumanCurves(clip, rootCurves, muscleCurves);

            var settings = AnimationUtility.GetAnimationClipSettings(clip);

            settings.loopBlendOrientation    = true;     // Root Transform Rotation: Bake Into Pose
            settings.keepOriginalOrientation = true;     // Root Transform Rotation: Based Upon = Origin
            settings.orientationOffsetY      = 0;        // Root Transform Rotation: Offset
            settings.loopBlendPositionY      = true;     // Root Transform Position (Y): Bake Into Pose
            settings.keepOriginalPositionY   = true;     // Root Transform Position (Y): Based Upon = Origin
            settings.level = 0;                          // Root Transform Position (Y): Offset
            settings.loopBlendPositionXZ    = true;      // Root Transform Position (XZ): Bake Into Pose
            settings.keepOriginalPositionXZ = true;      // Root Transform Position (XZ): Based Upon = Origin
            AnimationUtility.SetAnimationClipSettings(clip, settings);
        }
Beispiel #7
0
        public static AnimationClip OptimizeAnimation(AnimationClip _srcClip, int _floatPrecision, bool _clearScale)
        {
            AnimationClip _dstClip = _srcClip.Copy();

            _dstClip.ClearCurves();
            foreach (var binding in AnimationUtility.GetCurveBindings(_srcClip))
            {
                if (_clearScale && binding.propertyName.Contains("Scale"))
                {
                    continue;
                }
                AnimationCurve curve     = AnimationUtility.GetEditorCurve(_srcClip, binding);
                Keyframe[]     keyframes = curve.keys;
                for (int i = 0; i < keyframes.Length; i++)
                {
                    Keyframe keyframe = keyframes[i];
                    keyframe.value      = OptimizeFloat(keyframe.value, _floatPrecision);
                    keyframe.time       = OptimizeFloat(keyframe.time, _floatPrecision);
                    keyframe.inTangent  = OptimizeFloat(keyframe.inTangent, _floatPrecision);
                    keyframe.outTangent = OptimizeFloat(keyframe.outTangent, _floatPrecision);
                    keyframe.inWeight   = OptimizeFloat(keyframe.inWeight, _floatPrecision);
                    keyframe.outWeight  = OptimizeFloat(keyframe.outWeight, _floatPrecision);
                    keyframes[i]        = keyframe;
                }
                curve.keys = keyframes;
                _dstClip.SetCurve(binding.path, binding.type, binding.propertyName, curve);
            }
            return(_dstClip);
        }
Beispiel #8
0
        public void ClearAnimation()
        {
            clip.ClearCurves();

            curveRotationW = new AnimationCurve(keyRotationW);
            curveRotationX = new AnimationCurve(keyRotationX);
            curveRotationY = new AnimationCurve(keyRotationY);
            curveRotationZ = new AnimationCurve(keyRotationZ);

            curveScaleX = new AnimationCurve(keyScaleX);
            curveScaleY = new AnimationCurve(keyScaleY);
            curveScaleZ = new AnimationCurve(keyScaleZ);

            curvePositionX = new AnimationCurve(keyPositionX);
            curvePositionY = new AnimationCurve(keyPositionY);
            curvePositionZ = new AnimationCurve(keyPositionZ);
        }
Beispiel #9
0
    static int ClearCurves(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        AnimationClip obj = LuaScriptMgr.GetNetObject <AnimationClip>(L, 1);

        obj.ClearCurves();
        return(0);
    }
Beispiel #10
0
    static int ClearCurves(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        AnimationClip obj = (AnimationClip)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AnimationClip");

        obj.ClearCurves();
        return(0);
    }
Beispiel #11
0
        public override void ClearCandidates()
        {
            StopCandidateRecording();

            if (m_CandidateClip != null)
            {
                m_CandidateClip.ClearCurves();
            }
        }
 private void SetClipProperties()
 {
     input.legacy = false;
     input.ClearCurves();
     for (var i = 0; i < clipPaths.Length; i++)
     {
         input.SetCurve(clipPaths[i], clipTypes[i], clipProperties[i], clipCurves[i]);
     }
     input.legacy = isLegacy;
 }
Beispiel #13
0
    // Start is called before the first frame update
    void Start()
    {
        AnimationClip testClip = new AnimationClip();

        if (testClip.isLooping)
        {
            print("WARNING: CLIP SET TO LOOP");
        }
        testClip.ClearCurves();
    }
Beispiel #14
0
        public void ClearAnimation()
        {
            //string clipFile = animationAssetPath;
            //animationClip = AssetDatabase.LoadAssetAtPath<AnimationClip>(clipFile);

            /*if (animationClip != null)
             * {*/
            animationClip.ClearCurves();
            animationClip.frameRate = 1;
            AssetDatabase.SaveAssets();
            //}
        }
    // Use this for initialization
    void Start()
    {
        anim = new AnimationClip();
        anim.ClearCurves();
        AnimationCurve curve = AnimationCurve.Linear(0.0F, transform.position.x, 2.0F, transform.position.x + 1);

        anim.SetCurve("", typeof(Transform), "localPosition.x", curve);
        anim.name = "Hit";
        GetComponent <Animation>().clip = anim;
        GetComponent <Animator>().Play("Note_Hit_Animation");
        //GetComponent<Animation>().Play("Sheep_Hit");
    }
 public void SaveToClip(AnimationClip newClip)
 {
     newClip.ClearCurves();
     foreach (var data in AnimationUtility.GetAllCurves(Clip))
     {
         AnimationUtility.SetEditorCurve(newClip,
                                         data.path,
                                         data.type,
                                         data.propertyName,
                                         data.curve);
     }
 }
Beispiel #17
0
    static void RemoveScaleAndPosition()
    {
        if (null == Selection.activeObject)
        {
            return;
        }
        // AnimationClipを持つFBXのパス
        string fbxPath = AssetDatabase.GetAssetPath(Selection.activeObject);

        Debug.Log(fbxPath);
        // AnimationClipの取得
        Object[]             animations = AssetDatabase.LoadAllAssetsAtPath(fbxPath);
        List <AnimationClip> cs         = new List <AnimationClip> ();

        foreach (object c in animations)
        {
            if (c is AnimationClip)
            {
                cs.Add(c  as AnimationClip);
            }
        }
        int    idx      = fbxPath.LastIndexOf("/");
        string rootPath = fbxPath.Substring(0, idx + 1);

        foreach (AnimationClip _c in cs)
        {
            if (_c.name.Contains("__preview__") == false)
            {
                AnimationClip UpClip = Object.Instantiate(_c);
                Dictionary <EditorCurveBinding, AnimationCurve> bcMap = new Dictionary <EditorCurveBinding, AnimationCurve> ();
                List <EditorCurveBinding> newBinds = new List <EditorCurveBinding> ();
                EditorCurveBinding[]      binds    = AnimationUtility.GetCurveBindings(UpClip);
                foreach (EditorCurveBinding b in binds)
                {
                    if (b.propertyName.Contains("m_LocalPosition") || b.propertyName.Contains("m_LocalScale"))
                    {
                        continue;
                    }

                    newBinds.Add(b);
                    AnimationCurve __clip = AnimationUtility.GetEditorCurve(UpClip, b);
                    bcMap [b] = __clip;
                }

                UpClip.ClearCurves();
                foreach (EditorCurveBinding b in newBinds)
                {
                    AnimationUtility.SetEditorCurve(UpClip, b, bcMap [b]);
                }
                AssetDatabase.CreateAsset(UpClip, rootPath + _c.name + ".anim");
            }
        }
    }
Beispiel #18
0
    static void FirstCommand()
    {
        if (Selection.activeGameObject.GetComponent <Animation> () != null)
        {
            Debug.Log("Deleting animation curves!!");

            Animation     anim     = Selection.activeGameObject.GetComponent <Animation> ();
            AnimationClip animClip = anim.clip;

            animClip.ClearCurves();
        }
    }
 public static void CopyAnimationClip(AnimationClip _src, AnimationClip _dstClip)
 {
     AnimationUtility.SetAnimationEvents(_dstClip, _src.events);
     _dstClip.frameRate   = _src.frameRate;
     _dstClip.wrapMode    = _src.wrapMode;
     _dstClip.legacy      = _src.legacy;
     _dstClip.localBounds = _src.localBounds;
     _dstClip.ClearCurves();
     foreach (var curveBinding in AnimationUtility.GetCurveBindings(_src))
     {
         _dstClip.SetCurve(curveBinding.path, curveBinding.type, curveBinding.propertyName, AnimationUtility.GetEditorCurve(_src, curveBinding));
     }
 }
Beispiel #20
0
    //TODO
    public void StartRecording()
    {
        if (m_clip != null)
        {
            SteamVR_Controller.Input(Input.GetButtonDown("Button1") ? 1 : 2).TriggerHapticPulse(1000);
            m_recording = true;

            //previewAnimator.SetTrigger("StopPreview");
            controlBoard_RecordControl.RequestControlBoardFocus();
            m_clip.ClearCurves();
            foreach (GameObject indicator in indicators)
            {
                indicator.SetActive(true);
            }
        }
    }
Beispiel #21
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // cube1 = newCube;
            cube1.ClearCurves();
            print("a");
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            cube1 = newCube;
            // cube1.ClearCurves();
            print("newCube");
        }
    }
Beispiel #22
0
    void OnDisable()
    {
        if (clip == null)
        {
            return;
        }

        if (m_Recorder.isRecording && crash == false)
        {
            m_Recorder.SaveToClip(clip);
        }
        else
        {
            clip.ClearCurves();
        }
    }
Beispiel #23
0
    public static int ClearCurves(IntPtr l)
    {
        int result;

        try
        {
            AnimationClip animationClip = (AnimationClip)LuaObject.checkSelf(l);
            animationClip.ClearCurves();
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Beispiel #24
0
        private static void Trim(string dir)
        {
            foreach (var animFile in Directory.GetFiles(dir, "*.anim", SearchOption.AllDirectories))
            {
                var           anim = animFile.Replace("\\", "/");
                AnimationClip clip = AssetDatabase.LoadAssetAtPath(anim, typeof(AnimationClip)) as AnimationClip;
                if (clip != null)
                {
                    if (clip.length > 0)
                    {
                        AnimationClip copiedClip = Object.Instantiate(clip);
                        copiedClip.ClearCurves();
                        int trimScale = 0;

                        foreach (var editorCurveBinding in AnimationUtility.GetCurveBindings(clip))
                        {
                            var curve = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);

                            if (editorCurveBinding.propertyName.StartsWith("m_LocalScale"))
                            {
                                trimScale++;
                            }
                            else
                            {
                                copiedClip.SetCurve(editorCurveBinding.path, editorCurveBinding.type,
                                                    editorCurveBinding.propertyName, curve);
                            }
                        }

                        if (trimScale > 0)
                        {
                            EditorLogger.Log("{0} trim scale count ={1}", anim, trimScale);
                            AssetDatabase.CreateAsset(copiedClip, anim);
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("animation clip length <= 0: {0} {1}", anim, clip.length);
                    }
                }
                else
                {
                    Debug.LogErrorFormat("Can't load animation clip: {0}", anim);
                }
            }
        }
Beispiel #25
0
    private static int ClearCurves(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            AnimationClip animationClip = (AnimationClip)ToLua.CheckObject(L, 1, typeof(AnimationClip));
            animationClip.ClearCurves();
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Beispiel #26
0
    void Start()
    {
        //Clear animation so we get a fresh one with no keyframes or curves
        animation.ClearCurves();
        material = GetComponent <Renderer>().material;

        //Create a new list of the ShaderProperties that has Keyframing enabled (So we dont uselessly write to non existent curves)
        keyframeProperties = properties.Where(x => x._UseForKeyframing).ToList();

        List <AnimationCurve> c = new List <AnimationCurve>();

        for (int i = 0; i < keyframeProperties.Count; i++)
        {
            //add animationcurve for every shaderproperty that we want to keyframe
            c.Add(new AnimationCurve());
        }
        curve = c.ToArray();
    }
        public void ApplyChanges()
        {
            animationClip.ClearCurves();

            foreach (AnimationCurveWithBinding curveWithBinding in poseCurveBindings)
            {
                animationClip.SetCurve(PoseObjectName, curveWithBinding.curveBinding.type, curveWithBinding.curveBinding.propertyName, curveWithBinding.curve);
            }

            foreach (AnimationCurveWithBinding curveWithBinding in blendshapesCurveBindings)
            {
                animationClip.SetCurve(BlendshapesObjectName, curveWithBinding.curveBinding.type, curveWithBinding.curveBinding.propertyName, curveWithBinding.curve);
            }

            AssetDatabase.SaveAssets();

            ReadAnimationClip();
        }
Beispiel #28
0
        private List <AnimationClip> ImportAnimationClips(glTF gltf, Axises invertAxis)
        {
            var animationClips = new List <AnimationClip>();

            for (var i = 0; i < gltf.animations.Count; ++i)
            {
                var clip = new AnimationClip();
                clip.ClearCurves();
                clip.legacy = true;
                clip.name   = gltf.animations[i].name;
                if (string.IsNullOrEmpty(clip.name))
                {
                    clip.name = $"legacy_{i}";
                }
                clip.wrapMode = WrapMode.Loop;

                var animation = gltf.animations[i];
                if (string.IsNullOrEmpty(animation.name))
                {
                    animation.name = $"animation:{i}";
                }

                AxisInverter inverter = default;
                switch (invertAxis)
                {
                case Axises.X:
                    inverter = AxisInverter.ReverseX;
                    break;

                case Axises.Z:
                    inverter = AxisInverter.ReverseZ;
                    break;

                default:
                    throw new System.Exception();
                }

                animationClips.Add(AnimationImporterUtil.ConvertAnimationClip(gltf, animation, inverter));
            }

            return(animationClips);
        }
Beispiel #29
0
        public static void clone(AnimationClip srcClip, AnimationClip dstClip)
        {
            dstClip.wrapMode  = srcClip.wrapMode;
            dstClip.frameRate = srcClip.frameRate;
            var srcAcs = AnimationUtility.GetAnimationClipSettings(srcClip);
            var dstAcs = AnimationUtility.GetAnimationClipSettings(dstClip);

            dstAcs.cycleOffset             = srcAcs.cycleOffset;
            dstAcs.heightFromFeet          = srcAcs.heightFromFeet;
            dstAcs.keepOriginalOrientation = srcAcs.keepOriginalOrientation;
            dstAcs.keepOriginalPositionXZ  = srcAcs.keepOriginalPositionXZ;
            dstAcs.keepOriginalPositionY   = srcAcs.keepOriginalPositionY;
            dstAcs.level                     = srcAcs.level;
            dstAcs.loopBlend                 = srcAcs.loopBlend;
            dstAcs.loopBlendOrientation      = srcAcs.loopBlendOrientation;
            dstAcs.loopBlendPositionXZ       = srcAcs.loopBlendPositionXZ;
            dstAcs.loopBlendPositionY        = srcAcs.loopBlendPositionY;
            dstAcs.loopTime                  = srcAcs.loopTime;
            dstAcs.mirror                    = srcAcs.mirror;
            dstAcs.orientationOffsetY        = srcAcs.orientationOffsetY;
            dstAcs.startTime                 = srcAcs.startTime;
            dstAcs.stopTime                  = srcAcs.stopTime;
            dstAcs.additiveReferencePoseClip = srcAcs.additiveReferencePoseClip;
            dstAcs.additiveReferencePoseTime = srcAcs.additiveReferencePoseTime;
            dstAcs.hasAdditiveReferencePose  = srcAcs.hasAdditiveReferencePose;
            AnimationUtility.SetAnimationClipSettings(dstClip, dstAcs);

            dstClip.ClearCurves();

            foreach (var i in AnimationUtility.GetCurveBindings(srcClip))
            {
                var ac = AnimationUtility.GetEditorCurve(srcClip, i);
                AnimationUtility.SetEditorCurve(dstClip, i, ac);
            }

            foreach (var i in AnimationUtility.GetObjectReferenceCurveBindings(srcClip))
            {
                var keys = AnimationUtility.GetObjectReferenceCurve(srcClip, i);
                AnimationUtility.SetObjectReferenceCurve(dstClip, i, keys);
            }
        }
        public void Modify(string path)
        {
            var clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(path);

            if (clip == null)
            {
                return;
            }
            var bindings = AnimationUtility.GetCurveBindings(clip);
            var newPaths = new string[bindings.Length];
            var findFlag = false;

            for (int i = 0; i < bindings.Length; i++)
            {
                var binding = bindings[i];
                newPaths[i] = binding.path;
                foreach (var key in replaceNamePairDictionary.Keys)
                {
                    if (newPaths[i].Contains(key))
                    {
                        newPaths[i] = newPaths[i].Replace(key, replaceNamePairDictionary[key]);
                        findFlag    = true;
                    }
                }
            }
            if (findFlag)
            {
                var newClip = new AnimationClip();
                EditorUtility.CopySerialized(clip, newClip);
                newClip.ClearCurves();
                for (int i = 0; i < bindings.Length; i++)
                {
                    var binding = bindings[i];
                    var curve   = AnimationUtility.GetEditorCurve(clip, binding);
                    newClip.SetCurve(newPaths[i], binding.type, binding.propertyName, curve);
                }
                AssetDatabase.CreateAsset(newClip, path);
            }
        }