static void ProcessTree(ObjectTreeNode parent, ArchiveFileInfo file, string[] paths, int index)
        {
            string currentPath = paths[index];

            if (paths.Length - 1 == index)
            {
                var    fileNode = new ObjectTreeNode(currentPath);
                string ext      = Utils.GetExtension(currentPath);
                if (FileImageKeys.Lookup.ContainsKey(ext))
                {
                    fileNode.ImageKey = FileImageKeys.Lookup[ext];
                }
                else
                {
                    fileNode.ImageKey = "File";
                }
                fileNode.Type = ext;
                fileNode.Size = STMath.GetFileSize(file.GetFileSize());
                fileNode.Tag  = file;

                parent.AddChild(fileNode);
                return;
            }

            var node = FindFolderNode(parent, currentPath);

            if (node == null)
            {
                node          = new ObjectTreeNode(currentPath);
                node.ImageKey = "Folder";
                parent.AddChild(node);
            }

            ProcessTree(node, file, paths, index + 1);
        }
        public void SetupSettings(GTXImporterSettings setting)
        {
            if (setting.Format == GX2.GX2SurfaceFormat.INVALID || SelectedIndex == -1)
            {
                return;
            }

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is GX2.GX2SurfaceFormat)
            {
                setting.Format = (GX2.GX2SurfaceFormat)formatComboBox.SelectedItem;

                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString();
            }
            HeightLabel.Text = $"Height: {setting.TexHeight}";
            WidthLabel.Text  = $"Width: {setting.TexWidth}";

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            pictureBox1.Image = bitmap;

            Thread = new Thread((ThreadStart)(() =>
            {
                setting.IsFinishedCompressing = false;
                ToggleOkButton(false);

                var mips = setting.GenerateMipList();
                setting.DataBlockOutput.Clear();
                setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);

                setting.Compress();

                bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting.
                                                   TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format(
                                                       (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]);

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }
        public void SetupSettings()
        {
            if (SelectedIndex == -1)
            {
                return;
            }

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is CTR_3DS.PICASurfaceFormat)
            {
                SelectedTexSettings.Format = (CTR_3DS.PICASurfaceFormat)formatComboBox.SelectedItem;
                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = SelectedTexSettings.Format.ToString();
            }

            HeightLabel.Text = $"Height: {SelectedTexSettings.TexHeight}";
            WidthLabel.Text  = $"Width: {SelectedTexSettings.TexWidth}";

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            pictureBox1.Image = bitmap;

            Thread = new Thread((ThreadStart)(() =>
            {
                SelectedTexSettings.IsFinishedCompressing = false;
                ToggleOkButton(false);

                var mips = SelectedTexSettings.GenerateMipList();

                SelectedTexSettings.DataBlockOutput.Clear();
                SelectedTexSettings.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);
                SelectedTexSettings.IsFinishedCompressing = true;

                bitmap = CTR_3DS.DecodeBlockToBitmap(mips[0], (int)SelectedTexSettings.TexWidth, (int)SelectedTexSettings.TexHeight, SelectedTexSettings.Format);
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }
Пример #4
0
        public static void Save(STSkeletonAnimation anim, String Fname)
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            STSkeleton Skeleton = anim.GetActiveSkeleton();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname))
            {
                file.WriteLine("version 1");

                file.WriteLine("nodes");
                foreach (STBone b in Skeleton.bones)
                {
                    file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex);
                }
                file.WriteLine("end");

                file.WriteLine("skeleton");
                anim.SetFrame(0);
                for (int i = 0; i <= anim.FrameCount; i++)
                {
                    anim.SetFrame(i);
                    anim.NextFrame();

                    file.WriteLine($"time {i}");

                    foreach (var sb in anim.AnimGroups)
                    {
                        STBone b = Skeleton.GetBone(sb.Name);
                        if (b == null)
                        {
                            continue;
                        }
                        Vector3 eul       = STMath.ToEulerAngles(b.rot);
                        Vector3 scale     = b.GetScale();
                        Vector3 translate = b.GetPosition();

                        file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}");
                    }
                }
                file.WriteLine("end");

                file.Close();
            }
        }
