Pixel-Composer/scripts/node_rigid_render/node_rigid_render.gml

109 lines
3.4 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-10-06 11:51:11 +02: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-06 11:51:11 +02:00
manual_ungroupable = false;
2024-03-23 07:26:11 +01:00
//use_cache = CACHE_USE.auto;
2023-10-06 11:51:11 +02:00
update_on_frame = true;
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)
.setDisplay(VALUE_DISPLAY.vector);
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-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-10-07 09:09:18 +02:00
attributes.show_objects = true;
array_push(attributeEditors, "Display");
array_push(attributeEditors, ["Show objects", function() { return attributes.show_objects; },
new checkBox(function() {
attributes.show_objects = !attributes.show_objects;
})]);
2023-03-02 07:59:14 +01:00
insp2UpdateTooltip = "Clear cache";
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
2024-04-03 09:40:37 +02:00
2023-03-02 07:59:14 +01:00
static onInspector2Update = function() { clearCache(); }
2024-05-23 10:59:39 +02:00
static createNewInput = function() {
2023-10-09 07:36:20 +02:00
var index = ds_list_size(inputs);
inputs[| index] = nodeValue("Object", self, JUNCTION_CONNECT.input, VALUE_TYPE.rigid, noone )
.setVisible(true, true);
2023-01-25 06:49:00 +01:00
2024-05-23 10:59:39 +02:00
return inputs[| index];
} setDynamicInput(1, true, VALUE_TYPE.rigid);
2023-01-25 06:49:00 +01:00
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
2023-12-19 14:30:34 +01:00
var gr = is_instanceof(group, Node_Rigid_Group)? group : noone;
if(inline_context != noone) gr = inline_context;
2023-12-19 14:30:34 +01:00
if(gr == noone) return;
2023-10-07 09:09:18 +02:00
if(!attributes.show_objects) return;
for( var i = 0, n = array_length(gr.nodes); i < n; i++ ) {
var _node = gr.nodes[i];
2023-10-07 09:09:18 +02:00
if(!is_instanceof(_node, Node_Rigid_Object)) continue;
2024-03-22 11:15:22 +01:00
var _hov = _node.drawOverlayPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2023-10-09 07:36:20 +02:00
active &= !_hov;
2023-10-07 09:09:18 +02:00
}
} #endregion
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { #region
var _dim = getInputData(0);
2024-03-22 11:15:22 +01:00
preview_surface = surface_verify(preview_surface, _dim[0], _dim[1], attrDepth());
2024-03-23 07:26:11 +01:00
//if(!(TESTING && keyboard_check(ord("D"))) )
// return;
2024-03-22 11:15:22 +01:00
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 {
2024-05-23 10:59:39 +02:00
for( var i = input_fix_len; i < ds_list_size(inputs); i++ ) {
var objNode = getInputData(i);
2024-03-22 11:15:22 +01:00
if(!is_array(objNode)) continue;
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++ ) {
2024-03-22 11:15:22 +01:00
var _o = objNode[j];
2023-12-19 14:30:34 +01:00
2024-03-22 11:15:22 +01:00
if(_o == noone || !instance_exists(_o)) continue;
if(is_undefined(_o.phy_active)) continue;
2023-04-10 20:02:59 +02:00
2024-03-22 11:15:22 +01:00
var ixs = max(0, _o.xscale);
var iys = max(0, _o.yscale);
2023-04-10 20:02:59 +02:00
2024-03-22 11:15:22 +01:00
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
2024-03-22 11:15:22 +01:00
draw_surface_ext_safe(_o.surface, xx, yy, ixs, iys, _o.image_angle, _o.image_blend, _o.image_alpha);
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-10-09 07:36:20 +02:00
} #endregion
2024-03-22 11:15:22 +01:00
static getPreviewValues = function() { #region
var _surf = outputs[| 0].getValue();
if(is_surface(_surf)) return _surf;
return preview_surface;
} #endregion
2023-01-25 06:49:00 +01:00
}