-
Notifications
You must be signed in to change notification settings - Fork 1
/
cube.py
56 lines (42 loc) · 1.15 KB
/
cube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Cube model.
Copyright (c) 2010, Renaud Blanch <rndblnch at gmail dot com>
Licence: GPLv3 or higher <http://www.gnu.org/licenses/gpl.html>
"""
# imports ####################################################################
from linalg import vector as _v
# model ######################################################################
bbox = [-1., 1.]
points = [(x, y, z) for x in bbox for y in bbox for z in bbox]
faces = [
[0, 1, 2, 3],
[1, 5, 3, 7],
[5, 4, 7, 6],
[4, 0, 6, 2],
[2, 3, 6, 7],
[4, 5, 0, 1],
]
def rgb(x, y, z):
return x / 2 + .5, y / 2 + .5, z / 2 + .5
sizes = []
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))
tex_coords = verticies
indicies = list(range(sum(sizes)))
__all__ = [
"sizes",
"indicies",
"verticies",
"tex_coords",
"normals",
"colors",
]