示例#1
0
        void generateRandomMotion(ref Random rnd, out MotionVelocity velocity, out MotionData motion, bool allowInfiniteMass)
        {
            motion = new MotionData
            {
                WorldFromMotion = generateRandomTransform(ref rnd),
                BodyFromMotion  = generateRandomTransform(ref rnd)
            };

            float3 inertia = rnd.NextFloat3(1e-3f, 100.0f);

            switch (rnd.NextInt(3))
            {
            case 0:     // all values random
                break;

            case 1:     // two values the same
                int index = rnd.NextInt(3);
                inertia[(index + 1) % 2] = inertia[index];
                break;

            case 2:     // all values the same
                inertia = inertia.zzz;
                break;
            }

            velocity = new MotionVelocity
            {
                LinearVelocity        = rnd.NextBool() ? float3.zero : rnd.NextFloat3(-50.0f, 50.0f),
                AngularVelocity       = rnd.NextBool() ? float3.zero : rnd.NextFloat3(-50.0f, 50.0f),
                InverseInertiaAndMass = (allowInfiniteMass && rnd.NextBool()) ? float4.zero : new float4(1.0f / inertia, rnd.NextFloat(1e-3f, 100.0f))
            };
        }
示例#2
0
    void Start()
    {
        currentMotionFrameData = new MotionFrameData();
        motionOwner            = this.transform;
        currentComputeTime     = motionMatcherSettings.ComputeMotionsBestCostGap;
        motionDebugDataList    = new List <MotionDebugData>();

        //HumanoidCrouchIdle 动画有问题,只能通过这种方式临时处理一下
        for (int i = 0; i < motionsData.motionDataList.Length; i++)
        {
            MotionData motionData = motionsData.motionDataList[i];
            if (motionData.motionName.Contains("HumanoidCrouchIdle"))
            {
                for (int j = 0; j < motionData.motionFrameDataList.Length; j++)
                {
                    MotionFrameData motionFrameData = motionData.motionFrameDataList[j];
                    for (int k = 0; k < motionFrameData.motionTrajectoryDataList.Length; k++)
                    {
                        MotionTrajectoryData motionTrajectoryData = motionFrameData.motionTrajectoryDataList[k];
                        motionTrajectoryData.localPosition = Vector3.zero;
                    }
                }
            }
        }
    }
示例#3
0
    public void gunMotionCtrl(MotionData mtData)
    {
        float xRange = 40f;                     //x軸向可動範圍
        float yRange = 35f;                     //y軸向可動範圍
        //加速度x軸參數正規化,並提高1.5倍靈敏度,調整區間限制於±xRange中
        float rotateX = rotateAvg(rotateXAvg, Mathf.Clamp(-(mtData.x / 1024f) * xRange * 1.5f, -xRange, xRange));

        /*if((rotateX - gunRotateOld.x) / gunRotateOld.x < rotateDeviation)	//誤差過小則不做動(防止靜止時晃動)
         *      rotateX = gunRotateOld.x;*/
        //計算遊戲中武器的左右轉動角度,正規化於yRange之間,提高range倍靈敏度,限制於±30度
        float rotateY = rotateAvg(rotateYAvg, Mathf.Clamp((mtData.angle / 180f) * yRange * range, -yRange, yRange));

        /*if((rotateY - gunRotateOld.y) / gunRotateOld.y < rotateDeviation / 2f)	//誤差過小則不做動(防止靜止時晃動)
         *      rotateY = gunRotateOld.y;*/
        //將算完的結果存起來,用做判斷下次誤差
        //gunRotateOld.Set(rotateX, rotateY, 0);

        //使武器轉動滑順
        gun.transform.localEulerAngles = new Vector3(
            Mathf.LerpAngle(gun.transform.localEulerAngles.x, rotateX, Time.deltaTime * lerpSpeed),
            Mathf.LerpAngle(gun.transform.localEulerAngles.y, rotateY, Time.deltaTime * lerpSpeed),
            0);
        //準星位置對應,準星可動範圍定為800*400(Canva為1920*1080)
        gunRay.position = new Vector3(
            Mathf.Lerp(gunRay.position.x, Mathf.Clamp((mtData.angle / 180f) * 800f * range, -800, 800), Time.deltaTime * lerpSpeed),
            Mathf.Lerp(gunRay.position.y, -(rotateX / xRange) * 400, Time.deltaTime * lerpSpeed),
            0);
        sight.GetComponent <RectTransform>().localPosition = gunRay.position;

        if (oldState != mtData.gunSt)
        {
            gunStateChangedEvt(this, mtData.gunSt);             //觸發事件,送出槍目前狀態
            oldState = mtData.gunSt;
        }
    }
示例#4
0
        //
        // Tiny simulation for a single body pair and joint, used by all of the tests
        //

        void applyGravity(ref MotionVelocity velocity, ref MotionData motion, float3 gravity, float timestep)
        {
            if (velocity.InverseMass > 0.0f)
            {
                velocity.LinearVelocity += gravity * timestep;
            }
        }
    public void ExportTest(MotionData data)
    {
        Lines = GenerateLines(data);
        string InputData  = Destination + "/" + "TestInput.txt";
        string OutputData = Destination + "/" + "TestOutput.txt";

        if (!File.Exists(InputData))
        {
            using (FileStream fs = File.Create(InputData)) { }
            Debug.Log("Create new file: " + InputData);
            File.AppendAllLines(InputData, Lines);
        }
        else
        {
            File.AppendAllLines(InputData, Lines);
        }

        if (!File.Exists(OutputData))
        {
            using (FileStream fs = File.Create(OutputData)) { }
            Debug.Log("Create new file: " + OutputData);
            File.AppendAllLines(OutputData, Lines);
        }
        else
        {
            File.AppendAllLines(OutputData, Lines);
        }

        Debug.Log("Export Test MotionData: " + data.GetName() + "Successfully!");
    }
        public override void Update(MotionData data)
        {
            base.Update(data);

            if (start != null && 
                start.Length() != 0.0f &&
                end != null &&
                end.Length() != 0.0f)
            {
                Vector3 lpDataN, startN, endN;
                Vector3.Normalize(ref lpData, out lpDataN);
                Vector3.Normalize(ref start, out startN);
                Vector3.Normalize(ref end, out endN);

                float total = Vector3.Dot(startN, endN);
                float fromStart = Vector3.Dot(startN, lpDataN);
                float fromEnd = Vector3.Dot(endN, lpDataN);

                float aTotal = (float)Math.Acos((double)total);
                float aFromStart = (float)Math.Acos((double)fromStart) / aTotal;
                float aFromEnd = (float)Math.Acos((double)fromEnd) / aTotal;

                Value = MathHelper.Clamp((aFromStart + (1.0f - aFromEnd)) / 2.0f, 0.0f, 1.0f);

                if (IsOutputEnabled && Output != null)
                {
                    Output.Trigger(Value);
                }

                if (ValueChanged != null)
                {
                    ValueChanged(this, Value);
                }
            }
        }
