forked from Ozeuth/Houdini-Plugin-For-Mesh-Reparation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.py
145 lines (136 loc) · 4.13 KB
/
session.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -- Houdini Mesh Repairer -- #
import hou
import glob
import nodesearch
import os
from PIL import ImageFont
import time
from threading import Thread
HDA_name = "Mesh_Repairer_Oz"
cameras_info = {
"centers": [],
"rotationsx": [],
"rotationsy": [],
"normals": [],
"zooms": []
}
# ------------ Generic Utility Functions ------------ #
def find_parm(node, name):
params = hou.parent().parms()
found_eval = None
for param in params:
if (name in param.name()):
found_eval = param.eval()
break
return found_eval
# ------------ Pipeline Functions ------------ #
def reset_camera(camera):
camera.parmTuple('t').set((0, 0, 0))
camera.parmTuple('r').set((0, 0, 0))
def reset_camera_info():
cameras_info["center"] = []
cameras_info["rotationsx"] = []
cameras_info["rotationsy"] = []
cameras_info["normals"] = []
cameras_info["zooms"] = []
def render_then_map(image_paths, node_2d, is_full):
'''
NOTE: This is a tenuous solution to a synchronicity issue.
Absence of a rendering checkpoint file means:
A. Rendering has ended
OR
B. Rendering has not started
We must first check that all renders have started, then that all renders have ended
This must be done in a thread (Or renders that have not started will not start)
'''
print("Rendering Start!")
render_started = [False] * len(image_paths)
while sum(render_started) != len(image_paths):
for i in range(len(image_paths)):
render_started[i] = render_started[i] or os.path.isfile(image_paths[i] + ".mantra_checkpoint")
time.sleep(1)
for image_path in image_paths:
while (os.path.isfile(image_path + ".mantra_checkpoint")):
time.sleep(1)
print("Rendering Complete!")
node_2d.bypass(False)
if is_full:
low_repair()
def preprocess():
matcher = nodesearch.Name(HDA_name)
for node in matcher.nodes(hou.node("/obj/"), recursive=True):
if hou.node(node.path() + "/repeat_end"):
node_prep = hou.node(node.path() + "/repeat_end")
break
'''
1. Clean Tooth Edges
'''
node_prep.parm("stopcondition").set(0)
def low_repair():
preprocess()
# Low Frequency Pass
matcher = nodesearch.Name(HDA_name)
for node in matcher.nodes(hou.node("/obj/"), recursive=True):
if hou.node(node.path() + "/lf_3d"):
node_prep_clean = hou.node(node.path() + "/lf_3d")
break
'''
1. Topology Repair
'''
node_prep_clean.bypass(False)
def high_repair(is_full=False):
preprocess()
# High Frequency Pass
matcher = nodesearch.Name(HDA_name)
for node in matcher.nodes(hou.node("/obj/"), recursive=True):
if hou.node(node.path() + "/hf_prepare_3d"):
node_3d = hou.node(node.path() + "/hf_prepare_3d")
if hou.node(node.path() + "/hf_optimize_3d"):
node_op_3d = hou.node(node.path() + "/hf_optimize_3d")
if hou.node(node.path() + "/hf_prepare_2d"):
node_2d = hou.node(node.path() + "/hf_prepare_2d")
'''
1. Choose 3D Context Region
'''
node_3d.bypass(False)
'''
2-4. 3D Context Region Optimization
'''
node_op_3d.bypass(False)
'''
5. Generate 2D Render
'''
num_images = len(glob.glob(hou.hipFile.name().split(".")[0] + "/*_opening.png"))
mark_for_destroy = []
image_paths = []
cameras = hou.nodeType(hou.objNodeTypeCategory(),"cam").instances()
for camera in cameras:
camera_name = camera.name()
if "oz_camera_" in camera_name and int(filter(str.isdigit, camera_name)) > num_images:
mark_for_destroy.append(camera)
renders = hou.nodeType(hou.ropNodeTypeCategory(), "ifd").instances()
for render in renders:
render_name = render.name()
if "oz_render_" in render_name:
if int(filter(str.isdigit, render_name)) <= num_images:
image_paths.append(render.parm("vm_picture").eval())
render.render()
else:
mark_for_destroy.append(render)
'''
6. Map 3D Region -> 2D Render
7. 2D Repair
'''
#render_then_map(image_paths, node_2d)
render_map_thread = Thread(target=render_then_map, args=(image_paths,node_2d,is_full,))
render_map_thread.start()
'''
*. Clean-Up
'''
for node in mark_for_destroy:
node.destroy()
reset_camera_info()
# Both Passes
def repair():
preprocess()
high_repair(is_full=True)