File: povray_movie.py

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (44 lines) | stat: -rwxr-xr-x 1,616 bytes parent folder | download | duplicates (9)
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
#
# Render a simple movie of the current models being rotated around the look-at vector of the camera by
# 360 degrees. Output is written as povray models, so make sure your file system has sufficient space
# left if you render larger surfaces.
#

# The step size in degrees between subsequent frames. 2 obviously leads to 180 frames being generated
step = 5
# directory for storing the POVRay files (Warning: these can get HUGE!)
movie_dir = '.'
# base filename for the movie files. a number and .pob will be appended
movie_base = 'movie'

import os

# Get access to the maincontrol.
mc = MainControl.getInstance(0)
cm = mc.getCompositeManager()
s = Scene.getInstance(0)
camera = Camera(s.getStage().getCamera())
old_viewpoint = Vector3(camera.getViewPoint())

vv = Vector3(camera.getViewPoint())
la = Vector3(camera.getLookAtPosition())

# Compute rotation matrix for rotation about (camera) Y-axis
frame_angle = Angle(step, 0)
matrix = Matrix4x4()
matrix.setRotation(frame_angle, camera.getLookUpVector())

for snap in range(360. / step):
	print "writing snapshot",snap, "of", (360 / step)
	vv = camera.getViewPoint() - la
	vv = Vector3(matrix.m11 * vv.x + matrix.m12 * vv.y + matrix.m13 * vv.z + matrix.m14, matrix.m21 * vv.x + matrix.m22 * vv.y + matrix.m23 * vv.z + matrix.m24, matrix.m31 * vv.x + matrix.m32 * vv.y + matrix.m33 * vv.z + matrix.m34)
	camera.setViewPoint(vv + la)
	s.setCamera(camera)
	filename = os.path.join(movie_dir, movie_base + "_%04d.pov" % snap)
	s.exportScene(POVRenderer(filename))

print "finished"

# Reset the camera.
camera.setViewPoint(old_viewpoint)
s.setCamera(Camera(camera))