static void MakeMeshNoUVNoCol(MegaCacheOBJMesh newMesh, Mesh mesh, bool adjust, bool recalcnormals, bool tangents) { int v1 = 0; int v2 = 1; int v3 = 2; int v4 = 3; Vector3 n1 = Vector3.forward; Vector3 n2 = Vector3.forward; Vector3 n3 = Vector3.forward; Vector3 n4 = Vector3.forward; for (int t = 0; t < newMesh.faces.Count; t++) { MegaCacheOBJFace f = newMesh.faces[t]; if (newMesh.normals.Count > 0) { n1 = newMesh.normals[f.n[v1]]; n2 = newMesh.normals[f.n[v2]]; n3 = newMesh.normals[f.n[v3]]; if (f.quad) { n4 = newMesh.normals[f.n[v4]]; } } if (adjust) { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v3]], newMesh.vertices[f.v[v2]], n1, n3, n2, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } else { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v2]], newMesh.vertices[f.v[v3]], n1, n2, n3, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } if (f.quad) { if (adjust) { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v4]], newMesh.vertices[f.v[v3]], n1, n4, n3, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } else { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v3]], newMesh.vertices[f.v[v4]], n1, n3, n4, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } } } MegaCacheMeshConstructorOBJNoUV.Construct(faces, mesh, newMesh.vertices.ToArray(), false, recalcnormals, tangents); }
static public Mesh ImportFile(string filePath, float scale, bool adjust, bool tangents, bool loadmtls, bool optimize, bool recalcnormals) { faces.Clear(); importpath = Path.GetDirectoryName(filePath); StreamReader stream = File.OpenText(filePath); string entireText = stream.ReadToEnd(); stream.Close(); MegaCacheOBJMesh newMesh = new MegaCacheOBJMesh(); populateMeshStructNew(entireText, ref newMesh, loadmtls); Mesh mesh = new Mesh(); int v1 = 0; int v2 = 1; int v3 = 2; int v4 = 3; currentmtl = 0; smthgrp = 0; for (int i = 0; i < newMesh.vertices.Count; i++) { newMesh.vertices[i] *= scale; if (adjust) { Vector3 p = newMesh.vertices[i]; p.x = -p.x; newMesh.vertices[i] = p; } } for (int i = 0; i < newMesh.normals.Count; i++) { Vector3 p = newMesh.normals[i]; p.x = -p.x; newMesh.normals[i] = p; } Vector3 n1 = Vector3.forward; Vector3 n2 = Vector3.forward; Vector3 n3 = Vector3.forward; Vector3 n4 = Vector3.forward; if (newMesh.normals.Count == 0) { recalcnormals = true; } if (newMesh.uv.Count == 0) { for (int t = 0; t < newMesh.faces.Count; t++) { MegaCacheOBJFace f = newMesh.faces[t]; if (newMesh.normals.Count > 0) { n1 = newMesh.normals[f.n[v1]]; n2 = newMesh.normals[f.n[v2]]; n3 = newMesh.normals[f.n[v3]]; if (f.quad) { n4 = newMesh.normals[f.n[v4]]; } } if (adjust) { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v3]], newMesh.vertices[f.v[v2]], n1, n3, n2, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } else { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v2]], newMesh.vertices[f.v[v3]], n1, n2, n3, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } if (f.quad) { if (adjust) { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v4]], newMesh.vertices[f.v[v3]], n1, n4, n3, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } else { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v3]], newMesh.vertices[f.v[v4]], n1, n3, n4, Vector3.zero, Vector3.zero, Vector3.zero, 1, f.mtl)); } } } MegaCacheMeshConstructorOBJNoUV.Construct(faces, mesh, newMesh.vertices.ToArray(), false, recalcnormals, tangents); } else { for (int t = 0; t < newMesh.faces.Count; t++) { MegaCacheOBJFace f = newMesh.faces[t]; if (newMesh.normals.Count > 0) { n1 = newMesh.normals[f.n[v1]]; n2 = newMesh.normals[f.n[v2]]; n3 = newMesh.normals[f.n[v3]]; if (f.quad) { n4 = newMesh.normals[f.n[v4]]; } } if (adjust) { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v3]], newMesh.vertices[f.v[v2]], n1, n3, n2, newMesh.uv[f.uv[v1]], newMesh.uv[f.uv[v3]], newMesh.uv[f.uv[v2]], 1, f.mtl)); } else { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v2]], newMesh.vertices[f.v[v3]], n1, n2, n3, newMesh.uv[f.uv[v1]], newMesh.uv[f.uv[v2]], newMesh.uv[f.uv[v3]], 1, f.mtl)); } if (f.quad) { if (adjust) { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v4]], newMesh.vertices[f.v[v3]], n1, n4, n3, newMesh.uv[f.uv[v1]], newMesh.uv[f.uv[v4]], newMesh.uv[f.uv[v3]], 1, f.mtl)); } else { faces.Add(new MegaCacheFace(newMesh.vertices[f.v[v1]], newMesh.vertices[f.v[v3]], newMesh.vertices[f.v[v4]], n1, n3, n4, newMesh.uv[f.uv[v1]], newMesh.uv[f.uv[v3]], newMesh.uv[f.uv[v4]], 1, f.mtl)); } } } MegaCacheMeshConstructorOBJ.Construct(faces, mesh, newMesh.vertices.ToArray(), false, recalcnormals, tangents); } return(mesh); }