Ejemplo n.º 1
0
        public override void Export(Asset asset, string path)
        {
            var model = (asset as Model);
            var act = new ACT();

            TravelTree(model.Root, ref act, true);

            act.Save(path);
        }
Ejemplo n.º 2
0
        public static void TravelTree(ModelBone bone, ref ACT act, bool root = false)
        {
            act.AddActor(
                bone.Name,
                (bone.Type == BoneType.Mesh && bone.Mesh != null ? bone.Mesh.Name : null),
                new Matrix3D(
                    bone.Transform.M11, bone.Transform.M21, bone.Transform.M31,
                    bone.Transform.M12, bone.Transform.M22, bone.Transform.M32,
                    bone.Transform.M13, bone.Transform.M23, bone.Transform.M33,
                    bone.Transform.M41, bone.Transform.M42, bone.Transform.M43
                ),
                true
            );

            foreach (var b in bone.Children)
            {
                TravelTree(b, ref act);
                act.AddSubLevelEnd();
            }
        }
Ejemplo n.º 3
0
        public static void ProcessOBJ(string PathIn, string PathOut, Single scale)
        {
            string pathIn = PathIn.Substring(0, PathIn.LastIndexOf("\\") + 1);
            string fileIn = PathIn.Replace(pathIn, "");

            BinaryReader br = new BinaryReader(new FileStream(pathIn + fileIn, FileMode.Open));
            bool bDebug = false;

            ACT a1 = new ACT();
            ACT a2 = new ACT();
            ACT a7 = new ACT();
            ACT a8 = new ACT();
            ACT a9 = new ACT();
            ACT a13 = new ACT();

            a1.AddRootNode("Type1");
            a2.AddRootNode("Type2");
            a7.AddRootNode("Type7");
            a8.AddRootNode("Type8");
            a9.AddRootNode("Type9");
            a13.AddRootNode("Type13");

            br.ReadInt32(); // always 0
            int objCount = br.ReadInt32();

            for (int i = 0; i < objCount; i++)
            {
                int oType = br.ReadInt32();

                //switch (oType)
                //{
                //    case 1:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 2:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 7:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 8:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 9:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 10:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 12:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 13:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    case 14:
                //        br.ReadBytes(108);
                //        continue;
                //        break;

                //    default:
                //        Console.WriteLine("Unknown type " + oType);
                //        return;
                //        break;
                //}

                if (bDebug)
                {
                    Console.Write(fileIn + "\t");
                    Console.Write(oType + "\t");
                    Console.Write(i + "\t");
                }

                if (br.ReadInt32() != 0) { Console.WriteLine("Byte A not zero!"); }
                if (br.ReadInt32() != 0) { Console.WriteLine("Byte B not zero!"); }

                Vector3 pos = new Vector3(-br.ReadInt32(), br.ReadInt32(), br.ReadInt32()) * scale;

                if (bDebug)
                {
                    Console.Write(br.ReadInt32() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                }
                else
                {
                    br.ReadBytes(6);
                }

                int rotateY = br.ReadInt16();
                if (bDebug)
                {
                    Console.Write(rotateY + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                }
                else
                {
                    br.ReadBytes(4);
                }

                if (br.ReadInt32() != 0) { Console.WriteLine("Byte D not zero!"); }
                if (br.ReadInt32() != 0) { Console.WriteLine("Byte E not zero!"); }
                if (br.ReadInt32() != 0) { Console.WriteLine("Byte F not zero!"); }
                if (br.ReadInt32() != 0) { Console.WriteLine("Byte G not zero!"); }
                if (br.ReadInt32() != 0) { Console.WriteLine("Byte H not zero!"); }
                int index = br.ReadInt16();

                if (bDebug)
                {
                    Console.Write(index + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt16() + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                    Console.Write(br.ReadInt32() + "\t");
                    Console.WriteLine(br.ReadInt32());
                }
                else
                {
                    br.ReadBytes(54);
                }

                switch (oType)
                {
                    case 1:
                        a1.AddActor("a1" + i, "Sphere_48", new Matrix3D(pos), false);
                        break;

                    case 2:
                        Matrix3D m = Matrix3D.Identity;// Matrix3D.CreateRotationY(-rotateY / 11.4f);
                        m.Position = pos;
                        a2.AddActor("a2" + i, "cell" + index.ToString().PadLeft(2, "0"[0]) + "_00", m, false);
                        break;

                    case 7:
                        a7.AddActor("a7" + i, "Sphere_48", new Matrix3D(pos), false);
                        break;

                    case 8:
                        a8.AddActor("a8" + i, "Sphere_48", new Matrix3D(pos), false);
                        break;

                    case 9:
                        a9.AddActor("a9" + i, "Sphere_48", new Matrix3D(pos), false);
                        break;

                    case 13:
                        a13.AddActor("a13" + i, "Sphere_48", new Matrix3D(pos), false);
                        break;
                }
            }

            a1.Save(PathOut + "\\1.act");
            a2.Save(PathOut + "\\2.act");
            a7.Save(PathOut + "\\7.act");
            a8.Save(PathOut + "\\8.act");
            a9.Save(PathOut + "\\9.act");
            a13.Save(PathOut + "\\13.act");

            br.Close();
        }
Ejemplo n.º 4
0
        // Meta/Aggregate functions
        public static void ProcessCar(string CarName, string DisplayName, string InRoot, string OutParent, Single 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); }
            cpsxTex[] psxTex;

            gameCarmaPSX.ProcessTEX(InRoot + "CARS\\TEX\\" + CarName + ".TEX", outPath, out psxTex);
            //gameCarmaPSX.ProcessTEX(InRoot + "RUNTIME\\GFX\\MODELS\\TEX\\" + CarName + ".TEX", outPath, out psxTex);
            gameCarmaPSX.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");
        }
Ejemplo n.º 5
0
        public static ACT Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            ACT act = new ACT();

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x8 ||
                    br.ReadUInt32() != 0x1 ||
                    br.ReadUInt32() != 0x2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid ACT file", path);
                    return(null);
                }

                ACTNode a;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    Section tag = (Section)br.ReadUInt32();
                    int     _   = (int)br.ReadUInt32();

                    a = new ACTNode(tag);

                    switch (tag)
                    {
                    case Section.Name:      // 00 00 00 23
                        a.ActorType   = (ActorType)br.ReadByte();
                        a.RenderStyle = (RenderStyle)br.ReadByte();
                        a.Identifier  = br.ReadString();
                        if (a.Identifier.Length == 0)
                        {
                            a.Identifier = "NO_IDENTIFIER";
                        }
                        break;

                    case Section.Model:
                        a.Model = br.ReadString();
                        break;

                    case Section.Section37:     // 00 00 00 25
                        break;

                    case Section.Material:
                        a.Material = br.ReadString();
                        break;

                    case Section.SubLevelBegin:     // 00 00 00 29
                        break;

                    case Section.SubLevelEnd:
                        break;

                    case Section.Matrix:     // 00 00 00 2B
                        a.Transform = new Matrix3D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        break;

                    case Section.BoundingBox:     // 00 00 00 32
                        a.Bounds = new MeshExtents(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        break;

                    case Section.EOF:
                        break;

                    default:
                        Console.WriteLine("Unknown ACT tag: {0} ({1} of {2})", tag, br.BaseStream.Position, br.BaseStream.Length);
                        return(null);
                    }

                    act.Sections.Add(a);
                }
            }

            return(act);
        }
