static Stream ConvertKCL(Stream data)
        {
            KCLFile kcl = new KCLFile(data);

            kcl.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
            var mem = new MemoryStream();

            kcl.Save(mem);
            return(mem);
        }
        public static void SaveKCL(KCLFile kcl, string fileName,
                                   MaterialAttributeFileBase AttributeFile)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = "Supported Formats|*.kcl;";
            sfd.FileName = Path.GetFileNameWithoutExtension(fileName);
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                kcl.Save(sfd.FileName);
                if (AttributeFile != null)
                {
                    AttributeFile.Save(AttributeFile.SetupFileName(sfd.FileName));
                }
            }
        }
Ejemplo n.º 3
0
        static void ReimportCollison(string fileName, FileVersion version, bool bigEndian, CollisionImportSettings settings = null)
        {
            var kcl = new KCLFile(fileName);

            Console.WriteLine($"Smallest Cube Size {kcl.Models[0].GetMinCubeSize()}");
            Console.WriteLine($"Max Tri {kcl.Models[0].GetMaxTriangleCount()}");
            Console.WriteLine($"Padding Size {kcl.Models[0].GetCoordinatePadding()}");
            Console.WriteLine($"Depth {kcl.Models[0].GetMaxOctreeDepth()}");

            var obj = kcl.CreateGenericModel();

            obj.Save($"{fileName}.obj");

            var triangles = obj.ToTriangles();

            kcl = new KCLFile(triangles, version, bigEndian, settings);
            kcl.Save($"{fileName}.new.kcl");
        }