示例#7
0
    private MotionFrameData AcquireBakedMotionFrameData(string motionName, float normalizedTime, MotionMainEntryType motionMainEntryType)
    {
        MotionFrameData motionFrameData = null;

        for (int i = 0; i < motionsData.motionDataList.Length; i++)
        {
            MotionData motionData = motionsData.motionDataList[i];
            if (motionMainEntryType != MotionMainEntryType.none)
            {
                if (motionData.motionName.IndexOf(motionMatcherSettings.StandTag) >= 0 &&
                    motionMainEntryType == MotionMainEntryType.stand)
                {
                    motionFrameData = motionData.motionFrameDataList[0];
                    break;
                }
                if (motionData.motionName.IndexOf(motionMatcherSettings.CrouchTag) >= 0 &&
                    motionMainEntryType == MotionMainEntryType.crouch)
                {
                    motionFrameData = motionData.motionFrameDataList[0];
                    break;
                }
            }
            else if (motionData.motionName == motionName)
            {
                int frame = Mathf.FloorToInt(motionData.motionFrameDataList.Length * normalizedTime);
                motionFrameData = motionData.motionFrameDataList[frame];
            }
        }
        return(motionFrameData);
    }
 public override Module Initialise(MotionData data)
 {
     Data  = data;
     Bones = new bool[data.Source.Bones.Length];
     Compute();
     return(this);
 }
示例#9
0
 public Sequence(MotionData data)
 {
     Data             = data;
     TransitionCopies = new int[data.Styles.Length];
     StyleCopies      = new int[data.Styles.Length];
     Copies           = new Interval[0];
 }
