Esempio n. 1
0
            public override void Import(string[] FileNames)
            {
                foreach (var FileName in FileNames)
                {
                    string extension = System.IO.Path.GetExtension(FileName);

                    if (extension == ".bfbon")
                    {
                        BfresBone bn = new BfresBone();

                        if (SkeletonU != null)
                        {
                            ResU.Bone bone = new ResU.Bone();
                            bone.Import(FileName, GetResFileU());

                            BfresWiiU.ReadBone(bn, bone, false);
                        }
                        else
                        {
                            Bone bone = new Bone();
                            bone.Import(FileName);

                            BfresSwitch.ReadBone(bn, bone, false);
                        }
                    }
                }
            }
Esempio n. 2
0
 public FSKL(ResU.Skeleton skl)
 {
     node           = new fsklNode();
     node.fskl      = this;
     node.SkeletonU = skl;
     BfresWiiU.ReadSkeleton(node, skl, this);
 }
Esempio n. 3
0
        public void NewChild()
        {
            BfresBone bn = new BfresBone(skeletonParent);

            if (BoneU != null)
            {
                BoneU      = new ResU.Bone();
                BoneU.Name = CheckDuplicateBoneNames("NewBone");

                BfresWiiU.ReadBone(bn, BoneU, false);
                Nodes.Add(bn);
                skeletonParent.bones.Add(bn);

                BoneU.ParentIndex = (short)bn.parentIndex;
                ((FSKL)skeletonParent).AddBone(BoneU);
            }
            else
            {
                Bone      = new Bone();
                Bone.Name = CheckDuplicateBoneNames("NewBone");

                BfresSwitch.ReadBone(bn, Bone, false);
                Nodes.Add(bn);
                skeletonParent.bones.Add(bn);

                Bone.ParentIndex = (short)bn.parentIndex;
                ((FSKL)skeletonParent).AddBone(Bone);
            }
        }
Esempio n. 4
0
            public override void Replace(string FileName)
            {
                string extension = System.IO.Path.GetExtension(FileName);

                if (extension == ".bfskl")
                {
                    //Todo regenerate indices.
                    //This will just fix swapping the same bonesets with slightly adjusted indices
                    if (SkeletonU != null)
                    {
                        var indices = this.SkeletonU.MatrixToBoneList;

                        SkeletonU = new ResU.Skeleton();
                        SkeletonU.Import(FileName, GetResFileU());
                        SkeletonU.MatrixToBoneList = indices;

                        Nodes.Clear();
                        fskl.bones.Clear();
                        BfresWiiU.ReadSkeleton(this, SkeletonU, fskl);
                    }
                    else
                    {
                        var indices = this.SkeletonU.MatrixToBoneList;

                        Skeleton = new Skeleton();
                        Skeleton.Import(FileName);
                        SkeletonU.MatrixToBoneList = indices;

                        Nodes.Clear();
                        fskl.bones.Clear();
                        BfresSwitch.ReadSkeleton(this, Skeleton, fskl);
                    }
                }
            }
Esempio n. 5
0
        private void Export()
        {
            bool IncludeTextureMaps = true;

            if (MaterialU != null)
            {
                BfresWiiU.SetMaterial(this, MaterialU, GetResFileU());
            }
            else
            {
                BfresSwitch.SetMaterial(this, Material);
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Supported Formats|*.bfmat;";

            sfd.DefaultExt = ".bfmat";
            sfd.FileName   = Text;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                Export(sfd.FileName, IncludeTextureMaps);
            }
        }
Esempio n. 6
0
            public void NewChildBone()
            {
                BfresBone bone = new BfresBone(fskl);

                bone.parentIndex = -1;

                if (SkeletonU != null)
                {
                    bone.BoneU      = new ResU.Bone();
                    bone.BoneU.Name = CheckDuplicateBoneNames("NewBone");

                    BfresWiiU.ReadBone(bone, bone.BoneU, false);

                    Nodes.Add(bone);
                    fskl.bones.Add(bone);

                    bone.BoneU.ParentIndex = (short)bone.parentIndex;
                    fskl.AddBone(bone.BoneU);
                }
                else
                {
                    bone.Bone      = new Bone();
                    bone.Bone.Name = CheckDuplicateBoneNames("NewBone");

                    BfresSwitch.ReadBone(bone, bone.Bone, false);

                    Nodes.Add(bone);
                    fskl.bones.Add(bone);

                    bone.Bone.ParentIndex = (short)bone.parentIndex;
                    fskl.AddBone(bone.Bone);
                }
            }
Esempio n. 7
0
        public void ImportChild()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter   = FileFilters.BONE;
            ofd.FileName = Text;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                BfresBone bn = new BfresBone(skeletonParent);

                if (BoneU != null)
                {
                    BoneU = new ResU.Bone();
                    BoneU.Import(ofd.FileName, GetResFileU());
                    BoneU.Name = CheckDuplicateBoneNames(BoneU.Name);

                    BfresWiiU.ReadBone(bn, BoneU, false);
                    Nodes.Add(bn);
                    skeletonParent.bones.Add(bn);
                    ((FSKL)skeletonParent).AddBone(BoneU);
                }
                else
                {
                    Bone = new Bone();
                    Bone.Import(ofd.FileName);
                    Bone.Name = CheckDuplicateBoneNames(Bone.Name);

                    BfresSwitch.ReadBone(bn, Bone, false);
                    Nodes.Add(bn);
                    skeletonParent.bones.Add(bn);
                    ((FSKL)skeletonParent).AddBone(Bone);
                }
            }
        }
Esempio n. 8
0
 public void SaveShape(bool IsWiiU)
 {
     if (IsWiiU)
     {
         ShapeU = BfresWiiU.SaveShape(this);
     }
     else
     {
         Shape = BfresSwitch.SaveShape(this);
     }
 }
Esempio n. 9
0
 public void SaveShape()
 {
     if (!BFRES.IsWiiU)
     {
         Shape = BfresSwitch.SaveShape(this);
     }
     else
     {
         ShapeU = BfresWiiU.SaveShape(this);
     }
 }
Esempio n. 10
0
 public void Replace(string path)
 {
     if (GetResFileU() != null)
     {
         MaterialU.Import(path, GetResFileU());
         MaterialU.Name = Text;
         BfresWiiU.ReadMaterial(this, MaterialU);
     }
     else
     {
         Material.Import(path);
         Material.Name = Text;
         BfresSwitch.ReadMaterial(this, Material);
     }
 }
Esempio n. 11
0
        public void NewModel()
        {
            BFRESGroupNode group = new BFRESGroupNode();
            FMDL           anim  = new FMDL();

            if (IsWiiU)
            {
                BfresWiiU.ReadModel(anim, new ResU.Model());
            }
            else
            {
                BfresSwitch.ReadModel(anim, new ResNX.Model());
            }

            group.AddNode(anim, "NewModel");
        }
Esempio n. 12
0
            public void ReplaceMatchingFolder()
            {
                FolderSelectDialog ofd = new FolderSelectDialog();

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    foreach (var file in System.IO.Directory.GetFiles(ofd.SelectedPath))
                    {
                        string extension = System.IO.Path.GetExtension(file);

                        if (extension == ".bfbon")
                        {
                            if (SkeletonU != null)
                            {
                                ResU.Bone BoneTemp = new ResU.Bone();
                                BoneTemp.Import(file, GetResFileU());

                                foreach (BfresBone bone in fskl.bones)
                                {
                                    if (BoneTemp.Name == bone.Text)
                                    {
                                        bone.CopyData(BoneTemp);
                                    }
                                }

                                BfresWiiU.ReadSkeleton(this, SkeletonU, fskl);
                            }
                            else
                            {
                                Bone BoneTemp = new Bone();
                                BoneTemp.Import(file);

                                foreach (BfresBone bone in fskl.bones)
                                {
                                    if (BoneTemp.Name == bone.Text)
                                    {
                                        bone.CopyData(BoneTemp);
                                    }
                                }

                                BfresSwitch.ReadSkeleton(this, Skeleton, fskl);
                            }
                        }
                    }
                }
            }
