Expression

This commit is contained in:
Tanasart 2023-04-15 14:48:29 +02:00
parent 4f1dbc7f8f
commit 5b322526da
28 changed files with 575 additions and 68 deletions

View file

@ -681,6 +681,7 @@
{"name":"spr_gameframe_buttons","order":1,"path":"sprites/spr_gameframe_buttons/spr_gameframe_buttons.yy",},
{"name":"s_node_draw_stack","order":4,"path":"sprites/s_node_draw_stack/s_node_draw_stack.yy",},
{"name":"delaunay","order":1,"path":"scripts/delaunay/delaunay.yy",},
{"name":"s_node_noise_fbm","order":26,"path":"sprites/s_node_noise_fbm/s_node_noise_fbm.yy",},
{"name":"sh_color_select_content","order":1,"path":"shaders/sh_color_select_content/sh_color_select_content.yy",},
{"name":"sh_outline","order":18,"path":"shaders/sh_outline/sh_outline.yy",},
{"name":"s_node_strandSim_break","order":8,"path":"sprites/s_node_strandSim_break/s_node_strandSim_break.yy",},
@ -795,6 +796,7 @@
{"name":"s_node_fluidSim_update_paused","order":7,"path":"sprites/s_node_fluidSim_update_paused/s_node_fluidSim_update_paused.yy",},
{"name":"s_node_decorner","order":17,"path":"sprites/s_node_decorner/s_node_decorner.yy",},
{"name":"s_node_text_combine","order":3,"path":"sprites/s_node_text_combine/s_node_text_combine.yy",},
{"name":"sh_noise_fbm","order":27,"path":"shaders/sh_noise_fbm/sh_noise_fbm.yy",},
{"name":"s_node_gradient","order":1,"path":"sprites/s_node_gradient/s_node_gradient.yy",},
{"name":"fd_rectangle_get_acceleration_x","order":2,"path":"scripts/fd_rectangle_get_acceleration_x/fd_rectangle_get_acceleration_x.yy",},
{"name":"s_node_padding","order":4,"path":"sprites/s_node_padding/s_node_padding.yy",},
@ -1131,6 +1133,7 @@
{"name":"draw_surface_functions","order":4,"path":"scripts/draw_surface_functions/draw_surface_functions.yy",},
{"name":"node_rigid_variable","order":8,"path":"scripts/node_rigid_variable/node_rigid_variable.yy",},
{"name":"s_node_zoom","order":54,"path":"sprites/s_node_zoom/s_node_zoom.yy",},
{"name":"node_noise_fbm","order":30,"path":"scripts/node_noise_fbm/node_noise_fbm.yy",},
{"name":"sh_channel_V","order":6,"path":"shaders/sh_channel_V/sh_channel_V.yy",},
{"name":"__shapes","order":3,"path":"scripts/__shapes/__shapes.yy",},
{"name":"node_alpha_to_grey","order":3,"path":"scripts/node_alpha_to_grey/node_alpha_to_grey.yy",},

View file

@ -566,6 +566,7 @@
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_node_name_type.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_node_processor.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_node_resize.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_node_use_experssion.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_node_use_global.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_noti_icon_error_strip2.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_noti_icon_file_load.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/icon",},
@ -1443,6 +1444,7 @@
{"id":{"name":"spr_gameframe_buttons","path":"sprites/spr_gameframe_buttons/spr_gameframe_buttons.yy",},},
{"id":{"name":"s_node_draw_stack","path":"sprites/s_node_draw_stack/s_node_draw_stack.yy",},},
{"id":{"name":"delaunay","path":"scripts/delaunay/delaunay.yy",},},
{"id":{"name":"s_node_noise_fbm","path":"sprites/s_node_noise_fbm/s_node_noise_fbm.yy",},},
{"id":{"name":"sh_color_select_content","path":"shaders/sh_color_select_content/sh_color_select_content.yy",},},
{"id":{"name":"sh_outline","path":"shaders/sh_outline/sh_outline.yy",},},
{"id":{"name":"s_node_strandSim_break","path":"sprites/s_node_strandSim_break/s_node_strandSim_break.yy",},},
@ -1567,6 +1569,7 @@
{"id":{"name":"s_node_fluidSim_update_paused","path":"sprites/s_node_fluidSim_update_paused/s_node_fluidSim_update_paused.yy",},},
{"id":{"name":"s_node_decorner","path":"sprites/s_node_decorner/s_node_decorner.yy",},},
{"id":{"name":"s_node_text_combine","path":"sprites/s_node_text_combine/s_node_text_combine.yy",},},
{"id":{"name":"sh_noise_fbm","path":"shaders/sh_noise_fbm/sh_noise_fbm.yy",},},
{"id":{"name":"s_node_gradient","path":"sprites/s_node_gradient/s_node_gradient.yy",},},
{"id":{"name":"fd_rectangle_get_acceleration_x","path":"scripts/fd_rectangle_get_acceleration_x/fd_rectangle_get_acceleration_x.yy",},},
{"id":{"name":"s_node_padding","path":"sprites/s_node_padding/s_node_padding.yy",},},
@ -1960,6 +1963,7 @@
{"id":{"name":"node_rigid_variable","path":"scripts/node_rigid_variable/node_rigid_variable.yy",},},
{"id":{"name":"s_node_zoom","path":"sprites/s_node_zoom/s_node_zoom.yy",},},
{"id":{"name":"migration_function","path":"scripts/migration_function/migration_function.yy",},},
{"id":{"name":"node_noise_fbm","path":"scripts/node_noise_fbm/node_noise_fbm.yy",},},
{"id":{"name":"sh_channel_V","path":"shaders/sh_channel_V/sh_channel_V.yy",},},
{"id":{"name":"__shapes","path":"scripts/__shapes/__shapes.yy",},},
{"id":{"name":"node_alpha_to_grey","path":"scripts/node_alpha_to_grey/node_alpha_to_grey.yy",},},