示例#10
0
    public static MotionData LoadData(string filename)
    {
        if (!File.Exists(filename))
        {
            return(null);
        }

        MotionData data = new MotionData();

        using (BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open)))
        {
            data.framesPerSecond = reader.ReadInt32();
            int count = reader.ReadInt32();

            data.positions = new List <Vector3>(count);
            data.rotations = new List <Quaternion>(count);
            for (int i = 0; i < count; i++)
            {
                data.positions.Add(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
                data.rotations.Add(new Quaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
            }
        }

        return(data);
    }
        public override void Update(MotionData data)
        {
            base.Update(data);

            if (DateTime.UtcNow - lastMovement > TimeSpan.FromMilliseconds(MAX_REPEAT * Repeat))
            {
                float dx = Math.Abs(hpData.X);
                float dy = Math.Abs(hpData.Y);
                float dz = Math.Abs(hpData.Z);

                if (dx > Sensitivity || dy > Sensitivity || dz > Sensitivity)
                {
                    lastMovement = DateTime.UtcNow;

                    if (IsOutputEnabled && Output != null)
                    {
                        Output.Trigger();
                    }

                    if (MovementOccurred != null)
                    {
                        MovementOccurred(this);
                    }
                }
            }
        }
示例#12
0
 public Module Initialize(MotionData data)
 {
     Data = data;
     ResetPrecomputation();
     DerivedInitialize();
     return(this);
 }
示例#13
0
    public MotionData LoadData(string guid)
    {
        if (guid != null && Data != null && Data.GetName() == Utility.GetAssetName(guid))
        {
            return(Data);
        }
        MotionData data = GetAsset(guid);

        if (Data != data)
        {
            //Unload Previous
            UnloadData();

            //Character
            if (Model == null && Actor != null)
            {
                Utility.Destroy(Actor.gameObject);
            }

            //Load Next
            Data = data;
            if (Data != null)
            {
                Data.Load(this);
                LoadFrame(0f);
            }

            //Assign Index
            AssetIndex = FindIndex(Assets, Utility.GetAssetGUID(Data));
        }
        return(Data);
    }
 public void LoadData(MotionData data)
 {
     if (Data != data)
     {
         if (Data != null)
         {
             if (Save)
             {
                 Data.Save();
             }
             Data.Unload();
         }
         if (Character == null && Actor != null)
         {
             Utility.Destroy(Actor.gameObject);
         }
         Data = data;
         if (Data != null)
         {
             Data.Load();
             LoadBoneMapping();
             LoadFrame(0f);
         }
     }
 }
示例#15
0
        BvhWriter2(string filename, MotionData motion)
        {
            this.filename = filename;
            this.motion = motion;

            writer = new StreamWriter(filename, false, Encoding.ASCII);
        }
示例#16
0
 protected override void DerivedCallback(MotionEditor editor)
 {
     if (BallInstance == null)
     {
         BallInstance = editor.GetActor().FindTransform(Data.Source.Bones[Ball].Name);
     }
     if (BallInstance != null)
     {
         Matrix4x4 m = ShowSource ? editor.GetCurrentFrame().GetSourceTransformation(Ball, editor.Mirror) : editor.GetCurrentFrame().GetBoneTransformation(Ball, editor.Mirror);
         BallInstance.transform.position = m.GetPosition();
         BallInstance.transform.rotation = m.GetRotation();
     }
     if (GetRival() != null)
     {
         float      t     = editor.GetCurrentFrame().Timestamp;
         MotionData asset = GetRivalAsset(t);
         if (asset == null)
         {
             asset = Data;
         }
         int[] bones = MotionEditor.GetInstance().GetBoneMapping();
         for (int i = 0; i < GetRival().Bones.Length; i++)
         {
             Matrix4x4 m = asset.GetFrame(t).GetBoneTransformation(bones[i], editor.Mirror);
             GetRival().Bones[i].Transform.position = m.GetPosition();
             GetRival().Bones[i].Transform.rotation = m.GetRotation();
         }
     }
 }
示例#17
0
    public override Module Init(MotionData data)
    {
        Data   = data;
        Bones  = new bool[Data.Root.Bones.Length];
        Record = Data.Mirrored;


        Phases[0] = new LocalPhaseFunction("Head", new int[2] {
            4, 5
        }, this);
        if (Data.Mirrored)
        {
            Phases[1] = new LocalPhaseFunction("Left Hand", new int[5] {
                7, 8, 9, 10, 11
            }, this);
            Phases[2] = new LocalPhaseFunction("Right Hand", new int[5] {
                12, 13, 14, 15, 16
            }, this);
        }
        else
        {
            Phases[1] = new LocalPhaseFunction("Left Hand", new int[5] {
                12, 13, 14, 15, 16
            }, this);
            Phases[2] = new LocalPhaseFunction("Right Hand", new int[5] {
                7, 8, 9, 10, 11
            }, this);
        }

        Compute();

        return(this);
    }
示例#18
0
 public static void Write(string filename, MotionData motion)
 {
     using (var writer = new BvhWriter2(filename, motion))
     {
         writer.Write();
     }
 }
示例#19
0
 protected void NotifyData(MotionData data)
 {
     foreach (var observer in _motionDataObservers)
     {
         observer.OnNext(data);
     }
 }
示例#20
0
 public Frame(MotionData data, int index, float timestamp)
 {
     Data      = data;
     Index     = index;
     Timestamp = timestamp;
     World     = new Matrix4x4[Data.Root.Bones.Length];
 }
示例#21
0
    public override Module Initialise(MotionData data)
    {
        Data    = data;
        Inspect = true;

        return(this);
    }
示例#22
0
    public IEnumerator Import(System.Action callback)
    {
        Importing = true;

        string[] folders = GetFolders();
        if (folders.Length == 0)
        {
            Assets = new string[0];
        }
        else
        {
            string[] candidates = AssetDatabase.FindAssets("t:MotionData", folders);
            TotalFiles = candidates.Length;
            if (!LoadExportable || !LoadUnexportable)
            {
                List <string> assets = new List <string>();
                for (int i = 0; i < candidates.Length; i++)
                {
                    if (!Importing)
                    {
                        break;
                    }
                    CurrentFile += 1;
                    MotionData asset = (MotionData)AssetDatabase.LoadMainAssetAtPath(Utility.GetAssetPath(candidates[i]));
                    if ((LoadExportable && asset.Export) || (LoadUnexportable && !asset.Export))
                    {
                        if (!LoadTagged || LoadTagged && asset.Tagged)
                        {
                            assets.Add(candidates[i]);
                        }
                    }
                    if (i % 10 == 0)
                    {
                        Resources.UnloadUnusedAssets();
                    }
                    Progress = (float)(i + 1) / candidates.Length;
                    yield return(new WaitForSeconds(0f));
                }
                if (Importing)
                {
                    Assets = assets.ToArray();
                }
            }
            else
            {
                Assets = candidates;
            }
        }
        if (Importing)
        {
            LoadData(null);
            callback();
        }

        CurrentFile = 0;
        TotalFiles  = 0;
        Progress    = 0f;
        Importing   = false;
    }
示例#23
0
 public override Module Initialise(MotionData data)
 {
     Data       = data;
     Inspect    = true;
     Transition = 0.5f;
     Functions  = new StyleFunction[0];
     return(this);
 }
示例#24
0
 public void Setup(MotionData data)
 {
     Transformations = new Matrix4x4[data.Frames.Length];
     for (int i = 0; i < Transformations.Length; i++)
     {
         Transformations[i] = Matrix4x4.identity;
     }
 }
示例#25
0
 public Frame(MotionData data, int index, float timestamp, Matrix4x4[] matrices)
 {
     Data            = data;
     Index           = index;
     Timestamp       = timestamp;
     World           = (Matrix4x4[])matrices.Clone();
     Transformations = (Matrix4x4[])matrices.Clone();
 }
示例#26
0
        public static MotionTable ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((MotionTable)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader   datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                MotionTable m         = new MotionTable();
                m.Id = datReader.ReadUInt32();

                m.DefaultStyle = datReader.ReadUInt32();

                uint numStyleDefaults = datReader.ReadUInt32();
                for (uint i = 0; i < numStyleDefaults; i++)
                {
                    m.StyleDefaults.Add(datReader.ReadUInt32(), datReader.ReadUInt32());
                }

                uint numCycles = datReader.ReadUInt32();
                for (uint i = 0; i < numCycles; i++)
                {
                    uint       key = datReader.ReadUInt32();
                    MotionData md  = MotionData.Read(datReader);
                    m.Cycles.Add(key, md);
                }

                uint numModifiers = datReader.ReadUInt32();
                for (uint i = 0; i < numModifiers; i++)
                {
                    uint       key = datReader.ReadUInt32();
                    MotionData md  = MotionData.Read(datReader);
                    m.Modifiers.Add(key, md);
                }

                uint numLinks = datReader.ReadUInt32();
                for (uint i = 0; i < numLinks; i++)
                {
                    uint firstKey    = datReader.ReadUInt32();
                    uint numSubLinks = datReader.ReadUInt32();
                    Dictionary <uint, MotionData> links = new Dictionary <uint, MotionData>();
                    for (uint j = 0; j < numSubLinks; j++)
                    {
                        uint       subKey = datReader.ReadUInt32();
                        MotionData md     = MotionData.Read(datReader);
                        links.Add(subKey, md);
                    }
                    m.Links.Add(firstKey, links);
                }

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = m;

                return(m);
            }
        }
 public override Module Initialise(MotionData data)
 {
     Data                  = data;
     Functions             = new StyleFunction[0];
     Keys                  = new bool[data.GetTotalFrames()];
     Keys[0]               = true;
     Keys[Keys.Length - 1] = true;
     return(this);
 }
示例#28
0
 public override Module Initialise(MotionData data)
 {
     Data    = data;
     Inspect = true;
     RegularPhaseFunction = new PhaseFunction(this);
     InversePhaseFunction = new PhaseFunction(this);
     Variables            = new bool[Data.Source.Bones.Length];
     return(this);
 }
 public void UnloadFile()
 {
     Data      = null;
     Playing   = false;
     PlayTime  = 0f;
     Timestamp = Utility.GetTimestamp();
     Timescale = 1f;
     CheckSkeleton();
 }
示例#30
0
 public Sequence(MotionData data, int start, int end)
 {
     Data             = data;
     TransitionCopies = new int[data.Styles.Length];
     StyleCopies      = new int[data.Styles.Length];
     Copies           = new Interval[0];
     SetStart(start);
     SetEnd(end);
 }