Esempio n. 13
0
            public void ReplaceMatchingFile( )
            {
                OpenFileDialog ofd = new OpenFileDialog();

                ofd.DefaultExt = ReplaceFilter;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string extension = System.IO.Path.GetExtension(ofd.FileName);

                    if (extension == ".bfskl")
                    {
                        if (SkeletonU != null)
                        {
                            ResU.Skeleton SkeltonTemp = new ResU.Skeleton();
                            SkeltonTemp.Import(ofd.FileName, GetResFileU());

                            foreach (BfresBone bone in fskl.bones)
                            {
                                if (SkeltonTemp.Bones.ContainsKey(bone.Text))
                                {
                                    bone.CopyData(SkeltonTemp.Bones[bone.Text]);
                                }
                            }

                            BfresWiiU.ReadSkeleton(this, SkeletonU, fskl);
                        }
                        else
                        {
                            Skeleton SkeltonTemp = new Skeleton();
                            SkeltonTemp.Import(ofd.FileName);

                            foreach (BfresBone bone in fskl.bones)
                            {
                                if (SkeltonTemp.BoneDict.ContainsKey(bone.Text))
                                {
                                    int index = SkeltonTemp.BoneDict.GetIndex(bone.Text);
                                    bone.CopyData(SkeltonTemp.Bones[index]);
                                }
                            }

                            BfresSwitch.ReadSkeleton(this, Skeleton, fskl);
                        }
                    }
                }
            }
Esempio n. 14
0
            public override void Import(string[] FileNames)
            {
                foreach (var FileName in FileNames)
                {
                    string extension = System.IO.Path.GetExtension(FileName);

                    if (extension == ".bfbon")
                    {
                        BfresBone bn = new BfresBone(fskl);

                        List <string> boneKeys = fskl.bones.Select(i => i.Text).ToList();
                        if (SkeletonU != null)
                        {
                            ResU.Bone bone = new ResU.Bone();
                            bone.Import(FileName, GetResFileU());
                            bone.ParentIndex = -1;
                            bone.Name        = Utils.RenameDuplicateString(boneKeys, bone.Name);

                            BfresWiiU.ReadBone(bn, bone, false);

                            Nodes.Add(bn);
                            fskl.bones.Add(bn);

                            bn.BoneU.ParentIndex = (short)bn.parentIndex;
                            fskl.AddBone(bn.BoneU);
                        }
                        else
                        {
                            Bone bone = new Bone();
                            bone.Import(FileName);
                            bone.ParentIndex = -1;
                            bone.Name        = Utils.RenameDuplicateString(boneKeys, bone.Name);

                            BfresSwitch.ReadBone(bn, bone, false);

                            Nodes.Add(bn);
                            fskl.bones.Add(bn);

                            bn.Bone.ParentIndex = (short)bn.parentIndex;
                            fskl.AddBone(bn.Bone);
                        }
                    }
                }
            }
Esempio n. 15
0
            public override void Import(string[] FileNames)
            {
                foreach (var FileName in FileNames)
                {
                    string extension = System.IO.Path.GetExtension(FileName);

                    if (extension == ".bfbon")
                    {
                        BfresBone bn = new BfresBone(fskl);

                        if (SkeletonU != null)
                        {
                            ResU.Bone bone = new ResU.Bone();
                            bone.Import(FileName, GetResFileU());
                            bone.ParentIndex = -1;

                            BfresWiiU.ReadBone(bn, bone, false);

                            Nodes.Add(bn);
                            fskl.bones.Add(bn);

                            bn.BoneU.ParentIndex = (short)bn.parentIndex;
                            fskl.AddBone(bn.Bone);
                        }
                        else
                        {
                            Bone bone = new Bone();
                            bone.Import(FileName);
                            bone.ParentIndex = -1;

                            BfresSwitch.ReadBone(bn, bone, false);

                            Nodes.Add(bn);
                            fskl.bones.Add(bn);

                            bn.Bone.ParentIndex = (short)bn.parentIndex;
                            fskl.AddBone(bn.Bone);
                        }
                    }
                }
            }
Esempio n. 16
0
        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.bfmat;";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (GetResFileU() != null)
                {
                    MaterialU.Import(ofd.FileName, GetResFileU());
                    MaterialU.Name = Text;
                    BfresWiiU.ReadMaterial(this, MaterialU);
                }
                else
                {
                    Material.Import(ofd.FileName);
                    Material.Name = Text;
                    BfresSwitch.ReadMaterial(this, Material);
                }
            }
        }
Esempio n. 17
0
            public override void Replace(string FileName)
            {
                string extension = System.IO.Path.GetExtension(FileName);

                if (extension == ".bfskl")
                {
                    if (SkeletonU != null)
                    {
                        SkeletonU = new ResU.Skeleton();
                        SkeletonU.Import(FileName, GetResFileU());
                        Nodes.Clear();
                        fskl.bones.Clear();
                        BfresWiiU.ReadSkeleton(this, SkeletonU, fskl);
                    }
                    else
                    {
                        Skeleton = new Skeleton();
                        Skeleton.Import(FileName);
                        Nodes.Clear();
                        fskl.bones.Clear();
                        BfresSwitch.ReadSkeleton(this, Skeleton, fskl);
                    }
                }
            }
Esempio n. 18
0
        public void Replace(object sender, EventArgs args)
        {
            bool IsWiiU = (GetResFileU() != null);

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.bfobj;*.fbx;*.dae; *.obj;|" +
                         "Bfres Object (shape/vertices) |*.bfobj|" +
                         "FBX |*.fbx|" +
                         "DAE |*.dae|" +
                         "OBJ |*.obj|" +
                         "All files(*.*)|*.*";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string ext = System.IO.Path.GetExtension(ofd.FileName);
                ext = ext.ToLower();

                switch (ext)
                {
                case ".bfobj":
                    if (IsWiiU)
                    {
                        var shp = new ResU.Shape();
                        shp.Import(ofd.FileName, VertexBufferU, GetResFileU());
                        shp.Name          = Text;
                        shp.MaterialIndex = (ushort)MaterialIndex;
                        BfresWiiU.ReadShapesVertices(this, shp, VertexBufferU, GetParentModel());
                    }
                    else
                    {
                        Shape shp = new Shape();
                        shp.Import(ofd.FileName, VertexBuffer);
                        shp.Name          = Text;
                        shp.MaterialIndex = (ushort)MaterialIndex;
                        BfresSwitch.ReadShapesVertices(this, shp, VertexBuffer, GetParentModel());
                    }

                    break;

                default:
                    AssimpData assimp = new AssimpData();
                    assimp.LoadFile(ofd.FileName);
                    AssimpMeshSelector selector = new AssimpMeshSelector();
                    selector.LoadMeshes(assimp, Index);

                    if (selector.ShowDialog() == DialogResult.OK)
                    {
                        if (assimp.objects.Count == 0)
                        {
                            MessageBox.Show("No models found!");
                            return;
                        }
                        BfresModelImportSettings settings = new BfresModelImportSettings();
                        settings.SetModelAttributes(assimp.objects[0]);
                        if (settings.ShowDialog() == DialogResult.OK)
                        {
                            STGenericObject obj = selector.GetSelectedMesh();

                            Cursor.Current    = Cursors.WaitCursor;
                            VertexBufferIndex = obj.VertexBufferIndex;
                            vertices          = obj.vertices;
                            CreateBoneList(obj, (FMDL)Parent.Parent);
                            CreateIndexList(obj, (FMDL)Parent.Parent);
                            VertexSkinCount  = obj.GetMaxSkinInfluenceCount();
                            vertexAttributes = settings.CreateNewAttributes();
                            ApplyImportSettings(settings, GetMaterial());
                            lodMeshes = obj.lodMeshes;
                            CreateNewBoundingBoxes();
                            SaveShape(IsWiiU);
                            SaveVertexBuffer();
                            Cursor.Current = Cursors.Default;
                        }
                    }
                    break;
                }
                UpdateVertexData();
            }
        }
