Exemplo n.º 1
0
        private void UpdateTarget()
        {
            listKeyframes.BeginUpdate();
            listKeyframes.Items.Clear();
            if (_target != null)
            {
                if (_target.FrameCount > 0)
                {
                    CHRAnimationFrame a;
                    for (int x = 0; x < _target.FrameCount; x++)
                    {
                        if ((a = _target.GetAnimFrame(x)).HasKeys)
                        {
                            listKeyframes.Items.Add(a);
                        }
                    }

                    _numFrames = _target.FrameCount;

                    _currentPage       = 0;
                    numFrame.Value     = 1;
                    numFrame.Maximum   = _numFrames;
                    lblFrameCount.Text = String.Format("/ {0}", _numFrames);
                }
                else
                {
                    numFrame.Value = 1;
                }
            }
            listKeyframes.EndUpdate();

            RefreshPage();
        }
Exemplo n.º 2
0
        private void RefreshPage()
        {
            if (_target == null)
            {
            }
            else
            {
                //_currentPage = (int)numFrame.Value - 1;

                _currentFrame = _target.GetAnimFrame(_currentPage);

                numScaleX.Value = _currentFrame.Scale._x;
                numScaleY.Value = _currentFrame.Scale._y;
                numScaleZ.Value = _currentFrame.Scale._z;

                numRotX.Value = _currentFrame.Rotation._x;
                numRotY.Value = _currentFrame.Rotation._y;
                numRotZ.Value = _currentFrame.Rotation._z;

                numTransX.Value = _currentFrame.Translation._x;
                numTransY.Value = _currentFrame.Translation._y;
                numTransZ.Value = _currentFrame.Translation._z;

                for (int i = 0; i < 9; i++)
                {
                    UpdateBox(i);
                }

                btnPrev.Enabled = _currentPage > 0;
                btnNext.Enabled = _currentPage < (_numFrames - 1);

                listKeyframes.SelectedIndex = FindKeyframe(_currentPage);
            }
        }
Exemplo n.º 3
0
        private void ReloadIcons()
        {
            if (miscdata80 == null)
            {
                return;
            }
            CHR0Node chr0 = miscdata80.FindChild("AnmChr(NW4R)/MenSelmapPos_TopN__" + (MyMusic ? "1" : "0"), false) as CHR0Node;

            if (chr0 == null)
            {
                return;
            }

            icons = new Tuple <Image, RectangleF> [_numIcons + 1];

            CHR0EntryNode entry  = chr0.FindChild("MenSelmapPos_TopN", false) as CHR0EntryNode;
            Vector3       offset = entry.GetAnimFrame(_numIcons + OFFSET).Translation;

            for (int i = 1; i <= _numIcons; i++)
            {
                entry = chr0.FindChild("pos" + i.ToString("D2"), false) as CHR0EntryNode;
                CHRAnimationFrame frame = entry.GetAnimFrame(_numIcons + OFFSET, true);
                float             x     = (BRAWLWIDTH / 2 + frame.Translation._x + offset._x) / BRAWLWIDTH;
                float             y     = (BRAWLHEIGHT / 2 - frame.Translation._y - offset._y) / BRAWLHEIGHT;
                float             w     = 6.4f * (frame.Scale._x) / BRAWLWIDTH;
                float             h     = 5.6f * (frame.Scale._y) / BRAWLHEIGHT;
                RectangleF        r     = new RectangleF(x, y, w, h);

                TextureContainer tc = new TextureContainer(miscdata80,
                                                           IconOrder != null && i <= IconOrder.Length ? IconOrder[i - 1] : 100);
                if (tc.icon.tex0 == null)
                {
                    continue;
                }
                Image image = tc.icon.tex0.GetImage(0);

                icons[i] = new Tuple <Image, RectangleF>(image, r);
            }

            var nexttex0 = miscdata80.FindChild("Textures(NW4R)/MenSelmapIcon_Change.1", false) as TEX0Node;

            if (nexttex0 != null)
            {
                float NEXTOFFSET = 10.8f;
                entry = chr0.FindChild("pos" + (_numIcons + 1).ToString("D2"), false) as CHR0EntryNode;
                CHRAnimationFrame frame2 = entry.GetAnimFrame(_numIcons + OFFSET, true);
                float             x2     = (BRAWLWIDTH / 2 + frame2.Translation._x - NEXTOFFSET) / BRAWLWIDTH;
                float             y2     = (BRAWLHEIGHT / 2 - frame2.Translation._y) / BRAWLHEIGHT;
                float             w2     = 14.4f * (frame2.Scale._x) / BRAWLWIDTH;
                float             h2     = 4.8f * (frame2.Scale._y) / BRAWLHEIGHT;
                RectangleF        r2     = new RectangleF(x2, y2, w2, h2);
                Image             image2 = nexttex0.GetImage(0);
                icons[0] = new Tuple <Image, RectangleF>(image2, r2);                //pos00 is not used anyway, so let's overwrite it
            }

            this.Invalidate();
        }