示例#31
0
 public Sequence(MotionData data)
 {
     Data             = data;
     TransitionCopies = new int[data.Styles.Length];
     StyleCopies      = new int[data.Styles.Length];
     Copies           = new Interval[0];
     SetStart(1);
     SetEnd(data.GetTotalFrames());
 }
示例#32
0
        public static BVHNode ToBVHData(Bone node, MotionData motionData, out BVHMotionData bvhMotionData)
        {
            Dictionary <BVHNode, List <Quaternion> > data = new Dictionary <BVHNode, List <Quaternion> >();
            var resultNode = ToBVHNode(node, motionData.Data, null, data);

            bvhMotionData = new BVHMotionData(1.0 / motionData.FPS, data);

            return(resultNode);
        }
示例#33
0
        private PmdBone m_pNeckBone;            // 首のボーン


        private void getMotionPosRot(MotionData pMotionData, float fFrame, MmdVector3 pvec3Pos, MmdVector4 pvec4Rot)
        {
            int i;
            int ulNumKeyFrame = pMotionData.ulNumKeyFrames;

            // 最終フレームを過ぎていた場合
            if (fFrame > pMotionData.pKeyFrames[ulNumKeyFrame - 1].fFrameNo)
            {
                fFrame = pMotionData.pKeyFrames[ulNumKeyFrame - 1].fFrameNo;
            }

            // 現在の時間がどのキー近辺にあるか
            for (i = 0; i < ulNumKeyFrame; i++)
            {
                if (fFrame <= pMotionData.pKeyFrames[i].fFrameNo)
                {
                    break;
                }
            }

            // 前後のキーを設定
            int lKey0,
                lKey1;

            lKey0 = i - 1;
            lKey1 = i;

            if (lKey0 <= 0)
            {
                lKey0 = 0;
            }
            if (i == ulNumKeyFrame)
            {
                lKey1 = ulNumKeyFrame - 1;
            }

            // 前後のキーの時間
            float fTime0 = pMotionData.pKeyFrames[lKey0].fFrameNo;
            float fTime1 = pMotionData.pKeyFrames[lKey1].fFrameNo;

            // 前後のキーの間でどの位置にいるか
            float fLerpValue;

            if (lKey0 != lKey1)
            {
                fLerpValue = (fFrame - fTime0) / (fTime1 - fTime0);
                pvec3Pos.Vector3Lerp(pMotionData.pKeyFrames[lKey0].vec3Position, pMotionData.pKeyFrames[lKey1].vec3Position, fLerpValue);
                pvec4Rot.QuaternionSlerp(pMotionData.pKeyFrames[lKey0].vec4Rotate, pMotionData.pKeyFrames[lKey1].vec4Rotate, fLerpValue);
                pvec4Rot.QuaternionNormalize(pvec4Rot);//これほんとにいるの?
            }
            else
            {
                pvec3Pos.setValue(pMotionData.pKeyFrames[lKey0].vec3Position);
                pvec4Rot.setValue(pMotionData.pKeyFrames[lKey0].vec4Rotate);
            }
        }
 public override Module Initialise(MotionData data)
 {
     Data       = data;
     Ground     = LayerMask.GetMask("Ground");
     LeftHip    = data.Source.FindBone("LeftHip").Index;
     LeftAnkle  = data.Source.FindBone("LeftAnkle").Index;
     RightHip   = data.Source.FindBone("RightHip").Index;
     RightAnkle = data.Source.FindBone("RightAnkle").Index;
     return(this);
 }
示例#35
0
 public void OperationSpan2()
 {
     var buffer = EditorUtil.CreateBuffer("foo", "  bar");
     var data = new MotionData(
         new SnapshotSpan(buffer.GetLine(1).Start.Add(1), 1),
         true,
         MotionKind.Exclusive,
         OperationKind.CharacterWise,
         FSharpOption<int>.None);
     Assert.AreEqual(new SnapshotSpan(buffer.GetLine(1).Start.Add(1), 1), data.OperationSpan);
 }
示例#36
0
 public void ColumnOrFirstPoint1()
 {
     var buffer = EditorUtil.CreateBuffer("foo","bar");
     var data = new MotionData(
         buffer.GetLine(0).Extent,
         true,
         MotionKind.Inclusive,
         OperationKind.LineWise,
         FSharpOption<int>.None);
     Assert.AreEqual(0, data.ColumnOrFirstPoint.Position);
 }
示例#37
0
 public void ColumnOrFirstPoint2()
 {
     var buffer = EditorUtil.CreateBuffer("foo","bar");
     var data = new MotionData(
         buffer.GetLine(0).Extent,
         false,
         MotionKind.Inclusive,
         OperationKind.LineWise,
         FSharpOption<SnapshotPoint>.None);
     Assert.AreEqual(buffer.GetLine(0).End, data.ColumnOrFirstPoint);
 }
        public virtual void Update(MotionData data)
        {
            this.rawData = data.Data;

            lpData.X = rawData.X * LP_ALPHA + (lpData.X * (1.0f - LP_ALPHA));
            lpData.Y = rawData.Y * LP_ALPHA + (lpData.Y * (1.0f - LP_ALPHA));
            lpData.Z = rawData.Z * LP_ALPHA + (lpData.Z * (1.0f - LP_ALPHA));

            hpData.X = rawData.X - lpData.X;
            hpData.Y = rawData.Y - lpData.Y;
            hpData.Z = rawData.Z - lpData.Z;
        }
        public override void Update(MotionData data)
        {
            base.Update(data);

            if (start != null && 
                start.Length() != 0.0f &&
                quarter != null &&
                quarter.Length() != 0.0f &&
                end != null &&
                end.Length() != 0.0f)
            {
                Vector3 lpDataN, startN, quarterN, endN;
                Vector3.Normalize(ref lpData, out lpDataN);
                Vector3.Normalize(ref start, out startN);
                Vector3.Normalize(ref quarter, out quarterN);
                Vector3.Normalize(ref end, out endN);

                float total = Vector3.Dot(startN, endN);
                float fromStart = Vector3.Dot(lpDataN, startN);
                float fromEnd = Vector3.Dot(lpDataN, endN);

                float aTotal = (float)Math.Acos((double)total);
                float aFromStart = (float)Math.Acos((double)fromStart) / aTotal;
                float aFromEnd = (float)Math.Acos((double)fromEnd) / aTotal;

                float v = MathHelper.Clamp((aFromStart + (1.0f - aFromEnd)) / 2.0f, 0.0f, 1.0f);
                
                Vector3 vn = Vector3.Cross(start, quarter);
                Vector3 v3 = Vector3.Cross(vn, lpData);
                float sign = Vector3.Dot(v3, start);

                if (sign <= 0.0f)
                {
                    Value = v / 2.0f;
                }
                else
                {
                    Value = 1.0f - (v / 2.0f);
                }

                if (IsOutputEnabled && Output != null)
                {
                    Output.Trigger(Value);
                }

                if (ValueChanged != null)
                {
                    ValueChanged(this, Value);
                }
            }
        }
        public override void Update(MotionData data)
        {
            base.Update(data);

            if (up != null && down != null)
            {
                Vector3 lpDataN, upN, downN;
                Vector3.Normalize(ref lpData, out lpDataN);
                Vector3.Normalize(ref up, out upN);
                Vector3.Normalize(ref down, out downN);

                float total = Vector3.Dot(upN, downN);
                float fromUp = Vector3.Dot(upN, lpDataN);
                float fromDown = Vector3.Dot(downN, lpDataN);

                float aTotal = (float)Math.Acos((double)total);
                float aFromUp = (float)Math.Acos((double)fromUp) / aTotal;
                float aFromDown = (float)Math.Acos((double)fromDown) / aTotal;

                float position = MathHelper.Clamp((aFromUp + (1.0f - aFromDown)) / 2.0f, 0.0f, 1.0f);

                if (!pressed && position > (1.0f - Sensitivity))
                {
                    pressed = true;

                    if (IsOutputEnabled && OutputOne != null)
                    {
                        OutputOne.Trigger();
                    }
                    
                    if (PedalButtonPressed != null)
                    {
                        PedalButtonPressed(this);
                    }
                }
                else if (pressed && position <= Sensitivity)
                {                  
                    pressed = false;

                    if (IsOutputEnabled && OutputTwo != null)
                    {
                        OutputTwo.Trigger();
                    }

                    if (PedalButtonReleased != null)
                    {
                        PedalButtonReleased(this);
                    }
                }
            }
        }