Binary file not shown.

View file

@ -142,6 +142,8 @@ function __APPEND_MAP(_map, context = PANEL_GRAPH.getCurrentContext()) {
}
ds_map_destroy(_map);
refreshNodeMap();
return node_create;
}

View file

@ -33,17 +33,19 @@
globalvar VERSION, SAVEFILE_VERSION, VERSION_STRING;
globalvar COLLECTION_VERSION, THEME_VERSION;
VERSION = 1140;
VERSION = 1141;
SAVEFILE_VERSION = 1400;
COLLECTION_VERSION = 1140.090;
THEME_VERSION = 1140.090;
VERSION_STRING = "1.14.0pr9.4";
VERSION_STRING = "1.14.1";
globalvar NODES, NODE_MAP, APPEND_MAP, HOTKEYS, HOTKEY_CONTEXT, NODE_INSTANCES;
globalvar NODES, NODE_MAP, APPEND_MAP, NODE_NAME_MAP;
globalvar HOTKEYS, HOTKEY_CONTEXT, NODE_INSTANCES;
NODES = ds_list_create();
NODE_INSTANCES = ds_list_create();
NODE_MAP = ds_map_create();
NODE_NAME_MAP = ds_map_create();
APPEND_MAP = ds_map_create();
HOTKEYS = ds_map_create();

View file

@ -195,5 +195,7 @@ function __LOAD_PATH(path, readonly = false, safe_mode = false) {
PANEL_MENU.setNotiIcon(THEME.noti_icon_file_load);
ds_map_destroy(_map);
refreshNodeMap();
return true;
}

View file