Exemplo n.º 4
0
        private void UpdateTarget()
        {
            listKeyframes.BeginUpdate();
            listKeyframes.Items.Clear();
            if (_target != null)
            {
                if (_target.FrameCount > 0)
                {
                    AnimationFrame a;
                    bool           check = false;
                    for (int x = 0; x < _target.FrameCount; x++) //Loop thru each frame
                    {
                        a       = _target.GetAnimFrame(x);       //Get the frame to check
                        a.Index = x;
                        a.ResetBools();
                        for (int i = 0x10; i < 0x19; i++)                        //Loop thru trans, rotate and scale
                        {
                            if (_target.GetKeyframe((KeyFrameMode)i, x) != null) //Check for a keyframe
                            {
                                check = true;                                    //Keyframe found
                                a.SetBools(i);                                   //Make sure the anim frame displays this
                            }
                        }
                        if (check == true)
                        {   //Only add the frame if it has a keyframe
                            a.forKeyframeCHR = true;
                            listKeyframes.Items.Add(a);
                            check = false; //Reset the check for the loop
                        }
                    }
                    //foreach (AnimationKeyframe f in _target.Keyframes.Keyframes)
                    //    listKeyframes.Items.Add(f);

                    _numFrames = _target.FrameCount;

                    _currentPage       = 0;
                    numFrame.Value     = 1;
                    numFrame.Maximum   = _numFrames;
                    lblFrameCount.Text = String.Format("/ {0}", _numFrames);
                }
                else
                {
                    numFrame.Value = 1;
                }
            }
            listKeyframes.EndUpdate();

            RefreshPage();
        }
Exemplo n.º 5
0
        private static AnimCurve GenerateCurve(uint AnimOffset, CHR0EntryNode entry)
        {
            AnimCurve curve = new AnimCurve();

            curve.AnimDataOffset = AnimOffset;
            curve.StartFrame     = 0;
            curve.Offset         = 0;
            curve.Scale          = 1;
            curve.FrameType      = AnimCurveFrameType.Single;
            curve.KeyType        = AnimCurveKeyType.Single;
            curve.CurveType      = AnimCurveType.Linear;

            List <float> Frames = new List <float>();
            List <float> Keys   = new List <float>();

            CHRAnimationFrame ain, aout;

            for (int frame = 0; frame < entry.FrameCount; frame++)
            {
                //Max of 4 values.  Cubic using 4, linear using 2, and step using 1
                float[] KeyValues = new float[4];

                //Set the main values to the curve based on offset for encoding later
                if ((ain = entry.GetAnimFrame(frame)).HasKeys)
                {
                    aout = entry.GetAnimFrame(frame, true);
                    FillKeyList(aout, frame, curve.AnimDataOffset, Frames, Keys);

                    if (!ain.Equals(aout))
                    {
                        FillKeyList(aout, frame, curve.AnimDataOffset, Frames, Keys);
                    }
                }
            }

            if (Frames.Count <= 0)
            {
                return(null);
            }

            //   Console.WriteLine($"AnimOffset {AnimOffset} Keys {Keys.Count}");

            //Max value in frames is our end frame
            curve.EndFrame = Frames.Max();
            curve.Frames   = Frames.ToArray();

            //If a curve only has one frame we don't need to interpolate or add keys to a curve as it's constant
            if (curve.Frames.Length <= 1)
            {
                return(null);
            }

            switch (curve.CurveType)
            {
            case AnimCurveType.Cubic:
                curve.Keys = new float[Keys.Count, 4];
                for (int frame = 0; frame < Keys.Count; frame++)
                {
                    float Delta = 0;

                    if (frame < Keys.Count - 1)
                    {
                        Delta = Keys[frame + 1] - Keys[frame];
                    }

                    float value  = Keys[frame];
                    float Slope  = 0;
                    float Slope2 = 0;

                    curve.Keys[frame, 0] = value;
                    curve.Keys[frame, 1] = Slope;
                    curve.Keys[frame, 2] = Slope2;
                    curve.Keys[frame, 3] = Delta;
                }
                break;

            case AnimCurveType.StepInt:
                //Step requires no interpolation
                curve.Keys = new float[Keys.Count, 1];
                for (int frame = 0; frame < Keys.Count; frame++)
                {
                    curve.Keys[frame, 0] = Keys[frame];
                }
                break;

            case AnimCurveType.Linear:
                curve.Keys = new float[Keys.Count, 2];
                for (int frame = 0; frame < Keys.Count; frame++)
                {
                    //Delta for second value used in linear curves
                    float time  = curve.Frames[frame];
                    float Delta = 0;

                    if (frame < Keys.Count - 1)
                    {
                        Delta = Keys[frame + 1] - Keys[frame];
                    }

                    curve.Keys[frame, 0] = Keys[frame];
                    curve.Keys[frame, 1] = Delta;
                }
                break;
            }

            QuantizeCurveData(curve);

            return(curve);
        }