示例#41
0
 public void AssertData(
     MotionData data,
     SnapshotSpan? span,
     MotionKind motionKind = null,
     OperationKind operationKind = null)
 {
     if (span.HasValue)
     {
         Assert.AreEqual(span.Value, data.Span);
     }
     if (motionKind != null)
     {
         Assert.AreEqual(motionKind, data.MotionKind);
     }
     if (operationKind != null)
     {
         Assert.AreEqual(operationKind, data.OperationKind);
     }
 }
        void Apply(EditMode mode, ApplyOffsetForm f, bool previewOnly, ref Action reset)
        {
            var offset = new
            {
                f.Position,
                f.IsPositionLocal,
                Rotation = MathHelper.ToRadians(f.Rotation),
                f.IsRotationLocal,
                Quaternion = Quaternion.RotationYawPitchRoll(MathHelper.ToRadians(f.Rotation.Y), MathHelper.ToRadians(f.Rotation.X), MathHelper.ToRadians(f.Rotation.Z)),
                f.Weight,
                f.Distance,
                f.Color,
            };

            if (reset != null)
            {
                reset();
                reset = null;
            }

            switch (mode)
            {
                case EditMode.AccessoryMode:
                    var acc = this.Scene.ActiveAccessory;

                    if (acc != null)
                    {
                        var rotationOffset = new Lazy<Quaternion>(() => GetLocalRotation(offset.IsRotationLocal, null, offset.Rotation, offset.Quaternion));

                        foreach (var i in acc.SelectedLayers)
                        {
                            var local = i.CurrentLocalMotion;
                            var newLocal = new MotionData(local.Move, offset.IsRotationLocal ? Quaternion.Multiply(local.Rotation, offset.Quaternion) : Quaternion.Multiply(offset.Quaternion, local.Rotation));

                            newLocal.Move += GetLocalPosition(offset.IsPositionLocal, null, offset.Position, newLocal.Rotation);

                            reset += () => i.CurrentLocalMotion = local;
                            i.CurrentLocalMotion = newLocal;
                        }

                        if (!previewOnly)
                            foreach (var i in acc.Layers.SelectMany(_ => _.SelectedFrames))
                            {
                                var resetPosition = i.Position;
                                var resetQuaternion = i.Quaternion;

                                reset += () =>
                                {
                                    i.Position = resetPosition;
                                    i.Quaternion = resetQuaternion;
                                };
                                i.Quaternion = offset.IsRotationLocal ? Quaternion.Multiply(i.Quaternion, offset.Quaternion) : Quaternion.Multiply(offset.Quaternion, i.Quaternion);
                                i.Position += GetLocalPosition(offset.IsPositionLocal, null, offset.Position, i.Quaternion);
                            }
                    }

                    break;
                case EditMode.None:
                case EditMode.CameraMode:
                    foreach (var camera in this.Scene.Cameras.Where(_ => _.Layers.SelectMany(__ => __.SelectedFrames).Any()).DefaultIfEmpty(this.Scene.ActiveCamera).Where(_ => _ != null))
                    {
                        var local = camera.CurrentMotion;
                        var newLocal = new CameraMotionData(local.Position, local.Angle + offset.Rotation, local.Radius + offset.Distance, local.Fov);

                        newLocal.Position += GetLocalCameraPosition(offset.IsPositionLocal, offset.Position, newLocal.Angle);

                        reset += () => camera.CurrentMotion = local;
                        camera.CurrentMotion = newLocal;

                        if (!previewOnly)
                            foreach (var i in camera.Layers.SelectMany(_ => _.SelectedFrames))
                            {
                                var resetPosition = i.Position;
                                var resetAngle = i.Angle;
                                var resetRadius = i.Radius;

                                reset += () =>
                                {
                                    i.Position = resetPosition;
                                    i.Angle = resetAngle;
                                    i.Radius = resetRadius;
                                };
                                i.Angle += offset.Rotation;
                                i.Radius += offset.Distance;
                                i.Position += GetLocalCameraPosition(offset.IsPositionLocal, offset.Position, i.Angle);
                            }
                    }

                    foreach (var light in this.Scene.Lights.Where(_ => _.SelectedFrames.Any()).DefaultIfEmpty(this.Scene.ActiveLight).Where(_ => _ != null))
                    {
                        var local = light.CurrentMotion;

                        reset += () => light.CurrentMotion = local;
                        light.CurrentMotion = new LightMotionData(local.Position + offset.Position, local.Color + offset.Color);

                        if (!previewOnly)
                            foreach (var i in light.SelectedFrames)
                            {
                                var resetPosition = i.Position;
                                var resetColor = i.Color;

                                reset += () =>
                                {
                                    i.Position = resetPosition;
                                    i.Color = resetColor;
                                };
                                i.Position += offset.Position;
                                i.Color += offset.Color;
                            }
                    }

                    break;
                case EditMode.CaptionMode:
                    foreach (var i in this.Scene.SelectedCaptions)
                    {
                        var resetLocation = i.Location;

                        reset += () => i.Location = resetLocation;
                        i.Location += offset.Position;
                    }

                    break;
                case EditMode.EffectMode:
                    var eff = this.Scene.ActiveEffect;

                    if (eff != null)
                    {
                        var local = eff.CurrentMotion;
                        var newLocal = new MotionData(local.Move, offset.IsRotationLocal ? Quaternion.Multiply(local.Rotation, offset.Quaternion) : Quaternion.Multiply(offset.Quaternion, local.Rotation));

                        newLocal.Move += GetLocalPosition(offset.IsPositionLocal, null, offset.Position, newLocal.Rotation);

                        reset += () => eff.CurrentMotion = local;
                        eff.CurrentMotion = newLocal;

                        if (!previewOnly)
                            foreach (var i in eff.SelectedFrames)
                            {
                                var resetPosition = i.Position;
                                var resetQuaternion = i.Quaternion;

                                reset += () =>
                                {
                                    i.Position = resetPosition;
                                    i.Quaternion = resetQuaternion;
                                };
                                i.Quaternion = offset.IsRotationLocal ? Quaternion.Multiply(i.Quaternion, offset.Quaternion) : Quaternion.Multiply(offset.Quaternion, i.Quaternion);
                                i.Position += GetLocalPosition(offset.IsPositionLocal, null, offset.Position, i.Quaternion);
                            }
                    }

                    break;
                case EditMode.ModelMode:
                    var model = this.Scene.ActiveModel;

                    if (model != null)
                    {
                        foreach (var bone in model.Bones)
                        {
                            var rotationOffset = new Lazy<Quaternion>(() => GetLocalRotation(offset.IsRotationLocal, bone, offset.Rotation, offset.Quaternion));

                            foreach (var i in bone.SelectedLayers)
                            {
                                var local = i.CurrentLocalMotion;
                                var newLocal = new MotionData(local.Move, (bone.BoneFlags & BoneType.Rotate) != 0
                                    ? offset.IsRotationLocal ? Quaternion.Multiply(local.Rotation, rotationOffset.Value) : Quaternion.Multiply(rotationOffset.Value, local.Rotation)
                                    : local.Rotation);

                                if ((bone.BoneFlags & BoneType.XYZ) != 0)
                                    newLocal.Move += GetLocalPosition(offset.IsPositionLocal, bone, offset.Position, newLocal.Rotation);

                                reset += () => i.CurrentLocalMotion = local;
                                i.CurrentLocalMotion = newLocal;
                            }

                            if (!previewOnly)
                                foreach (var i in bone.Layers.SelectMany(_ => _.SelectedFrames))
                                {
                                    var resetPosition = i.Position;
                                    var resetQuaternion = i.Quaternion;

                                    reset += () =>
                                    {
                                        i.Position = resetPosition;
                                        i.Quaternion = resetQuaternion;
                                    };

                                    i.Quaternion = offset.IsRotationLocal ? Quaternion.Multiply(i.Quaternion, rotationOffset.Value) : Quaternion.Multiply(rotationOffset.Value, i.Quaternion);
                                    i.Position += GetLocalPosition(offset.IsPositionLocal, bone, offset.Position, i.Quaternion);
                                }
                        }

                        foreach (var morph in model.Morphs)
                        {
                            if (morph.Selected)
                            {
                                var local = morph.CurrentWeight;

                                reset += () => morph.CurrentWeight = local;
                                morph.CurrentWeight += offset.Weight;
                            }

                            if (!previewOnly)
                                foreach (var i in morph.SelectedFrames)
                                {
                                    var resetWeight = i.Weight;

                                    reset += () => i.Weight = resetWeight;
                                    i.Weight += offset.Weight;
                                }
                        }
                    }

                    break;
            }
        }