@ -15,7 +15,7 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover, _focus, _scr
var lb_y = yy + lb_h / 2;
var butx = xx;
if(jun.connect_type == JUNCTION_CONNECT.input && jun.isAnimable() && !jun.global_use && !global_var) {
if(jun.connect_type == JUNCTION_CONNECT.input && jun.isAnimable() && !jun.expUse && !global_var) {
var index = jun.value_from == noone? jun.is_anim : 2;
draw_sprite_ui_uniform(THEME.animate_clock, index, butx, lb_y, 1, index == 2? COLORS._main_accent : c_white, 0.8);
if(_hover && point_in_circle(_m[0], _m[1], butx, lb_y, ui(10))) {
@ -43,8 +43,8 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover, _focus, _scr
butx += ui(20);
if(!global_var) {
if(jun.global_use) {
draw_sprite_ui_uniform(THEME.node_use_global, GLOBAL.inputGetable(jun, jun.global_key)? 0 : 2, butx, lb_y, 1,, 0.8);
if(jun.expUse) {
draw_sprite_ui_uniform(THEME.node_use_expression, jun.expTree.validate()? 0 : 2, butx, lb_y, 1,, 0.8);
} else {
index = jun.visible;
draw_sprite_ui_uniform(THEME.junc_visible, index, butx, lb_y, 1,, 0.8);
@ -62,15 +62,17 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover, _focus, _scr
}
}
} else
draw_sprite_ui_uniform(THEME.node_use_global, 0, butx, lb_y, 1,, 0.8);
draw_sprite_ui_uniform(THEME.node_use_expression, 0, butx, lb_y, 1,, 0.8);
if(visi_hold != noone && mouse_release(mb_left))
visi_hold = noone;
var cc = COLORS._main_text;
if(jun.global_use)
cc = GLOBAL.inputGetable(jun, jun.global_key)? COLORS._main_value_positive : COLORS._main_value_negative;
if(jun.expUse) {
var expValid = jun.expTree != noone && jun.expTree.validate();
cc = expValid? COLORS._main_value_positive : COLORS._main_value_negative;
}
draw_set_text(f_p0, fa_left, fa_center, cc);
draw_text_add(xx + ui(40), lb_y - ui(2), jun.name);
var lb_w = string_width(jun.name) + ui(32);
@ -163,9 +165,9 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover, _focus, _scr
if(jun.connect_type == JUNCTION_CONNECT.input && lineBreak && !jun.is_anim && !global_var) {
var bx = xx + ww - ui(12);
var by = lb_y;
var ic_b = jun.global_use? c_white : COLORS._main_icon;
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, "Use global variable", THEME.node_use_global, jun.global_use, ic_b) == 2)
jun.global_use = !jun.global_use;
var ic_b = jun.expUse? c_white : COLORS._main_icon;
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, "Use expression", THEME.node_use_expression, jun.expUse, ic_b) == 2)
jun.expUse = !jun.expUse;
}
#endregion
@ -182,13 +184,15 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover, _focus, _scr
var widH = lineBreak? editBoxH : 0;
var mbRight = true;
if(jun.global_use) {
jun.global_edit.boxColor = GLOBAL.inputGetable(jun, jun.global_key)? COLORS._main_value_positive : COLORS._main_value_negative;
if(jun.expUse) {
var expValid = jun.expTree != noone && jun.expTree.validate();
jun.global_edit.boxColor = expValid? COLORS._main_value_positive : COLORS._main_value_negative;
jun.global_edit.setActiveFocus(_focus, _hover);
jun.global_edit.setInteract(jun.value_from == noone);
if(_focus) jun.global_edit.register(_scrollPane);
var wd_h = jun.global_edit.draw(editBoxX, editBoxY, editBoxW, editBoxH, jun.global_key, _m);
var wd_h = jun.global_edit.draw(editBoxX, editBoxY, editBoxW, editBoxH, jun.expression, _m);
widH = lineBreak? wd_h : 0;
} else if(jun.editWidget) {
jun.editWidget.setActiveFocus(_focus, _hover);

View file

@ -204,7 +204,7 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
lvs[i] = _node;
lvs[i].inputs[| 0].setFrom(outputs[| 1]);
lvs[i].display_name = _name;
lvs[i].setDisplayName(_name);
}
}

View file

