[Replace Color] Fix auto refresh not working.

This commit is contained in:
Tanasart 2024-09-04 11:14:10 +07:00
parent e1a81fea4c
commit 1bdbad4604
24 changed files with 124 additions and 157 deletions

View file

@ -19,6 +19,13 @@ function NodeValue_Array(_name, _node, _value, _tooltip = "", _length = 2) : Nod
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var _d = array_get_depth(val);
if(_d == 0) return array_create(def_length, val);
if(_d == 1) return array_verify(val, def_length);
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return array_verify(v, def_length)});
return val;
}

View file

@ -379,18 +379,12 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {}
static getPreviewObject = function() {
var _scene = array_safe_get_fast(all_inputs, in_d3d + 4, noone);
if(is_array(_scene))
_scene = array_safe_get_fast(_scene, preview_index, noone);
return _scene;
return getSingleValue(in_d3d + 4);
}
static getPreviewObjects = function() {
var _posm = getInputData(in_d3d + 9);
var _scene = array_safe_get_fast(all_inputs, in_d3d + 4, noone);
if(is_array(_scene))
_scene = array_safe_get_fast(_scene, preview_index, noone);
var _posm = getInputData(in_d3d + 9);
var _scene = getSingleValue(in_d3d + 4);
switch(_posm) {
case 0 : return [ object, _scene ];

View file

@ -38,17 +38,17 @@ function Node_3D_Camera_Set(_x, _y, _group = noone) : Node_3D_Camera(_x, _y, _gr
["Fill light", false], in_cam + 4, in_cam + 5, in_cam + 6, in_cam + 7,
]);
static submitShadow = function() { #region
static submitShadow = function() {
light_key.submitShadow(scene, light_key);
light_fill.submitShadow(scene, light_fill);
} #endregion
}
static submitShader = function() { #region
static submitShader = function() {
scene.submitShader(light_key);
scene.submitShader(light_fill);
} #endregion
}
static preProcessData = function(_data) { #region
static preProcessData = function(_data) {
var _han = _data[in_cam + 0];
var _van = _data[in_cam + 1];
var _col = _data[in_cam + 2];
@ -74,13 +74,11 @@ function Node_3D_Camera_Set(_x, _y, _group = noone) : Node_3D_Camera(_x, _y, _gr
light_fill.color = _col;
light_fill.intensity = _int;
} #endregion
static getPreviewObjects = function() { #region
var _scene = array_safe_get_fast(all_inputs, in_d3d + 4, noone);
if(is_array(_scene)) _scene = array_safe_get_fast(_scene, preview_index, noone);
}
static getPreviewObjects = function() {
var _scene = getSingleValue(in_d3d + 4);
return [ object, lookat, lookLine, lookRad, _scene, light_key, light_fill ];
} #endregion
}
}

View file

@ -35,5 +35,5 @@ function Node_3D_Mesh_Cone(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group
return object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 1, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 1); }
}

View file

@ -65,5 +65,5 @@ function Node_3D_Mesh_Cube(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group
return object;
}
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 1, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 1); }
}

View file

@ -51,5 +51,5 @@ function Node_3D_Mesh_Cylinder(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _g
return object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 1, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 1); }
}

View file

@ -104,5 +104,5 @@ function Node_3D_Mesh_Extrude(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _gr
return _object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 0, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 0); }
}

View file

@ -229,7 +229,7 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group)
return _object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 3, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 3); }
static onDrawNodeOver = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
if(!obj_reading) return;

View file

@ -114,5 +114,5 @@ function Node_3D_Mesh_Path_Extrude(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y
return object;
}
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 2, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 2); }
}

View file

@ -40,5 +40,5 @@ function Node_3D_Mesh_Plane(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _grou
return object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 0, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 0); }
}

View file

@ -31,5 +31,5 @@ function Node_3D_Mesh_Sphere_Ico(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y,
return object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 1, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 1); }
}

View file

