- [IsoSurf] Add per surface offset property.

This commit is contained in:
Tanasart 2024-06-02 09:15:18 +07:00
parent 1bf10aac2e
commit 741a77c8a7
7 changed files with 153 additions and 29 deletions

View file

@ -1,6 +1,23 @@
function draw_rectangle_border(x1, y1, x2, y2, thick) { function draw_rectangle_border(x1, y1, x2, y2, thick) {
INLINE
draw_line_width(x1 - thick / 2, y1, x2 + thick / 2, y1, thick); draw_line_width(x1 - thick / 2, y1, x2 + thick / 2, y1, thick);
draw_line_width(x1 - thick / 2, y2, x2 + thick / 2, y2, thick); draw_line_width(x1 - thick / 2, y2, x2 + thick / 2, y2, thick);
draw_line_width(x1, y1 - thick / 2, x1, y2 + thick / 2, thick); draw_line_width(x1, y1 - thick / 2, x1, y2 + thick / 2, thick);
draw_line_width(x2, y1 - thick / 2, x2, y2 + thick / 2, thick); draw_line_width(x2, y1 - thick / 2, x2, y2 + thick / 2, thick);
}
function ui_rect(x1, y1, x2, y2, color, alpha = 1) {
INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 1, x1, y1, x2 - x1, y2 - y1, color, 1);
}
function ui_rect_wh(x1, y1, w, h, color, alpha = 1) {
INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 1, x1, y1, w, h, color, 1);
}
function ui_fill_rect(x1, y1, x2, y2, color, alpha = 1) {
INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 0, x1, y1, x2 - x1, y2 - y1, color, 1);
}
function ui_fill_rect_wh(x1, y1, w, h, color, alpha = 1) {
INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 0, x1, y1, w, h, color, 1);
} }

View file