@ -23,6 +23,7 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
name = "";
display_name = "";
internalName = "";
tooltip = "";
x = _x;
y = _y;
@ -38,6 +39,8 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
inputs = ds_list_create();
outputs = ds_list_create();
inputMap = ds_map_create();
outputMap = ds_map_create();
input_display_list = -1;
output_display_list = -1;
@ -171,6 +174,13 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
h = max(min_h, (preview_surface && previewable)? 128 : 0, _hi, _ho);
}
static setDisplayName = function(_name) {
display_name = _name;
internalName = string_replace_all(display_name, " ", "_");
refreshNodeMap();
}
static getOutput = function(junc = noone) {
for( var i = 0; i < ds_list_size(outputs); i++ ) {
if(!outputs[| i].visible) continue;
@ -1241,7 +1251,7 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
NODE_MAP[? node_id] = self;
if(ds_map_exists(load_map, "name"))
display_name = ds_map_try_get(load_map, "name", "");
setDisplayName(ds_map_try_get(load_map, "name", ""));
_group = ds_map_try_get(load_map, "group", noone);
if(_group == -1) _group = noone;
@ -1339,6 +1349,10 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
ds_list_destroy(inputs);
ds_list_destroy(outputs);
ds_map_destroy(inputMap);
ds_map_destroy(outputMap);
ds_map_destroy(attributes);
for( var i = 0; i < array_length(temp_surface); i++ )

View file

@ -45,7 +45,7 @@ function variable_editor(nodeVal) constructor {
} );
sc_disp.update_hover = false;
value_name = "New value";
value_name = "NewValue";
type_index = 0;
_type_index = 0;
@ -193,7 +193,7 @@ function Node_Global(_x = 0, _y = 0) : __Node_Base(_x, _y) constructor {
}
static createValue = function() {
var _in = nodeValue("New value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
var _in = nodeValue("NewValue", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
_in.editor = new variable_editor(_in);
ds_list_add(inputs, _in);

View file

@ -222,7 +222,10 @@ function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constru
static step = function() {
if(is_undefined(inParent)) return;
inParent.name = display_name;
if(inParent.name != display_name) {
inParent.name = display_name;
group.inputMap[? string_replace_all(display_name, " ", "_")] = inParent;
}
}
PATCH_STATIC

View file

@ -64,7 +64,7 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
case ".jpg":
case ".jpeg":
case ".gif":
display_name = _name;
setDisplayName(_name);
outputs[| 1].setValue(path);
if(spr) sprite_delete(spr);

View file

@ -107,7 +107,7 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
path_loaded[i] = paths[i];
var path = try_get_path(paths[i]);
if(path == -1) continue;
display_name = string_replace(filename_name(path), filename_ext(path), "");
setDisplayName(string_replace(filename_name(path), filename_ext(path), ""));
var ext = string_lower(filename_ext(path));

View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "generator",
"path": "folders/nodes/data/generator.yy",
},
"resourceVersion": "1.0",
"name": "node_gradient",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -0,0 +1,81 @@
function Node_Noise_FBM(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "FBM Noise";
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2 )
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 1] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, irandom_range(10000, 99999));
inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 3] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 4, 4 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 4] = nodeValue("Iteration", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4);
inputs[| 5] = nodeValue("Color mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Greyscale", "RGB", "HSV" ]);
inputs[| 6] = nodeValue("Color R range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
.setDisplay(VALUE_DISPLAY.slider_range, [0, 1, .01]);
inputs[| 7] = nodeValue("Color G range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
.setDisplay(VALUE_DISPLAY.slider_range, [0, 1, .01]);
inputs[| 8] = nodeValue("Color B range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
.setDisplay(VALUE_DISPLAY.slider_range, [0, 1, .01]);
input_display_list = [
["Output", false], 0,
["Noise", false], 1, 2, 3, 4,
["Color", false], 5, 6, 7, 8,
];
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
attribute_surface_depth();
static step = function() {
var _col = inputs[| 5].getValue();
inputs[| 6].setVisible(_col != 0);
inputs[| 7].setVisible(_col != 0);
inputs[| 8].setVisible(_col != 0);
inputs[| 6].name = _col == 1? "Color R range" : "Color H range";
inputs[| 7].name = _col == 1? "Color G range" : "Color S range";
inputs[| 8].name = _col == 1? "Color B range" : "Color V range";
}
static process_data = function(_outSurf, _data, _output_index, _array_index) {
var _dim = _data[0];
var _sed = _data[1];
var _pos = _data[2];
var _sca = _data[3];
var _itr = _data[4];
var _col = _data[5];
var _clr = _data[6];
var _clg = _data[7];
var _clb = _data[8];
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
surface_set_shader(_outSurf, sh_noise_fbm);
shader_set_f("position", _pos);
shader_set_f("scale", _sca);
shader_set_f("seed", _sed);
shader_set_i("iteration", _itr);
shader_set_i("colored", _col);
shader_set_f("colorRanR", _clr);
shader_set_f("colorRanG", _clg);
shader_set_f("colorRanB", _clb);
draw_sprite_ext(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1], 0, c_white, 1);
surface_reset_shader();
return _outSurf;
}
}

View file

@ -0,0 +1,11 @@
{
"resourceType": "GMScript",
"resourceVersion": "1.0",
"name": "node_noise_fbm",
"isCompatibility": false,
"isDnD": false,
"parent": {
"name": "generator",
"path": "folders/nodes/data/generator.yy",
},
}

View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "generator",
"path": "folders/nodes/data/generator.yy",
},
"resourceVersion": "1.0",
"name": "node_perlin",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -612,6 +612,73 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
PANEL_GRAPH.node_focus = node;
PANEL_GRAPH.fullView();
}
function refreshNodeMap() {
ds_map_clear(NODE_NAME_MAP);
var key = ds_map_find_first(NODE_MAP);
var amo = ds_map_size(NODE_MAP);
repeat(amo) {
var node = NODE_MAP[? key];
if(node.internalName != "")
NODE_NAME_MAP[? node.internalName] = node;
key = ds_map_find_next(NODE_MAP, key);
}
}
function nodeGetData(str) {
var strs = string_splice(str, ".");
var _val = 0;
var _ind = [];
if(array_length(strs) == 0) return 0;
if(array_length(strs) == 1) {
var splt = string_splice(strs[0], "[");
var inp = GLOBAL.getInput(splt[0]);
_val = inp == noone? 0 : inp.getValueRecursive()[0];
for( var i = 1; i < array_length(splt); i++ )
array_push(_ind, toNumber(splt[i]));
} else if(strs[0] == "Project") {
switch(strs[1]) {
case "frame" : return ANIMATOR.current_frame;
case "frameTotal" : return ANIMATOR.frames_total;
case "fps" : return ANIMATOR.framerate;
}
return 0;
} else {
var key = strs[0];
if(!ds_map_exists(NODE_NAME_MAP, key)) return 0;
var node = NODE_NAME_MAP[? key];
var splt = string_splice(strs[1], "[");
if(array_length(splt) < 2) return 0;
var mmap = splt[0] == "inputs"? node.inputMap : node.outputMap;
var ind = string_replace_all(string_replace(splt[1], "]", ""), "\"", "");
//print("key: " + string(key));
//print("map: " + string(splt[0]));
//print("ind: " + string(ind));
//print("==========");
if(!ds_map_exists(mmap, ind)) return 0;
_val = mmap[? ind].getValue();
for( var i = 2; i < array_length(splt); i++ )
array_push(_ind, toNumber(splt[i]));
}
for( var i = 0; i < array_length(_ind); i++ ) {
if(!is_array(_val)) break;
_val = array_safe_get(_val, _ind[i]);
}
return _val;
}
#endregion
#region attribute

