-
Notifications
You must be signed in to change notification settings - Fork 3
/
awbwnd_modelview.lua
202 lines (168 loc) · 5.58 KB
/
awbwnd_modelview.lua
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
--
-- AWB 3D Model Viewer
--
local shader_seqn = 1;
local function set_shader(modelv)
local lshdr = load_shader("shaders/dir_light.vShader",
"shaders/dir_light.fShader", "media3d_" .. tostring(shader_seqn));
shader_seqn = shader_seqn + 1;
shader_uniform(lshdr, "map_diffuse", "i", PERSIST, 0);
shader_uniform(lshdr, "wlightdir", "fff", PERSIST, 1, 0, 0);
shader_uniform(lshdr, "wambient", "fff", PERSIST, 0.3, 0.3, 0.3);
shader_uniform(lshdr, "wdiffuse", "fff", PERSIST, 0.6, 0.6, 0.6);
image_shader(modelv, lshdr);
return lshdr;
end
local function zoom_in(self)
local pwin = self.parent.parent;
pwin:focus();
props = image_surface_properties(pwin.model.vid);
move3d_model(pwin.model.vid, props.x, props.y, props.z + 1.0,
awbwman_cfg().animspeed);
end
local function zoom_out(self)
local pwin = self.parent.parent;
pwin:focus();
props = image_surface_properties(pwin.model.vid);
move3d_model(pwin.model.vid, props.x, props.y, props.z - 1.0,
awbwman_cfg().animspeed);
end
local function datashare(wnd)
local res = awbwman_setup_cursortag(sysicons.floppy);
res.kind = "media";
res.source = wnd;
res.audio = wnd.recv;
res.name = wnd.name;
return res;
end
local function add_3dmedia_top(pwin)
local bar = pwin:add_bar("tt", pwin.ttbar_bg, pwin.ttbar_bg,
pwin.dir.t.rsize, pwin.dir.t.bsize);
local cfg = awbwman_cfg();
bar:add_icon("zoom_in", "l", cfg.bordericns["plus"], zoom_in);
bar:add_icon("zoom_out", "l", cfg.bordericns["minus"], zoom_out);
bar:add_icon("light_r", "l", cfg.bordericns["r1"],
function(self)
awbwman_popupslider(0.01, pwin.amb_r, 1.0, function(val)
pwin.amb_r = val;
shader_uniform(pwin.shader, "wambient", "fff", PERSIST,
pwin.amb_r, pwin.amb_g, pwin.amb_b);
end, {ref = self.vid})
end);
bar:add_icon("light_g", "l", cfg.bordericns["g1"],
function(self)
awbwman_popupslider(0.01, pwin.amb_g, 1.0, function(val)
pwin.amb_g = val;
shader_uniform(pwin.shader, "wambient", "fff", PERSIST,
pwin.amb_r, pwin.amb_g, pwin.amb_b);
end, {ref = self.vid})
end);
bar:add_icon("light_b", "l", cfg.bordericns["b1"],
function(self)
awbwman_popupslider(0.01, pwin.amb_b, 1.0, function(val)
pwin.amb_b = val;
shader_uniform(pwin.shader, "wambient", "fff", PERSIST,
pwin.amb_r, pwin.amb_g, pwin.amb_b);
end, {ref = self.vid})
end);
bar.hoverlut[
(bar:add_icon("clone", "r", cfg.bordericns["clone"],
function() datashare(pwin); end)).vid
] = MESSAGE["HOVER_CLONE"];
bar.name = "3dmedia_top";
end
local function input_3dwin(self, iotbl)
if (iotbl.active == false or iotbl.lutsym == nil) then
return;
end
-- dropped the rotate functions from here as some want
-- to play using global input capture and game output on display
end
--
-- pwin is a previously set-up awbwnd,
-- source is a table populated by the load_model call.
--
function awbwnd_modelview(pwin, source)
local dstvid = alloc_surface(VRESW, VRESH);
image_tracetag(dstvid, "3dmedia_rendertarget");
pwin.shader = set_shader(source.vid);
show_image(source.vid);
-- render to texture for easier clipping, position etc.
-- but also for chaining onwards (using as recordtarget)
define_rendertarget(dstvid, {source.vid},
RENDERTARGET_DETACH, RENDERTARGET_NOSCALE, -1, RENDERTARGET_FULL);
-- camera for the new rendertarget
local camera = null_surface(1, 1);
scale3d_model(camera, 1.0, -1.0, 1.0);
rendertarget_attach(dstvid, camera, RENDERTARGET_DETACH);
camtag_model(camera, 0.01, 100.0, 45.0, 1.33);
image_tracetag(camera, "3dcamera");
pwin:update_canvas(dstvid);
pwin.name = "3d model";
pwin.model = source;
pwin.input = input_3dwin;
pwin.amb_r = 0.3;
pwin.amb_g = 0.3;
pwin.amb_b = 0.3;
pwin.helpmsg = MESSAGE["HELP_3DMEDIA"];
pwin.on_resized = function(wnd, wndw, wndh, cnvw, cnvh)
image_resize_storage(dstvid, cnvw, cnvh);
resize_image(dstvid, cnvw, cnvh);
end
-- this needs to be unique for each window as it's also
-- used as handler table for another window
pwin.dispsrc_update = function(self, srcwnd)
if (pwin.alive == false) then
return;
end
local newdisp = null_surface(32, 32);
image_tracetag(newdisp, "media_displaytag");
image_sharestorage(srcwnd.canvas.vid, newdisp);
pwin.model:update_display(newdisp, true);
end
local mh = {
name = "3dwindow_canvas",
own = function(self, vid) return vid == dstvid; end,
drag = function(self, vid, dx, dy)
pwin:focus();
if (awbwman_cfg().meta.shift) then
local props = image_surface_properties(pwin.model.vid);
move3d_model(pwin.model.vid, props.x,
props.y + 0.01 * dy, props.z + 0.01 * dx);
else
rotate3d_model(source.vid, 0.0, dy, dx, 0, ROTATE_RELATIVE);
end
end,
-- hint that this window accepts drag'n'drop for media
over = function(self, vid)
local tag = awbwman_cursortag();
if (tag and tag.kind == "media" and vid == pwin.canvas.vid) then
tag:hint(true);
end
end,
out = function()
local tag = awbwman_cursortag();
if (tag and tag.kind == "media") then
tag:hint(false);
end
end,
-- for drag'n'drop, also make sure to register as an update
-- handler so the display will be changed
-- whenever the source material does
click = function()
local tag = awbwman_cursortag();
pwin:focus();
if (tag and tag.kind == "media") then
if (pwin.update_source and pwin.update_source.alive) then
pwin.update_source:drop_handler("on_update", pwin.dispsrc_update);
end
pwin.update_source = tag.source;
pwin.update_source:add_handler("on_update", pwin.dispsrc_update);
pwin:dispsrc_update(tag.source);
tag:drop();
end
end};
mouse_addlistener(mh, {"drag", "click", "over", "out"});
add_3dmedia_top(pwin, active, inactive);
table.insert(pwin.handlers, mh);
end