@ -23,12 +23,12 @@ function dynaSurf_iso() : dynaSurf() constructor {
static draw = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) { static draw = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) {
var _ind = getIndex(_rot); var _ind = getIndex(_rot);
var _surf = array_get(surfaces, _ind); var _surf = array_get(surfaces, _ind);
var _offx = array_get(offsetx, _ind); var _offx = array_get(offsetx, _ind) * _xs;
var _offy = array_get(offsety, _ind); var _offy = array_get(offsety, _ind) * _ys;
var _pos = getAbsolutePos(_x, _y, _xs, _ys, _rot); var _pos = getAbsolutePos(_x, _y, _xs, _ys, _rot);
draw_surface_ext_safe(_surf, _pos[0] + _offx, _pos[1] + _offy, _xs, _ys, 0, _col, _alp); draw_surface_ext_safe(_surf, _pos[0] - _offx, _pos[1] - _offy, _xs, _ys, 0, _col, _alp);
} }
static drawTile = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _col = c_white, _alp = 1) { static drawTile = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _col = c_white, _alp = 1) {
@ -39,10 +39,10 @@ function dynaSurf_iso() : dynaSurf() constructor {
static drawPart = function(_l, _t, _w, _h, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) { static drawPart = function(_l, _t, _w, _h, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) {
var _ind = getIndex(_rot); var _ind = getIndex(_rot);
var _surf = array_get(surfaces, _ind); var _surf = array_get(surfaces, _ind);
var _offx = array_get(offsetx, _ind); var _offx = array_get(offsetx, _ind) * _xs;
var _offy = array_get(offsety, _ind); var _offy = array_get(offsety, _ind) * _ys;
draw_surface_part_ext_safe(_surf, _l, _t, _w, _h, _x + _offx, _y + _offy, _xs, _ys, 0, _col, _alp); draw_surface_part_ext_safe(_surf, _l, _t, _w, _h, _x - _offx, _y - _offy, _xs, _ys, 0, _col, _alp);
} }
static clone = function() { static clone = function() {

View file

@ -1529,7 +1529,12 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
var _sw = __preview_sw; var _sw = __preview_sw;
var _sh = __preview_sh; var _sh = __preview_sh;
var _ss = min(bbox.w / _sw, bbox.h / _sh); var _ss = min(bbox.w / _sw, bbox.h / _sh);
draw_surface_ext_safe(preview_surface, bbox.xc - _sw * _ss / 2, bbox.yc - _sh * _ss / 2, _ss, _ss);
var _ps = preview_surface;
if(is_struct(_ps) && is_instanceof(_ps, dynaSurf))
_ps = array_safe_get_fast(_ps.surfaces, 0, noone);
draw_surface_ext_safe(_ps, bbox.xc - _sw * _ss / 2, bbox.yc - _sh * _ss / 2, _ss, _ss);
} #endregion } #endregion
static getNodeDimension = function(showFormat = true) { #region static getNodeDimension = function(showFormat = true) { #region
@ -1738,15 +1743,15 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
static getPreviewValues = function() { #region static getPreviewValues = function() { #region
if(preview_channel >= ds_list_size(outputs)) return noone; if(preview_channel >= ds_list_size(outputs)) return noone;
switch(outputs[| preview_channel].type) { var _type = outputs[| preview_channel].type;
case VALUE_TYPE.surface : if(_type != VALUE_TYPE.surface && _type != VALUE_TYPE.dynaSurface)
case VALUE_TYPE.dynaSurface : return noone;
break;
default :
return noone;
}
return outputs[| preview_channel].getValue(); var val = outputs[| preview_channel].getValue();
if(is_struct(val) && is_instanceof(val, dynaSurf))
val = array_safe_get_fast(val.surfaces, 0, noone);
return val;
} #endregion } #endregion
static getPreviewBoundingBox = function() { #region static getPreviewBoundingBox = function() { #region

View file

@ -1,7 +1,8 @@
function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "IsoSurf"; name = "IsoSurf";
inputs[| 0] = nodeValue("Direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4); inputs[| 0] = nodeValue("Direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4)
.setRange(1, undefined);
inputs[| 1] = nodeValue("Surfaces", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone) inputs[| 1] = nodeValue("Surfaces", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
.setVisible(true, true) .setVisible(true, true)
@ -20,6 +21,7 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
outputs[| 0] = nodeValue("IsoSurf", self, JUNCTION_CONNECT.output, VALUE_TYPE.dynaSurface, noone); outputs[| 0] = nodeValue("IsoSurf", self, JUNCTION_CONNECT.output, VALUE_TYPE.dynaSurface, noone);
knob_select = noone;
knob_hover = noone; knob_hover = noone;
knob_dragging = noone; knob_dragging = noone;
drag_sv = 0; drag_sv = 0;
@ -65,17 +67,26 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
draw_surface_ext(_surf, _knx - _sw * _ss / 2, _kny - _sh * _ss / 2, _ss, _ss, 0, c_white, 1); draw_surface_ext(_surf, _knx - _sw * _ss / 2, _kny - _sh * _ss / 2, _ss, _ss, 0, c_white, 1);
} }
draw_set_color(COLORS._main_text_sub); var cc = COLORS._main_icon;
draw_rectangle(_knx - 16, _kny - 16, _knx + 16, _kny + 16, true); if(i == knob_hover) cc = COLORS._main_icon_light;
if(i == knob_select) cc = COLORS._main_accent;
ui_rect_wh(_knx - 20, _kny - 20, 40, 40, cc);
if(point_in_rectangle(_m[0], _m[1], _knx - 20, _kny - 20, _knx + 20, _kny + 20))
_khover = i;
} }
knob_hover = _khover; knob_hover = _khover;
if(mouse_press(mb_left, _focus) && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh))
knob_select = knob_hover;
if(knob_dragging == noone) { if(knob_dragging == noone) {
if(knob_hover >= 0 && mouse_press(mb_left, _focus)) { if(knob_hover >= 0 && mouse_press(mb_left, _focus)) {
knob_dragging = knob_hover; knob_dragging = knob_hover;
drag_sv = _angle[knob_hover]; drag_sv = _angle[knob_hover];
drag_sa = _angle[knob_hover]; drag_sa = point_direction(_kx, _ky, _m[0], _m[1]);
} }
} else { } else {
var delta = angle_difference(point_direction(_kx, _ky, _m[0], _m[1]), drag_sa); var delta = angle_difference(point_direction(_kx, _ky, _m[0], _m[1]), drag_sa);
@ -92,21 +103,97 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
return hh; return hh;
}); #endregion }); #endregion
offsetRenderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
var hh = ui(160);
var _surfs = getInputData(1);
var _offs = getInputData(4);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, hh, COLORS.node_composite_bg_blend, 1);
if(!is_array(_surfs) || !is_array(_offs)) return hh;
if(knob_select == noone) return hh;
var surf = array_safe_get(_surfs, knob_select);
if(!is_surface(surf)) return hh;
var amo = array_length(_surfs);
var _off = array_safe_get(_offs, knob_select);
var pd = ui(8);
var sw = _w - pd * 2;
var sh = hh - pd * 2;
var srw = surface_get_width(surf);
var srh = surface_get_height(surf);
var ss = min((sw - pd) / srw, (sh - pd) / srh);
var sx = _x + _w / 2 - srw * ss / 2;
var sy = _y + hh / 2 - srh * ss / 2;
ui_fill_rect_wh(sx, sy, srw * ss, srh * ss, CDEF.main_dkblack);
draw_surface_ext(surf, sx, sy, ss, ss, 0, c_white, 1);
if(point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh)) {
var _mx = clamp(value_snap((_m[0] - sx) / ss, 0.5), 0, srw);
var _my = clamp(value_snap((_m[1] - sy) / ss, 0.5), 0, srh);
draw_set_text(f_p3, fa_right, fa_bottom, COLORS._main_text_sub);
draw_text(_x + _w - 4, _y + hh - 4, $"{_mx}, {_my}");
var _ox = sx + _mx * ss - 1;
var _oy = sy + _my * ss - 1;
draw_set_color(CDEF.main_dkgrey);
draw_line(sx, _oy, sx + srw * ss, _oy);
draw_line(_ox, sy, _ox, sy + srh * ss);
if(mouse_click(mb_left, _focus)) {
_offs[knob_select][0] = _mx;
_offs[knob_select][1] = _my;
inputs[| 4].setValue(_offs);
}
}
ui_rect_wh(sx, sy, srw * ss, srh * ss, COLORS._main_icon);
if(!is_array(_off)) return hh;
var _ox = sx + _off[0] * ss - 1;
var _oy = sy + _off[1] * ss - 1;
draw_set_color(c_white);
draw_line_width(_ox - 4, _oy, _ox + 4, _oy, 2);
draw_line_width(_ox, _oy - 4, _ox, _oy + 4, 2);
return hh;
}); #endregion
input_display_list = [ input_display_list = [
["Iso", false], 0, 2, angle_renderer, ["Iso", false], 0, 2, angle_renderer, offsetRenderer,
["Data", false], 1, 4, ["Data", false], 1, 4,
]; ];
static resetOffset = function() {
var _amo = getInputData(0);
var _off = array_create(_amo);
for( var i = 0, n = _amo; i < n; i++ )
_off[i] = [ 0, 0 ];
inputs[| 4].setValue(_off);
}
static onValueUpdate = function(index) { static onValueUpdate = function(index) {
if(index != 0) return; if(index != 0) return;
var _amo = getInputData(0); var _amo = getInputData(0);
var _off = getInputData(4);
var _ang = array_create(_amo); var _ang = array_create(_amo);
var _off = array_create(_amo); array_resize(_off, _amo);
for( var i = 0, n = _amo; i < n; i++ ) { for( var i = 0, n = _amo; i < n; i++ ) {
_ang[i] = 360 * (i / _amo); _ang[i] = 360 * (i / _amo);
_off[i] = [ 0, 0 ]; _off[i] = array_verify(_off[i], 2);
} }
inputs[| 3].setValue(_ang); inputs[| 3].setValue(_ang);

View file

@ -125,6 +125,9 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
node.input_value_map[$ internalName] = _value; node.input_value_map[$ internalName] = _value;
__curr_get_val = [ 0, 0 ]; __curr_get_val = [ 0, 0 ];
value_range_min = undefined;
value_range_max = undefined;
#endregion #endregion
#region ---- draw ---- #region ---- draw ----
@ -302,6 +305,13 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
return self; return self;
} #endregion } #endregion
static setRange = function(_min, _max) { #region
value_range_min = _min;
value_range_max = _max;
return self;
} #endregion
static rejectArray = function() { #region static rejectArray = function() { #region
accept_array = false; accept_array = false;
return self; return self;
@ -1041,6 +1051,9 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
value[i] = clamp(value[i], 0, 8192); value[i] = clamp(value[i], 0, 8192);
} }
if(value_range_min != undefined) value = max(value, value_range_min);
if(value_range_max != undefined) value = min(value, value_range_max);
return value; return value;
} #endregion } #endregion