View file

@ -335,6 +335,11 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
index = _connect == JUNCTION_CONNECT.input? ds_list_size(node.inputs) : ds_list_size(node.outputs);
type = _type;
if(struct_has(node, "inputMap")) {
if(_connect == JUNCTION_CONNECT.input) node.inputMap[? string_replace_all(name, " ", "_")] = self;
else if(_connect == JUNCTION_CONNECT.output) node.outputMap[? string_replace_all(name, " ", "_")] = self;
}
tooltip = _tooltip;
editWidget = noone;
@ -391,12 +396,14 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
cache_value = [ false, undefined ];
cache_array = [ false, false ];
global_use = false;
global_key = "";
expUse = false;
expression = "";
expTree = noone;
global_edit = new textBox(TEXTBOX_INPUT.text, function(str) {
global_key = str;
node.triggerRender();
UPDATE |= RENDER_TYPE.partial;
expression = str;
expTree = evaluateFunctionTree(expression);
node.triggerRender();
});
global_edit.boxColor = COLORS._main_value_positive;
global_edit.align = fa_left;
@ -1047,14 +1054,13 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(value_from == noone) {
var _val = __getAnimValue(_time);
if(global_use && GLOBAL.inputGetable(self, global_key))
return GLOBAL.getInput(global_key).getValueRecursive(_time);
else
val = [ _val, self ];
val = [ _val, self ];
} else if(value_from != self)
val = value_from.getValueRecursive(_time);
if(expUse)
val[0] = is_struct(expTree)? expTree.eval(val[0]) : 0;
return val;
}
@ -1541,8 +1547,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
_map[? "shift y"] = draw_line_shift_y;
_map[? "from node"] = !preset && value_from? value_from.node.node_id : -1;
_map[? "from index"] = !preset && value_from? value_from.index : -1;
_map[? "global_use"] = global_use;
_map[? "global_key"] = global_key;
_map[? "global_use"] = expUse;
_map[? "global_key"] = expression;
_map[? "anim"] = is_anim;
ds_map_add_list(_map, "raw value", animator.serialize(scale));
@ -1571,8 +1577,10 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
//printIf(TESTING, " |- Applying deserialize to junction " + name + " of node " + node.name);
on_end = ds_map_try_get(_map, "on end", on_end);
unit.mode = ds_map_try_get(_map, "unit", VALUE_UNIT.constant);
global_use = ds_map_try_get(_map, "global_use");
global_key = ds_map_try_get(_map, "global_key");
expUse = ds_map_try_get(_map, "global_use");
expression = ds_map_try_get(_map, "global_key");
expTree = evaluateFunctionTree(expression);
sep_axis = ds_map_try_get(_map, "sep_axis");
is_anim = ds_map_try_get(_map, "anim");

View file

