コード例 #1
0
        // Meta/Aggregate functions
        public static void ProcessCar(string CarName, string DisplayName, string InRoot, string OutParent, float ChassisOffset = 0.5f, Vector3 frontOffset = null, Vector3 backOffset = null)
        {
            frontOffset = frontOffset ?? Vector3.Zero;
            backOffset  = backOffset ?? Vector3.Zero;

            string outPath = OutParent + "\\" + CarName + "\\";

            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }

            ProcessTEX(InRoot + "CARS\\TEX\\" + CarName + ".TEX", outPath, out CpsxTex[] psxTex);
            //ProcessTEX(InRoot + "RUNTIME\\GFX\\MODELS\\TEX\\" + CarName + ".TEX", outPath, out psxTex);
            ProcessMOD(InRoot + "CARS\\MOD\\" + CarName + ".MOD", outPath, psxTex, 0.00165f);

            int datCount = new DirectoryInfo(outPath).GetFiles("*_00.dat").Length;

            DAT dChassis = DAT.Load(outPath + CarName + "_cell00_00.dat");
            DAT dFRWheel = DAT.Load(outPath + CarName + "_cell01_00.dat");
            DAT dFLWheel = DAT.Load(outPath + CarName + "_cell01_00.dat");
            DAT dRRWheel = DAT.Load(outPath + CarName + "_cell0" + (datCount > 2 ? "2" : "1") + "_00.dat");
            DAT dRLWheel = DAT.Load(outPath + CarName + "_cell0" + (datCount > 2 ? "2" : "1") + "_00.dat");
            DAT car      = new DAT();

            dChassis.DatMeshes[0].Name = DisplayName + "PSX.dat";
            dFRWheel.DatMeshes[0].Name = "FRWHEEL.DAT";
            dFLWheel.DatMeshes[0].Name = "FLWHEEL.DAT";
            dRRWheel.DatMeshes[0].Name = "RRWHEEL.DAT";
            dRLWheel.DatMeshes[0].Name = "RLWHEEL.DAT";

            dChassis.DatMeshes[0].Mesh.Translate(new Vector3(0, -dChassis.DatMeshes[0].Mesh.Extents.Min.Y + (Math.Max(dFRWheel.DatMeshes[0].Mesh.Extents.Max.Y, dRRWheel.DatMeshes[0].Mesh.Extents.Max.Y) * ChassisOffset), 0));
            //dFRWheel.DatMeshes[0].Mesh.Translate(new Vector3(frontOffset.X, dFRWheel.DatMeshes[0].Mesh.Extents.Max.Y, frontOffset.Z));
            //dFLWheel.DatMeshes[0].Mesh.Translate(new Vector3(-frontOffset.X, dFLWheel.DatMeshes[0].Mesh.Extents.Max.Y, frontOffset.Z));
            //dRRWheel.DatMeshes[0].Mesh.Translate(new Vector3(backOffset.X, dRRWheel.DatMeshes[0].Mesh.Extents.Max.Y, backOffset.Z));
            //dRLWheel.DatMeshes[0].Mesh.Translate(new Vector3(-backOffset.X, dRLWheel.DatMeshes[0].Mesh.Extents.Max.Y, backOffset.Z));

            dChassis.DatMeshes[0].Mesh.GenerateKDOP(18);
            SaveBoundingBox(dChassis.DatMeshes[0].Mesh.intersectionPoints, outPath + DisplayName + "PSX_BB.txt");
            //ACT kdop = new ACT();
            //kdop.AddRootNode("pointcloud");
            //for (int i = 0; i < dChassis.DatMeshes[0].Mesh.intersectionPoints.Count; i++)
            //{
            //    Matrix3D m = Matrix3D.Identity;
            //    m.Scale = 0.05f;
            //    m.Position = dChassis.DatMeshes[0].Mesh.intersectionPoints[i];

            //    kdop.AddActor("p" + i, "Sphere_48", m, false);
            //}
            //kdop.Save("D:\\kdop.act");

            dChassis.DatMeshes[0].Mesh.ProcessMesh();
            Console.WriteLine(dChassis.DatMeshes[0].Mesh.Extents);

            car.DatMeshes.Add(dChassis.DatMeshes[0]);
            car.DatMeshes.Add(dFRWheel.DatMeshes[0]);
            car.DatMeshes.Add(dFLWheel.DatMeshes[0]);
            car.DatMeshes.Add(dRRWheel.DatMeshes[0]);
            car.DatMeshes.Add(dRLWheel.DatMeshes[0]);
            car.Optimise();
            car.Save(outPath + DisplayName + "PSX.dat");

            C2Mesh mSimple = new C2Mesh();

            mSimple.BuildFromExtents(car.DatMeshes[0].Mesh.Extents);
            DAT dSimple = new DAT(new DatMesh(DisplayName + "PSX.1", mSimple));

            dSimple.Save(outPath + "simple_" + DisplayName + "PSX.dat");

            ACT aSimple = new ACT();

            aSimple.AddActor(DisplayName + "PSX.1", DisplayName + "PSX.1", Matrix3D.Identity, true);
            aSimple.Save(outPath + "simple_" + DisplayName + "PSX.act");

            dChassis.DatMeshes[0].Name = "SHELL";
            DAT shell = new DAT();

            shell.DatMeshes.Add(dChassis.DatMeshes[0]);
            shell.Optimise();
            shell.Save(outPath + DisplayName + "PSXshell.dat");

            ACT a = new ACT();

            a.AddActor(DisplayName + "PSX.dat", DisplayName + "PSX.dat", Matrix3D.Identity, true);
            a.AddActor("RRWHEEL.ACT", "RRWHEEL.DAT", new Matrix3D(car.DatMeshes[3].Mesh.Centre + new Vector3(backOffset.X, dRRWheel.DatMeshes[0].Mesh.Extents.Max.Y, backOffset.Z)), false);
            a.AddActor("RLWHEEL.ACT", "RLWHEEL.DAT", new Matrix3D(car.DatMeshes[4].Mesh.Centre + new Vector3(-backOffset.X, dRLWheel.DatMeshes[0].Mesh.Extents.Max.Y, backOffset.Z)), false);
            a.AddPivot("FRPIVOT.ACT", "FRWHEEL.ACT", "FRWHEEL.DAT", new Matrix3D(car.DatMeshes[1].Mesh.Centre + new Vector3(frontOffset.X, dFRWheel.DatMeshes[0].Mesh.Extents.Max.Y, frontOffset.Z)));
            a.AddPivot("FLPIVOT.ACT", "FLWHEEL.ACT", "FLWHEEL.DAT", new Matrix3D(car.DatMeshes[2].Mesh.Centre + new Vector3(-frontOffset.X, dFLWheel.DatMeshes[0].Mesh.Extents.Max.Y, frontOffset.Z)));
            a.Save(outPath + DisplayName + "PSX.act");
        }