private static void CheckAndAttachDefaultGroup(ref ObjGroup currentGroup, ref ObjItem result) { if (currentGroup == null) { currentGroup = new ObjGroup("default"); var defaultGroupName = "HeadShopDefaultMaterial".ToLower(); var defaultMaterial = new ObjMaterial(defaultGroupName); result.Groups.Add(defaultMaterial, currentGroup); result.Materials.Add(defaultGroupName, defaultMaterial); } }
public static void AppendObjTriangle(ObjItem objModel, ObjFaceVertex faceVertex, ref List <float> vertexPositions, ref List <float> vertexNormals, ref List <float> vertexTextureCoordinates, ref List <float> vertexBoneWeights, ref List <float> vertexBoneIndices, ref List <uint> indeces) { if (indeces != null) { indeces.Add((uint)(vertexPositions.Count / 3)); } if (vertexPositions != null) { var vertexPosition = objModel.Vertices[faceVertex.VertexIndex - 1]; vertexPositions.Add(vertexPosition.X); vertexPositions.Add(vertexPosition.Y); vertexPositions.Add(vertexPosition.Z); } if (vertexNormals != null) { if (objModel.Normals.Count == 0) { vertexNormals.AddRange(new[] { 0.0f, 0.0f, 0.0f }); } else { var vertexNormal = objModel.Normals[faceVertex.NormalIndex - 1]; vertexNormals.Add(vertexNormal.X); vertexNormals.Add(vertexNormal.Y); vertexNormals.Add(vertexNormal.Z); } } if (vertexTextureCoordinates != null) { var vertexTexture = objModel.TextureCoords[faceVertex.TextureIndex - 1]; vertexTextureCoordinates.Add(vertexTexture.X); vertexTextureCoordinates.Add(vertexTexture.Y); } if (vertexBoneIndices != null) { vertexBoneIndices.AddRange(new[] { 0.0f, 0.0f, 0.0f, 0.0f }); } if (vertexBoneWeights != null) { vertexBoneWeights.AddRange(new[] { 0.0f, 0.0f, 0.0f, 0.0f }); } }
public static void AppendObjTriangle(ObjItem objModel, ObjFaceVertex faceVertex, ref List<float> vertexPositions, ref List<float> vertexNormals, ref List<float> vertexTextureCoordinates, ref List<float> vertexBoneWeights, ref List<float> vertexBoneIndices, ref List<uint> indeces) { if (indeces != null) indeces.Add((uint)(vertexPositions.Count / 3)); if (vertexPositions != null) { var vertexPosition = objModel.Vertices[faceVertex.VertexIndex - 1]; vertexPositions.Add(vertexPosition.X); vertexPositions.Add(vertexPosition.Y); vertexPositions.Add(vertexPosition.Z); } if (vertexNormals != null) { if (objModel.Normals.Count == 0) { vertexNormals.AddRange(new[] { 0.0f, 0.0f, 0.0f }); } else { var vertexNormal = objModel.Normals[faceVertex.NormalIndex - 1]; vertexNormals.Add(vertexNormal.X); vertexNormals.Add(vertexNormal.Y); vertexNormals.Add(vertexNormal.Z); } } if (vertexTextureCoordinates != null) { var vertexTexture = objModel.TextureCoords[faceVertex.TextureIndex - 1]; vertexTextureCoordinates.Add(vertexTexture.X); vertexTextureCoordinates.Add(vertexTexture.Y); } if (vertexBoneIndices != null) vertexBoneIndices.AddRange(new[] { 0.0f, 0.0f, 0.0f, 0.0f }); if (vertexBoneWeights != null) vertexBoneWeights.AddRange(new[] { 0.0f, 0.0f, 0.0f, 0.0f }); }
private static void LoadMtlib(string filePath, ref ObjItem result) { var fi = new FileInfo(filePath); if (!fi.Exists) { return; } using (var sr = new StreamReader(fi.FullName)) { var material = default(ObjMaterial); while (!sr.EndOfStream) { var currentLine = sr.ReadLine(); if (String.IsNullOrWhiteSpace(currentLine) || currentLine[0] == '#') { continue; } var fields = currentLine.Trim().Split(null, 2); var keyword = fields[0].Trim().ToLower(); var data = fields[1].Trim(); switch (keyword) { case "newmtl": var dt = data.ToLower(); if (result.Materials.ContainsKey(dt)) { material = result.Materials[dt]; } else { material = new ObjMaterial(data); result.Materials.Add(dt, material); } break; case "ka": if (material != null) { material.AmbientColor = ParseVector3(data); } break; case "kd": if (material != null) { var color = ParseVector3(data); material.DiffuseColor = new Vector4(color.X, color.Y, color.Z, 1f); } break; case "ks": if (material != null) { material.SpecularColor = ParseVector3(data); } break; case "ns": if (material != null) { material.SpecularCoefficient = StringConverter.ToFloat(data); } break; case "ni": if (material != null) { material.OpticalDensity = StringConverter.ToFloat(data); } break; case "d": case "tr": if (material != null) { material.Transparency = StringConverter.ToFloat(data); } break; case "illum": if (material != null) { material.IlluminationModel = StringConverter.ToInt(data); } break; case "map_ka": if (material != null) { material.AmbientTextureMap = GetMapFullPath(data, filePath); } break; case "map_kd": if (material != null) { material.DiffuseTextureMap = GetMapFullPath(data, filePath); } break; case "map_ks": if (material != null) { material.SpecularTextureMap = GetMapFullPath(data, filePath); } break; case "map_ns": if (material != null) { material.SpecularHighlightTextureMap = GetMapFullPath(data, filePath); } break; case "map_d": if (material != null) { material.TransparentTextureMap = GetMapFullPath(data, filePath); } break; case "map_bump": case "bump": if (material != null) { material.BumpMap = GetMapFullPath(data, filePath); } break; case "disp": if (material != null) { material.DisplacementMap = GetMapFullPath(data, filePath); } break; case "decal": if (material != null) { material.StencilDecalMap = GetMapFullPath(data, filePath); } break; } } } }
public static ObjItem LoadObjFile(string filePath, bool needExporter) { var result = new ObjItem(needExporter); var fi = new FileInfo(filePath); if (!fi.Exists) { return(null); } using (var sr = new StreamReader(fi.FullName, Encoding.Default)) { var currentGroup = default(ObjGroup); CheckAndAttachDefaultGroup(ref currentGroup, ref result); var index = 0; var lastGroupName = String.Empty; if (ProgramCore.PluginMode) { var folderPath = Path.Combine(Application.StartupPath, "Models\\Model", ProgramCore.Project.ManType.GetObjDirPath()); switch (ProgramCore.Project.ManType) { case ManType.Male: LoadMtlib(Path.Combine(folderPath, "Male.mtl"), ref result); break; case ManType.Female: LoadMtlib(Path.Combine(folderPath, "Fem.mtl"), ref result); break; case ManType.Child: LoadMtlib(Path.Combine(folderPath, "Child.mtl"), ref result); break; } } while (!sr.EndOfStream) { var currentLine = sr.ReadLine(); if (String.IsNullOrWhiteSpace(currentLine) || currentLine[0] == '#') { if (currentLine == "#Accessories") { result.accessoryByHeadShop = true; } else if (currentLine == "#HeadShop Model") { result.modelByHeadShop = true; } continue; } var fields = currentLine.Trim().Split(null, 2); if (fields.Length < 2) { ProgramCore.EchoToLog(String.Format("Bad obj file format. File: '{0}'", fi.FullName), EchoMessageType.Warning); continue; } var keyword = fields[0].Trim().ToLower(); var data = fields[1].Trim(); switch (keyword) { case "v": // verticles var vertex = ParseVector3(data); result.Vertices.Add(vertex); if (needExporter) { result.ObjExport.Vertices.Add(vertex); } break; case "vt": // texture coords var textureCoord = ParseTextureCoords(data); result.TextureCoords.Add(textureCoord); if (needExporter) { result.ObjExport.TexCoords.Add(textureCoord); } break; case "vn": // normals var normal = ParseVector3(data); result.Normals.Add(normal); if (needExporter) { result.ObjExport.Normals.Add(normal); } break; case "f": // faces var face = ParceFace(data); if (needExporter) { face.ObjExportIndex = result.ObjExport.Faces.Count; result.ObjExport.Faces.Add(new ObjExportFace(face.Count, face.Vertices)); } currentGroup.AddFace(face); index++; break; case "g": // start group if (needExporter) { lastGroupName = data; if (result.ObjExport.MaterialsGroups.Count > 0) { result.ObjExport.MaterialsGroups.Last().Groups.Last().EndFaceIndex = index - 1; result.ObjExport.MaterialsGroups.Last().Groups.Add(new ObjExportGroup { Group = data, StartFaceIndex = index }); } } break; case "mtllib": //parse mtl file var path = Path.Combine(fi.DirectoryName, data); LoadMtlib(path, ref result); break; case "usemtl": if (needExporter) { if (result.ObjExport.MaterialsGroups.Count > 0) { result.ObjExport.MaterialsGroups.Last().Groups.Last().EndFaceIndex = index - 1; } result.ObjExport.MaterialsGroups.Add(new ObjExportMaterial { Material = data, Groups = new List <ObjExportGroup> { new ObjExportGroup { Group = lastGroupName, StartFaceIndex = index } } }); } var lowerData = data.ToLower(); var materialKey = result.Materials.Keys.SingleOrDefault(x => x == lowerData); ObjMaterial material; if (materialKey == null) // if can't parse mtl, create default group { material = new ObjMaterial(lowerData); result.Materials.Add(lowerData, material); } else { material = result.Materials[materialKey]; } if (result.Groups.ContainsKey(material)) { currentGroup = result.Groups[material]; } else { currentGroup = new ObjGroup(material.Name); result.Groups.Add(material, currentGroup); } break; } } if (result.ObjExport != null && result.ObjExport.MaterialsGroups.Count > 0 && needExporter) { result.ObjExport.MaterialsGroups.Last().Groups.Last().EndFaceIndex = index - 1; } } return(result); }
private static void LoadMtlib(string filePath, ref ObjItem result) { var fi = new FileInfo(filePath); if (!fi.Exists) return; using (var sr = new StreamReader(fi.FullName)) { var material = default(ObjMaterial); while (!sr.EndOfStream) { var currentLine = sr.ReadLine(); if (String.IsNullOrWhiteSpace(currentLine) || currentLine[0] == '#') continue; var fields = currentLine.Trim().Split(null, 2); var keyword = fields[0].Trim().ToLower(); var data = fields[1].Trim(); switch (keyword) { case "newmtl": var dt = data.ToLower(); if (result.Materials.ContainsKey(dt)) material = result.Materials[dt]; else { material = new ObjMaterial(data); result.Materials.Add(dt, material); } break; case "ka": if (material != null) material.AmbientColor = ParseVector3(data); break; case "kd": if (material != null) { var color = ParseVector3(data); material.DiffuseColor = new Vector4(color.X, color.Y, color.Z, 1f); } break; case "ks": if (material != null) material.SpecularColor = ParseVector3(data); break; case "ns": if (material != null) material.SpecularCoefficient = StringConverter.ToFloat(data); break; case "ni": if (material != null) material.OpticalDensity = StringConverter.ToFloat(data); break; case "d": case "tr": if (material != null) material.Transparency = StringConverter.ToFloat(data); break; case "illum": if (material != null) material.IlluminationModel = StringConverter.ToInt(data); break; case "map_ka": if (material != null) material.AmbientTextureMap = GetMapFullPath(data, filePath); break; case "map_kd": if (material != null) material.DiffuseTextureMap = GetMapFullPath(data, filePath); break; case "map_ks": if (material != null) material.SpecularTextureMap = GetMapFullPath(data, filePath); break; case "map_ns": if (material != null) material.SpecularHighlightTextureMap = GetMapFullPath(data, filePath); break; case "map_d": if (material != null) material.TransparentTextureMap = GetMapFullPath(data, filePath); break; case "map_bump": case "bump": if (material != null) material.BumpMap = GetMapFullPath(data, filePath); break; case "disp": if (material != null) material.DisplacementMap = GetMapFullPath(data, filePath); break; case "decal": if (material != null) material.StencilDecalMap = GetMapFullPath(data, filePath); break; } } } }
public static ObjItem LoadObjFile(string filePath, bool needExporter) { var result = new ObjItem(needExporter); var fi = new FileInfo(filePath); if (!fi.Exists) return null; using (var sr = new StreamReader(fi.FullName, Encoding.Default)) { var currentGroup = default(ObjGroup); CheckAndAttachDefaultGroup(ref currentGroup, ref result); var index = 0; var lastGroupName = String.Empty; if (ProgramCore.PluginMode) { var folderPath = Path.Combine(Application.StartupPath, "Models\\Model", ProgramCore.Project.ManType.GetObjDirPath()); switch (ProgramCore.Project.ManType) { case ManType.Male: LoadMtlib(Path.Combine(folderPath, "Male.mtl"), ref result); break; case ManType.Female: LoadMtlib(Path.Combine(folderPath, "Fem.mtl"), ref result); break; case ManType.Child: LoadMtlib(Path.Combine(folderPath, "Child.mtl"), ref result); break; } } while (!sr.EndOfStream) { var currentLine = sr.ReadLine(); if (String.IsNullOrWhiteSpace(currentLine) || currentLine[0] == '#') { if (currentLine == "#Accessories") result.accessoryByHeadShop = true; else if (currentLine == "#HeadShop Model") result.modelByHeadShop = true; continue; } var fields = currentLine.Trim().Split(null, 2); if (fields.Length < 2) { ProgramCore.EchoToLog(String.Format("Bad obj file format. File: '{0}'", fi.FullName), EchoMessageType.Warning); continue; } var keyword = fields[0].Trim().ToLower(); var data = fields[1].Trim(); switch (keyword) { case "v": // verticles var vertex = ParseVector3(data); result.Vertices.Add(vertex); if (needExporter) result.ObjExport.Vertices.Add(vertex); break; case "vt": // texture coords var textureCoord = ParseTextureCoords(data); result.TextureCoords.Add(textureCoord); if (needExporter) result.ObjExport.TexCoords.Add(textureCoord); break; case "vn": // normals var normal = ParseVector3(data); result.Normals.Add(normal); if (needExporter) result.ObjExport.Normals.Add(normal); break; case "f": // faces var face = ParceFace(data); if (needExporter) { face.ObjExportIndex = result.ObjExport.Faces.Count; result.ObjExport.Faces.Add(new ObjExportFace(face.Count, face.Vertices)); } currentGroup.AddFace(face); index++; break; case "g": // start group if (needExporter) { lastGroupName = data; if (result.ObjExport.MaterialsGroups.Count > 0) { result.ObjExport.MaterialsGroups.Last().Groups.Last().EndFaceIndex = index - 1; result.ObjExport.MaterialsGroups.Last().Groups.Add(new ObjExportGroup { Group = data, StartFaceIndex = index }); } } break; case "mtllib": //parse mtl file var path = Path.Combine(fi.DirectoryName, data); LoadMtlib(path, ref result); break; case "usemtl": if (needExporter) { if (result.ObjExport.MaterialsGroups.Count > 0) result.ObjExport.MaterialsGroups.Last().Groups.Last().EndFaceIndex = index - 1; result.ObjExport.MaterialsGroups.Add(new ObjExportMaterial { Material = data, Groups = new List<ObjExportGroup> { new ObjExportGroup { Group = lastGroupName, StartFaceIndex = index } } }); } var lowerData = data.ToLower(); var materialKey = result.Materials.Keys.SingleOrDefault(x => x == lowerData); ObjMaterial material; if (materialKey == null) // if can't parse mtl, create default group { material = new ObjMaterial(lowerData); result.Materials.Add(lowerData, material); } else material = result.Materials[materialKey]; if (result.Groups.ContainsKey(material)) currentGroup = result.Groups[material]; else { currentGroup = new ObjGroup(material.Name); result.Groups.Add(material, currentGroup); } break; } } if (result.ObjExport != null && result.ObjExport.MaterialsGroups.Count > 0 && needExporter) result.ObjExport.MaterialsGroups.Last().Groups.Last().EndFaceIndex = index - 1; } return result; }
private void SetFaceTriangleIndex(ObjFace face, ObjItem objModel) { if (objModel.ObjExport != null && face.ObjExportIndex > -1) { objModel.ObjExport.Faces[face.ObjExportIndex].TriangleIndex0 = LastTriangleIndex++; if (face.Count == 4) objModel.ObjExport.Faces[face.ObjExportIndex].TriangleIndex1 = LastTriangleIndex++; } }
/// <summary> Accessory file saved in program. Here is a few accessories devided by groups </summary> private List<DynamicRenderMesh> LoadSpecialAccessoryMesh(ObjItem objModel) { var result = new List<DynamicRenderMesh>(); foreach (var modelGroup in objModel.Groups) { var vertexPositions = new List<float>(); var vertexNormals = new List<float>(); var vertexTextureCoordinates = new List<float>(); var vertexBoneIndices = new List<float>(); var vertexBoneWeights = new List<float>(); var indeces = new List<uint>(); foreach (var face in modelGroup.Value.Faces) { if (face.Count == 3) { for (var i = 0; i < face.Count; i++) { var faceVertex = face[i]; ObjLoader.AppendObjTriangle(objModel, faceVertex, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); } } else if (face.Count == 4) { var faceVertex0 = face[0]; var faceVertex1 = face[1]; var faceVertex2 = face[2]; var faceVertex3 = face[3]; ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex1, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex3, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); } } if (vertexPositions.Count == 0) continue; var renderMesh = new DynamicRenderMesh(MeshType.Accessory); if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty)) { renderMesh.Title = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name; renderMesh.Material.DiffuseColor = new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y, modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency); if (!string.IsNullOrEmpty(modelGroup.Key.DiffuseTextureMap)) renderMesh.Material.DiffuseTextureMap = modelGroup.Key.DiffuseTextureMap; if (!string.IsNullOrEmpty(modelGroup.Key.TransparentTextureMap)) renderMesh.Material.TransparentTextureMap = modelGroup.Key.TransparentTextureMap; var center = Vector3.Zero; var count = vertexPositions.Count / 3; const float scale = 246f; for (var i = 0; i < count; i++) { center.X += vertexPositions[i * 3] * scale; center.Y += vertexPositions[i * 3 + 1] * scale; center.Z += vertexPositions[i * 3 + 2] * scale; } center /= count; renderMesh.Transform = Matrix4.CreateScale(scale); /* renderMesh.Transform[3, 0] = -center.X; renderMesh.Transform[3, 1] = -center.Y; renderMesh.Transform[3, 2] = -center.Z;*/ renderMesh.Position = center; AccesoryMeshes.Add(renderMesh); result.Add(renderMesh); } } return result; }
private List<DynamicRenderMesh> LoadHairMeshes(ObjItem objModel, ObjItem objModelNull, bool fromDragAndDrop, ManType manType, MeshType meshType) { var result = new List<DynamicRenderMesh>(); var vertexPositions = new List<float>(); var vertexNormals = new List<float>(); var vertexTextureCoordinates = new List<float>(); var vertexBoneIndices = new List<float>(); var vertexBoneWeights = new List<float>(); var indeces = new List<uint>(); var vertexPositionsNull = new List<float>(); var vertexNormalsNull = new List<float>(); var vertexTextureCoordinatesNull = new List<float>(); var vertexBoneIndicesNull = new List<float>(); var vertexBoneWeightsNull = new List<float>(); var indecesNull = new List<uint>(); var groupsNull = objModelNull == null ? new Dictionary<ObjMaterial, ObjGroup>.Enumerator() : objModelNull.Groups.GetEnumerator(); ObjGroup groupNull; foreach (var modelGroup in objModel.Groups) // one group - one mesh { vertexPositions.Clear(); vertexNormals.Clear(); vertexTextureCoordinates.Clear(); vertexBoneIndices.Clear(); vertexBoneWeights.Clear(); indeces.Clear(); foreach (var face in modelGroup.Value.Faces) // combine all meshes in group - to one mesh. GetObjFace(face, objModel, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); var renderMesh = new DynamicRenderMesh(meshType); renderMesh.groupName = modelGroup.Value.Name; if (!objModel.modelByHeadShop) { for (var i = 0; i < vertexPositions.Count / 3; i++) vertexPositions[i * 3 + 1] = vertexPositions[i * 3 + 1] - 0.0060975609f; } ProgramCore.EchoToLog(String.Format("RenderMesh: {0}", modelGroup.Value.Name), EchoMessageType.Information); ProgramCore.EchoToLog( String.Format("renderMesh.Create: {0}, {1}, {2}, {3}, {4}", vertexPositions.Count, vertexTextureCoordinates.Count, vertexBoneIndices.Count, vertexBoneWeights.Count, indeces.Count), EchoMessageType.Information); if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty)) { if (objModelNull != null) { groupsNull.MoveNext(); groupNull = groupsNull.Current.Value; vertexPositionsNull.Clear(); vertexNormalsNull.Clear(); vertexTextureCoordinatesNull.Clear(); vertexBoneWeightsNull.Clear(); vertexBoneIndicesNull.Clear(); indecesNull.Clear(); foreach (var face in groupNull.Faces) { GetObjFace(face, objModelNull, ref vertexPositionsNull, ref vertexNormalsNull, ref vertexTextureCoordinatesNull, ref vertexBoneWeightsNull, ref vertexBoneIndicesNull, ref indecesNull); } renderMesh.SetNullPoints(vertexPositionsNull, vertexNormalsNull, vertexTextureCoordinatesNull); } renderMesh.Title = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name; renderMesh.Material = modelGroup.Key; renderMesh.Material.DiffuseColor = new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y, modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency); if (!string.IsNullOrEmpty(modelGroup.Key.DiffuseTextureMap)) renderMesh.Material.DiffuseTextureMap = modelGroup.Key.DiffuseTextureMap; if (!string.IsNullOrEmpty(modelGroup.Key.TransparentTextureMap)) renderMesh.Material.TransparentTextureMap = modelGroup.Key.TransparentTextureMap; var scale = meshType == MeshType.Head ? GetHeadScale(manType) : GetHairScale(manType); // перегруз сделан потому, что на этапе загрузки проекта самого проекта еще может не быть. поэтому лучше передавать renderMesh.Transform = Matrix4.CreateScale(scale); var center = Vector3.Zero; var count = vertexPositions.Count / 3; for (var i = 0; i < count; i++) { center.X += vertexPositions[i * 3] * scale; center.Y += vertexPositions[i * 3 + 1] * scale; center.Z += vertexPositions[i * 3 + 2] * scale; } if (fromDragAndDrop) { center /= count; renderMesh.Transform = Matrix4.CreateScale(scale); renderMesh.Transform[3, 0] = -center.X; renderMesh.Transform[3, 1] = -center.Y; renderMesh.Transform[3, 2] = -center.Z; renderMesh.Position = center; } if (vertexTextureCoordinates.Count > 0 && vertexTextureCoordinates.All(x => x == 0)) renderMesh.UpdateTextureCoordinates(0, 1); if (renderMesh.vertexArray.Length > 0) result.Add(renderMesh); } } return result; }
private void GetObjFace(ObjFace face, ObjItem objModel, ref List<float> vertexPositions, ref List<float> vertexNormals, ref List<float> vertexTextureCoordinates, ref List<float> vertexBoneWeights, ref List<float> vertexBoneIndices, ref List<uint> indeces) { if (face.Count == 3) { for (var i = 0; i < face.Count; i++) { var faceVertex = face[i]; ObjLoader.AppendObjTriangle(objModel, faceVertex, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); } SetFaceTriangleIndex(face, objModel); } else if (face.Count == 4) { var faceVertex0 = face[0]; var faceVertex1 = face[1]; var faceVertex2 = face[2]; var faceVertex3 = face[3]; ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex1, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex3, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); SetFaceTriangleIndex(face, objModel); } }