-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshapes.py
More file actions
executable file
·125 lines (111 loc) · 3.83 KB
/
shapes.py
File metadata and controls
executable file
·125 lines (111 loc) · 3.83 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from streams import ProcessingElement
from frames import Frame
from groups import Group
import math
class SquareGenerator(ProcessingElement):
def __init__(this):
ProcessingElement.__init__(this, 0)
def run(this):
out = Frame()
out.addValue((0.5, 0.5, 0))
out.addValue((-0.5, 0.5, 0))
out.addValue((-0.5, -0.5, 0))
out.addValue((0.5, -0.5, 0))
return out
class CubeGenerator(ProcessingElement):
def __init__(this):
ProcessingElement.__init__(this, 0)
def run(this):
out = Group()
out.addVector((0.5, 0.5, 0.5))
out.addVector((-0.5, 0.5, 0.5))
out.addVector((-0.5, -0.5, 0.5))
out.addVector((0.5, -0.5, 0.5))
out.addNormal((0.0, 0.0, 1.0))
out.addVector((0.5, 0.5, -0.5))
out.addVector((0.5, -0.5, -0.5))
out.addVector((-0.5, -0.5, -0.5))
out.addVector((-0.5, 0.5, -0.5))
out.addNormal((0.0, 0.0, -1.0))
out.addVector((-0.5, 0.5, -0.5))
out.addVector((-0.5, -0.5, -0.5))
out.addVector((-0.5, -0.5, 0.5))
out.addVector((-0.5, 0.5, 0.5))
out.addNormal((-1.0, 0.0, 0.0))
out.addVector((0.5, 0.5, -0.5))
out.addVector((0.5, 0.5, 0.5))
out.addVector((0.5, -0.5, 0.5))
out.addVector((0.5, -0.5, -0.5))
out.addNormal((1.0, 0.0, 0.0))
out.addVector((0.5, -0.5, -0.5))
out.addVector((0.5, -0.5, 0.5))
out.addVector((-0.5, -0.5, 0.5))
out.addVector((-0.5, -0.5, -0.5))
out.addNormal((0.0, -1.0, 0.0))
out.addVector((0.5, 0.5, -0.5))
out.addVector((-0.5, 0.5, -0.5))
out.addVector((-0.5, 0.5, 0.5))
out.addVector((0.5, 0.5, 0.5))
out.addNormal((0.0, 1.0, 0.0))
return out
class CircleGenerator(ProcessingElement):
def __init__(this, numPoints):
ProcessingElement.__init__(this, 0)
this.numPoints = numPoints
def run(this):
out = Frame()
for point in range(this.numPoints):
angle = point * 2 * math.pi / this.numPoints
out.addValue((math.cos(angle), math.sin(angle), 0))
return out
class SphereLineGenerator(ProcessingElement):
"""
Generate points that are distributed appropriately for slices of a sphere.
We want points that are distributed evenly around a circumference, projected
back onto the central axis.
"""
def __init__(this, numPoints):
ProcessingElement.__init__(this, 0)
this.numPoints = numPoints
this.point = 0
def run(this):
angle = this.point * math.pi / (this.numPoints - 1)
this.point = (this.point + 1) % this.numPoints
return (0, 0, math.cos(angle))
class SphereSliceSizeGenerator(ProcessingElement):
def __init__(this, numPoints):
ProcessingElement.__init__(this, 0)
this.numPoints = numPoints
this.point = 0
def run(this):
angle = this.point * math.pi / (this.numPoints - 1)
this.point = (this.point + 1) % this.numPoints
return math.sin(angle)
# TODO: consider replacing with a non-lifted version wrt shape, accompanied by a
# piecewise functor
class ScalingExtrusionElement(ProcessingElement):
def __init__(this):
ProcessingElement.__init__(this, 3)
def run(this, point, scale, shape):
out = Frame()
scale = scale.getNext()
point = point.getNext()
for value in shape.getNext().values:
out.addValue((value[0] * scale + point[1], value[1] * scale + point[1], value[2] * scale + point[2]))
return out
class PointsToQuadsElement(ProcessingElement):
def __init__(this):
ProcessingElement.__init__(this, 1)
this.lastFrame = None
def run(this, frames):
if this.lastFrame is None:
this.lastFrame = frames.getNext()
thisFrame = frames.getNext()
out = Group()
for i in range(min(len(thisFrame.values), len(this.lastFrame.values))) + [0]:
out.addVector(this.lastFrame.values[i])
out.addNormal(this.lastFrame.values[i])
out.addVector(thisFrame.values[i])
out.addNormal(thisFrame.values[i])
this.lastFrame = thisFrame
return out