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
|
|
|
|
2024-08-12 13:42:05 +02:00
|
|
|
onSurfaceSize = function() {
|
|
|
|
var _inp = getInputData(input_len, DEF_SURF);
|
|
|
|
return [ _inp[0], _inp[1] ];
|
|
|
|
};
|
2024-03-31 05:36:11 +02:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(input_len + 0, nodeValue_Vec2("Output dimension", self, DEF_SURF));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(input_len + 1, nodeValue_Bool("Round position", self, true, "Round position to the closest integer value to avoid jittering."));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(input_len + 2, nodeValue_Enum_Scroll("Blend mode", self, 0 , [ "Normal", "Alpha", "Additive" ]));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(input_len + 3, nodeValue_Surface("Background", self));
|
2024-01-12 10:38:58 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(input_len + 4, nodeValue_Enum_Button("Render Type", self, PARTICLE_RENDER_TYPE.surface , [ "Surface", "Line" ]));
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(input_len + 5, nodeValue_Int("Line life", self, 4 ));
|
2024-08-12 13:42:05 +02:00
|
|
|
|
2024-08-18 05:10:39 +02:00
|
|
|
inputs[3].setUnitRef(onSurfaceSize, VALUE_UNIT.reference);
|
2024-08-18 05:30:20 +02:00
|
|
|
inputs[3].setDefValue( DEF_AREA_REF );
|
2024-08-12 13:42:05 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
for(var i = input_len, n = array_length(inputs); i < n; i++) inputs[i].rejectArray();
|
2024-08-02 14:30:35 +02: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
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
array_insert( input_display_list, 0, ["Output", true], input_len + 3, input_len + 0);
|
|
|
|
array_push( input_display_list, input_len + 1, input_len + 2);
|
|
|
|
array_insert_before( input_display_list, 21, [ input_len + 4, input_len + 5 ]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-03-31 05:36:11 +02:00
|
|
|
def_surface = -1;
|
|
|
|
curr_dimension = [ 0, 0 ];
|
|
|
|
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(); }
|
|
|
|
|
2024-08-02 14:30:35 +02:00
|
|
|
static onValueUpdate = function(index = 0) {
|
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);
|
2024-08-08 06:57:51 +02:00
|
|
|
var _outSurf = outputs[0].getValue();
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2024-03-31 05:36:11 +02:00
|
|
|
_outSurf = surface_verify(_outSurf, array_safe_get_fast(_dim, 0, 1), array_safe_get_fast(_dim, 1, 1), attrDepth());
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_outSurf);
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2024-08-12 13:42:05 +02:00
|
|
|
if(IS_PLAYING) clearCache();
|
2024-08-02 14:30:35 +02:00
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2024-08-02 14:30:35 +02:00
|
|
|
static reLoop = function() {
|
2023-10-09 16:07:33 +02:00
|
|
|
var _loop = getInputData(21);
|
2024-01-29 14:33:55 +01:00
|
|
|
var _type = getInputData(input_len + 4);
|
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
if(!_loop) return;
|
|
|
|
|
|
|
|
for(var i = 0; i < TOTAL_FRAMES; i++) {
|
2024-01-29 14:33:55 +01:00
|
|
|
runVFX(i, _type);
|
2023-10-09 16:07:33 +02:00
|
|
|
updateParticleForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
seed = getInputData(32);
|
2024-08-02 14:30:35 +02:00
|
|
|
}
|
2023-10-09 16:07:33 +02:00
|
|
|
|
2024-08-02 14:30:35 +02:00
|
|
|
static onStep = function() {
|
2024-03-31 05:36:11 +02:00
|
|
|
var _dim = getInputData(input_len + 0);
|
2024-01-29 14:33:55 +01:00
|
|
|
var _typ = getInputData(input_len + 4);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[input_len + 5].setVisible(_typ == PARTICLE_RENDER_TYPE.line);
|
2024-03-31 05:36:11 +02:00
|
|
|
|
|
|
|
if(curr_dimension[0] != _dim[0] || curr_dimension[1] != _dim[1]) {
|
|
|
|
clearCache();
|
|
|
|
|
|
|
|
curr_dimension[0] = _dim[0];
|
|
|
|
curr_dimension[1] = _dim[1];
|
|
|
|
}
|
2024-08-02 14:30:35 +02:00
|
|
|
}
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-02 14:30:35 +02:00
|
|
|
static onUpdate = function(frame = CURRENT_FRAME) {
|
2024-08-12 13:42:05 +02:00
|
|
|
var _inSurf = getInputData(0);
|
|
|
|
var _dim = getInputData(input_len + 0);
|
|
|
|
var _bg = getInputData(input_len + 3);
|
|
|
|
var _outSurf = outputs[0].getValue();
|
2023-11-13 05:38:37 +01:00
|
|
|
|
2024-01-12 10:38:58 +01:00
|
|
|
if(is_surface(_bg)) _dim = surface_get_dimension(_bg)
|
|
|
|
|
2024-01-22 03:55:19 +01:00
|
|
|
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
|
|
|
|
render_amount = 0;
|
2023-11-13 05:38:37 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_outSurf);
|
2023-07-25 20:12:40 +02:00
|
|
|
|
2024-01-19 09:33:37 +01:00
|
|
|
if(IS_FIRST_FRAME) {
|
2022-12-13 09:20:36 +01:00
|
|
|
reset();
|
2024-01-10 08:37:15 +01:00
|
|
|
if(IS_PLAYING) reLoop();
|
2023-10-09 16:07:33 +02:00
|
|
|
}
|
2023-10-31 13:33:36 +01:00
|
|
|
|
|
|
|
if(IS_PLAYING) runVFX(frame);
|
2024-08-02 14:30:35 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-02 14:30:35 +02:00
|
|
|
function render(_time = CURRENT_FRAME) {
|
2024-08-08 06:57:51 +02: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);
|
|
|
|
var _bg = inputs[input_len + 3].getValue(_time);
|
2024-01-12 10:38:58 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _type = inputs[input_len + 4].getValue(_time);
|
|
|
|
var _llife = inputs[input_len + 5].getValue(_time);
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _outSurf = outputs[0].getValue();
|
2024-01-12 10:38:58 +01:00
|
|
|
|
|
|
|
if(is_surface(_bg)) _dim = surface_get_dimension(_bg)
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
surface_set_shader(_outSurf, _type == PARTICLE_RENDER_TYPE.surface? sh_sample : noone);
|
2024-07-10 03:45:25 +02:00
|
|
|
if(is_surface(_bg)) draw_surface_safe(_bg);
|
2024-01-12 10:38:58 +01:00
|
|
|
|
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;
|
|
|
|
}
|
2024-01-12 10:38:58 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
if(_type == PARTICLE_RENDER_TYPE.surface)
|
|
|
|
shader_set_interpolation(_outSurf);
|
|
|
|
|
2024-01-22 03:55:19 +01:00
|
|
|
for(var i = 0; i < attributes.part_amount; i++) {
|
2024-01-29 14:33:55 +01:00
|
|
|
parts[i].render_type = _type;
|
|
|
|
parts[i].line_draw = _llife;
|
|
|
|
|
|
|
|
if(parts[i].active || _type) parts[i].draw(_exact, _dim[0], _dim[1]);
|
2023-09-26 14:35:25 +02:00
|
|
|
}
|
2024-01-22 03:55:19 +01:00
|
|
|
surface_reset_shader();
|
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);
|
2024-08-02 14:30:35 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|