Pixel-Composer/scripts/node_path_map/node_path_map.gml

102 lines
2.8 KiB
Text
Raw Normal View History

2024-01-23 11:01:19 +01:00
function Node_Path_Map(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Map Path";
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_PathNode("Path", self, noone))
2024-01-23 11:01:19 +01:00
.setVisible(true, true)
.rejectArray();
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Dimension(self));
2024-01-23 11:01:19 +01:00
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Surface("Texture", self));
2024-01-23 11:01:19 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Int("Subdivision", self, 16))
.setValidator(VV_min(2))
2024-01-23 11:01:19 +01:00
.rejectArray();
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Rendered", self, VALUE_TYPE.surface, noone));
2024-01-23 11:01:19 +01:00
input_display_list = [ 0,
["Mapping", false], 1, 2, 3,
]
temp_surface = [ 0 ];
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2024-01-23 11:01:19 +01:00
var _path = getInputData(0);
2024-03-26 11:48:41 +01:00
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
2024-01-23 11:01:19 +01:00
static update = function() {
2024-01-23 11:01:19 +01:00
var _path = getInputData(0);
if(_path == noone) return;
var _dim = getInputData(1);
var _surf = getInputData(2);
var _sub = getInputData(3);
var _amo = _path.getLineCount();
if(_amo < 2) return;
if(!is_surface(_surf)) {
temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]);
surface_set_shader(temp_surface[0], sh_coord);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1]);
surface_reset_shader()
_surf = temp_surface[0];
}
2024-01-23 11:01:19 +01:00
var _pnt = array_create(_amo + 1);
var _isb = 1 / (_sub - 1);
2024-01-23 11:01:19 +01:00
var _pp = new __vec2();
for( var i = 0; i < _amo; i++ ) {
var _p = array_create(_sub + 1);
var _ind = 0;
for( var j = 0; j <= _sub; j++ ) {
var _prog = clamp(j * _isb, 0., 0.999);
_pp = _path.getPointRatio(_prog, i, _pp);
2024-01-23 11:01:19 +01:00
_p[_ind++] = [ _pp.x, _pp.y ];
}
_pnt[i] = _p;
}
2024-08-08 06:57:51 +02:00
var _out = outputs[0].getValue();
2024-01-23 11:01:19 +01:00
_out = surface_verify(_out, _dim[0], _dim[1])
surface_set_shader(_out, noone);
draw_set_color(c_white);
draw_primitive_begin_texture(pr_trianglelist, surface_get_texture(_surf));
for( var i = 0; i < _amo - 1; i++ )
for( var j = 0; j < _sub - 1; j++ ) {
var p0 = _pnt[i + 0][j + 0];
var p1 = _pnt[i + 1][j + 0];
var p2 = _pnt[i + 0][j + 1];
var p3 = _pnt[i + 1][j + 1];
var p0u = (j + 0) / (_sub - 1), p0v = (i + 0) / (_amo - 1);
var p1u = (j + 0) / (_sub - 1), p1v = (i + 1) / (_amo - 1);
var p2u = (j + 1) / (_sub - 1), p2v = (i + 0) / (_amo - 1);
var p3u = (j + 1) / (_sub - 1), p3v = (i + 1) / (_amo - 1);
draw_vertex_texture(p0[0], p0[1], p0u, p0v);
draw_vertex_texture(p1[0], p1[1], p1u, p1v);
draw_vertex_texture(p2[0], p2[1], p2u, p2v);
draw_vertex_texture(p1[0], p1[1], p1u, p1v);
draw_vertex_texture(p2[0], p2[1], p2u, p2v);
draw_vertex_texture(p3[0], p3[1], p3u, p3v);
}
draw_primitive_end();
surface_reset_shader();
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_out);
}
2024-01-23 11:01:19 +01:00
}