Create multiple snapshots

snapshots.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3newScene()
 4
 5import time, tempfile, os
 6
 7number_of_snapshots = 5
 8
 9path = os.path.join(tempfile.gettempdir(), 'vred_snapshots')
10if not os.path.exists(path):    
11    os.mkdir(path)
12print("Using temp directory for snapshots: " + path)
13# now delete all old snapshots.
14for root, dirs, files in os.walk(path, topdown=False):
15    for name in files:
16        if name[:4] == 'test':
17            os.remove(os.path.join(root, name))
18print("snapshot directory:", path)
19
20box = createBox(1000, 1000, 1000, 10, 10, 10, 1.0, 0.0, 0.0)
21updateScene()
22
23#setSuperSampling(true)
24setSnapshotQuality(75)
25
26createSnapshotFastInit(640, 320)
27
28t = time.time()
29for i in range(number_of_snapshots):
30    setCameraRotation(1.0 / number_of_snapshots, 0.0)
31    filename = os.path.join(path, ('testa%04d.jpg') % (i))
32    createSnapshotFast(filename)
33
34box2 = createBox(1000, 1000, 1000, 10, 10, 10, 0.0, 0.0, 1.0)
35box2.setTranslation(1000, 0, 0)
36updateScene()
37for i in range(number_of_snapshots):
38    setCameraRotation(1.0 / number_of_snapshots, 0.0)
39    filename = os.path.join(path, ('testb%04d.jpg') % (i))
40    createSnapshotFast(filename)
41
42createSnapshotFastTerminate()
43
44sps = (1.0 / (time.time() - t)) * number_of_snapshots
45print(sps, "snapshots per second.")