Esempio n. 19
0
        public void SaveVertexBuffer()
        {
            if (BFRES.IsWiiU)
            {
                BfresWiiU.SaveVertexBuffer(this);
                return;
            }

            VertexBufferHelper helpernx           = new VertexBufferHelper(new VertexBuffer(), Syroot.BinaryData.ByteOrder.LittleEndian);
            List <VertexBufferHelperAttrib> atrib = new List <VertexBufferHelperAttrib>();

            UpdateVertices();

            foreach (VertexAttribute att in vertexAttributes)
            {
                if (att.Name == "_p0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = verts.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_n0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = norms.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_u0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = uv0.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_u1")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = uv1.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_u2")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = uv2.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_w0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = weights.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_i0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = boneInd.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_b0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = bitans.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_t0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = tans.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
                if (att.Name == "_c0")
                {
                    VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
                    vert.Name   = att.Name;
                    vert.Data   = colors.ToArray();
                    vert.Format = att.Format;
                    atrib.Add(vert);
                }
            }
            if (atrib.Count == 0)
            {
                MessageBox.Show("Attributes are empty?");
                return;
            }
            helpernx.Attributes = atrib;
            VertexBuffer        = helpernx.ToVertexBuffer();
        }
Esempio n. 20
0
        public void NewModel()
        {
            FMDL fmdl = new FMDL();

            if (IsWiiU)
            {
                fmdl.ModelU = new ResU.Model();

                //Create skeleton with empty bone
                var skeleton = new ResU.Skeleton();

                //Create skeleton with empty bone
                skeleton.Bones.Add("Root", new ResU.Bone()
                {
                    Name = "Root"
                });

                fmdl.ModelU.Skeleton = skeleton;

                var shape = new ResU.Shape()
                {
                    Name = "NewShape"
                };
                shape.CreateEmptyMesh();

                var VertexBuffer = new ResU.VertexBuffer();
                VertexBuffer.CreateEmptyVertexBuffer();

                fmdl.ModelU.VertexBuffers.Add(VertexBuffer);
                fmdl.ModelU.Shapes.Add("NewShape", shape);
                fmdl.ModelU.Materials.Add("NewMaterial", new ResU.Material()
                {
                    Name = "NewMaterial"
                });

                BfresWiiU.ReadModel(fmdl, fmdl.ModelU);
                ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
            }
            else
            {
                fmdl.Model = new ResNX.Model();

                //Create skeleton with empty bone
                var skeleton = new ResNX.Skeleton();

                //Create skeleton with empty bone
                skeleton.Bones.Add(new ResNX.Bone()
                {
                    Name = "Root"
                });

                fmdl.Model.Skeleton = skeleton;

                var shape = new ResNX.Shape()
                {
                    Name = "NewShape"
                };
                shape.CreateEmptyMesh();

                fmdl.Model.Shapes.Add(shape);
                fmdl.Model.Materials.Add(new ResNX.Material()
                {
                    Name = "NewMaterial"
                });

                var VertexBuffer = new ResNX.VertexBuffer();
                VertexBuffer.CreateEmptyVertexBuffer();

                fmdl.Model.VertexBuffers.Add(VertexBuffer);

                BfresSwitch.ReadModel(fmdl, fmdl.Model);
                ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
            }

            AddNode(fmdl, "NewModel");
        }
