public int AddVertex(Material mat, VertexEntry newEntry) { if (!vertexSets.ContainsKey(mat)) { vertexSets[mat] = new List <VertexEntry>(); } List <VertexEntry> vertices = vertexSets[mat]; for (int i = 0; i < vertices.Count; ++i) { VertexEntry v = vertices[i]; if (newEntry.Matches(v)) { return(i); } } vertices.Add(newEntry); return(vertices.Count - 1); }
public void AddMesh(Mesh m) { MeshNormals meshNormals = m.GetMeshNormals(); MeshTextureCoords meshTextureCoords = m.GetMeshTextureCoords(); MeshMaterialList meshMaterialList = m.GetMeshMaterialList(); Debug.Assert(meshNormals != null); Debug.Assert(meshTextureCoords != null); Debug.Assert(meshMaterialList != null); Debug.Assert(meshNormals.faceNormals.Length == m.faces.Length); for (int faceIndex = 0; faceIndex < m.faces.Length; ++faceIndex) { MeshFace face = m.faces[faceIndex]; MeshFace normalFace = meshNormals.faceNormals[faceIndex]; Material material = meshMaterialList.GetMaterialByFace(faceIndex); Debug.Assert(face.faceVertexIndices.Length == normalFace.faceVertexIndices.Length); List <int> polygonPoints = new List <int>(); for (int pointIndex = 0; pointIndex < face.faceVertexIndices.Length; ++pointIndex) { int vertexIndex = face.faceVertexIndices[pointIndex]; int normalIndex = normalFace.faceVertexIndices[pointIndex]; Vector position = m.vertices[vertexIndex]; Vector normal = meshNormals.normals[normalIndex]; Coords2d texCoords = meshTextureCoords.textureCoords[vertexIndex]; VertexEntry vertexEntry = new VertexEntry(position, normal, texCoords); int newVertexIndex = AddVertex(material, vertexEntry); polygonPoints.Add(newVertexIndex); // Either add the point to poly, or add a new poly for the point. } if (!indexSets.ContainsKey(material)) { indexSets[material] = new List <List <int> >(); } indexSets[material].Add(polygonPoints); } }
public bool Matches(VertexEntry other) { return position.Matches(other.position) && normal.Matches(other.normal) && texCoords.Matches(other.texCoords); }
public int AddVertex(Material mat, VertexEntry newEntry) { if (!vertexSets.ContainsKey(mat)) vertexSets[mat] = new List<VertexEntry>(); List<VertexEntry> vertices = vertexSets[mat]; for (int i = 0; i < vertices.Count; ++i) { VertexEntry v = vertices[i]; if (newEntry.Matches(v)) return i; } vertices.Add(newEntry); return vertices.Count - 1; }
public void AddMesh(Mesh m) { MeshNormals meshNormals = m.GetMeshNormals(); MeshTextureCoords meshTextureCoords = m.GetMeshTextureCoords(); MeshMaterialList meshMaterialList = m.GetMeshMaterialList(); Debug.Assert(meshNormals != null); Debug.Assert(meshTextureCoords != null); Debug.Assert(meshMaterialList != null); Debug.Assert(meshNormals.faceNormals.Length == m.faces.Length); for (int faceIndex = 0; faceIndex < m.faces.Length; ++faceIndex) { MeshFace face = m.faces[faceIndex]; MeshFace normalFace = meshNormals.faceNormals[faceIndex]; Material material = meshMaterialList.GetMaterialByFace(faceIndex); Debug.Assert(face.faceVertexIndices.Length == normalFace.faceVertexIndices.Length); List<int> polygonPoints = new List<int>(); for (int pointIndex = 0; pointIndex < face.faceVertexIndices.Length; ++pointIndex) { int vertexIndex = face.faceVertexIndices[pointIndex]; int normalIndex = normalFace.faceVertexIndices[pointIndex]; Vector position = m.vertices[vertexIndex]; Vector normal = meshNormals.normals[normalIndex]; Coords2d texCoords = meshTextureCoords.textureCoords[vertexIndex]; VertexEntry vertexEntry = new VertexEntry(position, normal, texCoords); int newVertexIndex = AddVertex(material, vertexEntry); polygonPoints.Add(newVertexIndex); // Either add the point to poly, or add a new poly for the point. } if (!indexSets.ContainsKey(material)) indexSets[material] = new List<List<int>>(); indexSets[material].Add(polygonPoints); } }
public bool Matches(VertexEntry other) { return(position.Matches(other.position) && normal.Matches(other.normal) && texCoords.Matches(other.texCoords)); }