示例#1
0
文件: model.py 项目: flintforge/Aris
def IndexedNormals(V, F):
    '''
    Keep the face index, and provide one normal per vertex
    '''
    # normals = np.ndarray((len(V)*3,3), dtype=np.float32)
    normals = [[] for x in range(len(V))]
    A = [[] for x in range(len(V))]
    # normals = np.ndarray((len(F)*3,3), dtype=np.float32)
    x = 0
    for f in F:
        p0, p1, p2 = [V[f[x]] for x in range(3)]
        n = _v.cross(_v.vector(p0, p1), _v.vector(p0, p2))
        for i in range(3):  # in triangle
            # print (f[i] , n)
            # normals[x].append(n)  # append the face normal
            # normals[x].append(f[i]) # keep the vertex index
            normals[f[i]].append(n)  # would index the normal by face
            # compute the adjacency list while we are in
            A[f[i]] += [fa for fa in f if fa != f[i] and fa not in A[f[i]]]
            x += 1

    for i, n in enumerate(normals):
        # print(n,len(n),_v.sum(*n), _v.div(float(len(n)),_v.sum(*n)))
        # weighted by the number of face = wrong
        normals[i] = _v.div(float(len(n)), _v.sum(*n))
        # print('>',normals[i])

    # print('#',A)
    # print('//',normals, len(normals))
    return normals
示例#2
0
文件: model.py 项目: flintforge/Aris
def vertexAndNormalsList(V, F):
    '''
    one normal per faces = one normal for each distinct vertices
    no shared verts. Gouraud Shading, diamond sharp edges

    the unormalized normals list, indexed on the vertex list
    unormalized = relative to the surface of the face.
    check the influence of the face size on the illumination model
    '''

    vertices = np.ndarray((len(F) * 3, 3), dtype=np.float32)
    normals = np.ndarray((len(F) * 3, 3), dtype=np.float32)

    x = 0
    for f in F:
        p0, p1, p2 = [V[f[y]] for y in range(3)]
        n = _v.cross(_v.vector(p0, p1), _v.vector(p0, p2))
        for i in range(3):
            vertices[x] = V[f[i]]  # flatten / recopy the vertex
            # the three vertex hold the same normal value
            normals[x] = _v.div(_v.mag(n), n)
            x += 1

    return vertices, normals
示例#3
0
    [4, 5, 0, 1],
]


def rgb(x, y, z):
    return x / 2 + .5, y / 2 + .5, z / 2 + .5


sizes = []
# noinspection SpellCheckingInspection
verticies, normals, colors = [], [], []

for indexes in faces:
    sizes.append(len(indexes))
    p0, p1, p2 = [points[indexes[i]] for i in range(3)]
    normal = _v.cross(_v.vector(p0, p1), _v.vector(p0, p2))
    for index in indexes:
        vertex = points[index]
        verticies.append(vertex)
        normals.append(normal)
        colors.append(rgb(*vertex))

# noinspection SpellCheckingInspection
tex_coords = verticies
# noinspection SpellCheckingInspection
indicies = list(range(sum(sizes)))

# noinspection SpellCheckingInspection
__all__ = [
    "sizes",
    "indicies",