Esempio n. 21
0
            public void ReplaceMatchingFile( )
            {
                OpenFileDialog ofd = new OpenFileDialog();

                ofd.DefaultExt = ReplaceFilter;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string extension = System.IO.Path.GetExtension(ofd.FileName);

                    if (extension == ".bfskl")
                    {
                        if (SkeletonU != null)
                        {
                            ResU.Skeleton SkeltonTemp = new ResU.Skeleton();
                            SkeltonTemp.Import(ofd.FileName, GetResFileU());

                            foreach (BfresBone bone in fskl.bones)
                            {
                                if (SkeltonTemp.Bones.ContainsKey(bone.Text))
                                {
                                    bone.CopyData(SkeltonTemp.Bones[bone.Text]);
                                }
                            }

                            BfresWiiU.ReadSkeleton(this, SkeletonU, fskl);
                        }
                        else
                        {
                            Skeleton SkeltonTemp = new Skeleton();
                            SkeltonTemp.Import(ofd.FileName);

                            foreach (BfresBone bone in fskl.bones)
                            {
                                if (SkeltonTemp.BoneDict.ContainsKey(bone.Text))
                                {
                                    int index = SkeltonTemp.BoneDict.GetIndex(bone.Text);
                                    bone.CopyData(SkeltonTemp.Bones[index]);
                                }
                            }

                            BfresSwitch.ReadSkeleton(this, Skeleton, fskl);
                        }
                    }
                    if (extension == ".csv")
                    {
                        using (var reader = new System.IO.StringReader(System.IO.File.ReadAllText(ofd.FileName)))
                        {
                            string value = reader.ReadLine();
                            if (value != "Bones Geometry")
                            {
                                return;
                            }

                            float X = 0;
                            float Y = 0;
                            float Z = 0;
                            float W = 0;
                            while (true)
                            {
                                string line = reader.ReadLine();
                                if (line != null)
                                {
                                    foreach (BfresBone bone in fskl.bones)
                                    {
                                        if (bone.Text == line)
                                        {
                                            string name           = line;
                                            string scaleStr       = reader.ReadLine();
                                            string rotationStr    = reader.ReadLine();
                                            string translationStr = reader.ReadLine();

                                            string[] valuesS = scaleStr.Replace("\n", "").Replace("\r", "").Split(',');
                                            string[] valuesR = rotationStr.Replace("\n", "").Replace("\r", "").Split(',');
                                            string[] valuesT = translationStr.Replace("\n", "").Replace("\r", "").Split(',');

                                            Syroot.Maths.Vector3F translate;
                                            Syroot.Maths.Vector3F scale;
                                            Syroot.Maths.Vector4F rotate;

                                            float.TryParse(valuesT[0], out X);
                                            float.TryParse(valuesT[1], out Y);
                                            float.TryParse(valuesT[2], out Z);
                                            translate = new Syroot.Maths.Vector3F(X, Y, Z);

                                            float.TryParse(valuesR[0], out X);
                                            float.TryParse(valuesR[1], out Y);
                                            float.TryParse(valuesR[2], out Z);
                                            float.TryParse(valuesR[3], out W);
                                            rotate = new Syroot.Maths.Vector4F(X, Y, Z, W);

                                            float.TryParse(valuesS[0], out X);
                                            float.TryParse(valuesS[1], out Y);
                                            float.TryParse(valuesS[2], out Z);
                                            scale = new Syroot.Maths.Vector3F(X, Y, Z);

                                            if (bone.BoneU != null)
                                            {
                                                bone.BoneU.Position = translate;
                                                bone.BoneU.Scale    = scale;
                                                bone.BoneU.Rotation = rotate;
                                            }
                                            else
                                            {
                                                bone.Bone.Position = translate;
                                                bone.Bone.Scale    = scale;
                                                bone.Bone.Rotation = rotate;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            if (SkeletonU != null)
                            {
                                BfresWiiU.ReadSkeleton(this, SkeletonU, fskl);
                            }
                            else
                            {
                                BfresSwitch.ReadSkeleton(this, Skeleton, fskl);
                            }

                            LibraryGUI.UpdateViewport();
                        }
                    }
                }
            }
Esempio n. 22
0
        //Function addes shapes, vertices and meshes
        public void AddOjects(string FileName, bool Replace = true)
        {
            bool IsWiiU = (GetResFileU() != null);

            int    MatStartIndex = materials.Count;
            string ext           = System.IO.Path.GetExtension(FileName);

            ext = ext.ToLower();

            switch (ext)
            {
            case ".bfobj":
                Cursor.Current = Cursors.WaitCursor;

                if (Replace)
                {
                    shapes.Clear();
                    Nodes["FshpFolder"].Nodes.Clear();
                }

                Shape        shpS         = new Shape();
                VertexBuffer vertexBuffer = new VertexBuffer();
                shpS.Import(FileName, vertexBuffer);

                FSHP shapeS = new FSHP();
                shapeS.Shape = shpS;
                BfresSwitch.ReadShapesVertices(shapeS, shpS, vertexBuffer, this);
                shapes.Add(shapeS);
                Nodes["FshpFolder"].Nodes.Add(shapeS);
                Cursor.Current = Cursors.Default;
                break;

            case ".bfmdl":
                Cursor.Current = Cursors.WaitCursor;

                if (Replace)
                {
                    shapes.Clear();
                    Nodes["FshpFolder"].Nodes.Clear();
                }

                Model mdl = new Model();
                mdl.Import(FileName, GetResFile());
                mdl.Name = Text;
                shapes.Clear();
                foreach (Shape shp in mdl.Shapes)
                {
                    FSHP shape = new FSHP();
                    shape.Shape = shp;
                    BfresSwitch.ReadShapesVertices(shape, shp, mdl.VertexBuffers[shp.VertexBufferIndex], this);
                    shapes.Add(shape);
                    Nodes["FshpFolder"].Nodes.Add(shape);
                }
                Cursor.Current = Cursors.Default;
                break;

            case ".csv":
                CsvModel csvModel = new CsvModel();
                csvModel.LoadFile(FileName, true);

                if (csvModel.objects.Count == 0)
                {
                    MessageBox.Show("No models found!");
                    return;
                }
                BfresModelImportSettings csvsettings = new BfresModelImportSettings();
                csvsettings.DisableMaterialEdits();
                csvsettings.SetModelAttributes(csvModel.objects[0]);
                if (csvsettings.ShowDialog() == DialogResult.OK)
                {
                    if (Replace)
                    {
                        shapes.Clear();
                        Nodes["FshpFolder"].Nodes.Clear();
                    }

                    Cursor.Current = Cursors.WaitCursor;

                    foreach (STGenericObject obj in csvModel.objects)
                    {
                        FSHP shape = new FSHP();
                        shape.VertexBufferIndex = shapes.Count;
                        shape.vertices          = obj.vertices;
                        shape.MaterialIndex     = 0;
                        shape.vertexAttributes  = csvsettings.CreateNewAttributes();
                        shape.boneIndx          = 0;
                        shape.Text      = obj.ObjectName;
                        shape.lodMeshes = obj.lodMeshes;
                        shape.CreateNewBoundingBoxes();
                        shape.CreateBoneList(obj, this);
                        shape.CreateIndexList(obj, this);
                        shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
                        shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
                        shape.SaveShape(IsWiiU);
                        shape.SaveVertexBuffer(IsWiiU);
                        shape.BoneIndices = new List <ushort>();

                        Nodes["FshpFolder"].Nodes.Add(shape);
                        shapes.Add(shape);
                    }
                    Cursor.Current = Cursors.Default;
                }
                break;

            default:
                AssimpData assimp = new AssimpData();
                assimp.LoadFile(FileName);

                if (assimp.objects.Count == 0)
                {
                    MessageBox.Show("No models found!");
                    return;
                }
                BfresModelImportSettings settings = new BfresModelImportSettings();
                settings.SetModelAttributes(assimp.objects[0]);
                if (settings.ShowDialog() == DialogResult.OK)
                {
                    if (Replace)
                    {
                        shapes.Clear();
                        Nodes["FshpFolder"].Nodes.Clear();
                    }

                    Cursor.Current = Cursors.WaitCursor;
                    if (Replace)
                    {
                        materials.Clear();
                        Nodes["FmatFolder"].Nodes.Clear();
                        MatStartIndex = 0;
                    }
                    foreach (STGenericMaterial mat in assimp.materials)
                    {
                        FMAT fmat = new FMAT();
                        if (settings.ExternalMaterialPath != string.Empty)
                        {
                            if (GetResFileU() != null)
                            {
                                fmat.MaterialU = new ResU.Material();
                                fmat.MaterialU.Import(settings.ExternalMaterialPath, GetResFileU());
                                BfresWiiU.ReadMaterial(fmat, fmat.MaterialU);
                            }
                            else
                            {
                                fmat.Material = new Material();
                                fmat.Material.Import(settings.ExternalMaterialPath);
                                fmat.ReadMaterial(fmat.Material);
                            }
                        }

                        fmat.Text = mat.Text;
                        //Setup placeholder textures
                        //Note we can't add/remove samplers so we must fill these slots
                        foreach (var t in fmat.TextureMaps)
                        {
                            t.wrapModeS = 0;
                            t.wrapModeT = 0;

                            switch (t.Type)
                            {
                            case STGenericMatTexture.TextureType.Diffuse:
                                t.Name = "Basic_Alb";
                                break;

                            case STGenericMatTexture.TextureType.Emission:
                                t.Name = "Basic_Emm";
                                break;

                            case STGenericMatTexture.TextureType.Normal:
                                t.Name = "Basic_Nrm";
                                break;

                            case STGenericMatTexture.TextureType.Specular:
                                t.Name = "Basic_Spm";
                                break;

                            case STGenericMatTexture.TextureType.SphereMap:
                                t.Name = "Basic_Sphere";
                                break;

                            case STGenericMatTexture.TextureType.Metalness:
                                t.Name = "Basic_Mtl";
                                break;

                            case STGenericMatTexture.TextureType.Roughness:
                                t.Name = "Basic_Rgh";
                                break;

                            case STGenericMatTexture.TextureType.MRA:
                                t.Name = "Basic_MRA";
                                break;

                            case STGenericMatTexture.TextureType.Shadow:
                                t.Name = "Basic_Bake_st0";
                                break;

                            case STGenericMatTexture.TextureType.Light:
                                t.Name = "Basic_Bake_st1";
                                break;
                            }
                        }

                        if (PluginRuntime.bntxContainers.Count > 0)
                        {
                            foreach (var node in Parent.Parent.Nodes["EXT"].Nodes)
                            {
                                if (node is BNTX)
                                {
                                    var bntx = (BNTX)node;

                                    bntx.ImportBasicTextures("Basic_Alb");
                                    bntx.ImportBasicTextures("Basic_Nrm");
                                    bntx.ImportBasicTextures("Basic_Spm");
                                    bntx.ImportBasicTextures("Basic_Sphere");
                                    bntx.ImportBasicTextures("Basic_Mtl");
                                    bntx.ImportBasicTextures("Basic_Rgh");
                                    bntx.ImportBasicTextures("Basic_MRA");
                                    bntx.ImportBasicTextures("Basic_Bake_st0");
                                    bntx.ImportBasicTextures("Basic_Bake_st1");
                                    bntx.ImportBasicTextures("Basic_Emm");
                                }
                            }
                        }

                        foreach (var tex in mat.TextureMaps)
                        {
                            foreach (var t in fmat.TextureMaps)
                            {
                                if (t.Type == tex.Type)
                                {
                                    t.Name      = tex.Name;
                                    t.wrapModeS = tex.wrapModeS;
                                    t.wrapModeT = tex.wrapModeT;
                                    t.wrapModeW = tex.wrapModeW;
                                    t.Type      = tex.Type;
                                }
                            }
                        }

                        List <string> keyList = new List <string>(materials.Keys);
                        fmat.Text = Utils.RenameDuplicateString(keyList, fmat.Text);

                        materials.Add(fmat.Text, fmat);
                        Nodes["FmatFolder"].Nodes.Add(fmat);

                        if (GetResFileU() != null)
                        {
                            fmat.MaterialU.Name = Text;
                            fmat.SetMaterial(fmat.MaterialU);
                        }
                        else
                        {
                            fmat.Material.Name = Text;
                            fmat.SetMaterial(fmat.Material);
                        }
                    }


                    foreach (STGenericObject obj in assimp.objects)
                    {
                        FSHP shape = new FSHP();
                        shape.VertexBufferIndex = shapes.Count;
                        shape.vertices          = obj.vertices;
                        shape.VertexSkinCount   = obj.MaxSkinInfluenceCount;
                        shape.vertexAttributes  = settings.CreateNewAttributes();
                        shape.boneIndx          = obj.BoneIndex;
                        shape.MaterialIndex     = obj.MaterialIndex + MatStartIndex;

                        shape.Text      = obj.ObjectName;
                        shape.lodMeshes = obj.lodMeshes;
                        shape.CreateNewBoundingBoxes();
                        shape.CreateBoneList(obj, this);
                        shape.CreateIndexList(obj, this);
                        shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex));
                        shape.SaveShape(IsWiiU);
                        shape.SaveVertexBuffer(IsWiiU);
                        shape.BoneIndices = new List <ushort>();

                        List <string> keyList = shapes.Select(o => o.Text).ToList();

                        shape.Text = Utils.RenameDuplicateString(keyList, shape.Text);

                        Nodes["FshpFolder"].Nodes.Add(shape);
                        shapes.Add(shape);
                    }
                    Console.WriteLine("Finshed Importing Model");

                    Cursor.Current = Cursors.Default;
                }
                break;
            }
            UpdateVertexData();
        }
Esempio n. 23
0
        public void Import(string[] FileNames, ResNX.ResFile resFileNX, ResU.ResFile resFileU)
        {
            if (Type == BRESGroupType.Textures)
            {
                ImportTexture(FileNames);
                return;
            }

            foreach (string FileName in FileNames)
            {
                string ResourceName = Path.GetFileNameWithoutExtension(FileName);
                string extension    = Path.GetExtension(FileName);

                switch (Type)
                {
                case BRESGroupType.Models:
                    FMDL fmdl = new FMDL();
                    fmdl.Text = ResourceName;

                    if (IsWiiU)
                    {
                        fmdl.ModelU      = new ResU.Model();
                        fmdl.ModelU      = new ResU.Model();
                        fmdl.ModelU.Name = ResourceName;

                        var skeleton = new ResU.Skeleton();

                        //Create skeleton with empty bone
                        skeleton.Bones.Add("Root", new ResU.Bone()
                        {
                            Name = "Root"
                        });

                        fmdl.ModelU.Skeleton = skeleton;

                        BfresWiiU.ReadModel(fmdl, fmdl.ModelU);
                        ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
                    }
                    else
                    {
                        fmdl.Model      = new ResNX.Model();
                        fmdl.Model.Name = ResourceName;

                        //Create skeleton with empty bone
                        var skeleton = new ResNX.Skeleton();
                        skeleton.Bones.Add(new ResNX.Bone()
                        {
                            Name = "Root"
                        });

                        fmdl.Model.Skeleton = skeleton;

                        BfresSwitch.ReadModel(fmdl, fmdl.Model);
                        ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
                    }
                    fmdl.Replace(FileName, resFileNX, resFileU);

                    Nodes.Add(fmdl);


                    fmdl.UpdateVertexData();
                    break;

                case BRESGroupType.SkeletalAnim:
                    FSKA fska = new FSKA();
                    fska.Text = ResourceName;
                    if (IsWiiU)
                    {
                        fska.SkeletalAnimU = new ResU.SkeletalAnim();
                    }
                    else
                    {
                        fska.SkeletalAnim = new ResNX.SkeletalAnim();
                    }

                    fska.Replace(FileName, resFileNX, resFileU);
                    Nodes.Add(fska);
                    break;

                case BRESGroupType.ShaderParamAnim:
                    FSHU fshu = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.ShaderParam);
                    fshu.Text = ResourceName;
                    fshu.Replace(FileName, resFileU);
                    Nodes.Add(fshu);
                    break;

                case BRESGroupType.ColorAnim:
                    FSHU fclh = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.Color);
                    fclh.Text = ResourceName;
                    fclh.Replace(FileName, resFileU);
                    Nodes.Add(fclh);
                    break;

                case BRESGroupType.TexSrtAnim:
                    FSHU fsth = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.TextureSrt);
                    fsth.Text = ResourceName;
                    fsth.Replace(FileName, resFileU);
                    Nodes.Add(fsth);
                    break;

                case BRESGroupType.TexPatAnim:
                    FTXP ftxp = new FTXP(new ResU.TexPatternAnim());
                    ftxp.Text = ResourceName;
                    ftxp.Replace(FileName, resFileU);
                    Nodes.Add(ftxp);
                    break;

                case BRESGroupType.BoneVisAnim:
                    FVIS fbnv = new FVIS();
                    fbnv.Text = ResourceName;
                    if (IsWiiU)
                    {
                        fbnv.VisibilityAnimU = new ResU.VisibilityAnim()
                        {
                            Type = ResU.VisibilityAnimType.Bone
                        }
                    }
                    ;
                    else
                    {
                        fbnv.VisibilityAnim = new ResNX.VisibilityAnim();
                    }

                    fbnv.Replace(FileName, resFileNX, resFileU);
                    Nodes.Add(fbnv);
                    break;

                case BRESGroupType.MatVisAnim:
                    FVIS fmtv = new FVIS(new ResU.VisibilityAnim()
                    {
                        Type = ResU.VisibilityAnimType.Material
                    });
                    fmtv.Text = ResourceName;
                    fmtv.Replace(FileName, resFileNX, resFileU);
                    Nodes.Add(fmtv);
                    break;

                case BRESGroupType.ShapeAnim:
                    FSHA fsha = new FSHA();
                    fsha.Text = ResourceName;
                    if (IsWiiU)
                    {
                        fsha.ShapeAnimU = new ResU.ShapeAnim();
                    }
                    else
                    {
                        fsha.ShapeAnim = new ResNX.ShapeAnim();
                    }

                    fsha.Replace(FileName, resFileNX, resFileU);
                    Nodes.Add(fsha);
                    break;

                case BRESGroupType.SceneAnim:
                    FSCN fscn = new FSCN();
                    fscn.Text = ResourceName;
                    if (IsWiiU)
                    {
                        fscn.SceneAnimU = new ResU.SceneAnim();
                    }
                    else
                    {
                        fscn.SceneAnim = new ResNX.SceneAnim();
                    }

                    fscn.Replace(FileName, resFileNX, resFileU);
                    Nodes.Add(fscn);
                    break;

                case BRESGroupType.Embedded:
                    ExternalFileData ext = new ExternalFileData(ResourceName, File.ReadAllBytes(FileName));
                    ext.Replace(FileName);
                    Nodes.Add(ext);
                    break;

                case BRESGroupType.MaterialAnim:
                    FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.ShaderParam);
                    fmaa.Replace(FileName);
                    Nodes.Add(fmaa);
                    break;
                }
            }
        }