@ -37,7 +37,7 @@ function Panel_Inspector() : PanelContent() constructor {
min_w = ui(160);
tb_node_name = new textBox(TEXTBOX_INPUT.text, function(txt) {
if(inspecting) inspecting.display_name = txt;
if(inspecting) inspecting.setDisplayName(txt);
})
tb_prop_filter = new textBox(TEXTBOX_INPUT.text, function(txt) { filter_text = txt; })
@ -483,8 +483,8 @@ function Panel_Inspector() : PanelContent() constructor {
}
array_push(_menuItem,
menuItem(get_text("use_global_var", "Use global variable"), function() {
__dialog_junction.global_use = !__dialog_junction.global_use;
menuItem(get_text("use_global_var", "Use expression"), function() {
__dialog_junction.expUse = !__dialog_junction.expUse;
}),
-1,
menuItem(get_text("copy", "Copy"), function() {
@ -538,9 +538,14 @@ function Panel_Inspector() : PanelContent() constructor {
tb_node_name.draw(ui(64), ui(14), w - ui(128), ui(32), txt, [mx, my], VALUE_DISPLAY.node_title);
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_sub);
draw_text(w / 2, ui(56), inspecting.name);
draw_text(w / 2 + ui(8), ui(56), inspecting.name);
var lx = w / 2 - string_width(inspecting.name) / 2 - ui(18);
draw_set_text(f_p3, fa_center, fa_center, COLORS._main_text_sub);
draw_set_alpha(0.65);
draw_text(w / 2, ui(74), inspecting.internalName);
draw_set_alpha(1);
var lx = w / 2 - string_width(inspecting.name) / 2 - ui(16);
var ly = ui(56 - 8);
if(buttonInstant(THEME.button_hide, lx, ly, ui(16), ui(16), [mx, my], pFOCUS, pHOVER, "Lock", THEME.lock, !locked, locked? COLORS._main_icon_light : COLORS._main_icon,, 0.5) == 2)
locked = !locked;

View file

@ -25,4 +25,9 @@ function toNumber(str) {
if(str == ".") return 0;
if(str == "-") return 0;
return real(str) * power(10, expo);
}
function isNumber(str) {
if(is_real(str)) return true;
return str == string_decimal(str);
}

View file

@ -1,20 +1,91 @@
#region evaluator
function __fucnTree(symbol, l = noone, r = noone) constructor {
function __funcTree(symbol, l = noone, r = noone) constructor {
self.symbol = symbol;
self.l = l;
self.r = r;
isFunc = false;
static eval = function() {
var v1 = is_struct(l)? l.eval() : l;
var v2 = is_struct(r)? r.eval() : r;
static getVal = function(val, inp = 0) {
if(is_struct(val)) return val.eval();
if(is_real(val)) return val;
var splt = string_splice(val, "[");
var key = splt[0];
var _val = 0;
if(key == "value") {
_val = inp;
for( var i = 1; i < array_length(splt); i++ ) {
if(!is_array(_val)) break;
var _ind = toNumber(splt[i]);
_val = array_safe_get(_val, _ind, 0);
}
} else
_val = nodeGetData(val);
return _val;
}
static _validate = function(val) {
if(is_real(val)) return true;
if(is_struct(val)) return val.validate();
var splt = string_splice(val, "[");
if(splt[0] == "value") return true;
var strs = string_splice(val, ".");
if(array_length(strs) == 0) return false;
if(array_length(strs) == 1) {
var splt = string_splice(val, "[");
return GLOBAL.inputExist(splt[0]);
}
if(strs[0] == "Project") {
switch(strs[1]) {
case "frame" :
case "frameTotal" :
case "fps" :
return true;
}
return false;
}
var key = strs[0];
if(!ds_map_exists(NODE_NAME_MAP, key)) return false;
var node = NODE_NAME_MAP[? key];
var splt = string_splice(strs[1], "[");
if(array_length(splt) < 2) return false;
var mmap = splt[0] == "inputs"? node.inputMap : node.outputMap;
if(array_length(splt) < 2) return false;
var mkey = string_replace_all(string_replace(splt[1], "]", ""), "\"", "");
return ds_map_exists(mmap, mkey);
}
static validate = function() {
return _validate(l) && _validate(r);
}
static eval = function(inp = 0) {
var v1 = getVal(l, inp);
var v2 = getVal(r, inp);
//print("symbol " + string(symbol));
//print("l : " + string(l));
//print("r : " + string(r));
//print("v1 : " + string(v1));
//print("v2 : " + string(v2));
//print("====================");
switch(symbol) {
case "+": return v1 + v2;
case "-": return v1 - v2;
case "*": return v1 * v2;
case "*": return v1 * v2;
case "^": return power(v1, v2);
case "/": return v1 / v2;
case "/": return v1 / v2;
case "sin" : return sin(v1);
case "cos" : return cos(v1);
@ -25,11 +96,11 @@
case "floor" : return floor(v1);
}
return 0;
return v1;
}
}
function evaluateFunctionTree(fx, params = {}) {
function evaluateFunctionTree(fx) {
var pres = global.EQUATION_PRES;
var vl = ds_stack_create();
var op = ds_stack_create();
@ -44,14 +115,13 @@
while(l <= len) {
ch = string_char_at(fx, l);
if(ds_map_exists(pres, ch)) {
if(ds_map_exists(pres, ch)) { //symbol is operator
if(ds_stack_empty(op)) ds_stack_push(op, ch);
else {
if(pres[? ch] > pres[? ds_stack_top(op)] || ds_stack_top(op) == "(") ds_stack_push(op, ch);
else {
while(pres[? ch] <= pres[? ds_stack_top(op)] && !ds_stack_empty(op)) {
ds_stack_push(vl, evalToken(ds_stack_pop(op), vl));
}
while(pres[? ch] <= pres[? ds_stack_top(op)] && !ds_stack_empty(op))
ds_stack_push(vl, buildFuncTree(ds_stack_pop(op), vl));
ds_stack_push(op, ch);
}
}
@ -62,7 +132,7 @@
l++;
} else if (ch == ")") {
while(ds_stack_top(op) != "(" && !ds_stack_empty(op)) {
ds_stack_push(vl, evalToken(ds_stack_pop(op), vl));
ds_stack_push(vl, buildFuncTree(ds_stack_pop(op), vl));
}
ds_stack_pop(op);
l++;
@ -83,25 +153,46 @@
ds_stack_push(op, vsl);
} else {
switch(vsl) {
case "e": ds_stack_push(vl, 2.71828); break;
case "pi": ds_stack_push(vl, pi); break;
default :
if(variable_struct_exists(params, vsl))
ds_stack_push(vl, variable_struct_get(params, vsl));
else
ds_stack_push(vl, toNumber(vsl));
break;
case "e": ds_stack_push(vl, 2.71828); break;
case "pi": ds_stack_push(vl, pi); break;
default : ds_stack_push(vl, isNumber(vsl)? toNumber(vsl) : vsl); break;
}
}
}
}
while(!ds_stack_empty(op)) {
ds_stack_push(vl, evalToken(ds_stack_pop(op), vl));
}
while(!ds_stack_empty(op))
ds_stack_push(vl, buildFuncTree(ds_stack_pop(op), vl));
ds_stack_destroy(op);
return ds_stack_empty(vl)? 0 : ds_stack_pop(vl);
var tree = ds_stack_empty(vl)? noone : ds_stack_pop(vl)
ds_stack_destroy(vl);
if(is_string(tree))
tree = new __funcTree("", tree);
return tree;
}
function buildFuncTree(operator, vl) {
if(ds_stack_empty(vl)) return noone;
switch(operator) {
case "+":
if(ds_stack_size(vl) >= 2) return new __funcTree("+", ds_stack_pop(vl), ds_stack_pop(vl));
case "-":
if(ds_stack_size(vl) >= 2) return new __funcTree("-", ds_stack_pop(vl), ds_stack_pop(vl));
else return new __funcTree("-", ds_stack_pop(vl), 0);
case "*":
if(ds_stack_size(vl) >= 2) return new __funcTree("*", ds_stack_pop(vl), ds_stack_pop(vl));
case "^":
if(ds_stack_size(vl) >= 2) return new __funcTree("^", ds_stack_pop(vl), ds_stack_pop(vl));
case "/":
if(ds_stack_size(vl) >= 2) return new __funcTree("/", ds_stack_pop(vl), ds_stack_pop(vl));
default: return new __funcTree(operator, ds_stack_pop(vl));
}
return noone;
}
#endregion

View file

@ -0,0 +1,78 @@
// Fractal Brownian Motion
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform vec2 position;
uniform float scale;
uniform float seed;
uniform int iteration;
uniform int colored;
uniform vec2 colorRanR;
uniform vec2 colorRanG;
uniform vec2 colorRanB;
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
float random (in vec2 st) {
return fract(sin(dot(st.xy + mod(seed, 1000.), vec2(1892.9898, 78.23453))) * 437.54123);
}
float noise (in vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
// Four corners in 2D of a tile
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
float fbm (in vec2 st) {
float value = 0.0;
float amplitude = pow(2., float(iteration) - 1.) / (pow(2., float(iteration)) - 1.);
float frequency = 0.;
for (int i = 0; i < iteration; i++) {
value += amplitude * noise(st);
st *= 2.;
amplitude *= .5;
}
return value;
}
void main() {
vec2 pos = position + v_vTexcoord * scale;
if(colored == 0)
gl_FragColor = vec4(vec3(fbm(pos)), 1.0);
else if(colored == 1) {
float randR = colorRanR[0] + fbm(pos) * (colorRanR[1] - colorRanR[0]);
float randG = colorRanG[0] + fbm(pos + vec2(1.7227, 4.55529)) * (colorRanG[1] - colorRanG[0]);
float randB = colorRanB[0] + fbm(pos + vec2(6.9950, 6.82063)) * (colorRanB[1] - colorRanB[0]);
gl_FragColor = vec4(randR, randG, randB, 1.0);
} else if(colored == 2) {
float randH = colorRanR[0] + fbm(pos) * (colorRanR[1] - colorRanR[0]);
float randS = colorRanG[0] + fbm(pos + vec2(1.7227, 4.55529)) * (colorRanG[1] - colorRanG[0]);
float randV = colorRanB[0] + fbm(pos + vec2(6.9950, 6.82063)) * (colorRanB[1] - colorRanB[0]);
gl_FragColor = vec4(hsv2rgb(vec3(randH, randS, randV)), 1.0);
}
}

View file

@ -0,0 +1,19 @@
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}

View file

@ -0,0 +1,10 @@
{
"resourceType": "GMShader",
"resourceVersion": "1.0",
"name": "sh_noise_fbm",
"parent": {
"name": "generator",
"path": "folders/shader/generator.yy",
},
"type": 1,
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1,74 @@
{
"resourceType": "GMSprite",
"resourceVersion": "1.0",
"name": "s_node_noise_fbm",
"bbox_bottom": 63,
"bbox_left": 0,
"bbox_right": 63,
"bbox_top": 0,
"bboxMode": 0,
"collisionKind": 1,
"collisionTolerance": 0,
"DynamicTexturePage": false,
"edgeFiltering": false,
"For3D": false,
"frames": [
{"resourceType":"GMSpriteFrame","resourceVersion":"1.1","name":"607d38c0-92b7-4285-b337-20f8a9a43f29",},
],
"gridX": 0,
"gridY": 0,
"height": 64,
"HTile": false,
"layers": [
{"resourceType":"GMImageLayer","resourceVersion":"1.0","name":"d427d56b-7703-4165-9e09-3b06b2ebe7e6","blendMode":0,"displayName":"default","isLocked":false,"opacity":100.0,"visible":true,},
],
"nineSlice": null,
"origin": 4,
"parent": {
"name": "generator",
"path": "folders/nodes/icons/generator.yy",
},
"preMultiplyAlpha": false,
"sequence": {
"resourceType": "GMSequence",
"resourceVersion": "1.4",
"name": "s_node_noise_fbm",
"autoRecord": true,
"backdropHeight": 768,
"backdropImageOpacity": 0.5,
"backdropImagePath": "",
"backdropWidth": 1366,
"backdropXOffset": 0.0,
"backdropYOffset": 0.0,
"events": {"resourceType":"KeyframeStore<MessageEventKeyframe>","resourceVersion":"1.0","Keyframes":[],},
"eventStubScript": null,
"eventToFunction": {},
"length": 1.0,
"lockOrigin": false,
"moments": {"resourceType":"KeyframeStore<MomentsEventKeyframe>","resourceVersion":"1.0","Keyframes":[],},
"playback": 1,
"playbackSpeed": 30.0,
"playbackSpeedType": 0,
"showBackdrop": true,
"showBackdropImage": false,
"timeUnits": 1,
"tracks": [
{"resourceType":"GMSpriteFramesTrack","resourceVersion":"1.0","name":"frames","builtinName":0,"events":[],"inheritsTrackColour":true,"interpolation":1,"isCreationTrack":false,"keyframes":{"resourceType":"KeyframeStore<SpriteFrameKeyframe>","resourceVersion":"1.0","Keyframes":[
{"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"1.0","Channels":{"0":{"resourceType":"SpriteFrameKeyframe","resourceVersion":"1.0","Id":{"name":"607d38c0-92b7-4285-b337-20f8a9a43f29","path":"sprites/s_node_noise_fbm/s_node_noise_fbm.yy",},},},"Disabled":false,"id":"2a6555ac-8bf1-4788-a26c-fca752109e17","IsCreationKey":false,"Key":0.0,"Length":1.0,"Stretch":false,},
],},"modifiers":[],"spriteId":null,"trackColour":0,"tracks":[],"traits":0,},
],
"visibleRange": null,
"volume": 1.0,
"xorigin": 32,
"yorigin": 32,
},
"swatchColours": null,
"swfPrecision": 2.525,
"textureGroupId": {
"name": "Default",
"path": "texturegroups/Default",
},
"type": 0,
"VTile": false,
"width": 64,
}