Pixel-Composer/scripts/node_rigid_render/node_rigid_render.gml

122 lines
3.5 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Rigid_Render(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Render";
2023-02-14 05:32:32 +01:00
color = COLORS.node_blend_simulation;
2023-01-25 06:49:00 +01:00
icon = THEME.rigidSim;
2023-10-02 14:41:44 +02:00
use_cache = CACHE_USE.auto;
2023-01-25 06:49:00 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 0] = nodeValue("Render dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, DEF_SURF)
2023-02-14 05:32:32 +01:00
.setDisplay(VALUE_DISPLAY.vector)
.rejectArray();
inputs[| 1] = nodeValue("Round position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2023-01-25 06:49:00 +01:00
2023-08-05 14:00:33 +02:00
setIsDynamicInput(1);
2023-01-25 06:49:00 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-01-25 06:49:00 +01:00
static createNewInput = function() {
var index = ds_list_size(inputs);
2023-02-14 05:32:32 +01:00
inputs[| index] = nodeValue("Object", self, JUNCTION_CONNECT.input, VALUE_TYPE.rigid, noone )
2023-01-25 06:49:00 +01:00
.setVisible(true, true);
}
if(!LOADING && !APPENDING) createNewInput();
2023-03-02 07:59:14 +01:00
insp2UpdateTooltip = "Clear cache";
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
static onInspector2Update = function() { clearCache(); }
2023-01-25 06:49:00 +01:00
static refreshDynamicInput = function() {
var _l = ds_list_create();
for( var i = 0; i < ds_list_size(inputs); i++ ) {
if(i < input_fix_len || inputs[| i].value_from)
ds_list_add(_l, inputs[| i]);
else
delete inputs[| i];
}
for( var i = 0; i < ds_list_size(_l); i++ )
_l[| i].index = i;
ds_list_destroy(inputs);
inputs = _l;
createNewInput();
}
static onValueFromUpdate = function(index) {
if(index < input_fix_len) return;
if(LOADING || APPENDING) return;
refreshDynamicInput();
}
2023-03-07 14:29:47 +01:00
static step = function() {
var _dim = getInputData(0);
2023-03-07 14:29:47 +01:00
var _outSurf = outputs[| 0].getValue();
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2023-03-07 14:29:47 +01:00
outputs[| 0].setValue(_outSurf);
}
2023-07-06 19:49:16 +02:00
static update = function(frame = PROJECT.animator.current_frame) {
if(recoverCache() || !PROJECT.animator.is_playing)
2023-03-02 07:59:14 +01:00
return;
var _dim = getInputData(0);
var _rnd = getInputData(1);
2023-01-25 06:49:00 +01:00
var _outSurf = outputs[| 0].getValue();
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2023-01-25 06:49:00 +01:00
outputs[| 0].setValue(_outSurf);
surface_set_target(_outSurf);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2023-01-25 06:49:00 +01:00
2023-04-10 20:02:59 +02:00
if(TESTING && keyboard_check(ord("D"))) {
var flag = phy_debug_render_shapes | phy_debug_render_coms;
draw_set_color(c_white);
physics_world_draw_debug(flag);
} else {
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
var objNode = getInputData(i);
2023-04-10 20:02:59 +02:00
if(!is_array(objNode)) objNode = [ objNode ];
2023-01-25 06:49:00 +01:00
2023-04-10 20:02:59 +02:00
for( var j = 0; j < array_length(objNode); j++ ) {
if(!variable_struct_exists(objNode[j], "object")) continue;
var obj = objNode[j].object;
2023-01-25 06:49:00 +01:00
2023-04-10 20:02:59 +02:00
if(!is_array(obj)) obj = [ obj ];
2023-02-14 05:32:32 +01:00
2023-04-10 20:02:59 +02:00
for( var k = 0; k < array_length(obj); k++ ) {
var _o = obj[k];
if(_o == noone || !instance_exists(_o)) continue;
if(is_undefined(_o.phy_active)) continue;
var ixs = max(0, _o.xscale);
var iys = max(0, _o.yscale);
var xx = _rnd? round(_o.phy_position_x) : _o.phy_position_x;
var yy = _rnd? round(_o.phy_position_y) : _o.phy_position_y;
2023-04-10 20:02:59 +02:00
draw_surface_ext_safe(_o.surface, xx, yy, ixs, iys, _o.image_angle, _o.image_blend, _o.image_alpha);
//draw_set_color(c_red);
//draw_circle(_o.phy_com_x, _o.phy_com_y, 2, false);
//draw_set_color(c_blue);
//draw_circle(_o.phy_position_x, _o.phy_position_y, 2, false);
}
2023-01-25 06:49:00 +01:00
}
}
}
2023-04-10 20:02:59 +02:00
draw_set_color(c_white);
physics_draw_debug();
2023-01-25 06:49:00 +01:00
surface_reset_target();
2023-03-02 07:59:14 +01:00
cacheCurrentFrame(_outSurf);
2023-01-25 06:49:00 +01:00
}
}