Esempio n. 1
0
        private unsafe void BoxChanged(object sender, EventArgs e)
        {
            NumericInputBox   box = sender as NumericInputBox;
            SRTAnimationFrame 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 = (SRTAnimationFrame)listKeyframes.Items[kfIndex];
                        kf.SetBool(index, false);
                        pkf[index] = val;
                        for (x = 0; (x < 5) && float.IsNaN(pkf[x]); x++)
                        {
                            ;
                        }
                        if (x == 5)
                        {
                            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 = (SRTAnimationFrame)listKeyframes.Items[kfIndex];
                        kf.SetBool(index, true);
                        pkf[index] = val;
                        listKeyframes.Items[kfIndex] = kf;
                    }
                    else
                    {
                        kf       = SRTAnimationFrame.Empty;
                        kf.Index = _currentPage;
                        kf.SetBool(index, true);
                        pkf[index] = val;

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

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

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

                _currentFrame[index] = val;
                UpdateBox(index);
            }
        }
Esempio n. 2
0
        internal unsafe void BoxChanged(object sender, EventArgs e)
        {
            if (TargetTexRef == null || sender == null)
            {
                return;
            }

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

            if (index == 2 || index == 4 || index == 5 || index == 8)
            {
                return;
            }

            MDL0MaterialRefNode mr = TargetTexRef;

            if ((SelectedAnimation != null) && (CurrentFrame > 0))
            {
                SRT0TextureNode entry = SelectedAnimation.FindChild(mr.Parent.Name + "/Texture" + mr.Index, true) as SRT0TextureNode;

                if (entry == null)
                {
                    if (!float.IsNaN(box.Value))
                    {
                        entry = SelectedAnimation.FindOrCreateEntry(mr.Parent.Name, mr.Index);

                        //Set initial values (so they aren't null)
                        FrameState state = mr._bindState; //Get the texture's bindstate
                        float *    p     = (float *)&state;
                        for (int i = 0; i < 3; i++)       //Get the scale
                        {
                            if (p[i] != 1.0f)             //Check for default values
                            {
                                entry.SetKeyframe(KeyFrameMode.ScaleX + i, 0, p[i]);
                            }
                        }
                        for (int i = 3; i < 9; i++) //Get rotation and translation respectively
                        {
                            if (p[i] != 0.0f)       //Check for default values
                            {
                                entry.SetKeyframe(KeyFrameMode.ScaleX + i, 0, p[i]);
                            }
                        }
                        if (p[10] != 0.0f)
                        {
                            entry.SetKeyframe(KeyFrameMode.ScaleX + 10, 0, p[10]);
                        }

                        //Finally, replace with the changed value
                        entry.SetKeyframe(KeyFrameMode.ScaleX + index, CurrentFrame - 1, box.Value);
                    }
                }
                else //Set to existing SRT0 texture
                if (float.IsNaN(box.Value))
                {
                    entry.RemoveKeyframe(KeyFrameMode.ScaleX + index, CurrentFrame - 1);
                }
                else
                {
                    entry.SetKeyframe(KeyFrameMode.ScaleX + index, CurrentFrame - 1, box.Value);
                }
            }
            else
            {
                //Change base transform
                FrameState state = mr._bindState;
                float *    p     = (float *)&state;
                p[index]      = float.IsNaN(box.Value) ? (index > 2 ? 0.0f : 1.0f) : box.Value;
                mr._bindState = state;
                //mr.RecalcBindState();
                mr.SignalPropertyChange();
            }
            TargetModel.ApplySRT(SelectedAnimation, CurrentFrame);
            ResetBox(index);
            _mainWindow.modelPanel1.Invalidate();
        }