示例#43
0
 public void Edit_c_1()
 {
     Create("foo bar");
     var motionData = new MotionData(
         _view.TextBuffer.GetSpan(0, 4),
         true,
         MotionKind.Exclusive,
         OperationKind.CharacterWise,
         FSharpOption<int>.None);
     _operations
         .Setup(x => x.ChangeSpan(motionData))
         .Returns(motionData.OperationSpan)
         .Verifiable();
     _operations
         .Setup(x => x.UpdateRegisterForSpan(_unnamedRegister, RegisterOperation.Delete, motionData.OperationSpan, OperationKind.CharacterWise))
         .Verifiable();
     var res = _mode.Process("cw");
     Assert.IsTrue(res.IsSwitchMode);
     Assert.AreEqual(ModeKind.Insert, res.AsSwitchMode().Item);
     _operations.Verify();
 }
示例#44
0
 public void Edit_c_2()
 {
     Create("foo bar");
     var reg = _map.GetRegister('c');
     var motionData = new MotionData(
         _view.TextBuffer.GetSpan(0, 4),
         true,
         MotionKind.Exclusive,
         OperationKind.CharacterWise,
         FSharpOption<int>.None);
     _operations
         .Setup(x => x.ChangeSpan(motionData, reg))
         .Verifiable();
     var res = _mode.Process("\"ccw");
     Assert.IsTrue(res.IsSwitchMode);
     Assert.AreEqual(ModeKind.Insert, res.AsSwitchMode().Item);
     _operations.Verify();
 }
示例#45
0
 public void MoveCaretToMotionData7()
 {
     Create("foo", "bar", "");
     _editorOpts.Setup(x => x.ResetSelection());
     var data = new MotionData(
         new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length),
         true,
         MotionKind.Inclusive,
         OperationKind.LineWise,
         FSharpOption<int>.None);
     _operations.MoveCaretToMotionData(data);
     Assert.AreEqual(2, _view.GetCaretPoint().GetContainingLine().LineNumber);
 }
示例#46
0
 public void MoveCaretToMotionData10()
 {
     Create("foo", "bar", "");
     _editorOpts.Setup(x => x.ResetSelection());
     var data = new MotionData(
         _buffer.GetLineSpan(0, 1),
         true,
         MotionKind.Inclusive,
         OperationKind.LineWise,
         FSharpOption.Create(0));
     _operations.MoveCaretToMotionData(data);
     Assert.AreEqual(Tuple.Create(1, 0), SnapshotPointUtil.GetLineColumn(_view.GetCaretPoint()));
 }
