-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh_visualization.py
65 lines (52 loc) · 1.98 KB
/
mesh_visualization.py
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
from genericpath import exists
import bpy
import os
from pathlib import Path
import configparser
import numpy as np
C = bpy.context
D = bpy.data
scene = D.scenes['Scene']
def render_obj(input_filepath, output_filepath):
bpy.ops.import_scene.obj(filepath=input_filepath, axis_forward='Y', axis_up='Z')
obj_object = bpy.context.selected_objects[0] ####<--Fix
name = obj_object.name
target = D.objects[name]
bpy.context.view_layer.objects.active = target
bpy.context.active_object.select_set(state=True)
bpy.ops.object.material_slot_add()
# Get material
mat = bpy.data.materials.get("My_Water")
target.data.materials[0] = mat
bpy.ops.render.render()
D.images['Render Result'].save_render(filepath=output_filepath)
print('save to ' + output_filepath)
target = D.objects[2]
bpy.context.view_layer.objects.active = target
bpy.ops.object.delete()
def main():
parent_folder = "/Users/adrianchang/desktop/CS/CS2240/flip/results/workingFolder"
mesh_folder = os.path.join(parent_folder, "meshes")
render_folder = os.path.join(parent_folder, "renders")
if not os.path.exists(render_folder):
os.mkdir(render_folder)
print("Collecting filenames")
filenames = []
for file in os.listdir(mesh_folder):
filename = os.fsdecode(file)
if filename.endswith(".obj"):
filenames.append(filename)
filenames = sorted(filenames, key=lambda x: float(Path(x).stem))
print("Iterating through filenames")
for filename in filenames:
#Import relevant objs
input_filepath = os.path.join(mesh_folder, filename)
output_filepath = os.path.join(render_folder, Path(filename).stem + ".png")
if os.path.isfile(output_filepath):
print(output_filepath, "already exists, skipping render!")
else:
print(input_filepath)
print(output_filepath)
render_obj(input_filepath, output_filepath)
if __name__ == "__main__":
main()