View file

@ -833,7 +833,7 @@ function Panel_Inspector() : PanelContent() constructor {
prop_highlight = noone; prop_highlight = noone;
} }
return hh + ui(64); return hh;
} #endregion } #endregion
contentPane = new scrollPane(content_w, content_h, function(_y, _m) { #region contentPane = new scrollPane(content_w, content_h, function(_y, _m) { #region
@ -880,7 +880,7 @@ function Panel_Inspector() : PanelContent() constructor {
_hh += _h; _hh += _h;
} }
return _hh; return _hh + ui(64);
}); #endregion }); #endregion
function propSelectCopy() { #region function propSelectCopy() { #region

View file

@ -86,9 +86,12 @@ function surfaceBox(_onModify, def_path = "") : widget() constructor {
if(is_instanceof(_surface, __d3dMaterial)) if(is_instanceof(_surface, __d3dMaterial))
_surface = _surface.surface; _surface = _surface.surface;
if(is_surface(_surface)) { if(is_instanceof(_surface, dynaSurf))
var sfw = surface_get_width_safe(_surface); _surface = array_safe_get_fast(_surface.surfaces, 0, noone);
var sfh = surface_get_height_safe(_surface);
if(surface_exists(_surface)) {
var sfw = surface_get_width(_surface);
var sfh = surface_get_height(_surface);
var ss = min(sw / sfw, sh / sfh); var ss = min(sw / sfw, sh / sfh);
var _sx = sx0 + sw / 2 - ss * sfw / 2; var _sx = sx0 + sw / 2 - ss * sfw / 2;
var _sy = sy0 + sh / 2 - ss * sfh / 2; var _sy = sy0 + sh / 2 - ss * sfh / 2;
@ -114,8 +117,7 @@ function surfaceBox(_onModify, def_path = "") : widget() constructor {
draw_text_add(sx1 - ui(3), sy1 + ui(1), _txt); draw_text_add(sx1 - ui(3), sy1 + ui(1), _txt);
} }
draw_set_color(COLORS.widget_surface_frame); ui_rect(sx0, sy0, sx1, sy1, COLORS.widget_surface_frame);
draw_rectangle(sx0, sy0, sx1 - 1, sy1 - 1, true);
if(_type == VALUE_TYPE.surface) if(_type == VALUE_TYPE.surface)
draw_sprite_ui_uniform(THEME.scroll_box_arrow, 0, _x + _w - min(_h / 2, ui(20)), _y + _h / 2, min(1, _h / 64), COLORS._main_icon, 0.5 + 0.5 * interactable); draw_sprite_ui_uniform(THEME.scroll_box_arrow, 0, _x + _w - min(_h / 2, ui(20)), _y + _h / 2, min(1, _h / 64), COLORS._main_icon, 0.5 + 0.5 * interactable);