private unsafe void BoxChanged(object sender, EventArgs e)
        {
            NumericInputBox   box = sender as NumericInputBox;
            CHRAnimationFrame kf;
            float *           pkf = (float *)&kf;
            float             val = box.Value;
            int index             = (int)box.Tag;
            int x;

            if (val != _currentFrame[index])
            {
                int kfIndex = FindKeyframe(_currentPage);

                if (float.IsNaN(val))
                {
                    //Value removed find keyframe and zero it out
                    if (kfIndex >= 0)
                    {
                        kf = (CHRAnimationFrame)listKeyframes.Items[kfIndex];
                        kf.SetBool(index, false);
                        pkf[index] = val;
                        for (x = 0; (x < 9) && float.IsNaN(pkf[x]); x++)
                        {
                            ;
                        }
                        if (x == 9)
                        {
                            listKeyframes.Items.RemoveAt(kfIndex);
                            listKeyframes.SelectedIndex = -1;
                        }
                        else
                        {
                            listKeyframes.Items[kfIndex] = kf;
                        }
                    }

                    _target.RemoveKeyframe(index, _currentPage);
                    val       = _target.GetAnimFrame(_currentPage)[index];
                    box.Value = val;
                }
                else
                {
                    if (kfIndex >= 0)
                    {
                        kf = (CHRAnimationFrame)listKeyframes.Items[kfIndex];
                        kf.SetBool(index, true);
                        pkf[index] = val;
                        listKeyframes.Items[kfIndex] = kf;
                    }
                    else
                    {
                        kf = CHRAnimationFrame.Empty;
                        kf.SetBool(index, true);
                        kf.Index   = _currentPage;
                        pkf[index] = val;

                        int count = listKeyframes.Items.Count;
                        for (x = 0; (x < count) && (((CHRAnimationFrame)listKeyframes.Items[x]).Index < _currentPage); x++)
                        {
                            ;
                        }

                        listKeyframes.Items.Insert(x, kf);
                        listKeyframes.SelectedIndex = x;
                    }

                    _target.SetKeyframe(index, _currentPage, val);
                }

                _currentFrame[index] = val;
                UpdateBox(index);
            }
        }
Beispiel #2
0
        internal unsafe void BoxChanged(object sender, EventArgs e)
        {
            if (_transformObject == null)
            {
                return;
            }

            NumericInputBox box   = sender as NumericInputBox;
            int             index = (int)box.Tag;

            if (_transformObject is MDL0BoneNode)
            {
                MDL0BoneNode bone = _transformObject as MDL0BoneNode;

                if ((_selectedAnim != null) && (_animFrame > 0))
                {
                    //Find bone anim and change transform
                    CHR0EntryNode entry = _selectedAnim.FindChild(bone.Name, false) as CHR0EntryNode;
                    if (entry == null) //Create new bone animation
                    {
                        if (!float.IsNaN(box.Value))
                        {
                            entry       = _selectedAnim.CreateEntry();
                            entry._name = bone.Name;

                            //Set initial values
                            FrameState state = bone._bindState;
                            float *    p     = (float *)&state;
                            for (int i = 0; i < 3; i++)
                            {
                                if (p[i] != 1.0f)
                                {
                                    entry.SetKeyframe(KeyFrameMode.ScaleX + i, 0, p[i]);
                                }
                            }
                            for (int i = 3; i < 9; i++)
                            {
                                if (p[i] != 0.0f)
                                {
                                    entry.SetKeyframe(KeyFrameMode.ScaleX + i, 0, p[i]);
                                }
                            }

                            entry.SetKeyframe(KeyFrameMode.ScaleX + index, _animFrame - 1, box.Value);
                        }
                    }
                    else //Set existing
                    {
                        if (float.IsNaN(box.Value))
                        {
                            entry.RemoveKeyframe(KeyFrameMode.ScaleX + index, _animFrame - 1);
                        }
                        else
                        {
                            entry.SetKeyframe(KeyFrameMode.ScaleX + index, _animFrame - 1, box.Value);
                        }
                    }
                }
                else
                {
                    //Change base transform
                    FrameState state = bone._bindState;
                    float *    p     = (float *)&state;
                    p[index] = float.IsNaN(box.Value) ? (index > 2 ? 0.0f : 1.0f) : box.Value;
                    state.CalcTransforms();
                    bone._bindState = state;
                    bone.RecalcBindState();
                    bone.SignalPropertyChange();
                }

                _targetModel.ApplyCHR(_selectedAnim, _animFrame);
                ResetBox(index);
                if (RenderStateChanged != null)
                {
                    RenderStateChanged(this, null);
                }
            }
        }