Exemplo n.º 6
0
        private static BoneAnim Chr0Entry2BoneAnim(CHR0EntryNode entry)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = entry.Name;
            //   boneAnim.Name = NameConverterMkWii2Mk8(boneAnim.Name);

            if (entry.UseModelTranslate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
            }
            if (entry.UseModelRotate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
            }
            if (entry.UseModelScale)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
            }

            var baseData = new BoneAnimData();

            var FirstFrame = entry.GetAnimFrame(0);

            if (FirstFrame.HasKeys)
            {
                float xRadian = FirstFrame.Rotation._x * Deg2Rad;
                float yRadian = FirstFrame.Rotation._y * Deg2Rad;
                float zRadian = FirstFrame.Rotation._z * Deg2Rad;

                baseData.Translate = new Vector3F(FirstFrame.Translation._x, FirstFrame.Translation._y, FirstFrame.Translation._z);
                baseData.Rotate    = new Vector4F(xRadian, yRadian, zRadian, 1);
                baseData.Scale     = new Vector3F(FirstFrame.Scale._x, FirstFrame.Scale._y, FirstFrame.Scale._z);
                baseData.Flags     = 0;
                boneAnim.BaseData  = baseData;
            }
            else
            {
                baseData.Translate = new Vector3F(0, 0, 0);
                baseData.Rotate    = new Vector4F(0, 0, 0, 1);
                baseData.Scale     = new Vector3F(1, 1, 1);
                baseData.Flags     = 0;
                boneAnim.BaseData  = baseData;
            }


            boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
            boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
            boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;

            if (baseData.Rotate == new Vector4F(0, 0, 0, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.RotateZero;
            }
            if (baseData.Translate == new Vector3F(0, 0, 0))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.TranslateZero;
            }
            if (baseData.Scale == new Vector3F(1, 1, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleOne;
            }
            if (IsUniform(baseData.Scale))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleUniform;
            }
            if (!IsRoot(boneAnim))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.SegmentScaleCompensate;
            }

            boneAnim.BeginTranslate = 6;
            boneAnim.BeginRotate    = 3;

            if (FirstFrame.HasKeys)
            {
                var AnimFrame = entry.GetAnimFrame(0);
                if (AnimFrame.hasTx)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                    var curve = GenerateCurve(0x10, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasTy)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                    var curve = GenerateCurve(0x14, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasTz)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                    var curve = GenerateCurve(0x18, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasRx)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                    var curve = GenerateCurve(0x20, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasRy)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                    var curve = GenerateCurve(0x24, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasRz)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                    var curve = GenerateCurve(0x28, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasSx)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                    var curve = GenerateCurve(0x4, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasSy)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                    var curve = GenerateCurve(0x8, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasSz)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                    var curve = GenerateCurve(0xC, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
            }

            return(boneAnim);
        }