@ -35,5 +35,5 @@ function Node_3D_Mesh_Sphere_UV(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _
return object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 1, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 1); }
}

View file

@ -83,5 +83,5 @@ function Node_3D_Mesh_Terrain(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _gr
return object;
} #endregion
static getPreviewValues = function() { return array_safe_get_fast(all_inputs, in_mesh + 0, noone); }
static getPreviewValues = function() { return getSingleValue(in_mesh + 0); }
}

View file

@ -7,12 +7,12 @@ function Node_3D_Set_Material(_x, _y, _group = noone) : Node_3D_Modifier(_x, _y,
newInput(in_mesh + 1, nodeValue_Bool("Single material", self, true))
static preGetInputs = function() { #region
static preGetInputs = function() {
var _sing = inputs[in_mesh + 1].getValue();
inputs[in_mesh + 0].setArrayDepth(_sing? 0 : 1);
} #endregion
}
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
static processData = function(_output, _data, _output_index, _array_index = 0) {
var _obj = _data[0];
var _mat = _data[in_mesh + 0];
@ -29,17 +29,16 @@ function Node_3D_Set_Material(_x, _y, _group = noone) : Node_3D_Modifier(_x, _y,
_res.materials = _mat;
return _res;
} #endregion
}
static getPreviewValues = function() { #region
var _sing = getSingleValue(in_mesh + 1);
var res = array_safe_get_fast(all_inputs, in_mesh + 0, noone);
if(_sing) return res;
static getPreviewValues = function() {
var res = getSingleValue(in_mesh + 0);
var sng = getSingleValue(in_mesh + 1);
if(sng) return res;
var _r = array_create(array_length(res));
for( var i = 0, n = array_length(res); i < n; i++ )
_r[i] = array_safe_get_fast(res[i], 0);
return _r;
} #endregion
}
}

View file