示例#47
0
 public void MoveCaretToMotionData12()
 {
     Create("dog", "cat", "bear");
     _editorOpts.Setup(x => x.ResetSelection());
     var data = new MotionData(
         _buffer.GetLineSpan(0, 1),
         false,
         MotionKind.Inclusive,
         OperationKind.CharacterWise,
         FSharpOption.Create(2));
     _operations.MoveCaretToMotionData(data);
     Assert.AreEqual(Tuple.Create(0, 2), SnapshotPointUtil.GetLineColumn(_view.GetCaretPoint()));
 }
示例#48
0
 public void MoveCaretToMotionData15()
 {
     Create("dog", "cat", "bear");
     _editorOpts.Setup(x => x.ResetSelection());
     var data = new MotionData(
         _buffer.GetSpan(1, _buffer.GetLine(1).EndIncludingLineBreak.Position),
         true,
         MotionKind.Exclusive,
         OperationKind.CharacterWise,
         FSharpOption.Create(0));
     _operations.MoveCaretToMotionData(data);
     Assert.AreEqual(_buffer.GetLine(2).Start, _view.GetCaretPoint());
 }
示例#49
0
 public void ChangeSpan1()
 {
     Create("foo  bar");
     var data = new MotionData(
         _buffer.GetSpan(0, 5),
         true,
         MotionKind.Inclusive,
         OperationKind.CharacterWise,
         FSharpOption<int>.None);
     _operations.ChangeSpan(data, new Register('c'));
     Assert.AreEqual("  bar", _buffer.GetLineSpan(0).GetText());
 }
        public override void Update(MotionData data)
        {
            base.Update(data);

            if (start != null &&
                start.Length() != 0.0f &&
                quarter != null &&
                quarter.Length() != 0.0f &&
                end != null &&
                end.Length() != 0.0f)
            {
                Vector3 lpDataN, startN, quarterN, endN;
                Vector3.Normalize(ref lpData, out lpDataN);
                Vector3.Normalize(ref start, out startN);
                Vector3.Normalize(ref quarter, out quarterN);
                Vector3.Normalize(ref end, out endN);

                float total = Vector3.Dot(startN, endN);
                float fromStart = Vector3.Dot(lpDataN, startN);
                float fromEnd = Vector3.Dot(lpDataN, endN);

                float aTotal = (float)Math.Acos((double)total);
                float aFromStart = (float)Math.Acos((double)fromStart) / aTotal;
                float aFromEnd = (float)Math.Acos((double)fromEnd) / aTotal;

                float v = MathHelper.Clamp((aFromStart + (1.0f - aFromEnd)) / 2.0f, 0.0f, 1.0f);

                Vector3 vn = Vector3.Cross(start, quarter);
                Vector3 v3 = Vector3.Cross(vn, lpData);
                float sign = Vector3.Dot(v3, start);

                float value = 0.0f;
                if (sign <= 0.0f)
                {
                    value = v / 2.0f;
                }
                else
                {
                    value = 1.0f - (v / 2.0f);
                }

                float incrementF = 1.0f / (float)Increments;
                int position = (int)(value / incrementF);
                int diff = Math.Abs(position - last);

                if (diff != 0)
                {
                    if ((position > last && diff == 1) || (position < last && diff > 1))
                    {
                        if (RotaryEncoderAntiClockwise != null)
                        {
                            RotaryEncoderAntiClockwise(this);
                        }

                        if (IsOutputEnabled && OutputTwo != null)
                        {
                            OutputTwo.Trigger();
                        }
                    }
                    else if((position < last && diff == 1) || (position > last && diff > 1))
                    {
                        if (RotaryEncoderClockwise != null)
                        {
                            RotaryEncoderClockwise(this);
                        }

                        if (IsOutputEnabled && OutputOne != null)
                        {
                            OutputOne.Trigger();
                        }
                    }

                    last = position;
                }
            }
        }
示例#51
0
 public void MoveCaretToMotionData6()
 {
     Create("foo", "bar", "baz");
     _editorOpts.Setup(x => x.ResetSelection());
     var data = new MotionData(
         new SnapshotSpan(_buffer.CurrentSnapshot, 0, 1),
         true,
         MotionKind.Exclusive,
         OperationKind.CharacterWise,
         FSharpOption<int>.None);
     _operations.MoveCaretToMotionData(data);
     Assert.AreEqual(1, _view.GetCaretPoint().Position);
 }
示例#52
0
 void Start()
 {
     ankleVelocityMotionData = new MotionData(motionDataSize);
 }
        public override void Update(MotionData data)
        {
            
            /*************************************************************************
            Principal components analysis

            Subroutine  builds  orthogonal  basis  where  first  axis  corresponds  to
            direction with maximum variance, second axis maximizes variance in subspace
            orthogonal to first axis and so on.

            It should be noted that, unlike LDA, PCA does not use class labels.

            INPUT PARAMETERS:
            X           -   dataset, array[0..NPoints-1,0..NVars-1].
                            matrix contains ONLY INDEPENDENT VARIABLES.
            NPoints     -   dataset size, NPoints>=0
            NVars       -   number of independent variables, NVars>=1

            ÂÛÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ:
            Info        -   return code:
                            * -4, if SVD subroutine haven't converged
                            * -1, if wrong parameters has been passed (NPoints<0,
                                    NVars<1)
                            *  1, if task is solved
            S2          -   array[0..NVars-1]. variance values corresponding
                            to basis vectors.
            V           -   array[0..NVars-1,0..NVars-1]
                            matrix, whose columns store basis vectors.

            -- ALGLIB --
                Copyright 25.08.2008 by Bochkanov Sergey
            *************************************************************************/

            base.Update(data);

            if (recording)
            {
                pcaData[count, 0] = rawData.X;
                pcaData[count, 1] = rawData.Y;
                pcaData[count, 2] = rawData.Z;
                count++;

                if (count >= PCA_SAMPLES)
                {
                    double mx = 0;
                    double my = 0;
                    double mz = 0;
                    for (int i = 0; i < PCA_SAMPLES; i++)
                    {
                        mx += (pcaData[i, 0] / (double)PCA_SAMPLES);
                        my += (pcaData[i, 1] / (double)PCA_SAMPLES);
                        mz += (pcaData[i, 2] / (double)PCA_SAMPLES);
                    }

                    for (int i = 0; i < PCA_SAMPLES; i++)
                    {
                        pcaData[i, 0] -= mx;
                        pcaData[i, 0] -= my;
                        pcaData[i, 0] -= mz;
                    }

                    int info;
                    double[] s2;
                    double[,] v;
                    alglib.pcabuildbasis(pcaData, PCA_SAMPLES, 3, out info, out s2, out v);

                    if (info == 1)
                    {
                        direction.X = (float)v[0, 0];
                        direction.Y = (float)v[1, 0];
                        direction.Z = (float)v[2, 0];
                        trained = true;

                        Console.WriteLine("PCA Result: " + direction.X + ", " + direction.Y + ", " + direction.Z);
                    }

                    recording = false;
                }
            }
            else if(trained)
            {
                float projection = Vector3.Dot(hpData, direction);
              
                if (projection > Sensitivity)
                {
                    DateTime now = DateTime.UtcNow;
                    TimeSpan elapsed = now - lastEvent;
                    if (elapsed > TimeSpan.FromMilliseconds(RepeatTime))
                    {
                        if (PushButtonPressed != null)
                        {
                            PushButtonPressed(this);
                        }

                        if (IsOutputEnabled && Output != null)
                        {
                            Output.Trigger();
                        }

                        lastEvent = now;

                        Console.WriteLine("Button pressed: " + data.Id + " " + projection);
                    }
                }
            }
        }
