public override Asset Import(string path) { MSHS mshs = MSHS.Load(path); Model model = new Model(); string name = Path.GetFileNameWithoutExtension(path); int meshnum = 0; foreach (var tdrmesh in mshs.Meshes) { ModelMesh mesh = new ModelMesh(); mesh.Name = name + meshnum++.ToString("0000"); ModelMeshPart meshpart = new ModelMeshPart(); meshpart.PrimitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles; SceneManager.Current.UpdateProgress(string.Format("Processing {0}", mesh.Name)); for (int i = 0; i < tdrmesh.Faces.Count; i++) { var face = tdrmesh.Faces[i]; var v1 = tdrmesh.Vertexes[face.V1]; var v2 = tdrmesh.Vertexes[face.V2]; var v3 = tdrmesh.Vertexes[face.V3]; meshpart.AddFace( new OpenTK.Vector3[] { new OpenTK.Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), new OpenTK.Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z), new OpenTK.Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z) }, new OpenTK.Vector3[] { new OpenTK.Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), new OpenTK.Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z), new OpenTK.Vector3(v3.Normal.X, v3.Normal.Y, v3.Normal.Z) }, new OpenTK.Vector2[] { new OpenTK.Vector2(v1.UV.X, v1.UV.Y), new OpenTK.Vector2(v2.UV.X, v2.UV.Y), new OpenTK.Vector2(v3.UV.X, v3.UV.Y) } ); } mesh.AddModelMeshPart(meshpart); model.SetName(mesh.Name, model.AddMesh(mesh)); } return model; }
public override Asset Import(string path) { MSHS mshs = MSHS.Load(path); Model model = new Model(); string name = Path.GetFileNameWithoutExtension(path); int meshnum = 0; foreach (var tdrmesh in mshs.Meshes) { ModelMesh mesh = new ModelMesh(); mesh.Name = name + meshnum++.ToString("0000"); ModelMeshPart meshpart = new ModelMeshPart(); meshpart.PrimitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles; SceneManager.Current.UpdateProgress(string.Format("Processing {0}", mesh.Name)); for (int i = 0; i < tdrmesh.Faces.Count; i++) { var face = tdrmesh.Faces[i]; var v1 = tdrmesh.Vertexes[face.V1]; var v2 = tdrmesh.Vertexes[face.V2]; var v3 = tdrmesh.Vertexes[face.V3]; meshpart.AddFace( new OpenTK.Vector3[] { new OpenTK.Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), new OpenTK.Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z), new OpenTK.Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z) }, new OpenTK.Vector3[] { new OpenTK.Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), new OpenTK.Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z), new OpenTK.Vector3(v3.Normal.X, v3.Normal.Y, v3.Normal.Z) }, new OpenTK.Vector2[] { new OpenTK.Vector2(v1.UV.X, v1.UV.Y), new OpenTK.Vector2(v2.UV.X, v2.UV.Y), new OpenTK.Vector2(v3.UV.X, v3.UV.Y) } ); } mesh.AddModelMeshPart(meshpart); model.SetName(mesh.Name, model.AddMesh(mesh)); } return(model); }
public override Asset Import(string path) { MSHS mshs = MSHS.Load(path); Model model = new Model(); string name = Path.GetFileNameWithoutExtension(path); int meshnum = 0; foreach (TDRMesh tdrmesh in mshs.Meshes) { ModelMesh mesh = new ModelMesh { Name = $"{name}{meshnum++:0000}" }; ModelMeshPart meshpart = new ModelMeshPart { PrimitiveType = PrimitiveType.Triangles }; SceneManager.Current.UpdateProgress($"Processing {mesh.Name}"); TDRVertex v1 = null, v2 = null, v3 = null; switch (tdrmesh.Mode) { case TDRMesh.MSHMode.NGon: for (int i = 0; i < tdrmesh.Faces.Count; i++) { TDRFace face = tdrmesh.Faces[i]; for (int j = 2; j < face.VertexCount; j++) { int flip = j % 2; v1 = face.Vertices[j - (2 + flip)]; v2 = face.Vertices[j - 1]; v3 = face.Vertices[j - 0]; meshpart.AddFace( new Vector3[] { v1.Position, v2.Position, v3.Position }, new Vector3[] { v1.Normal, v2.Normal, v3.Normal }, new Vector2[] { v1.UV, v2.UV, v3.UV } ); } } break; case TDRMesh.MSHMode.TriIndexedPosition: for (int i = 0; i < tdrmesh.Faces.Count; i++) { TDRFace face = tdrmesh.Faces[i]; v1 = face.Vertices[0]; v2 = face.Vertices[1]; v3 = face.Vertices[2]; meshpart.AddFace( new Vector3[] { tdrmesh.Positions[v1.PositionIndex], tdrmesh.Positions[v2.PositionIndex], tdrmesh.Positions[v3.PositionIndex] }, new Vector3[] { v1.Normal, v2.Normal, v3.Normal }, new Vector2[] { v1.UV, v2.UV, v3.UV } ); } break; case TDRMesh.MSHMode.Tri: for (int i = 0; i < tdrmesh.Faces.Count; i++) { TDRFace face = tdrmesh.Faces[i]; v1 = tdrmesh.Vertices[face.V1]; v2 = tdrmesh.Vertices[face.V2]; v3 = tdrmesh.Vertices[face.V3]; meshpart.AddFace( new Vector3[] { v1.Position, v2.Position, v3.Position }, new Vector3[] { v1.Normal, v2.Normal, v3.Normal }, new Vector2[] { v1.UV, v2.UV, v3.UV } ); } break; } mesh.AddModelMeshPart(meshpart); model.SetName(mesh.Name, model.AddMesh(mesh)); } return(model); }
//public override string GetHints(string currentPath) //{ // string hints = string.Empty; // while (Directory.Exists(Directory.GetParent(currentPath).FullName)) // { // if (Directory.Exists(Path.Combine(Directory.GetParent(currentPath).FullName, "Models"))) // { // } // } // if (currentPath != null && Directory.Exists(Directory.GetParent(currentPath).FullName)) // { // hints = $"{currentPath};"; // if (Directory.Exists(Path.Combine(Directory.GetParent(currentPath).FullName, "PIXELMAP"))) // { // hints += $"{Path.Combine(Directory.GetParent(currentPath).FullName, "PIXELMAP")};"; // } // } // return hints; //} public override Asset Import(string path) { MDL mdl = MDL.Load(path); Model model = new Model(); ModelMesh mesh = new ModelMesh(); // 2015-07-12 : Commenting out SupportingDocuments["Source"] to see if anything breaks // model.SupportingDocuments["Source"] = mdl; bool bUsePrepData = true; for (int i = 0; i < mdl.Meshes.Count; i++) { Dictionary <int, int> newIndex = new Dictionary <int, int>(); ModelMeshPart meshpart = new ModelMeshPart(); MDLMaterialGroup mdlmesh = mdl.GetMesh(i); meshpart.Material = SceneManager.Current.Content.Load <Material, MaterialImporter>(mdlmesh.Name, Path.GetDirectoryName(path), true); if (bUsePrepData) { foreach (MDLFace f in mdl.Faces.Where(f => f.MaterialID == i)) { for (int j = 0; j < 3; j++) { if (!newIndex.ContainsKey(f.Verts[j])) { MDLVertex v = mdl.Vertices[f.Verts[j]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(f.Verts[j], index); } } meshpart.AddFace( newIndex[f.Verts[0]], newIndex[f.Verts[1]], newIndex[f.Verts[2]] ); } } else { int[] verts = new int[3]; for (int j = 0; j < mdlmesh.StripList.Count - 2; j++) { if (mdlmesh.StripList[j + 2].Degenerate) { continue; } verts[0] = mdlmesh.StripList[j + 0].Index; if (j % 2 == 0) { verts[1] = mdlmesh.StripList[j + 1].Index; verts[2] = mdlmesh.StripList[j + 2].Index; } else { verts[1] = mdlmesh.StripList[j + 2].Index; verts[2] = mdlmesh.StripList[j + 1].Index; } for (int k = 0; k < 3; k++) { if (!newIndex.ContainsKey(verts[k])) { MDLVertex v = mdl.Vertices[verts[k]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(verts[k], index); } } meshpart.AddFace( newIndex[verts[0]], newIndex[verts[1]], newIndex[verts[2]] ); } // Process patch list for (int j = 0; j < mdlmesh.TriList.Count; j += 3) { verts[0] = mdlmesh.TriList[j + 0].Index; verts[1] = mdlmesh.TriList[j + 1].Index; verts[2] = mdlmesh.TriList[j + 2].Index; for (int k = 0; k < 3; k++) { if (!newIndex.ContainsKey(verts[k])) { MDLVertex v = mdl.Vertices[verts[k]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(verts[k], index); } } meshpart.AddFace( newIndex[verts[0]], newIndex[verts[1]], newIndex[verts[2]] ); } } mesh.AddModelMeshPart(meshpart); Console.WriteLine(meshpart.VertexCount / 3); } mesh.Name = mdl.Name; model.SetName(mdl.Name, model.AddMesh(mesh)); return(model); }
public override Asset Import(string path) { BOM bom = BOM.Load(path); Model model = new Model(); model.SupportingDocuments["Source"] = bom; for (int i = 0; i < bom.Meshes.Count; i++) { var bommesh = bom.Meshes[i]; ModelMesh mesh = new ModelMesh(); ModelMeshPart meshpart = new ModelMeshPart(); if (i < 4) { for (int j = 0; j < bommesh.IndexBuffer.Count; j += 3) { int p0 = bommesh.IndexBuffer[j + 0]; int p1 = bommesh.IndexBuffer[j + 1]; int p2 = bommesh.IndexBuffer[j + 2]; meshpart.AddFace( new Vector3[] { new Vector3(bom.Verts[p0].Position.X, bom.Verts[p0].Position.Y, bom.Verts[p0].Position.Z), new Vector3(bom.Verts[p1].Position.X, bom.Verts[p1].Position.Y, bom.Verts[p1].Position.Z), new Vector3(bom.Verts[p2].Position.X, bom.Verts[p2].Position.Y, bom.Verts[p2].Position.Z), }, new Vector3[] { new Vector3(bom.Verts[p0].Normal.X, bom.Verts[p0].Normal.Y, bom.Verts[p0].Normal.Z), new Vector3(bom.Verts[p1].Normal.X, bom.Verts[p1].Normal.Y, bom.Verts[p1].Normal.Z), new Vector3(bom.Verts[p2].Normal.X, bom.Verts[p2].Normal.Y, bom.Verts[p2].Normal.Z), }, new Vector2[] { Vector2.Zero, Vector2.Zero, Vector2.Zero } ); } } else { // Process triangle strip for (int j = 0; j < bommesh.IndexBuffer.Count - 2; j++) { BOMVertex v0, v1, v2; v0 = bom.Verts[bommesh.IndexBuffer[j + 0]]; if (j % 2 != 0) { v1 = bom.Verts[bommesh.IndexBuffer[j + 1]]; v2 = bom.Verts[bommesh.IndexBuffer[j + 2]]; } else { v1 = bom.Verts[bommesh.IndexBuffer[j + 2]]; v2 = bom.Verts[bommesh.IndexBuffer[j + 1]]; } meshpart.AddFace( new Vector3[] { new Vector3(v0.Position.X, v0.Position.Y, v0.Position.Z), new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z) }, new Vector3[] { new Vector3(v0.Normal.X, v0.Normal.Y, v0.Normal.Z), new Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), new Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z) }, new Vector2[] { Vector2.Zero, Vector2.Zero, Vector2.Zero } ); } } mesh.AddModelMeshPart(meshpart); mesh.Name = bom.Name + "_" + i; model.SetName(bom.Name, model.AddMesh(mesh)); } return(model); }
public override Asset Import(string path) { BOM bom = BOM.Load(path); Model model = new Model(); model.SupportingDocuments["Source"] = bom; for (int i = 0; i < bom.Meshes.Count; i++) { var bommesh = bom.Meshes[i]; ModelMesh mesh = new ModelMesh(); ModelMeshPart meshpart = new ModelMeshPart(); if (i < 4) { for (int j = 0; j < bommesh.IndexBuffer.Count; j += 3) { int p0 = bommesh.IndexBuffer[j + 0]; int p1 = bommesh.IndexBuffer[j + 1]; int p2 = bommesh.IndexBuffer[j + 2]; meshpart.AddFace( new Vector3[] { new Vector3(bom.Verts[p0].Position.X, bom.Verts[p0].Position.Y, bom.Verts[p0].Position.Z), new Vector3(bom.Verts[p1].Position.X, bom.Verts[p1].Position.Y, bom.Verts[p1].Position.Z), new Vector3(bom.Verts[p2].Position.X, bom.Verts[p2].Position.Y, bom.Verts[p2].Position.Z), }, new Vector3[] { new Vector3(bom.Verts[p0].Normal.X, bom.Verts[p0].Normal.Y, bom.Verts[p0].Normal.Z), new Vector3(bom.Verts[p1].Normal.X, bom.Verts[p1].Normal.Y, bom.Verts[p1].Normal.Z), new Vector3(bom.Verts[p2].Normal.X, bom.Verts[p2].Normal.Y, bom.Verts[p2].Normal.Z), }, new Vector2[] { Vector2.Zero, Vector2.Zero, Vector2.Zero } ); } } else { // Process triangle strip for (int j = 0; j < bommesh.IndexBuffer.Count - 2; j++) { BOMVertex v0, v1, v2; v0 = bom.Verts[bommesh.IndexBuffer[j + 0]]; if (j % 2 != 0) { v1 = bom.Verts[bommesh.IndexBuffer[j + 1]]; v2 = bom.Verts[bommesh.IndexBuffer[j + 2]]; } else { v1 = bom.Verts[bommesh.IndexBuffer[j + 2]]; v2 = bom.Verts[bommesh.IndexBuffer[j + 1]]; } meshpart.AddFace( new Vector3[] { new Vector3(v0.Position.X, v0.Position.Y, v0.Position.Z), new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z) }, new Vector3[] { new Vector3(v0.Normal.X, v0.Normal.Y, v0.Normal.Z), new Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), new Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z) }, new Vector2[] { Vector2.Zero, Vector2.Zero, Vector2.Zero } ); } } mesh.AddModelMeshPart(meshpart); mesh.Name = bom.Name + "_" + i; model.SetName(bom.Name, model.AddMesh(mesh)); } return model; }
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); }
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; }
public void Draw() { if (asset == null) { ModelMeshPart sprite = new ModelMeshPart(); sprite.AddVertex(new Vector3(-0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 1)); sprite.AddVertex(new Vector3(-0.25f, 0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 0)); sprite.AddVertex(new Vector3(0.25f, 0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 0)); sprite.AddVertex(new Vector3(0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 1)); sprite.AddVertex(new Vector3(0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 1)); sprite.AddVertex(new Vector3(0.25f, 0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 0)); sprite.AddVertex(new Vector3(-0.25f, 0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 0)); sprite.AddVertex(new Vector3(-0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 1)); sprite.IndexBuffer.Initialise(); sprite.VertexBuffer.Initialise(); sprite.Material = new Material { Name = "Entity.Asset", Texture = SceneManager.Current.Content.Load <Texture, PNGImporter>(IconFilename) }; sprite.PrimitiveType = PrimitiveType.Quads; ModelMesh spritemesh = new ModelMesh(); spritemesh.AddModelMeshPart(sprite); Model spritemodel = new Model(); spritemodel.AddMesh(spritemesh); asset = spritemodel; } if (Linked) { Matrix4D parentTransform = ((ModelBone)Link).CombinedTransform; if (LinkType == LinkType.All) { Transform = parentTransform; } else { Transform = Matrix4D.Identity; Vector3 v = parentTransform.ExtractTranslation(); parentTransform.Normalise(); parentTransform.M41 = v.X; parentTransform.M42 = v.Y; parentTransform.M43 = v.Z; if (LinkType.HasFlag(LinkType.Rotation)) { Transform *= Matrix4D.CreateFromQuaternion(parentTransform.ExtractRotation()); } if (LinkType.HasFlag(LinkType.Scale)) { Transform *= Matrix4D.CreateScale(parentTransform.ExtractScale()); } if (LinkType.HasFlag(LinkType.Position)) { Transform *= Matrix4D.CreateTranslation(parentTransform.ExtractTranslation()); } } } Matrix4D mS = SceneManager.Current.Transform; Matrix4D mT = Transform; SceneManager.Current.Renderer.PushMatrix(); Matrix4D position = Matrix4D.CreateTranslation(mT.ExtractTranslation()); SceneManager.Current.Renderer.MultMatrix(ref mS); SceneManager.Current.Renderer.MultMatrix(ref position); if (Lollipop) { Matrix4D rotation = ViewportManager.Current.Active.Camera.Rotation; Matrix4D scale = Matrix4D.CreateScale(0.1f); SceneManager.Current.Renderer.MultMatrix(ref rotation); SceneManager.Current.Renderer.MultMatrix(ref scale); } SceneManager.Current.Renderer.Enable("Blend"); SceneManager.Current.Renderer.BlendFunc("SrcAlpha", "OneMinusSrcAlpha"); ((Model)asset).Draw(); SceneManager.Current.Renderer.Disable("Blend"); SceneManager.Current.Renderer.PopMatrix(); }
public override Asset Import(string path) { MDL mdl = MDL.Load(path); Model model = new Model(); ModelMesh mesh = new ModelMesh(); // 2015-07-12 : Commenting out SupportingDocuments["Source"] to see if anything breaks // model.SupportingDocuments["Source"] = mdl; bool bUsePrepData = true; for (int i = 0; i < mdl.Meshes.Count; i++) { Dictionary<int, int> newIndex = new Dictionary<int, int>(); ModelMeshPart meshpart = new ModelMeshPart(); var mdlmesh = mdl.GetMesh(i); meshpart.Material = SceneManager.Current.Content.Load<Material, MaterialImporter>(mdlmesh.Name, Path.GetDirectoryName(path), true); if (bUsePrepData) { foreach (var f in mdl.Faces.Where(f => f.MaterialID == i)) { for (int j = 0; j < 3; j++) { if (!newIndex.ContainsKey(f.Verts[j])) { var v = mdl.Vertices[f.Verts[j]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(f.Verts[j], index); } } meshpart.AddFace( newIndex[f.Verts[0]], newIndex[f.Verts[1]], newIndex[f.Verts[2]] ); } } else { int[] verts = new int[3]; for (int j = 0; j < mdlmesh.StripList.Count - 2; j++) { if (mdlmesh.StripList[j + 2].Degenerate) { continue; } verts[0] = mdlmesh.StripList[j + 0].Index; if (j % 2 == 0) { verts[1] = mdlmesh.StripList[j + 1].Index; verts[2] = mdlmesh.StripList[j + 2].Index; } else { verts[1] = mdlmesh.StripList[j + 2].Index; verts[2] = mdlmesh.StripList[j + 1].Index; } for (int k = 0; k < 3; k++) { if (!newIndex.ContainsKey(verts[k])) { var v = mdl.Vertices[verts[k]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(verts[k], index); } } meshpart.AddFace( newIndex[verts[0]], newIndex[verts[1]], newIndex[verts[2]] ); } // Process patch list for (int j = 0; j < mdlmesh.TriList.Count; j += 3) { verts[0] = mdlmesh.TriList[j + 0].Index; verts[1] = mdlmesh.TriList[j + 1].Index; verts[2] = mdlmesh.TriList[j + 2].Index; for (int k = 0; k < 3; k++) { if (!newIndex.ContainsKey(verts[k])) { var v = mdl.Vertices[verts[k]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(verts[k], index); } } meshpart.AddFace( newIndex[verts[0]], newIndex[verts[1]], newIndex[verts[2]] ); } } mesh.AddModelMeshPart(meshpart); Console.WriteLine(meshpart.VertexCount / 3); } mesh.Name = mdl.Name; model.SetName(mdl.Name, model.AddMesh(mesh)); return model; }
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); }