2023-02-28 09:43:01 +01:00
function Node_Particle(_x, _y, _group = noone) : Node_VFX_Spawner_Base(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Particle";
2023-10-02 14:41:44 +02:00
use_cache = CACHE_USE.auto;
2023-10-02 08:57:44 +02:00
2023-11-24 10:41:53 +01:00
onSurfaceSize = function() { return getInputData(input_len, DEF_SURF); };
2023-10-02 08:57:44 +02:00
inputs[| 3].setDisplay(VALUE_DISPLAY.area, { onSurfaceSize });
2023-02-14 05:32:32 +01:00
2023-11-13 07:11:52 +01:00
inputs[| 22].setDisplay(VALUE_DISPLAY.enum_scroll, [ "Random", "Order", "Animation", "Array" ]);
2023-07-21 12:40:20 +02:00
inputs[| input_len + 0] = nodeValue("Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
2023-07-30 13:56:22 +02:00
inputs[| input_len + 1] = nodeValue("Round position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Round position to the closest integer value to avoid jittering.")
.rejectArray();
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| input_len + 2] = nodeValue("Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2023-07-30 13:56:22 +02:00
.rejectArray()
2023-02-28 09:43:01 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Normal", "Alpha", "Additive" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-04-03 11:55:45 +02:00
attribute_interpolation();
2023-03-19 09:17:39 +01:00
2022-12-13 09:20:36 +01:00
array_insert(input_display_list, 0, ["Output", true], input_len + 0);
array_push(input_display_list, input_len + 1, input_len + 2);
2022-01-13 05:24:03 +01:00
2023-11-13 05:38:37 +01:00
def_surface = -1;
render_amount = 0;
2022-12-10 05:06:01 +01:00
2023-02-23 07:02:19 +01:00
insp2UpdateTooltip = "Clear cache";
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
static onInspector2Update = function() { clearCache(); }
2023-09-26 14:35:25 +02:00
static onValueUpdate = function(index = 0) { #region
2023-02-14 05:32:32 +01:00
if(index == input_len + 0) {
2023-10-02 08:57:44 +02:00
var _dim = getInputData(input_len + 0);
2023-02-14 05:32:32 +01:00
var _outSurf = outputs[| 0].getValue();
2023-10-08 13:20:31 +02:00
_outSurf = surface_verify(_outSurf, array_safe_get(_dim, 0, 1), array_safe_get(_dim, 1, 1), attrDepth());
2023-02-14 05:32:32 +01:00
outputs[| 0].setValue(_outSurf);
}
2023-02-23 07:02:19 +01:00
2023-07-06 19:49:16 +02:00
if(PROJECT.animator.is_playing)
PROJECT.animator.setFrame(-1);
2023-09-26 14:35:25 +02:00
} #endregion
2023-02-14 05:32:32 +01:00
2023-10-09 16:07:33 +02:00
static reLoop = function() { #region
var _loop = getInputData(21);
if(!_loop) return;
for(var i = 0; i < TOTAL_FRAMES; i++) {
runVFX(i, false);
updateParticleForward();
}
seed = getInputData(32);
} #endregion
static onUpdate = function(frame = CURRENT_FRAME) { #region
2023-11-13 05:38:37 +01:00
var _inSurf = getInputData(0);
var _arr_type = getInputData(22);
var _dim = getInputData(input_len + 0);
var _outSurf = outputs[| 0].getValue();
if(is_array(_inSurf) && _arr_type == 3) {
var _len = array_length(_inSurf);
if(!is_array(_outSurf))
_outSurf = array_create(_len);
else if(array_length(_outSurf) != _len)
array_resize(_outSurf, _len);
for( var i = 0; i < _len; i++ )
_outSurf[i] = surface_verify(_outSurf[i], _dim[0], _dim[1], attrDepth());
render_amount = _len;
} else {
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
render_amount = 0;
}
2023-10-08 13:20:31 +02:00
outputs[| 0].setValue(_outSurf);
2023-07-25 20:12:40 +02:00
2023-10-09 16:07:33 +02:00
if(CURRENT_FRAME == 0) {
2022-12-13 09:20:36 +01:00
reset();
2023-10-09 16:07:33 +02:00
reLoop();
}
2023-10-31 13:33:36 +01:00
if(IS_PLAYING) runVFX(frame);
2023-09-26 14:35:25 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-10-09 16:07:33 +02:00
function render(_time = CURRENT_FRAME) { #region
2022-12-13 09:20:36 +01:00
var _dim = inputs[| input_len + 0].getValue(_time);
var _exact = inputs[| input_len + 1].getValue(_time);
var _blend = inputs[| input_len + 2].getValue(_time);
2022-01-13 05:24:03 +01:00
var _outSurf = outputs[| 0].getValue();
2023-11-13 05:38:37 +01:00
if(render_amount == 0) {
surface_set_shader(_outSurf);
2023-11-17 12:33:25 +01:00
switch(_blend) {
case PARTICLE_BLEND_MODE.normal: BLEND_NORMAL; break;
case PARTICLE_BLEND_MODE.alpha: BLEND_ALPHA; break;
case PARTICLE_BLEND_MODE.additive: BLEND_ADD; break;
}
2023-11-13 05:38:37 +01:00
shader_set_interpolation(_outSurf);
for(var i = 0; i < attributes.part_amount; i++)
if(parts[i].active) parts[i].draw(_exact, _dim[0], _dim[1]);
surface_reset_shader();
} else if(is_array(_outSurf)) {
for( var o = 0, n = array_length(_outSurf); o < n; o++ ) {
surface_set_shader(_outSurf[o]);
2023-11-17 12:33:25 +01:00
switch(_blend) {
case PARTICLE_BLEND_MODE.normal: BLEND_NORMAL; break;
case PARTICLE_BLEND_MODE.alpha: BLEND_ALPHA; break;
case PARTICLE_BLEND_MODE.additive: BLEND_ADD; break;
}
2023-11-13 05:38:37 +01:00
shader_set_interpolation(_outSurf[o]);
for(var i = 0; i < attributes.part_amount; i++)
if(parts[i].active) parts[i].draw(_exact, _dim[0], _dim[1], o);
surface_reset_shader();
2023-09-26 14:35:25 +02:00
}
2023-11-13 05:38:37 +01:00
}
BLEND_NORMAL
2022-01-13 05:24:03 +01:00
2023-11-13 05:38:37 +01:00
if(PROJECT.animator.is_playing)
2023-02-23 07:02:19 +01:00
cacheCurrentFrame(_outSurf);
2023-10-30 14:21:34 +01:00
} #endregion
2022-01-13 05:24:03 +01:00
}