Пример #5
0
        public static void Save(Animation anim, STSkeleton Skeleton, String Fname)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname))
            {
                file.WriteLine("version 1");

                file.WriteLine("nodes");
                foreach (STBone b in Skeleton.bones)
                {
                    file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex);
                }
                file.WriteLine("end");

                file.WriteLine("skeleton");
                anim.SetFrame(0);
                for (int i = 0; i <= anim.FrameCount; i++)
                {
                    anim.NextFrame(Skeleton, false, true);

                    file.WriteLine($"time {i}");

                    foreach (Animation.KeyNode sb in anim.Bones)
                    {
                        STBone b = Skeleton.GetBone(sb.Text);
                        if (b == null)
                        {
                            continue;
                        }
                        Vector3 eul       = STMath.ToEulerAngles(b.rot);
                        Vector3 scale     = b.GetScale();
                        Vector3 translate = b.GetPosition();

                        file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}");
                    }
                }
                file.WriteLine("end");

                file.Close();
            }
        }
Пример #6
0
        private void AttachJoint(PartsModel partInfo, IRenderableFile actorRender)
        {
            var modelPart = actorRender.Renderer.Models[0];

            foreach (ModelAsset model in ModelFile.Renderer.Models)
            {
                var bone = model.ModelData.Skeleton.SearchBone(partInfo.JointName);

                if (bone != null)
                {
                    //Setup local transform
                    var localPosition = new OpenTK.Vector3(
                        partInfo.LocalTranslate.X,
                        partInfo.LocalTranslate.Y,
                        partInfo.LocalTranslate.Z);
                    var localRotation = STMath.FromEulerAngles(new OpenTK.Vector3(
                                                                   partInfo.LocalRotate.X,
                                                                   partInfo.LocalRotate.Y,
                                                                   partInfo.LocalRotate.Z) * STMath.Deg2Rad);
                    var localScale = new OpenTK.Vector3(
                        partInfo.LocalScale.X,
                        partInfo.LocalScale.Y,
                        partInfo.LocalScale.Z);

                    modelPart.ModelData.Skeleton.LocalTransform =
                        OpenTK.Matrix4.CreateScale(localScale) *
                        OpenTK.Matrix4.CreateFromQuaternion(localRotation) *
                        OpenTK.Matrix4.CreateTranslation(localPosition);

                    //Attach bone children
                    bone.AttachSkeleton(modelPart.ModelData.Skeleton);
                    model.ModelData.Skeleton.Update();
                    break;
                }
            }
        }
