Skip to content

Commit 0b21af7

Browse files
committed
Add blender loader script
1 parent 88a26c1 commit 0b21af7

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

blender/loader.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import bpy
3+
import math
4+
5+
6+
INPUT_PATH = '/home/...../crystal/explore'
7+
OUTPUT_PATH = '/home/...../crystal/output'
8+
RESOLUTION_X = 1920
9+
RESOLTUION_Y = 1080
10+
ITERATION = 8
11+
12+
13+
# Delete objects
14+
def delete_all_mesh():
15+
for obj in bpy.context.scene.objects:
16+
if obj.type == 'MESH':
17+
obj.select_set(True)
18+
else:
19+
obj.select_set(False)
20+
21+
# Call the operator only once
22+
bpy.ops.object.delete()
23+
24+
25+
def render(idx):
26+
filepath = os.path.join(INPUT_PATH, f'output-{idx}.obj')
27+
imported_object = bpy.ops.import_scene.obj(filepath=filepath)
28+
obj_object = bpy.context.selected_objects[0]
29+
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')
30+
print(f'Imported name: {obj_object.name}')
31+
32+
# Zoom to object
33+
for area in bpy.context.screen.areas:
34+
if area.type == 'VIEW_3D':
35+
for region in area.regions:
36+
if region.type == 'WINDOW':
37+
override = {'area': area, 'region': region}
38+
bpy.ops.view3d.camera_to_view_selected(override)
39+
40+
# Render frame
41+
bpy.context.scene.render.filepath = os.path.join(OUTPUT_PATH, f'output-{idx}.png')
42+
bpy.ops.render.render(write_still=True)
43+
44+
45+
for i in range(ITERATION):
46+
delete_all_mesh()
47+
idx = f"{i}".zfill(6)
48+
print(f"Rendering {idx}...")
49+
render(idx)

0 commit comments

Comments
 (0)