Пример #1
0
def norm(v):
    s = (v[0]**2 + v[1]**2 + v[2]**2)**0.5

    return np.array([v[0] / s, v[1] / s, v[2] / s])


def get_light(n):
    return min(max(dot(n, norm([0, 0, 1])), 0), 1)


zb_image = new_image(100, 16)
z_image = new_image(100, 16)

image = new_image(w, h)

model = load_obj('object.obj')

print('draw model')
for face in model[1]:
    points = []

    n = cross(np.array(model[0][face[0]]), np.array(model[0][face[1]]),
              np.array(model[0][face[2]]))
    l = get_light(n)

    if l > 0:
        for i in face:
            vert = model[0][i]

            points.append([(vert[0] + 1) * w / 2, (vert[1] + 1) * h / 2,
                           (vert[2] + 1) * 255 / 2])
Пример #2
0
import model
import corrections
import codecs
WORDS = model.load_obj('data')
ERRORS = model.load_obj('errors')


def proofread(fname):
    mispelt = []
    with codecs.open(fname, "r", encoding='utf-8', errors='ignore') as f:
        for i, line in enumerate(f):
            text = line.rstrip()
            print(text)
            from nltk.tokenize import word_tokenize
            tokens = word_tokenize(text)
            words = [word for word in tokens if word.isalpha()]
            for word in words:
                if (ERRORS[word.lower()] == 0):
                    if (WORDS[word.lower()] == 0):
                        mispelt.append((i, word, [
                            suggestion.term
                            for suggestion in corrections.suggest(word)
                        ]))
                        ERRORS[word.lower()] += 1
                else:
                    mispelt.append((i, word, [
                        suggestion.term
                        for suggestion in corrections.suggest(word)
                    ]))
            model.save_obj(ERRORS, 'errors')
    return mispelt
Пример #3
0
        A = t0 + (t2 - t0) * alpha
        B = t1 + (t2 - t1) * beta if second_half else t0 + (t1 - t0) * beta
        if (A[0] > B[0]):
            A, B = B, A
        for j in range(int(A[0]), int(B[0]) + 1):
            phi = 1. if (B[0] == A[0]) else (j - A[0]) / float(B[0] - A[0])
            P = A + (B - A) * phi
            # P = Vec(j, t0[1]+1, P[2] )
            idx = int(P[0]) + int(P[1]) * width
            if zbuffer[idx] <= P[2]:
                zbuffer[idx] = P[2]
                img.putpixel((int(round(P[0])), int(round(P[1]))), color)


# V, T, N, F = load_obj('african_head.obj')
V, T, N, F = load_obj('diablo3_pose.obj')


zbuffer = [0] * (width * height)
for face in F:
    screen_coord = []
    world_coord = []
    for j in range(3):
        v = V[face[j][0]]
        screen_coord.append(Vec((v[0] + 1.) * width / 2., (v[1] + 1.) * height / 2., (v[2] + 1.) * depth / 2.))
        world_coord.append(Vec(v[0], v[1], v[2]))
    n = ((world_coord[2] - world_coord[0]) ^ (world_coord[1] - world_coord[0])).normalize()
    intensity = n * light_dir
    if intensity > 0:
        triangle(Vec(screen_coord[0][0], height - screen_coord[0][1], screen_coord[0][2]),
                 Vec(screen_coord[1][0], height - screen_coord[1][1], screen_coord[1][2]),
Пример #4
0
        beta = float(i - (t1[1] - t0[1] if second_half else 0)) / segment_height
        A = t0 + (t2 - t0) * alpha
        B = t1 + (t2 - t1) * beta if second_half else t0 + (t1 - t0) * beta
        if (A[0] > B[0]):
            A, B = B, A
        for j in range(int(A[0]), int(B[0]) + 1):
            phi = 1. if (B[0] == A[0]) else (j - A[0]) / float(B[0] - A[0])
            P = A + (B - A) * phi
            # P = Vec(j, t0[1]+1, P[2] )
            idx = int(P[0]) + int(P[1]) * width
            if zbuffer[idx] <= P[2]:
                zbuffer[idx] = P[2]
                img.putpixel((int(round(P[0])), int(round(P[1]))), color)


V, T, N, F = load_obj('african_head.obj')
# V, T, N, F = load_obj('diablo3_pose.obj')

zbuffer = [0] * (width * height)
for face in F:
    screen_coord = []
    world_coord = []
    for j in range(3):
        temp = T[face[j][1]]
        r, g, b = obj[int(float(temp[0])*tex_w), 1024 - int(float(temp[1])*tex_h)]
        print r, g, b

        v = V[face[j][0]]
        screen_coord.append(Vec((v[0] + 1.) * width / 2., (v[1] + 1.) * height / 2., (v[2] + 1.) * depth / 2.))
        world_coord.append(Vec(v[0], v[1], v[2]))
    n = ((world_coord[2] - world_coord[0]) ^ (world_coord[1] - world_coord[0])).normalize()