[Vec2, 3, 4] Add individual axis output.

This commit is contained in:
Tanasart 2024-12-21 16:07:11 +07:00
parent 7ba50ad0fc
commit 239f52018f
9 changed files with 217 additions and 114 deletions

View file

@ -20,7 +20,7 @@ function Node_VFX_Spawner_Base(_x, _y, _group = noone) : Node(_x, _y, _group) co
newInput(7, nodeValue_Range("Acceleration", self, [ 0, 0 ] , { linked : true }));
newInput(8, nodeValue_Rotation_Random("Orientation", self, [ 0, 0, 0, 0, 0 ] ));
newInput(9, nodeValue_Range("Rotational speed", self, [ 0, 0 ] , { linked : true }));
newInput(10, nodeValue_Vec2_Range("Spawn scale", self, [ 1, 1, 1, 1 ] , { linked : true }));

View file

@ -56,7 +56,7 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
input_display_list = [ 0, 1,
["Editor", false], 2, 6, 3, 5, 4, 7,
["Gizmo", false], 8, 11, 12, 13, 14, 9, 10,
]
];
gz_style = 0;
gz_shape = 0;
@ -119,7 +119,7 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _ah = min(_rw, _rh) / 4;
var _lt = min(_rw, _rh) / 3;
draw_primitive_begin(pr_linestrip);
draw_primitive_begin(pr_linestrip); // arrow shape
draw_vertex(_rx0, _ry);
draw_vertex(_rx0 + _ah, _ry0);
draw_vertex(_rx0 + _ah, _ry0 + _lt);

View file

@ -2,10 +2,7 @@ function Node_Particle(_x, _y, _group = noone) : Node_VFX_Spawner_Base(_x, _y, _
name = "Particle";
use_cache = CACHE_USE.auto;
onSurfaceSize = function() {
var _inp = getInputData(input_len, DEF_SURF);
return [ _inp[0], _inp[1] ];
};
onSurfaceSize = function() /*=>*/ {return getInputData(input_len, DEF_SURF)};
newInput(input_len + 0, nodeValue_Vec2("Output dimension", self, DEF_SURF));

View file

@ -15,7 +15,7 @@ function Node_Path_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
newOutput(1, nodeValue_Output("Direction", self, VALUE_TYPE.float, 0));
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _path = getInputData(0);
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
@ -30,9 +30,9 @@ function Node_Path_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
draw_circle(_px, _py, 4, false);
}
} #endregion
}
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
static processData = function(_output, _data, _output_index, _array_index = 0) {
var _path = _data[0];
var _rat = _data[1];
var _mod = _data[2];
@ -43,9 +43,8 @@ function Node_Path_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
var inv = false;
switch(_mod) {
case 0 :
_rat = frac(_rat);
break;
case 0 : _rat = frac(_rat); break;
case 1 :
var fl = floor(_rat);
var fr = frac(_rat);
@ -70,10 +69,10 @@ function Node_Path_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
var dir = inv? p1.directionTo(p0) : p0.directionTo(p1);
return dir;
}
} #endregion
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(THEME.node_draw_path, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
} #endregion
}
}

View file

@ -50,7 +50,7 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
cached_pos = ds_map_create();
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _path = getInputData(0);
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
@ -61,13 +61,13 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
for( var i = 0; i < _amo; i++ ) {
var _len = getLength(i);
var _stp = 1 / clamp(_len * _s, 1, 64);
var ox, oy, nx, ny;
var _p = new __vec2();
for( var j = 0; j < 1; j += _stp ) {
_p = getPointRatio(j, i, _p);
nx = _x + _p.x * _s;
ny = _y + _p.y * _s;
p = getPointRatio(j, i, p);
nx = _x + p.x * _s;
ny = _y + p.y * _s;
if(j > 0) draw_line_width(ox, oy, nx, ny, 3);
@ -75,17 +75,17 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
oy = ny;
}
}
} #endregion
}
static getLineCount = function() { #region
static getLineCount = function() {
return struct_has(path, "getLineCount")? path.getLineCount() : 1;
} #endregion
}
static getSegmentCount = function(ind = 0) { #region
static getSegmentCount = function(ind = 0) {
return struct_has(path, "getSegmentCount")? path.getSegmentCount(ind) : 0;
} #endregion
}
static getLength = function(ind = 0) { #region
static getLength = function(ind = 0) {
var _fre = fre ; _fre = max(_fre[0], _fre[1]);
var _amo = amp ; _amo = max(_amo[0], _amo[1]);
@ -94,9 +94,9 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
_len *= _fre * sqrt(abs(_amo) + 1 / _fre);
return _len;
} #endregion
}
static getAccuLength = function(ind = 0) { #region
static getAccuLength = function(ind = 0) {
var _fre = fre ; _fre = max(_fre[0], _fre[1]);
var _amo = amp ; _amo = max(_amo[0], _amo[1]);
@ -108,9 +108,9 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
_len[i] *= _mul;
return _len;
} #endregion
}
static getPointRatio = function(_rat, ind = 0, out = undefined) { #region
static getPointRatio = function(_rat, ind = 0, out = undefined) {
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
var _cKey = $"{_rat},{ind}";
@ -170,15 +170,15 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
cached_pos[? _cKey] = out.clone();
return out;
} #endregion
}
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(), ind, out); }
static getBoundary = function(ind = 0) { #region
static getBoundary = function(ind = 0) {
return struct_has(path, "getBoundary")? path.getBoundary(ind) : new BoundingBox( 0, 0, 1, 1 );
} #endregion
}
static update = function() { #region
static update = function() {
ds_map_clear(cached_pos);
path = getInputData(0);
fre = getInputData(1);
@ -192,14 +192,13 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
wigf = getInputData(8);
var _ampc = getInputData(9);
amp_curve = new curveMap(_ampc, 128);
outputs[0].setValue(self);
} #endregion
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_path_wave, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
} #endregion
}
}

