-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.lua
More file actions
182 lines (132 loc) · 3.58 KB
/
Copy pathscript.lua
File metadata and controls
182 lines (132 loc) · 3.58 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
-- Helpers
function str_split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function goto_facet(f)
if f > 0 then
print("double click on facet:" .. tostring(f))
local min, max = get_facet_bbox(app.model, f)
print("min:" .. min:to_string())
print("max:" .. max:to_string())
app.camera:look_at_box({min, max})
end
end
function init()
end
-- Parameters
local filter_ids = ""
local id = ""
local invert = false
local n_ring_size = 0
function update_filter()
local tri_model = app.model:as_tri()
local fa = FacetAttributeDouble.new(invert and 0.0 or 1.0)
fa:bind("_filter", tri_model.surface_attributes, tri_model.mesh)
local v = invert and 0.0 or 1.0
print("choose " .. tostring(v))
fa:fill(v)
local t = str_split(filter_ids, ";")
for i=1, #t do
local id = tonumber(t[i])
if id then
fa[id] = invert and 1.0 or 0.0
local ring_ids = n_ring(app.model, id, n_ring_size)
for j=1, #ring_ids do
fa[ring_ids[j]] = invert and 1.0 or 0.0
end
end
end
app.model:set_filter(ElementKind.FACETS_ELT, true)
end
function layout_gui()
return {
["Toolbar##tool_bar_diagnostic"] = "tool_bar",
["Filter & N-Ring##window_filter_and_nring"] = "tool_bar"
}
end
local diagnostic_filter_and_nring_path = "diagnostic/filter-and-nring"
function draw_gui()
if not app.has_models then
return
end
imgui.Begin("Toolbar##tool_bar_diagnostic")
if app.navigation_path:str() == diagnostic_filter_and_nring_path then
imgui.BeginDisabled()
end
local has_changed = false
if imgui.Button("Filter & N-Ring") then
-- Change nav path
app.navigation_path = diagnostic_filter_and_nring_path
has_changed = true
end
if not has_changed and app.navigation_path:str() == diagnostic_filter_and_nring_path then
imgui.EndDisabled()
end
if imgui.Button("Return to main") then
-- Change nav path
app.navigation_path = ""
end
imgui.End()
if app.navigation_path:str() == diagnostic_filter_and_nring_path then
imgui.Begin("Filter & N-Ring##window_filter_and_nring")
local sel, new_filter_ids = imgui.InputText("Facet ids to filter", filter_ids, 255)
filter_ids = new_filter_ids
if sel then
update_filter()
end
local sel_n_ring_size, new_n_ring_size = imgui.InputInt("N Ring", n_ring_size)
if sel_n_ring_size then
n_ring_size = new_n_ring_size
update_filter()
end
imgui.SameLine()
local sel_invert, new_invert = imgui.Checkbox("Invert", invert)
if sel_invert then
invert = new_invert
update_filter()
end
if imgui.SmallButton("Go to facet") then
local t = str_split(filter_ids, ";")
if #t > 0 then
local id = tonumber(t[1])
if id then
goto_facet(id)
end
end
end
local hovered_facet = app.input_state.facet.hovered
imgui.Text("Hovered facet: " .. tostring(hovered_facet))
imgui.End()
end
end
function mouse_button()
if app.navigation_path:str() == diagnostic_filter_and_nring_path then
if app.input_state.mouse.dbl_buttons[1] then
-- Go to
local f = app.input_state.facet.hovered
goto_facet(f)
end
end
end
function navigation_path_changed(old_path, new_path)
-- Setup gfx !
-- if new_path[1] == "diagnostic" and new_path[2] == "filter-and-nring" then
if new_path:str() == "diagnostic/filter-and-nring" then
-- TODO save previous gfx
app.model.points.visible = false
app.model.edges.visible = true
app.model.edges.thickness = 1.
app.model.mesh.size = 1.
end
if #new_path == 0 then
app.model.edges.visible = false
app.model.mesh.size = 0.
end
end