Skip to content

Commit bb7aa6e

Browse files
committed
Add directory for scene template files
1 parent a5a2f12 commit bb7aa6e

3 files changed

Lines changed: 67 additions & 10 deletions

File tree

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"transform": {
2828
"scale": [0.05, 0.05, 0.05],
29-
"position": [-0.3, -0.2, -0.28]
29+
"translate": [-0.3, -0.2, -0.28]
3030
}
3131
},
3232
{
@@ -47,7 +47,7 @@
4747
"linearBounce": true
4848
},
4949
"transform": {
50-
"position": [-0.6, -0.25, -0.75],
50+
"translate": [-0.6, -0.25, -0.75],
5151
"scale": [0.25, 0.35, 0.25]
5252
}
5353
},
@@ -58,7 +58,7 @@
5858
"color": [0.8, 0.1, 0.1]
5959
},
6060
"transform": {
61-
"position": [-0.6, 0.45, -0.75],
61+
"translate": [-0.6, 0.45, -0.75],
6262
"scale": [0.25, 0.35, 0.25],
6363
"rotation": [
6464
[1, 0, 0, 180]
@@ -74,7 +74,7 @@
7474
"bounce": 1
7575
},
7676
"transform": {
77-
"position": [-1.55, 0.7, -1.2],
77+
"translate": [-1.55, 0.7, -1.2],
7878
"scale": [0.25, 1, 0.25],
7979
"rotation": [
8080
[1, 0, 0, 90],
@@ -83,6 +83,7 @@
8383
}
8484
},
8585
{
86+
"name": "torus1",
8687
"type": "torus",
8788
"minorRadius": 0.2,
8889
"majorRadius": 0.1,
@@ -91,7 +92,7 @@
9192
"color": [0.5, 1, 0.5]
9293
},
9394
"transform": {
94-
"position": [0, 0.05, -0.75],
95+
"translate": [0, 0.05, -0.75],
9596
"rotation": [
9697
[1, 0, 0, 90]
9798
]
@@ -112,7 +113,7 @@
112113
"color": [0.6, 0.6, 0.6]
113114
},
114115
"transform": {
115-
"position": [2, 0.5, -3]
116+
"translate": [2, 0.5, -3]
116117
}
117118
},
118119
{
@@ -124,7 +125,7 @@
124125
"color": [1, 0.65, 0]
125126
},
126127
"transform": {
127-
"position": [0.22, -0.2, -0.45]
128+
"translate": [0.22, -0.2, -0.45]
128129
}
129130
},
130131
{
@@ -134,7 +135,7 @@
134135
"color": [0.1, 0.8, 0.8]
135136
},
136137
"transform": {
137-
"position": [0, -0.25, 0]
138+
"translate": [0, -0.25, 0]
138139
}
139140
},
140141
{
@@ -144,7 +145,7 @@
144145
"color": [1, 1, 1]
145146
},
146147
"transform": {
147-
"position": [0, 0, -20],
148+
"translate": [0, 0, -20],
148149
"rotation": [
149150
[1, 0, 0, 90]
150151
]
@@ -193,4 +194,4 @@
193194
"shadowBands": 0
194195
}
195196
]
196-
}
197+
}

scene-template/scene.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
To produce image and gif from README:
2+
3+
[Scene image]
4+
5+
PixelRay -i scene.json -o output.png
6+
7+
8+
[Scene animation]
9+
10+
PixelRay -i scene.json -s script.lua 195 -g

scene-template/script.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
torus1 = scene:GetObject("torus1")
2+
3+
function update(t)
4+
torus1:ResetTransform() -- this resets transform back to default in scene file. Useful for parametrized equations
5+
6+
frames = 195 -- total frames required ()
7+
rotationFrames = 120 -- 120 is good for smooth full camera rotation
8+
9+
if t < 15 then
10+
-- keep camera at default position
11+
elseif t >= 15 and t < 30 then
12+
-- gradually move camera to look towards cone + zoom in a bit
13+
cosAngle = math.cos((2*math.pi/rotationFrames)*(t-15))
14+
sinAngle = math.sin((2*math.pi/rotationFrames)*(t-15))
15+
16+
camera:LookAt(-sinAngle, 0, -cosAngle)
17+
camera:Position(-0.02*(t-15), 0, -0.025*(t-15))
18+
elseif t >= 30 and t < 45 then
19+
-- keep camera pointed at cone
20+
elseif t >= 45 and t < 60 then
21+
-- revert back to default position
22+
cosAngle = math.cos((2*math.pi/rotationFrames)*(59-t))
23+
sinAngle = math.sin((2*math.pi/rotationFrames)*(59-t))
24+
25+
camera:LookAt(-sinAngle, 0, -cosAngle)
26+
camera:Position(-0.02*(59-t), 0, -0.025*(59-t))
27+
elseif t >= 60 and t < 75 then
28+
-- keep camera at default position
29+
else
30+
-- full xz-plane camera rotation around center
31+
cosAngle = math.cos((2*math.pi/rotationFrames)*(t-75))
32+
sinAngle = math.sin((2*math.pi/rotationFrames)*(t-75))
33+
center = {0, 0, -1}
34+
radius = 1.5
35+
x = radius*(sinAngle-center[1])
36+
z = radius*(cosAngle+center[3])
37+
38+
camera:Position(x, 0, z)
39+
end
40+
41+
-- torus y-axis rotation into opposite direction
42+
unit = 360 / frames;
43+
torus1:Translate(0, -0.05, 0.75)
44+
torus1:Rotate(0, 1, 0, -2*unit*t)
45+
torus1:Translate(0, 0.05, -0.75)
46+
end

0 commit comments

Comments
 (0)