public int GetHashCode(VertexInfo a) { return(GetHashCode(a.Position) * GetHashCode(a.TexCoords)); }
public bool Create(MeshPartInfo info, Vector3 Offset) { if (info.VertexPositions.Count == 0) { return(false); } Color = info.Color; Texture = info.Texture; TransparentTexture = info.TransparentTexture; Indices.Clear(); var positions = new List <Vector3>(); var texCoords = new List <Vector2>(); var pointnsDict = new Dictionary <VertexInfo, int>(new VectorEqualityComparer()); var positionsDict = new Dictionary <Vector3, int>(new VectorEqualityComparer()); for (var i = 0; i < info.VertexPositions.Count; i++) { var vertexInfo = new VertexInfo { Position = info.VertexPositions[i] + Offset, TexCoords = info.TextureCoords[i] }; if (!pointnsDict.ContainsKey(vertexInfo)) { var index = positions.Count; if (!positionsDict.ContainsKey(vertexInfo.Position)) { positionsDict.Add(vertexInfo.Position, MorphPoints.Count); PointIndices.Add(MorphPoints.Count); MorphPoints.Add(new MorphingPoint { Indices = new List <int> { index }, Position = vertexInfo.Position }); } else { var id = positionsDict[vertexInfo.Position]; PointIndices.Add(id); MorphPoints[id].Indices.Add(index); } pointnsDict.Add(vertexInfo, index); Indices.Add((uint)index); positions.Add(vertexInfo.Position); texCoords.Add(vertexInfo.TexCoords); } else { PointIndices.Add(positionsDict[vertexInfo.Position]); Indices.Add((uint)pointnsDict[vertexInfo]); } } CountIndices = Indices.Count; Vertices = new Vertex3d[positions.Count]; var normals = Normal.CalculateNormals(positions, Indices); for (var i = 0; i < Vertices.Length; i++) { Vertices[i].OriginalPosition = Vertices[i].Position = positions[i]; Vertices[i].Normal = normals[i]; Vertices[i].TexCoord = texCoords[i]; Vertices[i].Color = Vector4.One; } Destroy(); GL.GenBuffers(1, out VertexBuffer); GL.GenBuffers(1, out IndexBuffer); return(true); }
public bool Equals(VertexInfo a, VertexInfo b) { return(EqualsVector3(a.Position, b.Position) && Equals(a.TexCoords, b.TexCoords)); }