Esempio n. 24
0
        public void Replace(string path, bool UseReplaceDialog)
        {
            if (GetResFileU() != null)
            {
                if (UseReplaceDialog)
                {
                    MaterialReplaceDialog dialog = new MaterialReplaceDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        var mat = new ResU.Material();
                        mat.Import(path, GetResFileU());

                        if (PluginRuntime.MaterialReplace.SwapRenderInfos)
                        {
                            MaterialU.RenderInfos = mat.RenderInfos;
                        }
                        if (PluginRuntime.MaterialReplace.SwapShaderOptions)
                        {
                            MaterialU.ShaderAssign = mat.ShaderAssign;
                        }
                        if (PluginRuntime.MaterialReplace.SwapShaderParams)
                        {
                            MaterialU.ShaderParamData = mat.ShaderParamData;
                            MaterialU.ShaderParams    = mat.ShaderParams;
                        }
                        if (PluginRuntime.MaterialReplace.SwapTextures)
                        {
                            MaterialU.ShaderAssign.SamplerAssigns = mat.ShaderAssign.SamplerAssigns;
                            MaterialU.TextureRefs = mat.TextureRefs;
                            MaterialU.Samplers    = mat.Samplers;
                        }
                        if (PluginRuntime.MaterialReplace.SwapUserData)
                        {
                            MaterialU.UserData = mat.UserData;
                        }
                    }
                }
                else
                {
                    MaterialU.Import(path, GetResFileU());
                    MaterialU.Name = Text;
                    BfresWiiU.ReadMaterial(this, MaterialU);
                }
            }
            else
            {
                if (UseReplaceDialog)
                {
                    MaterialReplaceDialog dialog = new MaterialReplaceDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        var mat = new Material();
                        mat.Import(path);

                        if (PluginRuntime.MaterialReplace.SwapRenderInfos)
                        {
                            Material.RenderInfoDict = mat.RenderInfoDict;
                            Material.RenderInfos    = mat.RenderInfos;
                        }
                        if (PluginRuntime.MaterialReplace.SwapShaderOptions)
                        {
                            Material.ShaderAssign = mat.ShaderAssign;
                        }
                        if (PluginRuntime.MaterialReplace.SwapShaderParams)
                        {
                            Material.ShaderParamData = mat.ShaderParamData;
                            Material.ShaderParams    = mat.ShaderParams;
                            Material.ShaderParamDict = mat.ShaderParamDict;
                        }
                        if (PluginRuntime.MaterialReplace.SwapTextures)
                        {
                            Material.ShaderAssign.SamplerAssigns = mat.ShaderAssign.SamplerAssigns;
                            Material.TextureRefs      = mat.TextureRefs;
                            Material.Samplers         = mat.Samplers;
                            Material.SamplerDict      = mat.SamplerDict;
                            Material.SamplerSlotArray = mat.SamplerSlotArray;
                            Material.TextureSlotArray = mat.TextureSlotArray;
                        }
                        if (PluginRuntime.MaterialReplace.SwapUserData)
                        {
                            Material.UserDatas    = mat.UserDatas;
                            Material.UserDataDict = mat.UserDataDict;
                        }
                    }
                }
                else
                {
                    Material.Import(path);
                    Material.Name = Text;
                    BfresSwitch.ReadMaterial(this, Material);
                }
            }
        }
