public static void MarioKart_MK7_KCL_Regenerate(String OrigPath, String NewPath) { MK7.KCL oldkcl = new MK7.KCL(File.ReadAllBytes(OrigPath)); List <LibEveryFileExplorer._3D.Triangle> trilist = new List <LibEveryFileExplorer._3D.Triangle>(); foreach (var v in oldkcl.Planes) { trilist.Add(oldkcl.GetTriangle(v)); } oldkcl.Octree = KCLOctree.FromTriangles(trilist.ToArray(), oldkcl.Header, 2048, 128, 32, 10, null, null); File.WriteAllBytes(NewPath, oldkcl.Write()); }
private void KCLToObj(object sender, EventArgs e) { OpenFileDialog opn = new OpenFileDialog(); if (opn.ShowDialog() != DialogResult.OK) { return; } var kcl = new MarioKart.MK7.KCL(File.ReadAllBytes(opn.FileName)); #if DEBUG using (StreamWriter f = new System.IO.StreamWriter(opn.FileName + ".obj")) kcl.ToOBJ().toWritableObj().WriteObj(f, null); #else kcl.ToOBJ().toWritableObj().WriteObj(opn.FileName + ".obj"); #endif }
public static KCL FromOBJ(OBJ o) { KCL res = new KCL(); res.GlobalHeader = new KCLModel.KCLModelHeader(); Vector3D min = new Vector3D(float.MaxValue, float.MaxValue, float.MaxValue); Vector3D max = new Vector3D(float.MinValue, float.MinValue, float.MinValue); var MatDictionary = MaterialSetForm.ShowForm(o.MaterialNames); List <Triangle> Triangles = new List <Triangle>(); foreach (var v in o.Faces) { var coll = MatDictionary.ContainsKey(v.Mat) ? MatDictionary[v.Mat] : (ushort)0; if (coll == ushort.MaxValue) { continue; } Triangle t = new Triangle(v.VA.pos, v.VB.pos, v.VC.pos); t.Collision = coll; #region FindMaxMin if (t.PointA.X < min.X) { min.X = t.PointA.X; } if (t.PointA.Y < min.Y) { min.Y = t.PointA.Y; } if (t.PointA.Z < min.Z) { min.Z = t.PointA.Z; } if (t.PointA.X > max.X) { max.X = t.PointA.X; } if (t.PointA.Y > max.Y) { max.Y = t.PointA.Y; } if (t.PointA.Z > max.Z) { max.Z = t.PointA.Z; } if (t.PointB.X < min.X) { min.X = t.PointB.X; } if (t.PointB.Y < min.Y) { min.Y = t.PointB.Y; } if (t.PointB.Z < min.Z) { min.Z = t.PointB.Z; } if (t.PointB.X > max.X) { max.X = t.PointB.X; } if (t.PointB.Y > max.Y) { max.Y = t.PointB.Y; } if (t.PointB.Z > max.Z) { max.Z = t.PointB.Z; } if (t.PointC.X < min.X) { min.X = t.PointC.X; } if (t.PointC.Y < min.Y) { min.Y = t.PointC.Y; } if (t.PointC.Z < min.Z) { min.Z = t.PointC.Z; } if (t.PointC.X > max.X) { max.X = t.PointC.X; } if (t.PointC.Y > max.Y) { max.Y = t.PointC.Y; } if (t.PointC.Z > max.Z) { max.Z = t.PointC.Z; } #endregion Triangles.Add(t); } max += KCL.MaxOffset; min -= KCL.MinOffset; res.GlobalHeader.OctreeOrigin = min; res.GlobalHeader.OctreeMax = max; var size = max - min; res.GlobalHeader.CoordShift = (uint)KCLOctree.next_exponent(size.X); res.GlobalHeader.YShift = (uint)KCLOctree.next_exponent(size.Y); res.GlobalHeader.ZShift = (uint)KCLOctree.next_exponent(size.Z); var BoxSize = size / 2f; uint baseTriCount = 0; for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { for (int m = 0; m < 2; m++) { var Boxmin = min + new Vector3D(BoxSize.X * m, BoxSize.Y * l, BoxSize.Z * k); var mod = KCLModel.FromTriangles(Triangles, baseTriCount, Boxmin, BoxSize / 2); res.Models.Add(mod); if (mod != null) { baseTriCount += (uint)mod.Planes.Length; } } } } res.GlobalHeader.Unknown1 = baseTriCount; return(res); }