Ejemplo n.º 4
0
        //Exports the collision model as obj and reimports it into a new generated collision file.

        static void ReimportCollisonTPGC(string fileName)
        {
            var kcl = new KCLFile(fileName);

            Dictionary <int, ushort> materialIds = new Dictionary <int, ushort>();

            for (int i = 0; i < kcl.Models[0].Prisms.Length; i++)
            {
                materialIds.Add(i, kcl.Models[0].Prisms[i].CollisionFlags);
            }

            var obj = kcl.CreateGenericModel();

            //Export the kcl to a generic object file
            obj.Save($"{fileName}.obj");


            var settings = new CollisionImportSettings()
            {
                //Octree Settings
                PaddingMax         = new System.Numerics.Vector3(1, 1, 1),
                PaddingMin         = new System.Numerics.Vector3(-1, -1, -1),
                MaxRootSize        = 1024,
                MinRootSize        = 128,
                MinCubeSize        = 128,
                MaxTrianglesInCube = 50,
                //Model Settings
                PrismThickness = 1,
            };

            var triangles = obj.ToTriangles();

            kcl = new KCLFile(triangles, FileVersion.VersionGC, true, settings);
            for (int i = 0; i < kcl.Models[0].Prisms.Length; i++)
            {
                kcl.Models[0].Prisms[i].CollisionFlags = materialIds[i];
            }

            kcl.Save($"{fileName}.new.kcl");
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            bool bigEndian = args.Contains("-be");

            foreach (var file in args)
            {
                string ext  = Path.GetExtension(file);
                string name = file.Replace(ext, string.Empty);
                if (ext == ".obj")
                {
                    var obj = new ObjModel(file);
                    var kcl = new KCLFile(obj.ToTriangles(), FileVersion.Version2, bigEndian);
                    kcl.Save($"{name}.kcl");
                }
                if (ext == ".kcl")
                {
                    var kcl = new KCLFile(file);
                    var obj = kcl.CreateGenericModel();
                    obj.Save($"{name}.obj");
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var cmdArgs = new CommandLineArguments();

            if (args.Length == 0 || args.Contains("-h"))
            {
                cmdArgs.PrintHelp();
                return;
            }
            if (args.Contains("-adv"))
            {
                cmdArgs.PrintAdvanced();
                return;
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-import")
                {
                    cmdArgs.Import = true;
                }
                if (args[i] == "-export")
                {
                    cmdArgs.Export = true;
                }
                if (args[i].EndsWith(".obj"))
                {
                    cmdArgs.ObjectFilePath = args[i];
                }
                if (args[i].EndsWith(".kcl"))
                {
                    cmdArgs.CollisionFile = args[i];
                }
                if (args[i] == "-meshAtt")
                {
                    //2 required arguments afterwards
                    cmdArgs.MeshesToAttributes.Add(args[i + 1], ushort.Parse(args[i + 2]));
                }
                if (args[i] == "-matAtt")
                {
                    //2 required arguments afterwards
                    cmdArgs.MaterialsToAttributes.Add(args[i + 1], ushort.Parse(args[i + 2]));
                }

                //Endianness
                if (args[i] == "-le")
                {
                    cmdArgs.BigEndian = false;
                }
                //Platform
                if (args[i] == "-ds")
                {
                    cmdArgs.IsDS = true;
                }
                if (args[i] == "-wii")
                {
                    cmdArgs.IsWii = true;
                }
                if (args[i] == "-gcn")
                {
                    cmdArgs.IsGCN = true;
                }
                if (args[i] == "-3ds")
                {
                    cmdArgs.Is3DS = true;
                }

                //Octree and prism settings
                if (args[i] == "-padding")
                {
                    cmdArgs.PaddingSize = float.Parse(args[i + 1]);
                }
                if (args[i] == "-max_root")
                {
                    cmdArgs.MaxRootSize = int.Parse(args[i + 1]);
                }
                if (args[i] == "-min_root")
                {
                    cmdArgs.MinRootSize = int.Parse(args[i + 1]);
                }
                if (args[i] == "-min_cube")
                {
                    cmdArgs.MinCubeSize = int.Parse(args[i + 1]);
                }
                if (args[i] == "-thickness")
                {
                    cmdArgs.PrismThickness = int.Parse(args[i + 1]);
                }
                if (args[i] == "-radius")
                {
                    cmdArgs.SphereRadius = int.Parse(args[i + 1]);
                }
            }

            if (cmdArgs.Export && !string.IsNullOrEmpty(cmdArgs.CollisionFile))
            {
                Console.WriteLine($"Exporting OBJ from KCL {cmdArgs.CollisionFile} obj {cmdArgs.ObjectFilePath}");

                var kcl = new KCLFile(cmdArgs.CollisionFile);
                var obj = kcl.CreateGenericModel();
                //Export the kcl to a generic object file
                obj.Save(cmdArgs.ObjectFilePath);
            }
            if (cmdArgs.Import && !string.IsNullOrEmpty(cmdArgs.ObjectFilePath))
            {
                Console.WriteLine($"Importing OBJ to KCL {cmdArgs.ObjectFilePath}");

                var settings = new CollisionImportSettings()
                {
                    //Octree Settings
                    PaddingMax         = new System.Numerics.Vector3(cmdArgs.PaddingSize),
                    PaddingMin         = new System.Numerics.Vector3(-cmdArgs.PaddingSize),
                    MaxRootSize        = cmdArgs.MaxRootSize,
                    MinRootSize        = cmdArgs.MinRootSize,
                    MinCubeSize        = cmdArgs.MinCubeSize,
                    MaxTrianglesInCube = cmdArgs.MaxTrianglesInCube,
                    //Model Settings
                    PrismThickness = cmdArgs.PrismThickness,
                    SphereRadius   = cmdArgs.SphereRadius,
                };

                FileVersion version = FileVersion.Version2;
                if (cmdArgs.IsDS)
                {
                    version = FileVersion.VersionDS;
                }
                if (cmdArgs.IsWii)
                {
                    version = FileVersion.VersionWII;
                }
                if (cmdArgs.IsGCN)
                {
                    version = FileVersion.VersionGC;
                }
                if (cmdArgs.Is3DS)
                {
                    version = FileVersion.VersionWII;
                }

                if (cmdArgs.Is3DS)
                {
                    cmdArgs.BigEndian = false;
                }

                var obj = new ObjModel(cmdArgs.ObjectFilePath);
                var kcl = new KCLFile(obj.ToTriangles(), version, cmdArgs.BigEndian, settings);
                kcl.Save(cmdArgs.CollisionFile);
            }
        }