Esempio n. 25
0
        public FMDL NewModel(bool AddTreeNode = true)
        {
            FMDL fmdl = new FMDL();

            if (IsWiiU)
            {
                fmdl.ModelU = new ResU.Model();

                //Create skeleton with empty bone
                var skeleton = new ResU.Skeleton();

                //Create skeleton with empty bone
                skeleton.Bones.Add("Root", new ResU.Bone()
                {
                    Name = "Root"
                });

                fmdl.ModelU.Skeleton = skeleton;

                var shape = new ResU.Shape()
                {
                    Name = "NewShape"
                };
                shape.CreateEmptyMesh();

                var VertexBuffer = new ResU.VertexBuffer();
                VertexBuffer.CreateEmptyVertexBuffer();

                fmdl.ModelU.VertexBuffers.Add(VertexBuffer);
                fmdl.ModelU.Shapes.Add("NewShape", shape);
                fmdl.ModelU.Materials.Add("NewMaterial", new ResU.Material()
                {
                    Name = "NewMaterial", RenderState = new ResU.RenderState(),
                });

                BfresWiiU.ReadModel(fmdl, fmdl.ModelU);
                ((BFRES)Parent).DrawableContainer.Drawables.Add(fmdl.Skeleton);
            }
            else
            {
                fmdl.Model = new ResNX.Model();

                //Create skeleton with empty bone
                var skeleton = new ResNX.Skeleton();

                //Create skeleton with empty bone
                skeleton.Bones.Add(new ResNX.Bone()
                {
                    Name = "Root"
                });

                fmdl.Model.Skeleton = skeleton;

                var shape = new ResNX.Shape()
                {
                    Name = "NewShape"
                };
                shape.CreateEmptyMesh();

                fmdl.Model.Shapes.Add(shape);
                fmdl.Model.Materials.Add(new ResNX.Material()
                {
                    Name = "NewMaterial"
                });

                var VertexBuffer = new ResNX.VertexBuffer();
                VertexBuffer.CreateEmptyVertexBuffer();

                fmdl.Model.VertexBuffers.Add(VertexBuffer);

                BfresSwitch.ReadModel(fmdl, fmdl.Model);
                ((BFRES)Parent).DrawableContainer.Drawables.Add(fmdl.Skeleton);
            }

            if (AddTreeNode)
            {
                AddNode(fmdl, "NewModel");
            }

            return(fmdl);
        }