@ -228,7 +228,7 @@ function Node_Colors_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
}
static refreshPalette = function() {
var _surf = getInputData(0);
var _surf = inputs[0].getValue();
inputs[1].setValue([]);
inputs[2].setValue([]);
@ -271,7 +271,6 @@ function Node_Colors_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
static onValueFromUpdate = function(index) {
if(LOADING || APPENDING || CLONING) return;
if(index == 0 && attributes.auto_refresh) refreshPalette();
}

View file

@ -11,11 +11,12 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
attributes.array_process = ARRAY_PROCESS.loop;
current_data = [];
inputs_is_array = [];
all_inputs = [];
inputs_index = [];
dimension_index = 0;
process_amount = 0;
process_length = [];
dimension_index = 0;
process_running = [];
manage_atlas = true;
atlas_index = 0;
@ -40,22 +41,22 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
static processData = function(_outSurf, _data, _output_index, _array_index = 0) { return _outSurf; }
static getSingleValue = function(_index, _arr = preview_index, output = false) {
var _l = output? outputs : inputs;
if(_index < 0 || _index >= array_length(_l)) return 0;
var _l = output? outputs : inputs;
if(_index < 0 || _index >= array_length(_l)) return 0;
var _n = _l[_index];
var _in = output? _n.getValue() : getInputData(_index);
if(!_n.isArray(_in)) return _in;
if(!is_array(_in)) return 0;
var _aIndex = _arr;
if(!is_array(_in)) return 0;
switch(attributes.array_process) {
case ARRAY_PROCESS.loop : _aIndex = safe_mod(_arr, array_length(_in)); break;
case ARRAY_PROCESS.hold : _aIndex = min(_arr, array_length(_in) - 1 ); break;
case ARRAY_PROCESS.expand : _aIndex = floor(_arr / process_length[_index][1]) % process_length[_index][0]; break;
case ARRAY_PROCESS.expand_inv : _aIndex = floor(_arr / process_length[array_length(_l) - 1 - _index][1]) % process_length[_index][0]; break;
case ARRAY_PROCESS.loop : _aIndex = safe_mod(_arr, process_length[_index]); break;
case ARRAY_PROCESS.hold : _aIndex = min(_arr, process_length[_index] - 1 ); break;
case ARRAY_PROCESS.expand : _aIndex = floor(_arr / process_running[_index]) % process_length[_index]; break;
case ARRAY_PROCESS.expand_inv : _aIndex = floor(_arr / process_running[array_length(_l) - 1 - _index]) % process_length[_index]; break;
}
return array_safe_get_fast(_in, _aIndex);
@ -153,7 +154,7 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
for(var l = 0; l < process_amount; l++) {
for(var i = array_length(inputs) - 1; i >= 0; i--)
_data[i] = all_inputs[i][l];
_data[i] = inputs_index[i][l] == -1? inputs_data[i] : inputs_data[i][inputs_index[i][l]];
if(_output.type == VALUE_TYPE.surface) { #region // Output surface verification
if(manage_atlas) {
@ -270,7 +271,9 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
var _outputs = array_create(_os);
for( var l = 0; l < process_amount; l++ ) {
for(var i = 0; i < _is; i++) _inputs[i] = all_inputs[i][l];
for(var i = 0; i < _is; i++)
_inputs[i] = inputs_index[i][l] == -1? inputs_data[i] : inputs_data[i][inputs_index[i][l]];
if(l == 0 || l == preview_index) current_data = _inputs;
var _dim = getDimension(l);
@ -316,8 +319,9 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
process_amount = 1;
inputs_data = array_verify(inputs_data, _len);
inputs_is_array = array_verify(inputs_is_array, _len);
all_inputs = array_verify(all_inputs, _len);
process_length = array_verify_ext(process_length, _len, function() /*=>*/ {return [ 0, 0 ]});
inputs_index = array_verify(inputs_index, _len);
process_length = array_verify(process_length, _len);
process_running = array_verify(process_running, _len);
array_foreach(inputs, function(_in, i) /*=>*/ {
var raw = _in.getValue();
@ -327,12 +331,12 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
_in.bypass_junc.setValue(val);
if(amo == 0) val = noone; //empty array
else if(amo == 1) val = raw[0]; //spread single array
inputs_is_array[i] = amo > 1;
amo = max(1, amo);
inputs_data[i] = val; //setInputData(i, val);
input_value_map[$ _in.internalName] = val;
inputs_is_array[i] = _in.__is_array;
inputs_data[i] = val; //setInputData(i, val);
switch(attributes.array_process) {
case ARRAY_PROCESS.loop :
@ -346,44 +350,35 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
break;
}
process_length[i][0] = amo;
process_length[i][1] = process_amount;
process_length[i] = amo;
process_running[i] = process_amount;
});
var amoMax = process_amount;
for( var i = 0; i < _len; i++ ) {
amoMax /= process_length[i][0];
process_length[i][1] = amoMax;
}
amoMax /= process_length[i];
process_running[i] = amoMax;
for(var i = 0; i < _len; i++)
all_inputs[i] = array_verify(all_inputs[i], process_amount);
inputs_index[i] = array_verify(inputs_index[i], process_amount);
}
for(var l = 0; l < process_amount; l++) // input preparation
for(var i = 0; i < _len; i++) {
var _in = inputs_data[i];
if(!inputs_is_array[i]) {
all_inputs[i][l] = _in;
continue;
}
if(array_length(_in) == 0) {
all_inputs[i][l] = 0;
continue;
}
inputs_index[i][l] = -1;
if(!inputs_is_array[i]) continue;
var _index = 0;
switch(attributes.array_process) {
case ARRAY_PROCESS.loop : _index = safe_mod(l, array_length(_in)); break;
case ARRAY_PROCESS.hold : _index = min(l, array_length(_in) - 1); break;
case ARRAY_PROCESS.expand : _index = floor(l / process_length[i][1]) % process_length[i][0]; break;
case ARRAY_PROCESS.expand_inv : _index = floor(l / process_length[array_length(inputs) - 1 - i][1]) % process_length[i][0]; break;
case ARRAY_PROCESS.loop : _index = safe_mod(l, process_length[i]); break;
case ARRAY_PROCESS.hold : _index = min(l, process_length[i] - 1); break;
case ARRAY_PROCESS.expand : _index = floor(l / process_running[i]) % process_length[i]; break;
case ARRAY_PROCESS.expand_inv : _index = floor(l / process_running[array_length(inputs) - 1 - i]) % process_length[i]; break;
}
all_inputs[i][l] = inputs[i].arrayBalance(_in[_index]);
inputs_index[i][l] = _index;
}
// print($"{name}: {process_amount}");
}
static update = function(frame = CURRENT_FRAME) {

View file

@ -1404,20 +1404,11 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
static __arrayLength = function(val = undefined) {
val ??= getValue();
__is_array = false;
type_array = typeArray(display_type);
var _vdp = array_depth + type_array;
var _dep = array_get_depth(val);
__is_array = _dep > 0;
if(!is_array(val)) return -1;
__is_array = isArray(val);
if(!__is_array) return -1;
if(array_depth + type_array == 0) return array_length(val);
var ar = val;
var _depth = max(0, array_depth + type_array - 1);
repeat(_depth) ar = ar[0];
return array_length(ar);
return _dep > _vdp? array_length(val) : -1;
}
static arrayLengthSimple = function(val = undefined) {

View file

@ -30,15 +30,11 @@ function NodeValue_Area(_name, _node, _value, _data = {}) : NodeValue(_name, _no
/////============== GET =============
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var nod = __curr_get_val[1];
static valueProcess = function(val, nodeFrom, applyUnit = true, arrIndex = 0) {
val = array_verify(val, AREA_ARRAY_LENGTH);
if(!is_undefined(nod) && struct_has(nod.display_data, "onSurfaceSize")) {
var surf = nod.display_data.onSurfaceSize();
if(!is_undefined(nodeFrom) && struct_has(nodeFrom.display_data, "onSurfaceSize")) {
var surf = nodeFrom.display_data.onSurfaceSize();
var dispType = array_safe_get_fast(val, 5, AREA_MODE.area);
switch(dispType) {
@ -71,6 +67,14 @@ function NodeValue_Area(_name, _node, _value, _data = {}) : NodeValue(_name, _no
return applyUnit? unit.apply(val, arrIndex) : val;
}
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var nod = __curr_get_val[1];
return valueProcess(val, nod, applyUnit, arrIndex);
}
static __getAnimValue = function(_time = CURRENT_FRAME) {
if(!is_anim) {

View file

@ -6,28 +6,24 @@ function NodeValue_Dimension(_node, value) : NodeValue("Dimension", _node, CONNE
/////============== GET =============
static valueProcess = function(value, nodeFrom = undefined, applyUnit = true, arrIndex = 0) {
var typeFrom = nodeFrom == undefined? VALUE_TYPE.any : nodeFrom.type;
if(typeFrom == VALUE_TYPE.text) value = toNumber(value);
if(validator != noone) value = validator.validate(value);
return applyUnit? unit.apply(value, arrIndex) : value;
}
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var nod = __curr_get_val[1];
var typ = nod.type;
var dis = nod.display_type;
if(typ != VALUE_TYPE.surface) {
if(!is_array(val)) val = [ val, val ];
if(array_length(val) != 2) val = [ array_safe_get_fast(val, 0), array_safe_get_fast(val, 1) ];
var _d = array_get_depth(val);
return valueProcess(val, nod, applyUnit, arrIndex);
__nod = nod;
__applyUnit = applyUnit;
__arrIndex = arrIndex;
if(_d == 0) return [ val, val ];
if(_d == 1) return array_verify(val, 2);
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return array_verify(v, 2)});
return val;
}
// Dimension conversion
@ -52,6 +48,7 @@ function NodeValue_Dimension(_node, value) : NodeValue("Dimension", _node, CONNE
return sArr;
} else if (is_surface(val))
return [ surface_get_width_safe(val), surface_get_height_safe(val) ];
return [ 1, 1 ];
}

View file

@ -19,9 +19,17 @@ function NodeValue_Padding(_name, _node, _value, _tooltip = "") : NodeValue(_nam
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var nod = __curr_get_val[1];
var _d = array_get_depth(val);
val = array_verify(val, 4);
return valueProcess(val, nod, applyUnit, arrIndex);
__nod = nod;
__applyUnit = applyUnit;
__arrIndex = arrIndex;
if(_d == 0) return valueProcess([ val, val, val, val ], nod, applyUnit, arrIndex);
if(_d == 1) return valueProcess(array_verify(val, 4), nod, applyUnit, arrIndex);
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return valueProcess(array_verify(v, 4), __nod, __applyUnit, __arrIndex)});
return val;
}
static __getAnimValue = function(_time = CURRENT_FRAME) {

View file

@ -21,7 +21,7 @@ function NodeValue_Quaternion(_name, _node, _value, _tooltip = "") : NodeValue_A
var _d = array_get_depth(val);
if(_d == 1) return quarternionFromEuler(val[0], val[1], val[2]);
if(_d == 2) return array_map(val, function(v) /*=>*/ {return quarternionFromEuler(v[0], v[1], v[2])});
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return quarternionFromEuler(v[0], v[1], v[2])});
return val;
}

View file

@ -1,30 +1,5 @@
function nodeValue_Range(_name, _node, _value, _data = {}) { return new NodeValue_Range(_name, _node, _value, _data); }
function NodeValue_Range(_name, _node, _value, _data) : NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, _value, "") constructor {
function NodeValue_Range(_name, _node, _value, _data) : NodeValue_Array(_name, _node, _value, "", 2) constructor {
setDisplay(VALUE_DISPLAY.range, _data);
/////============== GET =============
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var nod = __curr_get_val[1];
if(!is_array(val)) val = [ val, val ];
return val;
}
static __getAnimValue = function(_time = CURRENT_FRAME) {
if(!is_anim) {
if(sep_axis) return array_create_ext(2, function(i) /*=>*/ {return animators[i].processType(animators[i].values[0].value)});
return array_empty(animator.values)? 0 : animator.processType(animator.values[0].value);
}
if(sep_axis) {
__temp_time = _time;
return array_create_ext(2, function(i) /*=>*/ {return animators[i].getValue(__temp_time)});
}
return animator.getValue(_time);
}
}

View file

@ -19,19 +19,18 @@ function NodeValue_Vec2(_name, _node, _value, _data = {}) : NodeValue(_name, _no
getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0];
var nod = __curr_get_val[1];
var typ = nod.type;
var dis = nod.display_type;
if(typ != VALUE_TYPE.surface) {
if(!is_array(val)) return [ val, val ];
var _d = array_get_depth(val);
__nod = nod;
__applyUnit = applyUnit;
__arrIndex = arrIndex;
if(_d == 0) return valueProcess([ val, val ], nod, applyUnit, arrIndex);
if(_d == 1) return valueProcess(val, nod, applyUnit, arrIndex);
if(_d == 2) {
for (var i = 0, n = array_length(val); i < n; i++)
val[i] = valueProcess(val[1], nod, applyUnit, arrIndex);
}
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return valueProcess(array_verify(v, 2), __nod, __applyUnit, __arrIndex)});
return val;
}

View file

@ -2500,10 +2500,11 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
var _tip = "";
if(DRAGGING || FILE_IS_DROPPING) {
if(DRAGGING || FILE_IS_DROPPING)
draw_sprite_stretched_ext(THEME.ui_panel_selection, 0, 8, 8, w - 16, h - 16, COLORS._main_value_positive, 1);
_tip = file_drop_tooltip;
}
if(FILE_IS_DROPPING)
_tip = file_drop_tooltip;
if(DRAGGING) { // file dropping
if(_node_hover && _node_hover.droppable(DRAGGING)) {