/// <summary> /// Exports the single map data. /// </summary> /// <param name="name">The name.</param> public void ExportSingleMapData(string Id) { try { foreach (var zn in Tasks.RandomPathTask.Options.Zones) { if (zn.id.ToString() == Id) { Logger.AddDebugText(Tc.rtbDebug, string.Format(@"Exporting {0} ID= {1}", zn.name, zn.id.ToString())); string str = zn.path.Replace(@"\", @"/"); if (zn.name != "NILL" && zn.path != "NILL" && !File.Exists(string.Format(@"Map Collision obj\{0}.obj", zn.name))) { Filename = zn.id.ToString(); dat = null; dat = new DAT(this, zn.id.ToString()); String[] foos = new String[] { str }; dat.Load(foos); } } } } catch (Exception ex) { Logger.AddDebugText(Tc.rtbDebug, string.Format(@"{0} Best comment out {1} from ZoneList.xml save it,reload and try again. Please use noesis to export that map", ex.ToString(), Filename)); } }
public void LoadDATs() { if (PlayerPortDAT.loadfile == "") { if (config.AutoLoad_PlayerPort[(int)model.FileVersion]) { PlayerPortDAT.loadfile = config.PlayerPortFiles[(int)model.FileVersion]; PlayerPortDAT.Load(); } } if (CoachPortDAT.loadfile == "") { if (config.AutoLoad_CoachPort[(int)model.FileVersion]) { CoachPortDAT.loadfile = config.CoachPortFiles[(int)model.FileVersion]; CoachPortDAT.Load(); } } }
/// <summary> /// Exports the map data. /// </summary> public void ExportMapData() { try { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); foreach (var zn in Tasks.RandomPathTask.Options.Zones) { Logger.AddDebugText(Tc.rtbDebug, string.Format(@"Exporting {0} ID= {1}", zn.name, zn.id.ToString())); string str = zn.path.Replace(@"\", @"/"); if (zn.name != "NILL" && zn.path != "NILL" && !File.Exists(string.Format(@"Map Collision obj\{0}.obj", zn.name))) { Filename = zn.id.ToString(); dat = new DAT(this, zn.id.ToString()); String[] foos = new String[] { str }; dat.Load(foos); } } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Logger.AddDebugText(Tc.rtbDebug, string.Format(@"Finished dumping all zones collision data .obj's")); Logger.AddDebugText(Tc.rtbDebug, string.Format(@"Time Taken to dump zones collision data .obj's = " + elapsedTime)); } catch (Exception ex) { Logger.AddDebugText(Tc.rtbDebug, string.Format(@"{0} Best comment out {1} from ZoneList.xml save it,reload and try again. Please use noesis to export that map", ex.ToString(), Filename)); } }
public override Asset Import(string path) { DAT dat = DAT.Load(path); SceneManager.Current.Content.LoadMany <MaterialList, MaterialImporter>(Path.GetFileName(path).Replace(".dat", ".mat", StringComparison.OrdinalIgnoreCase), Path.GetDirectoryName(path) + "\\", true); Model model = new Model(); foreach (var datmesh in dat.DatMeshes) { Console.WriteLine(datmesh.Name); datmesh.Mesh.GenerateNormals(); ModelMesh mesh = new ModelMesh(); mesh.Name = (datmesh.Name.Contains(".") ? datmesh.Name.Substring(0, datmesh.Name.IndexOf(".")) : datmesh.Name); SceneManager.Current.UpdateProgress(string.Format("Processing {0}", mesh.Name)); for (int i = -1; i < datmesh.Mesh.Materials.Count; i++) { var meshpart = new ModelMeshPart(); if (i > -1) { var material = SceneManager.Current.Materials.Entries.Find(m => m.Name == datmesh.Mesh.Materials[i]); if (material == null) { material = new Material { Name = datmesh.Mesh.Materials[i] }; SceneManager.Current.Add(material); } meshpart.Material = (Material)material; } foreach (var face in datmesh.Mesh.Faces.Where(f => f.MaterialID == i)) { int smoothingGroup = (face.SmoothingGroup << 8); meshpart.AddFace( new OpenTK.Vector3[] { new OpenTK.Vector3(datmesh.Mesh.Verts[face.V1].X, datmesh.Mesh.Verts[face.V1].Y, datmesh.Mesh.Verts[face.V1].Z), new OpenTK.Vector3(datmesh.Mesh.Verts[face.V2].X, datmesh.Mesh.Verts[face.V2].Y, datmesh.Mesh.Verts[face.V2].Z), new OpenTK.Vector3(datmesh.Mesh.Verts[face.V3].X, datmesh.Mesh.Verts[face.V3].Y, datmesh.Mesh.Verts[face.V3].Z) }, new OpenTK.Vector3[] { new OpenTK.Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V1].X, datmesh.Mesh.Normals[smoothingGroup + face.V1].Y, datmesh.Mesh.Normals[smoothingGroup + face.V1].Z), new OpenTK.Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V2].X, datmesh.Mesh.Normals[smoothingGroup + face.V2].Y, datmesh.Mesh.Normals[smoothingGroup + face.V2].Z), new OpenTK.Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V3].X, datmesh.Mesh.Normals[smoothingGroup + face.V3].Y, datmesh.Mesh.Normals[smoothingGroup + face.V3].Z) }, new OpenTK.Vector2[] { (datmesh.Mesh.HasUVs ? new OpenTK.Vector2(datmesh.Mesh.UVs[face.UV1].X, datmesh.Mesh.UVs[face.UV1].Y) : OpenTK.Vector2.Zero), (datmesh.Mesh.HasUVs ? new OpenTK.Vector2(datmesh.Mesh.UVs[face.UV2].X, datmesh.Mesh.UVs[face.UV2].Y) : OpenTK.Vector2.Zero), (datmesh.Mesh.HasUVs ? new OpenTK.Vector2(datmesh.Mesh.UVs[face.UV3].X, datmesh.Mesh.UVs[face.UV3].Y) : OpenTK.Vector2.Zero) } ); } mesh.AddModelMeshPart(meshpart, false); } for (int i = mesh.MeshParts.Count - 1; i >= 0; i--) { if (mesh.MeshParts[i].VertexCount == 0) { mesh.MeshParts.RemoveAt(i); } else { mesh.MeshParts[i].Finalise(); } } model.SetName(mesh.Name, model.AddMesh(mesh)); } return(model); }
// 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"); }
public override Asset Import(string path) { DAT dat = DAT.Load(path); SceneManager.Current.Content.LoadMany <MaterialList, MATImporter>($"{Path.GetFileNameWithoutExtension(path)}.mat", Path.GetDirectoryName(path), true); Model model = new Model(); model.SupportingDocuments.Add("Source", dat); foreach (DatMesh datmesh in dat.DatMeshes) { Console.WriteLine(datmesh.Name); datmesh.Mesh.GenerateNormals(); ModelMesh mesh = new ModelMesh { Name = datmesh.Name }; SceneManager.Current.UpdateProgress($"Processing {mesh.Name}"); for (int i = -1; i < datmesh.Mesh.Materials.Count; i++) { ModelMeshPart meshpart = new ModelMeshPart(); if (i > -1) { Asset material = SceneManager.Current.Materials.Entries.Find(m => m != null && m.Name == datmesh.Mesh.Materials[i]); if (material == null) { material = new Material { Name = datmesh.Mesh.Materials[i] }; SceneManager.Current.Add(material); } meshpart.Material = (Material)material; } foreach (ToxicRagers.Carmageddon2.Helpers.C2Face face in datmesh.Mesh.Faces.Where(f => f.MaterialID == i)) { int smoothingGroup = (face.SmoothingGroup << 8); meshpart.AddFace( new Vector3[] { new Vector3(datmesh.Mesh.Verts[face.V1].X, datmesh.Mesh.Verts[face.V1].Y, datmesh.Mesh.Verts[face.V1].Z), new Vector3(datmesh.Mesh.Verts[face.V2].X, datmesh.Mesh.Verts[face.V2].Y, datmesh.Mesh.Verts[face.V2].Z), new Vector3(datmesh.Mesh.Verts[face.V3].X, datmesh.Mesh.Verts[face.V3].Y, datmesh.Mesh.Verts[face.V3].Z) }, new Vector3[] { new Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V1].X, datmesh.Mesh.Normals[smoothingGroup + face.V1].Y, datmesh.Mesh.Normals[smoothingGroup + face.V1].Z), new Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V2].X, datmesh.Mesh.Normals[smoothingGroup + face.V2].Y, datmesh.Mesh.Normals[smoothingGroup + face.V2].Z), new Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V3].X, datmesh.Mesh.Normals[smoothingGroup + face.V3].Y, datmesh.Mesh.Normals[smoothingGroup + face.V3].Z) }, new Vector2[] { (datmesh.Mesh.HasUVs ? new Vector2(datmesh.Mesh.UVs[face.UV1].X, datmesh.Mesh.UVs[face.UV1].Y) : Vector2.Zero), (datmesh.Mesh.HasUVs ? new Vector2(datmesh.Mesh.UVs[face.UV2].X, datmesh.Mesh.UVs[face.UV2].Y) : Vector2.Zero), (datmesh.Mesh.HasUVs ? new Vector2(datmesh.Mesh.UVs[face.UV3].X, datmesh.Mesh.UVs[face.UV3].Y) : Vector2.Zero) } ); } mesh.AddModelMeshPart(meshpart, false); } for (int i = mesh.MeshParts.Count - 1; i >= 0; i--) { if (mesh.MeshParts[i].VertexCount == 0) { mesh.MeshParts.RemoveAt(i); } else { mesh.MeshParts[i].Finalise(); } } model.SetName(mesh.Name, model.AddMesh(mesh)); } return(model); }