Esempio n. 26
0
        //Function addes shapes, vertices and meshes
        public void AddOjects(string FileName, ResFile resFileNX, ResU.ResFile resFileU, bool Replace = true)
        {
            int totalSkinCountLimiter = 0;

            bool IsWiiU = (resFileU != null);

            if (shapes.Count > 0)
            {
                totalSkinCountLimiter = shapes[0].VertexSkinCount;
            }

            int    MatStartIndex = materials.Count;
            string ext           = System.IO.Path.GetExtension(FileName);

            ext = ext.ToLower();

            switch (ext)
            {
            case ".bfobj":
                Cursor.Current = Cursors.WaitCursor;

                if (Replace)
                {
                    shapes.Clear();
                    Nodes["FshpFolder"].Nodes.Clear();
                }
                if (IsWiiU)
                {
                    var shpS          = new ResU.Shape();
                    var vertexBufferU = new ResU.VertexBuffer();
                    shpS.Import(FileName, vertexBufferU, resFileU);

                    FSHP shapeS = new FSHP();
                    shapeS.ShapeU = shpS;
                    BfresWiiU.ReadShapesVertices(shapeS, shpS, vertexBufferU, this);
                    shapes.Add(shapeS);
                    Nodes["FshpFolder"].Nodes.Add(shapeS);
                }
                else
                {
                    Shape        shpS         = new Shape();
                    VertexBuffer vertexBuffer = new VertexBuffer();
                    shpS.Import(FileName, vertexBuffer);

                    FSHP shapeS = new FSHP();
                    shapeS.Shape = shpS;
                    BfresSwitch.ReadShapesVertices(shapeS, shpS, vertexBuffer, this);
                    shapes.Add(shapeS);
                    Nodes["FshpFolder"].Nodes.Add(shapeS);
                }

                IsEdited = true;

                Cursor.Current = Cursors.Default;
                break;

            case ".bfmdl":
                Cursor.Current = Cursors.WaitCursor;

                if (Replace)
                {
                    shapes.Clear();
                    Nodes["FshpFolder"].Nodes.Clear();
                    materials.Clear();
                    Nodes["FmatFolder"].Nodes.Clear();
                }

                if (IsWiiU)
                {
                    var mdlU = new ResU.Model();
                    mdlU.Import(FileName, resFileU);
                    mdlU.Name = Text;
                    BfresWiiU.ReadModel(this, mdlU);
                }
                else
                {
                    Model mdl = new Model();
                    mdl.Import(FileName, resFileNX);
                    mdl.Name = Text;

                    Console.WriteLine(mdl.ShapeCount);
                    Console.WriteLine(mdl.MaterialCount);
                    Console.WriteLine(mdl.VertexBufferCount);
                    Console.WriteLine(mdl.Skeleton.Bones.Count);

                    BfresSwitch.ReadModel(this, mdl);
                }
                IsEdited = true;

                Cursor.Current = Cursors.Default;
                break;

            case ".csv":
                CsvModel csvModel = new CsvModel();
                csvModel.LoadFile(new System.IO.FileStream(FileName, System.IO.FileMode.Open), true);

                if (csvModel.objects.Count == 0)
                {
                    MessageBox.Show("No models found!");
                    return;
                }
                BfresModelImportSettings csvsettings = new BfresModelImportSettings();
                csvsettings.DisableMaterialEdits();
                csvsettings.SkinCountLimit = totalSkinCountLimiter;
                csvsettings.SetModelAttributes(csvModel.objects[0]);
                if (csvsettings.ShowDialog() == DialogResult.OK)
                {
                    if (Replace)
                    {
                        shapes.Clear();
                        Nodes["FshpFolder"].Nodes.Clear();
                    }

                    Cursor.Current = Cursors.WaitCursor;

                    foreach (STGenericObject obj in csvModel.objects)
                    {
                        FSHP shape = new FSHP();
                        Nodes["FshpFolder"].Nodes.Add(shape);
                        shapes.Add(shape);

                        shape.VertexBufferIndex = shapes.Count;
                        shape.vertices          = obj.vertices;
                        shape.MaterialIndex     = 0;
                        shape.vertexAttributes  = csvsettings.CreateNewAttributes();
                        shape.BoneIndex         = 0;
                        shape.Text      = obj.ObjectName;
                        shape.lodMeshes = obj.lodMeshes;
                        shape.CreateNewBoundingBoxes();
                        shape.CreateBoneList(obj, this);
                        shape.CreateIndexList(obj, this);
                        //Todo find better way. Currently uses import settings now
                        shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
                        shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
                        shape.BoneIndices     = shape.GetIndices(Skeleton);
                        shape.SaveShape(IsWiiU);
                        shape.SaveVertexBuffer();

                        if (IsWiiU)
                        {
                            shape.ShapeU.SubMeshBoundingIndices = new List <ushort>();
                            shape.ShapeU.SubMeshBoundingIndices.Add(0);
                            shape.ShapeU.SubMeshBoundingNodes = new List <ResU.BoundingNode>();
                            shape.ShapeU.SubMeshBoundingNodes.Add(new ResU.BoundingNode()
                            {
                                LeftChildIndex  = 0,
                                NextSibling     = 0,
                                SubMeshIndex    = 0,
                                RightChildIndex = 0,
                                Unknown         = 0,
                                SubMeshCount    = 1,
                            });
                        }

                        if (IsWiiU)
                        {
                            BfresWiiU.ReadShapesVertices(shape, shape.ShapeU, shape.VertexBufferU, this);
                        }
                        else
                        {
                            BfresSwitch.ReadShapesVertices(shape, shape.Shape, shape.VertexBuffer, this);
                        }
                    }
                    Cursor.Current = Cursors.Default;
                }
                IsEdited = true;

                break;

            default:
                AssimpData assimp = new AssimpData();
                assimp.LoadFile(FileName);

                if (assimp.objects.Count == 0)
                {
                    MessageBox.Show("No models found!");
                    return;
                }
                BfresModelImportSettings settings = new BfresModelImportSettings();
                settings.SetModelAttributes(assimp.objects[0]);
                if (settings.ShowDialog() == DialogResult.OK)
                {
                    bool UseMats = settings.ExternalMaterialPath != string.Empty;

                    if (Replace)
                    {
                        shapes.Clear();
                        Nodes["FshpFolder"].Nodes.Clear();
                    }

                    Cursor.Current = Cursors.WaitCursor;
                    if (Replace && UseMats)
                    {
                        materials.Clear();
                        Nodes["FmatFolder"].Nodes.Clear();
                        MatStartIndex = 0;
                    }
                    if (UseMats)
                    {
                        foreach (STGenericMaterial mat in assimp.materials)
                        {
                            FMAT fmat = new FMAT();

                            if (IsWiiU)
                            {
                                fmat.MaterialU = new ResU.Material();
                                fmat.MaterialU.Import(settings.ExternalMaterialPath, resFileU);
                                BfresWiiU.ReadMaterial(fmat, fmat.MaterialU);
                            }
                            else
                            {
                                fmat.Material = new Material();
                                fmat.Material.Import(settings.ExternalMaterialPath);
                                fmat.ReadMaterial(fmat.Material);
                            }

                            fmat.Text = mat.Text;
                            //Setup placeholder textures
                            //Note we can't add/remove samplers so we must fill these slots
                            foreach (var t in fmat.TextureMaps)
                            {
                                t.wrapModeS = 0;
                                t.wrapModeT = 0;

                                switch (t.Type)
                                {
                                case STGenericMatTexture.TextureType.Diffuse:
                                    t.Name = "Basic_Alb";
                                    break;

                                case STGenericMatTexture.TextureType.Emission:
                                    t.Name = "Basic_Emm";
                                    break;

                                case STGenericMatTexture.TextureType.Normal:
                                    t.Name = "Basic_Nrm";
                                    break;

                                case STGenericMatTexture.TextureType.Specular:
                                    t.Name = "Basic_Spm";
                                    break;

                                case STGenericMatTexture.TextureType.SphereMap:
                                    t.Name = "Basic_Sphere";
                                    break;

                                case STGenericMatTexture.TextureType.Metalness:
                                    t.Name = "Basic_Mtl";
                                    break;

                                case STGenericMatTexture.TextureType.Roughness:
                                    t.Name = "Basic_Rgh";
                                    break;

                                case STGenericMatTexture.TextureType.MRA:
                                    t.Name = "Basic_MRA";
                                    break;

                                case STGenericMatTexture.TextureType.Shadow:
                                    t.Name = "Basic_Bake_st0";
                                    break;

                                case STGenericMatTexture.TextureType.Light:
                                    t.Name = "Basic_Bake_st1";
                                    break;
                                }
                            }

                            if (PluginRuntime.bntxContainers.Count > 0 && Parent != null)
                            {
                                foreach (var node in Parent.Parent.Nodes)
                                {
                                    if (node is BNTX)
                                    {
                                        var bntx = (BNTX)node;

                                        bntx.ImportBasicTextures("Basic_Alb");
                                        bntx.ImportBasicTextures("Basic_Nrm");
                                        bntx.ImportBasicTextures("Basic_Spm");
                                        bntx.ImportBasicTextures("Basic_Sphere");
                                        bntx.ImportBasicTextures("Basic_Mtl");
                                        bntx.ImportBasicTextures("Basic_Rgh");
                                        bntx.ImportBasicTextures("Basic_MRA");
                                        bntx.ImportBasicTextures("Basic_Bake_st0");
                                        bntx.ImportBasicTextures("Basic_Bake_st1");
                                        bntx.ImportBasicTextures("Basic_Emm");
                                    }
                                }
                            }
                            if (PluginRuntime.ftexContainers.Count > 0 && Parent != null)
                            {
                                foreach (var node in Parent.Parent.Nodes)
                                {
                                    if (node is BFRESGroupNode)
                                    {
                                        if (((BFRESGroupNode)node).Type == BRESGroupType.Textures)
                                        {
                                            var ftexCont = (BFRESGroupNode)node;

                                            ftexCont.ImportBasicTextures("Basic_Alb");
                                            ftexCont.ImportBasicTextures("Basic_Nrm");
                                            ftexCont.ImportBasicTextures("Basic_Spm");
                                            ftexCont.ImportBasicTextures("Basic_Sphere");
                                            ftexCont.ImportBasicTextures("Basic_Mtl");
                                            ftexCont.ImportBasicTextures("Basic_Rgh");
                                            ftexCont.ImportBasicTextures("Basic_MRA");
                                            ftexCont.ImportBasicTextures("Basic_Bake_st0");
                                            ftexCont.ImportBasicTextures("Basic_Bake_st1");
                                            ftexCont.ImportBasicTextures("Basic_Emm");
                                        }
                                    }
                                }
                            }

                            foreach (var tex in mat.TextureMaps)
                            {
                                foreach (var t in fmat.TextureMaps)
                                {
                                    if (t.Type == tex.Type)
                                    {
                                        t.Name      = tex.Name;
                                        t.wrapModeS = tex.wrapModeS;
                                        t.wrapModeT = tex.wrapModeT;
                                        t.wrapModeW = tex.wrapModeW;
                                        t.Type      = tex.Type;
                                    }
                                }
                            }

                            List <string> keyList = new List <string>(materials.Keys);
                            fmat.Text = Utils.RenameDuplicateString(keyList, fmat.Text);

                            if (IsWiiU)
                            {
                                fmat.MaterialU.Name = Text;
                                fmat.SetMaterial(fmat.MaterialU, resFileU);
                            }
                            else
                            {
                                fmat.Material.Name = Text;
                                fmat.SetMaterial(fmat.Material);
                            }

                            materials.Add(fmat.Text, fmat);
                            Nodes["FmatFolder"].Nodes.Add(fmat);
                        }
                    }

                    if (settings.ImportBones)
                    {
                        if (assimp.skeleton.bones.Count > 0)
                        {
                            Skeleton.bones.Clear();
                            Skeleton.node.Nodes.Clear();

                            if (IsWiiU)
                            {
                                BfresWiiU.SaveSkeleton(Skeleton, assimp.skeleton.bones);
                            }
                            else
                            {
                                BfresSwitch.SaveSkeleton(Skeleton, assimp.skeleton.bones);
                            }
                        }
                    }

                    if (materials.Count <= 0)
                    {
                        //Force material creation if there is none present
                        FMAT fmat = new FMAT();
                        fmat.Text = "NewMaterial";
                        materials.Add(fmat.Text, fmat);
                        Nodes["FmatFolder"].Nodes.Add(fmat);

                        if (IsWiiU)
                        {
                            fmat.MaterialU      = new ResU.Material();
                            fmat.MaterialU.Name = "NewMaterial";
                            BfresWiiU.ReadMaterial(fmat, fmat.MaterialU);
                        }
                        else
                        {
                            fmat.Material      = new Material();
                            fmat.Material.Name = "NewMaterial";
                            fmat.ReadMaterial(fmat.Material);
                        }
                    }

                    foreach (STGenericObject obj in assimp.objects)
                    {
                        FSHP shape = new FSHP();
                        Nodes["FshpFolder"].Nodes.Add(shape);
                        shapes.Add(shape);

                        shape.VertexBufferIndex = shapes.Count;
                        shape.vertices          = obj.vertices;
                        shape.vertexAttributes  = settings.CreateNewAttributes();
                        shape.BoneIndex         = obj.BoneIndex;

                        STConsole.WriteLine(Text + " " + obj.MaterialIndex);

                        if (UseMats)
                        {
                            shape.MaterialIndex = obj.MaterialIndex + MatStartIndex;
                        }
                        else
                        {
                            shape.MaterialIndex = 0;
                        }

                        if (shape.MaterialIndex >= materials.Count)
                        {
                            shape.MaterialIndex = 0;
                        }

                        shape.Text      = obj.ObjectName;
                        shape.lodMeshes = obj.lodMeshes;
                        shape.CreateNewBoundingBoxes();
                        shape.CreateBoneList(obj, this);
                        shape.CreateIndexList(obj, this);
                        shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex));
                        shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
                        shape.BoneIndices     = shape.GetIndices(Skeleton);

                        shape.SaveShape(IsWiiU);
                        shape.SaveVertexBuffer();

                        if (IsWiiU)
                        {
                            shape.ShapeU.SubMeshBoundingIndices = new List <ushort>();
                            shape.ShapeU.SubMeshBoundingIndices.Add(0);
                            shape.ShapeU.SubMeshBoundingNodes = new List <ResU.BoundingNode>();
                            shape.ShapeU.SubMeshBoundingNodes.Add(new ResU.BoundingNode()
                            {
                                LeftChildIndex  = 0,
                                NextSibling     = 0,
                                SubMeshIndex    = 0,
                                RightChildIndex = 0,
                                Unknown         = 0,
                                SubMeshCount    = 1,
                            });
                        }

                        List <string> keyList = shapes.Select(o => o.Text).ToList();
                        shape.Text = Utils.RenameDuplicateString(keyList, shape.Text);

                        if (IsWiiU)
                        {
                            BfresWiiU.ReadShapesVertices(shape, shape.ShapeU, shape.VertexBufferU, this);
                        }
                        else
                        {
                            BfresSwitch.ReadShapesVertices(shape, shape.Shape, shape.VertexBuffer, this);
                        }
                    }


                    IsEdited = true;

                    Cursor.Current = Cursors.Default;
                }
                break;
            }

            if (IsEdited)
            {
                UpdateVertexData();
            }
        }