Пример #7
0
        private void PlaySkeletalAnim(HSFMotionAnimation anim)
        {
            STSkeleton skeleton = Renderer.Scene.Models[0].Skeleton;

            foreach (var container in Runtime.ModelContainers)
            {
                var skel = container.SearchActiveSkeleton();
                if (skel != null)
                {
                    skeleton = skel;
                }
            }

            Console.WriteLine($"skeleton {skeleton != null}");

            if (skeleton == null)
            {
                return;
            }

            if (anim.Frame == 0)
            {
                skeleton.Reset();
            }

            bool Updated = false; // no need to update skeleton of animations that didn't change

            foreach (AnimationNode node in anim.AnimGroups)
            {
                var b = skeleton.SearchBone(node.Name);
                if (b == null)
                {
                    continue;
                }

                Updated = true;

                Vector3    position = b.Position;
                Vector3    scale    = b.Scale;
                Quaternion rotation = b.Rotation;

                if (node.TranslateX.HasKeys)
                {
                    position.X = node.TranslateX.GetFrameValue(anim.Frame) * HSF_Renderer.PreviewScale;
                }
                if (node.TranslateY.HasKeys)
                {
                    position.Y = node.TranslateY.GetFrameValue(anim.Frame) * HSF_Renderer.PreviewScale;
                }
                if (node.TranslateZ.HasKeys)
                {
                    position.Z = node.TranslateZ.GetFrameValue(anim.Frame) * HSF_Renderer.PreviewScale;
                }

                if (node.ScaleX.HasKeys)
                {
                    scale.X = node.ScaleX.GetFrameValue(anim.Frame);
                }
                if (node.ScaleY.HasKeys)
                {
                    scale.Y = node.ScaleY.GetFrameValue(anim.Frame);
                }
                if (node.ScaleZ.HasKeys)
                {
                    scale.Z = node.ScaleZ.GetFrameValue(anim.Frame);
                }

                if (node.RotationX.HasKeys || node.RotationY.HasKeys || node.RotationZ.HasKeys)
                {
                    float x = node.RotationX.HasKeys ? MathHelper.DegreesToRadians(node.RotationX.GetFrameValue(anim.Frame)) : b.EulerRotation.X;
                    float y = node.RotationY.HasKeys ? MathHelper.DegreesToRadians(node.RotationY.GetFrameValue(anim.Frame)) : b.EulerRotation.Y;
                    float z = node.RotationZ.HasKeys ? MathHelper.DegreesToRadians(node.RotationZ.GetFrameValue(anim.Frame)) : b.EulerRotation.Z;
                    rotation = STMath.FromEulerAngles(new Vector3(x, y, z));
                }

                b.AnimationController.Position = position;
                b.AnimationController.Scale    = scale;
                b.AnimationController.Rotation = rotation;
            }

            if (Updated)
            {
                skeleton.Update();
            }
        }
        public void SetupSettings(TextureImporterSettings setting)
        {
            if (setting.Format == SurfaceFormat.Invalid || SelectedIndex == -1)
            {
                return;
            }


            WidthLabel.Text  = $"Width: {setting.TexWidth}";
            HeightLabel.Text = $"Height: {setting.TexHeight}";

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is SurfaceDim)
            {
                setting.SurfaceDim = (SurfaceDim)formatComboBox.SelectedItem;
            }


            if (formatComboBox.SelectedItem is SurfaceFormat)
            {
                setting.Format = (SurfaceFormat)formatComboBox.SelectedItem;

                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString();
            }

            if (setting.Format == SurfaceFormat.BC7_UNORM ||
                setting.Format == SurfaceFormat.BC7_SRGB)
            {
                compressionModeCB.Visible = true;
                compModeLbl.Visible       = true;
            }
            else
            {
                compressionModeCB.Visible = false;
                compModeLbl.Visible       = false;
            }

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            if (compressionModeCB.SelectedIndex == 0)
            {
                CompressionMode = STCompressionMode.Fast;
            }
            else
            {
                CompressionMode = STCompressionMode.Normal;
            }

            Thread = new Thread((ThreadStart)(() =>
            {
                setting.IsFinishedCompressing = false;
                ToggleOkButton(false);

                pictureBox1.Image = bitmap;

                var mips = setting.GenerateMipList(CompressionMode);
                setting.DataBlockOutput.Clear();
                setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);
                setting.IsFinishedCompressing = true;

                if (setting.DataBlockOutput.Count > 0)
                {
                    if (setting.Format == SurfaceFormat.BC5_SNORM)
                    {
                        bitmap = DDSCompressor.DecompressBC5(mips[0],
                                                             (int)setting.TexWidth, (int)setting.TexHeight, true);
                    }
                    else
                    {
                        bitmap = STGenericTexture.DecodeBlockGetBitmap(mips[0],
                                                                       setting.TexWidth, setting.TexHeight, TextureData.ConvertFormat(setting.Format), new byte[0]);
                    }
                }

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }
Пример #9
0
        public static Animation Read(string FileName, STSkeleton skeleton)
        {
            Animation anim   = new Animation();
            var       seanim = SEAnim.Read(FileName);

            anim.FrameCount = seanim.FrameCount;
            anim.CanLoop    = seanim.Looping;

            foreach (var bone in seanim.Bones)
            {
                STBone genericBone = skeleton.GetBone(bone);
                if (genericBone != null)
                {
                    var boneAnim = new Animation.KeyNode(bone);
                    boneAnim.RotType = Animation.RotationType.EULER;
                    boneAnim.UseSegmentScaleCompensate = false;
                    anim.Bones.Add(boneAnim);

                    float PositionX = 0;
                    float PositionY = 0;
                    float PositionZ = 0;

                    float RotationX = 0;
                    float RotationY = 0;
                    float RotationZ = 0;

                    float ScaleX = 0;
                    float ScaleY = 0;
                    float ScaleZ = 0;

                    if (seanim.AnimType == AnimationType.Relative)
                    {
                        PositionX = genericBone.position[0];
                        PositionY = genericBone.position[1];
                        PositionZ = genericBone.position[2];

                        RotationX = genericBone.rotation[0];
                        RotationY = genericBone.rotation[1];
                        RotationZ = genericBone.rotation[2];

                        ScaleX = genericBone.scale[0];
                        ScaleY = genericBone.scale[1];
                        ScaleZ = genericBone.scale[2];
                    }

                    System.Console.WriteLine(bone);

                    if (seanim.AnimationPositionKeys.ContainsKey(bone))
                    {
                        var translationKeys = seanim.AnimationPositionKeys[bone];
                        foreach (SEAnimFrame animFrame in translationKeys)
                        {
                            System.Console.WriteLine(animFrame.Frame + " T " + ((SELib.Utilities.Vector3)animFrame.Data).X);
                            System.Console.WriteLine(animFrame.Frame + " T " + ((SELib.Utilities.Vector3)animFrame.Data).Y);
                            System.Console.WriteLine(animFrame.Frame + " T " + ((SELib.Utilities.Vector3)animFrame.Data).Z);

                            boneAnim.XPOS.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = (float)((SELib.Utilities.Vector3)animFrame.Data).X + PositionX,
                                Frame = animFrame.Frame,
                            });
                            boneAnim.YPOS.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Y + PositionY,
                                Frame = animFrame.Frame,
                            });
                            boneAnim.ZPOS.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Z + PositionZ,
                                Frame = animFrame.Frame,
                            });
                        }
                    }
                    if (seanim.AnimationRotationKeys.ContainsKey(bone))
                    {
                        var rotationnKeys = seanim.AnimationRotationKeys[bone];
                        foreach (SEAnimFrame animFrame in rotationnKeys)
                        {
                            var quat  = ((SELib.Utilities.Quaternion)animFrame.Data);
                            var euler = STMath.ToEulerAngles(quat.X, quat.Y, quat.Z, quat.W);

                            System.Console.WriteLine(animFrame.Frame + " R " + euler.X);
                            System.Console.WriteLine(animFrame.Frame + " R " + euler.Y);
                            System.Console.WriteLine(animFrame.Frame + " R " + euler.Z);

                            boneAnim.XROT.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = euler.X + RotationX,
                                Frame = animFrame.Frame,
                            });
                            boneAnim.YROT.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = euler.Y + RotationY,
                                Frame = animFrame.Frame,
                            });
                            boneAnim.ZROT.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = euler.Z + RotationZ,
                                Frame = animFrame.Frame,
                            });
                        }
                    }
                    if (seanim.AnimationScaleKeys.ContainsKey(bone))
                    {
                        var scaleKeys = seanim.AnimationScaleKeys[bone];
                        foreach (SEAnimFrame animFrame in scaleKeys)
                        {
                            System.Console.WriteLine(animFrame.Frame + " S " + ((SELib.Utilities.Vector3)animFrame.Data).X);
                            System.Console.WriteLine(animFrame.Frame + " S " + ((SELib.Utilities.Vector3)animFrame.Data).Y);
                            System.Console.WriteLine(animFrame.Frame + " S " + ((SELib.Utilities.Vector3)animFrame.Data).Z);

                            boneAnim.XSCA.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = (float)((SELib.Utilities.Vector3)animFrame.Data).X + ScaleX,
                                Frame = animFrame.Frame,
                            });
                            boneAnim.YSCA.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Y + ScaleY,
                                Frame = animFrame.Frame,
                            });
                            boneAnim.ZSCA.Keys.Add(new Animation.KeyFrame()
                            {
                                Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Z + ScaleZ,
                                Frame = animFrame.Frame,
                            });
                        }
                    }
                    else
                    {
                        boneAnim.XSCA.Keys.Add(new Animation.KeyFrame()
                        {
                            Value = 1,
                            Frame = 0,
                        });
                        boneAnim.YSCA.Keys.Add(new Animation.KeyFrame()
                        {
                            Value = 1,
                            Frame = 0,
                        });
                        boneAnim.ZSCA.Keys.Add(new Animation.KeyFrame()
                        {
                            Value = 1,
                            Frame = 0,
                        });
                    }
                }
            }



            return(anim);
        }