Ejemplo n.º 6
0
        public static ACT Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            ACT act = new ACT();

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x8 ||
                    br.ReadUInt32() != 0x1 ||
                    br.ReadUInt32() != 0x2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid ACT file", path);
                    return null;
                }

                ACTNode a;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    Section tag = (Section)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    a = new ACTNode(tag);

                    switch (tag)
                    {
                        case Section.Name:  // 00 00 00 23
                            a.ActorType = (ActorType)br.ReadByte();
                            a.RenderStyle = (RenderStyle)br.ReadByte();
                            a.Identifier = br.ReadString();
                            if (a.Identifier.Length == 0) { a.Identifier = "NO_IDENTIFIER"; }
                            break;

                        case Section.Model:
                            a.Model = br.ReadString();
                            break;

                        case Section.Section37: // 00 00 00 25
                            break;

                        case Section.Material:
                            a.Material = br.ReadString();
                            break;

                        case Section.SubLevelBegin: // 00 00 00 29
                            break;

                        case Section.SubLevelEnd:
                            break;

                        case Section.Matrix: // 00 00 00 2B
                            a.Transform = new Matrix3D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            break;

                        case Section.BoundingBox: // 00 00 00 32
                            a.Bounds = new MeshExtents(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                            break;

                        case Section.EOF:
                            break;

                        default:
                            Console.WriteLine("Unknown ACT tag: {0} ({1} of {2})", tag, br.BaseStream.Position, br.BaseStream.Length);
                            return null;
                    }

                    act.sections.Add(a);
                }
            }

            return act;
        }