示例#54
0
 public static void UpdateMotionData()
 {
     try{
         motionData = Motion.GetData(0);
     }catch(Exception){}
 }
示例#55
0
    // Use this for initialization
    void Start()
    {
        if (GameObject.Find("Bike Camera"))
        {
            bikeCamera = GameObject.Find("Bike Camera");
            Debug.Log("Camera found");
        }

        motionData = new MotionData (motionDataSize);
    }
        void Apply(EditMode mode, ApplyRotationForm f, bool previewOnly, ref Action reset)
        {
            var rotate = !f.IsMoveOnly;
            var quaternion = Quaternion.RotationYawPitchRoll(MathHelper.ToRadians(f.Rotation.Y), MathHelper.ToRadians(f.Rotation.X), MathHelper.ToRadians(f.Rotation.Z));
            var offset = Matrix.Translation(-f.Position) *
                         Matrix.RotationQuaternion(quaternion) *
                         Matrix.Translation(f.Position);

            if (reset != null)
            {
                reset();
                reset = null;
            }

            switch (mode)
            {
                case EditMode.AccessoryMode:
                    var acc = this.Scene.ActiveAccessory;

                    if (acc != null)
                    {
                        foreach (var i in acc.SelectedLayers)
                        {
                            var local = i.CurrentLocalMotion;
                            var newLocal = new MotionData
                            (
                                Vector3.TransformCoordinate(local.Move, offset),
                                rotate ? Quaternion.Multiply(quaternion, local.Rotation) : local.Rotation
                            );

                            reset += () => i.CurrentLocalMotion = local;
                            i.CurrentLocalMotion = newLocal;
                        }

                        if (!previewOnly)
                            foreach (var i in acc.Layers.SelectMany(_ => _.SelectedFrames))
                            {
                                var resetPosition = i.Position;
                                var resetQuaternion = i.Quaternion;

                                reset += () =>
                                {
                                    i.Position = resetPosition;
                                    i.Quaternion = resetQuaternion;
                                };

                                if (rotate)
                                    i.Quaternion = Quaternion.Multiply(quaternion, i.Quaternion);

                                i.Position = Vector3.TransformCoordinate(i.Position, offset);
                            }
                    }

                    break;
                case EditMode.EffectMode:
                    var eff = this.Scene.ActiveEffect;

                    if (eff != null)
                    {
                        var local = eff.CurrentMotion;
                        var newLocal = new MotionData
                        (
                            Vector3.TransformCoordinate(local.Move, offset),
                            rotate ? Quaternion.Multiply(quaternion, local.Rotation) : local.Rotation
                        );

                        reset += () => eff.CurrentMotion = local;
                        eff.CurrentMotion = newLocal;

                        if (!previewOnly)
                            foreach (var i in eff.SelectedFrames)
                            {
                                var resetPosition = i.Position;
                                var resetQuaternion = i.Quaternion;

                                reset += () =>
                                {
                                    i.Position = resetPosition;
                                    i.Quaternion = resetQuaternion;
                                };

                                if (rotate)
                                    i.Quaternion = Quaternion.Multiply(quaternion, i.Quaternion);

                                i.Position = Vector3.TransformCoordinate(i.Position, offset);
                            }
                    }

                    break;
                case EditMode.ModelMode:
                    var model = this.Scene.ActiveModel;

                    if (model != null)
                        foreach (var bone in model.Bones)
                        {
                            var initialPosition = Matrix.Translation(bone.InitialPosition);

                            if (bone.ParentBoneID != -1)
                                initialPosition *= GetMotion(model.Bones, bone);

                            var offsetWithInitialPosition = initialPosition * offset * Matrix.Invert(initialPosition);
                            Vector3 scale;
                            Quaternion rotation;
                            Vector3 translation;

                            offsetWithInitialPosition.Decompose(out scale, out rotation, out translation);

                            foreach (var i in bone.SelectedLayers)
                            {
                                var local = i.CurrentLocalMotion;
                                var newLocal = new MotionData
                                (
                                    (bone.BoneFlags & BoneType.XYZ) != 0 ? Vector3.TransformCoordinate(local.Move, offsetWithInitialPosition) : local.Move,
                                    (bone.BoneFlags & BoneType.Rotate) != 0 && rotate ? Quaternion.Multiply(rotation, local.Rotation) : local.Rotation
                                );

                                reset += () => i.CurrentLocalMotion = local;
                                i.CurrentLocalMotion = newLocal;
                            }

                            if (!previewOnly)
                                foreach (var i in bone.Layers.SelectMany(_ => _.SelectedFrames))
                                {
                                    var resetPosition = i.Position;
                                    var resetQuaternion = i.Quaternion;

                                    reset += () =>
                                    {
                                        i.Position = resetPosition;
                                        i.Quaternion = resetQuaternion;
                                    };

                                    if (rotate)
                                        i.Quaternion = Quaternion.Multiply(quaternion, i.Quaternion);

                                    i.Position = Vector3.TransformCoordinate(i.Position, offsetWithInitialPosition);
                                }
                        }

                    break;
            }
        }