Esempio n. 1
0
        private int SortInMergedVertex(int posIndex, int normalIndex, int texCoordIndex, ref Face face)
        {
            var vertHash = Vertex.GetHashForIndices(posIndex, normalIndex, texCoordIndex);

            if (VertexIndicesByHash.TryGetValue(vertHash, out var index))
            {
                return(index);
            }

            Vector3 tangent, bitangent;

            MeshUtils.CalcTBNSpace(p0: Positions[face.V0],
                                   uv0: TexCoords[face.V0t],
                                   p1: Positions[face.V1],
                                   uv1: TexCoords[face.V1t],
                                   p2: Positions[face.V2],
                                   uv2: TexCoords[face.V2t],
                                   normal: Normals[normalIndex],
                                   tangent: out tangent,
                                   bitangent: out bitangent);

            var newIndex = _distinctVertices.Count;
            var vert     = new Vertex(posIndex, normalIndex, texCoordIndex);

            VertexIndicesByHash[vertHash] = newIndex;
            VertexBinormals.Add(bitangent);
            VertexTangents.Add(tangent);
            _distinctVertices.Add(vert);
            return(newIndex);
        }
Esempio n. 2
0
        public int GetVertexIndex(int positionIndex, int normalIndex, int textureCoordsIndex)
        {
            var hash = Vertex.GetHashForIndices(positionIndex, normalIndex, textureCoordsIndex);

            if (VertexIndicesByHash.TryGetValue(hash, out var index))
            {
                return(index);
            }

            return(-1);
        }