View file

@ -716,7 +716,7 @@ function __initNodes() {
addNodeObject(d3d, "3D Material", s_node_3d_meterial, "Node_3D_Material", [1, Node_3D_Material],, "Create 3D material with adjustable parameters.").setVersion(11510);
addNodeObject(d3d, "3D Scene", s_node_3d_scene, "Node_3D_Scene", [1, Node_3D_Scene],, "Combine multiple 3D objects into a single junction.").setVersion(11510);
addNodeObject(d3d, "3D Repeat", s_node_3d_array, "Node_3D_Repeat", [1, Node_3D_Repeat],, "Repeat the same 3D mesh multiple times.").setVersion(11510);
addNodeObject(d3d, "Transform 3D", s_node_image_transform_3d, "Node_3D_Transform_Image", [1, Node_3D_Transform_Image],, "Transform image in 3D space").setVersion(11600);
addNodeObject(d3d, "Transform 3D", s_node_image_transform_3d, "Node_3D_Transform_Image", [1, Node_3D_Transform_Image], ["3d transform"], "Transform image in 3D space").setVersion(11600);
addNodeObject(d3d, "Mesh Export", s_node_3d_obj_export, "Node_3D_Mesh_Export", [1, Node_3D_Mesh_Export],, "Export 3D mesh as .obj file").setVersion(11740);
ds_list_add(d3d, "Mesh");

View file

@ -14,14 +14,33 @@ function Node_Vector2(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
newInput(3, nodeValue_Enum_Scroll("Display", self, 0, [ "Number", "Coordinate" ]));
newInput(4, nodeValue_Bool("Show on global", self, false, "Whether to show overlay gizmo when not selecting any nodes."));
newInput(5, nodeValue_Vec2("Gizmo offset", self, [ 0, 0 ]));
newInput(6, nodeValue_Float("Gizmo scale", self, 1));
newInput(7, nodeValue_Enum_Scroll("Gizmo style", self, 0, [ "Default", "Shapes", "Sprite" ]));
newInput(8, nodeValue_Enum_Scroll("Gizmo shape", self, 0, [ "Rectangle", "Ellipse" ]));
newInput(9, nodeValue_Surface("Gizmo sprite", self, noone));
newInput(10, nodeValue_Vec2("Gizmo size", self, [ 32, 32 ]));
////////////////////////////////////////////////////////////////////////////////////////////////////
newOutput(0, nodeValue_Output("Vector", self, VALUE_TYPE.float, [ 0, 0 ]))
.setDisplay(VALUE_DISPLAY.vector);
drag_type = 0;
drag_mx = 0;
drag_my = 0;
drag_sx = 0;
drag_sy = 0;
newOutput(1, nodeValue_Output("x", self, VALUE_TYPE.float, 0))
newOutput(2, nodeValue_Output("y", self, VALUE_TYPE.float, 0))
input_display_list = [ 0, 1, 2,
["Editor", false], 3,
["Gizmo", false], 4, 5, 6, 7, 8, 9, 10,
];
wd_dragging = false;
wd_minx = -1;
@ -36,73 +55,96 @@ function Node_Vector2(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
wd_pan_my = 0;
coordinate_menu = [
menuItem(__txt("Reset view"), function() {
wd_minx = -1;
wd_miny = -1;
wd_maxx = 1;
wd_maxy = 1;
}),
menuItem(__txt("Focus value"), function() {
menuItem(__txt("Reset view"), function() /*=>*/ { wd_minx = -1; wd_miny = -1; wd_maxx = 1; wd_maxy = 1; }),
menuItem(__txt("Focus value"), function() /*=>*/ {
var _x = getInputData(0);
var _y = getInputData(1);
wd_minx = _x - 1;
wd_miny = _y - 1;
wd_maxx = _x + 1;
wd_maxy = _y + 1;
wd_minx = _x - 1; wd_miny = _y - 1;
wd_maxx = _x + 1; wd_maxy = _y + 1;
}),
];
gz_style = 0;
gz_shape = 0;
gz_sprite = 0;
gz_pos = [ 0, 0 ];
gz_size = [ 0, 0 ];
gz_scale = 1;
gz_dragging = false;
gz_drag_mx = 0;
gz_drag_my = 0;
gz_drag_sx = 0;
gz_drag_sy = 0;
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
PROCESSOR_OVERLAY_CHECK
if(process_amount > 1) return;
var __ax = current_data[0];
var __ay = current_data[1];
var _hov = false;
var _gx = _x + gz_pos[0] * _s;
var _gy = _y + gz_pos[1] * _s;
if(is_array(__ax) || is_array(__ay)) return;
var _ax = __ax * _s + _x;
var _ay = __ay * _s + _y;
var _val;
draw_sprite_colored(THEME.anchor_selector, 0, _ax, _ay);
if(drag_type) {
draw_sprite_colored(THEME.anchor_selector, 1, _ax, _ay);
var _nx = value_snap((drag_sx + (_mx - drag_mx) - _x) / _s, _snx);
var _ny = value_snap((drag_sy + (_my - drag_my) - _y) / _s, _sny);
if(key_mod_press(CTRL)) {
_val[0] = round(_nx);
_val[1] = round(_ny);
} else {
_val[0] = _nx;
_val[1] = _ny;
}
var _ax = _gx + current_data[0] * _s;
var _ay = _gy + current_data[1] * _s;
var _vx, _vy;
var _nx, _ny;
if(gz_dragging) {
_nx = value_snap(gz_drag_sx + (_mx - gz_drag_mx) / _s, _snx);
_ny = value_snap(gz_drag_sy + (_my - gz_drag_my) / _s, _sny);
_vx = key_mod_press(CTRL)? round(_nx) : _nx;
_vy = key_mod_press(CTRL)? round(_ny) : _ny;
var s0 = inputs[0].setValue(_val[0]);
var s1 = inputs[1].setValue(_val[1]);
var s0 = inputs[0].setValue(_vx);
var s1 = inputs[1].setValue(_vy);
if(s0 || s1)
UNDO_HOLDING = true;
if(s0 || s1) UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
drag_type = 0;
gz_dragging = false;
UNDO_HOLDING = false;
}
}
if(point_in_circle(_mx, _my, _ax, _ay, 8)) {
hover = 1;
draw_sprite_colored(THEME.anchor_selector, 1, _ax, _ay);
if(mouse_press(mb_left, active)) {
drag_type = 1;
drag_mx = _mx;
drag_my = _my;
drag_sx = _ax;
drag_sy = _ay;
}
}
if(gz_style == 0) {
_hov = hover && point_in_circle(_mx, _my, _ax, _ay, 8);
draw_anchor(_hov, _ax, _ay, 8);
} else {
var _rx = _ax;
var _ry = _ay;
var _rw = gz_size[0] * _s;
var _rh = gz_size[1] * _s;
var _rx0 = _rx - _rw / 2;
var _ry0 = _ry - _rh / 2;
var _rx1 = _rx + _rw / 2;
var _ry1 = _ry + _rh / 2;
_hov = hover && point_in_rectangle(_mx, _my, _rx0, _ry0, _rx1, _ry1);
draw_set_color(_hov || gz_dragging? COLORS._main_accent : COLORS._main_icon);
draw_set_circle_precision(32);
if(gz_style == 1) {
switch(gz_shape) {
case 0 : draw_rectangle(_rx0, _ry0, _rx1, _ry1, true); break;
case 1 : draw_ellipse(_rx0, _ry0, _rx1, _ry1, true); break;
}
} else if(gz_style == 2)
if(is_surface(gz_sprite)) draw_surface_stretched_ext(gz_sprite, _rx0, _ry0, _rw, _rh, c_white, 0.5 + 0.5 * _hov);
}
if(_hov && mouse_press(mb_left, active)) {
gz_dragging = true;
gz_drag_mx = _mx;
gz_drag_my = _my;
gz_drag_sx = current_data[0];
gz_drag_sy = current_data[1];
}
}
static step = function() {
@ -120,12 +162,31 @@ function Node_Vector2(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
setDimension(160, 160, false);
}
static processData = function(_output, _data, _output_index, _array_index = 0) {
var vec = [ _data[0], _data[1] ];
for( var i = 0, n = array_length(vec); i < n; i++ )
vec[i] = _data[2]? round(vec[i]) : vec[i];
return vec;
static processData = function(_outData, _data, _output_index, _array_index = 0) {
var _x = _data[0];
var _y = _data[1];
var _int = _data[2];
isGizmoGlobal = _data[4];
gz_pos = _data[5];
gz_scale = _data[6];
gz_style = _data[7];
gz_shape = _data[8];
gz_sprite = _data[9];
gz_size = _data[10];
inputs[ 8].setVisible(gz_style == 1);
inputs[ 9].setVisible(gz_style == 2, gz_style == 2);
inputs[10].setVisible(gz_style != 0);
var vec = _outData[0];
vec[0] = _int? round(_x) : _x;
vec[1] = _int? round(_y) : _y;
_outData[1] = vec[0];
_outData[2] = vec[1];
return _outData;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {

View file

@ -14,9 +14,20 @@ function Node_Vector3(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
newInput(3, nodeValue_Bool("Integer", self, false));
////////////////////////////////////////////////////////////////////////////////////////////////////
newOutput(0, nodeValue_Output("Vector", self, VALUE_TYPE.float, [ 0, 0, 0 ]))
.setDisplay(VALUE_DISPLAY.vector);
newOutput(1, nodeValue_Output("x", self, VALUE_TYPE.float, 0))
newOutput(2, nodeValue_Output("y", self, VALUE_TYPE.float, 0))
newOutput(3, nodeValue_Output("z", self, VALUE_TYPE.float, 0))
input_display_list = [ 0, 1, 2, 3,
];
static step = function() {
var int = getInputData(3);
for( var i = 0; i < 3; i++ )
@ -25,12 +36,22 @@ function Node_Vector3(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
outputs[0].setType(int? VALUE_TYPE.integer : VALUE_TYPE.float);
}
static processData = function(_output, _data, _output_index, _array_index = 0) {
var vec = [ _data[0], _data[1], _data[2] ];
for( var i = 0, n = array_length(vec); i < n; i++ )
vec[i] = _data[3]? round(vec[i]) : vec[i];
return vec;
static processData = function(_outData, _data, _output_index, _array_index = 0) {
var _x = _data[0];
var _y = _data[1];
var _z = _data[2];
var _int = _data[3];
var vec = _outData[0];
vec[0] = _int? round(_x) : _x;
vec[1] = _int? round(_y) : _y;
vec[2] = _int? round(_z) : _z;
_outData[1] = vec[0];
_outData[2] = vec[1];
_outData[3] = vec[2];
return _outData;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {

View file

@ -17,9 +17,22 @@ function Node_Vector4(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
newInput(4, nodeValue_Bool("Integer", self, false));
////////////////////////////////////////////////////////////////////////////////////////////////////
newOutput(0, nodeValue_Output("Vector", self, VALUE_TYPE.float, [ 0, 0, 0, 0 ]))
.setDisplay(VALUE_DISPLAY.vector);
newOutput(1, nodeValue_Output("x", self, VALUE_TYPE.float, 0))
newOutput(2, nodeValue_Output("y", self, VALUE_TYPE.float, 0))
newOutput(3, nodeValue_Output("z", self, VALUE_TYPE.float, 0))
newOutput(4, nodeValue_Output("w", self, VALUE_TYPE.float, 0))
input_display_list = [ 0, 1, 2, 3, 4,
];
static step = function() {
var int = getInputData(4);
for( var i = 0; i < 4; i++ )
@ -28,13 +41,26 @@ function Node_Vector4(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
outputs[0].setType(int? VALUE_TYPE.integer : VALUE_TYPE.float);
}
static processData = function(_output, _data, _output_index, _array_index = 0) {
var vec = [ _data[0], _data[1], _data[2], _data[3] ];
for( var i = 0, n = array_length(vec); i < n; i++ )
vec[i] = _data[4]? round(vec[i]) : vec[i];
return vec;
}
static processData = function(_outData, _data, _output_index, _array_index = 0) {
var _x = _data[0];
var _y = _data[1];
var _z = _data[2];
var _w = _data[3];
var _int = _data[4];
var vec = _outData[0];
vec[0] = _int? round(_x) : _x;
vec[1] = _int? round(_y) : _y;
vec[2] = _int? round(_z) : _z;
vec[3] = _int? round(_w) : _w;
_outData[1] = vec[0];
_outData[2] = vec[1];
_outData[3] = vec[2];
_outData[4] = vec[3];
return _outData;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);