Пример #10
0
        public void SetupSettings()
        {
            if (SelectedTexSettings.Format == TEX_FORMAT.UNKNOWN || SelectedIndex == -1)
            {
                return;
            }


            WidthLabel.Text  = $"Width {SelectedTexSettings.TexWidth}";
            HeightLabel.Text = $"Height {SelectedTexSettings.TexHeight}";

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is TEX_FORMAT)
            {
                SelectedTexSettings.Format = (TEX_FORMAT)formatComboBox.SelectedItem;

                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = SelectedTexSettings.Format.ToString();
            }

            if (SelectedTexSettings.Format == TEX_FORMAT.BC7_UNORM ||
                SelectedTexSettings.Format == TEX_FORMAT.BC7_TYPELESS ||
                SelectedTexSettings.Format == TEX_FORMAT.BC7_UNORM_SRGB)
            {
                compressionModeCB.Visible = true;
            }
            else
            {
                compressionModeCB.Visible = false;
            }

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            if (compressionModeCB.SelectedIndex == 0)
            {
                CompressionMode = STCompressionMode.Fast;
            }
            else
            {
                CompressionMode = STCompressionMode.Normal;
            }

            Thread = new Thread((ThreadStart)(() =>
            {
                SelectedTexSettings.IsFinishedCompressing = false;
                ToggleOkButton(false);

                pictureBox1.Image = bitmap;

                var mips = SelectedTexSettings.GenerateMipList(CompressionMode, MultiThreading);
                SelectedTexSettings.DataBlockOutput.Clear();
                SelectedTexSettings.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);
                SelectedTexSettings.IsFinishedCompressing = true;

                if (SelectedTexSettings.DataBlockOutput.Count > 0)
                {
                    if (SelectedTexSettings.Format == TEX_FORMAT.BC5_SNORM)
                    {
                        bitmap = DDSCompressor.DecompressBC5(mips[0],
                                                             (int)SelectedTexSettings.TexWidth, (int)SelectedTexSettings.TexHeight, true);
                    }
                    else
                    {
                        bitmap = STGenericTexture.DecodeBlockGetBitmap(mips[0],
                                                                       SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight, SelectedTexSettings.Format, new byte[0]);
                    }
                }

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }
Пример #11
0
        static void ParseRotationTrack(FileReader reader, Header header, Track track, AnimationGroup group)
        {
            switch (track.OpCode)
            {
            case 0x0F:      //4 Singles Frame Count
            {
                for (int f = 0; f < header.FrameCount; f++)
                {
                    float   frame = f;
                    float[] quat  = reader.ReadSingles(4);

                    Quaternion quaternion = new Quaternion(quat[0], quat[1], quat[2], quat[3]);
                    group.RotateX.AddKey(frame, quaternion.X);
                    group.RotateY.AddKey(frame, quaternion.Y);
                    group.RotateZ.AddKey(frame, quaternion.Z);
                    group.RotateW.AddKey(frame, quaternion.W);
                }
            }
            break;

            case 0x13:     //4 Singles Custom Count
            {
                uint count = reader.ReadUInt32();
                for (int f = 0; f < count; f++)
                {
                    float   frame = f;
                    float[] quat  = reader.ReadSingles(4);
                    group.RotateX.AddKey(frame, quat[0]);
                    group.RotateY.AddKey(frame, quat[1]);
                    group.RotateZ.AddKey(frame, quat[2]);
                    group.RotateW.AddKey(frame, quat[3]);
                }
            }
            break;

            case 0x15:     //4 Singles Constant
            {
                float[] quat = reader.ReadSingles(4);
                group.RotateX.AddKey(0, quat[0]);
                group.RotateY.AddKey(0, quat[1]);
                group.RotateZ.AddKey(0, quat[2]);
                group.RotateW.AddKey(0, quat[3]);
            }
            break;

            case 0x16:     //Short Quat Constant
            {
                //Todo this gives weird results.
                short[] quat = reader.ReadInt16s(4);

                /*  group.RotateX.AddKey(0, quat[0] / 0x7FFF);
                 * group.RotateY.AddKey(0, quat[1] / 0x7FFF);
                 * group.RotateZ.AddKey(0, quat[2] / 0x7FFF);
                 * group.RotateW.AddKey(0, quat[3] / 0x7FFF);*/

                Console.WriteLine($"track {track.OpCode} Unknown {track.Unknown} {string.Join(",", quat)}");
            }
            break;

            case 0x17:     //Short X Axis Angle
            {
                var euler = new Vector3(reader.ReadInt16() / 180.0f, 0, 0) * STMath.Deg2Rad;
                var quat  = STMath.FromEulerAngles(euler);
                group.RotateX.AddKey(0, quat.X);
                group.RotateY.AddKey(0, quat.Y);
                group.RotateZ.AddKey(0, quat.Z);
                group.RotateW.AddKey(0, quat.W);
            }
            break;

            case 0x18:     //Short Y Axis Angle (Degrees) Frame Count
            {
                for (int f = 0; f < header.FrameCount; f++)
                {
                    float frame = f;

                    var euler = new Vector3(0, reader.ReadInt16() / 180.0f, 0) * STMath.Deg2Rad;
                    var quat  = STMath.FromEulerAngles(euler);
                    group.RotateX.AddKey(frame, quat.X);
                    group.RotateY.AddKey(frame, quat.Y);
                    group.RotateZ.AddKey(frame, quat.Z);
                    group.RotateW.AddKey(frame, quat.W);
                }
            }
            break;

            case 0x19:     //Short Z Axis Angle (Degrees) Frame Count
            {
                for (int f = 0; f < header.FrameCount; f++)
                {
                    float frame = f;

                    var euler = new Vector3(0, 0, reader.ReadInt16() / 180.0f) * STMath.Deg2Rad;
                    var quat  = STMath.FromEulerAngles(euler);
                    group.RotateX.AddKey(frame, quat.X);
                    group.RotateY.AddKey(frame, quat.Y);
                    group.RotateZ.AddKey(frame, quat.Z);
                    group.RotateW.AddKey(frame, quat.W);
                }
            }
            break;

            //Todo these give weird results.

            /*       case 0x1A: //Consta
             *         {
             *             ushort flag = reader.ReadUInt16();
             *             short[] angles = reader.ReadInt16s(2);
             *             ushort[] param = reader.ReadUInt16s(2);
             *
             *             var euler = new Vector3(reader.ReadInt16() / 180.0f, 0, 0) * STMath.Deg2Rad;
             *             var quat = STMath.FromEulerAngles(euler);
             *             group.RotateX.AddKey(0, quat.X);
             *             group.RotateY.AddKey(0, quat.Y);
             *             group.RotateZ.AddKey(0, quat.Z);
             *             group.RotateW.AddKey(0, quat.W);
             *         }
             *         break;
             *     case 0x1B:
             *         {
             *             ushort flag = reader.ReadUInt16();
             *             //  short[] quat = reader.ReadInt16s(4);
             *
             *             var euler = new Vector3(0, reader.ReadInt16() / 180.0f, 0) * STMath.Deg2Rad;
             *             var quat = STMath.FromEulerAngles(euler);
             *             group.RotateX.AddKey(0, quat.X);
             *             group.RotateY.AddKey(0, quat.Y);
             *             group.RotateZ.AddKey(0, quat.Z);
             *             group.RotateW.AddKey(0, quat.W);
             *         }
             *         break;
             *     case 0x1C:
             *         {
             *             ushort flag = reader.ReadUInt16();
             *           //  short[] quat = reader.ReadInt16s(4);
             *
             *             var euler = new Vector3(0, 0, reader.ReadInt16() / 180.0f) * STMath.Deg2Rad;
             *             var quat = STMath.FromEulerAngles(euler);
             *             group.RotateX.AddKey(0, quat.X);
             *             group.RotateY.AddKey(0, quat.Y);
             *             group.RotateZ.AddKey(0, quat.Z);
             *             group.RotateW.AddKey(0, quat.W);
             *         }
             *         break;*/
            default:
                Console.WriteLine($"Unknown Op Code! Track {track.Index} Type {track.Type} OpCode {track.OpCode}");
                break;
            }
        }
        public void SetupSettings()
        {
            if (SelectedIndex == -1)
            {
                return;
            }


            WidthLabel.Text  = $"Width {SelectedTexSettings.TexWidth}";
            HeightLabel.Text = $"Height {SelectedTexSettings.TexHeight}";

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is Decode_Gamecube.TextureFormats)
            {
                SelectedTexSettings.Format = (Decode_Gamecube.TextureFormats)formatComboBox.SelectedItem;
                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = SelectedTexSettings.Format.ToString();


                if (SelectedTexSettings.Format == Decode_Gamecube.TextureFormats.C4 ||
                    SelectedTexSettings.Format == Decode_Gamecube.TextureFormats.C8)
                {
                    paletteColorsUD.Enabled    = true;
                    paletteColorsUD.Enabled    = true;
                    paletteAlgorithmCB.Enabled = true;
                }
                else
                {
                    paletteColorsUD.Enabled    = false;
                    paletteColorsUD.Enabled    = false;
                    paletteAlgorithmCB.Enabled = false;
                }
            }
            if (paletteFormatCB.SelectedItem is Decode_Gamecube.PaletteFormats)
            {
                SelectedTexSettings.PaletteFormat = (Decode_Gamecube.PaletteFormats)paletteFormatCB.SelectedItem;
            }

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            Thread = new Thread((ThreadStart)(() =>
            {
                SelectedTexSettings.IsFinishedCompressing = false;
                ToggleOkButton(false);

                pictureBox1.Image = bitmap;

                var encodedData = SelectedTexSettings.GenerateMipList();

                var mips = encodedData.Item1;
                var paletteData = encodedData.Item2;

                SelectedTexSettings.DataBlockOutput.Clear();
                SelectedTexSettings.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);
                SelectedTexSettings.IsFinishedCompressing = true;

                bitmap = Decode_Gamecube.DecodeDataToBitmap(mips[0], paletteData,
                                                            SelectedTexSettings.TexWidth,
                                                            SelectedTexSettings.TexHeight,
                                                            SelectedTexSettings.Format,
                                                            SelectedTexSettings.PaletteFormat);

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }
Пример #13
0
        public void SetupSettings(GTXImporterSettings setting, bool setFormat = true)
        {
            if (setting.Format == GX2.GX2SurfaceFormat.INVALID || SelectedIndex == -1)
            {
                return;
            }

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is GX2.GX2SurfaceFormat && setFormat)
            {
                setting.Format = (GX2.GX2SurfaceFormat)formatComboBox.SelectedItem;

                if (setting.Format == GX2.GX2SurfaceFormat.T_BC4_UNORM && DisplayBC4Alpha ||
                    setting.Format == GX2.GX2SurfaceFormat.T_BC4_SNORM && DisplayBC4Alpha)
                {
                    chkBc4Alpha.Visible = true;
                }
                else
                {
                    chkBc4Alpha.Visible = false;
                }

                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString();
            }

            if (setting.MipCountOriginal >= 0)
            {
                chkOriginalMipCount.Enabled = true;
            }
            else
            {
                chkOriginalMipCount.Enabled = false;
            }

            HeightLabel.Text = $"Height: {setting.TexHeight}";
            WidthLabel.Text  = $"Width: {setting.TexWidth}";

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            pictureBox1.Image = bitmap;

            Thread = new Thread((ThreadStart)(() =>
            {
                setting.IsFinishedCompressing = false;
                ToggleOkButton(false);

                var mips = setting.GenerateMipList();
                setting.DataBlockOutput.Clear();
                setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);
                setting.IsFinishedCompressing = true;

                bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting.
                                                   TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format(
                                                       (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]);


                if (setting.FlipY)
                {
                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }
                if (setting.UseBc4Alpha)
                {
                    bitmap = BitmapExtension.SetChannel(bitmap,
                                                        STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red);
                }

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }