2023-02-28 09:43:01 +01:00
function Node_Scatter_Points(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Scatter Points";
color = COLORS.node_blend_number;
previewable = false;
w = 96;
2023-10-02 08:57:44 +02:00
onSurfaceSize = function() { return getInputData(7, DEF_SURF); };
2023-07-21 12:40:20 +02:00
inputs[| 0] = nodeValue("Point area", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ DEF_SURF_W / 2, DEF_SURF_H / 2, DEF_SURF_W / 2, DEF_SURF_H / 2, AREA_SHAPE.rectangle ])
2023-10-02 08:57:44 +02:00
.setDisplay(VALUE_DISPLAY.area, { onSurfaceSize });
2023-02-14 02:48:33 +01:00
inputs[| 1] = nodeValue("Point distribution", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Area", "Border", "Map" ])
.rejectArray();
inputs[| 2] = nodeValue("Scatter", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Uniform", "Random" ])
.rejectArray();
inputs[| 3] = nodeValue("Point amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2, "Amount of particle spawn in that frame.")
.rejectArray();
inputs[| 4] = nodeValue("Distribution map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0)
.rejectArray();
inputs[| 5] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, irandom(99999))
.rejectArray();
2023-02-21 04:48:50 +01:00
inputs[| 6] = nodeValue("Fixed position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false, "Fix point position, and only select point in the area.");
2023-07-21 12:40:20 +02:00
inputs[| 7] = nodeValue("Reference dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2023-02-21 04:48:50 +01:00
.setDisplay(VALUE_DISPLAY.vector);
input_display_list = [
["Base", false], 5, 6, 7,
["Scatter", false], 0, 1, 4, 2, 3,
];
2023-02-14 02:48:33 +01:00
outputs[| 0] = nodeValue("Points", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [ ])
.setDisplay(VALUE_DISPLAY.vector);
2023-02-21 04:48:50 +01:00
refVal = nodeValue("Reference value", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
2023-02-14 02:48:33 +01:00
static step = function() {
2023-10-02 08:57:44 +02:00
var _dist = getInputData(1);
2023-02-14 02:48:33 +01:00
inputs[| 2].setVisible(_dist != 2);
inputs[| 4].setVisible(_dist == 2, _dist == 2);
}
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
inputs[| 0].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
}
2023-08-17 16:56:54 +02:00
static getPreviewValues = function() { return refVal.getValue(); }
2023-02-21 04:48:50 +01:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
2023-10-02 08:57:44 +02:00
var _area = getInputData(0);
var _dist = getInputData(1);
var _scat = getInputData(2);
var _amo = getInputData(3);
var _distMap = getInputData(4);
var _seed = getInputData(5);
var _fix = getInputData(6);
var _fixRef = getInputData(7);
2023-02-21 04:48:50 +01:00
inputs[| 7].setVisible(_fix);
var pos = [];
2023-02-14 02:48:33 +01:00
2023-02-21 04:48:50 +01:00
if(_fix) {
var ref = refVal.getValue();
ref = surface_verify(ref, _fixRef[0], _fixRef[1]);
refVal.setValue(ref);
}
var aBox = area_get_bbox(_area);
2023-02-14 02:48:33 +01:00
if(_dist != 2) {
2023-02-21 04:48:50 +01:00
pos = [];
for( var i = 0; i < _amo; i++ ) {
if(_fix) {
var p = area_get_random_point([_fixRef[0], _fixRef[1], _fixRef[0], _fixRef[1]], _dist, _scat, i, _amo, _seed++);
if(point_in_rectangle(p[0], p[1], aBox[0], aBox[1], aBox[2], aBox[3]))
array_push(pos, p);
} else
pos[i] = area_get_random_point(_area, _dist, _scat, i, _amo, _seed++);
}
2023-02-14 02:48:33 +01:00
} else {
pos = [];
2023-02-28 09:43:01 +01:00
var p = get_points_from_dist(_distMap, _amo, _seed, 8);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(p); i < n; i++ ) {
2023-02-14 02:48:33 +01:00
if(p[i] == 0) continue;
2023-02-21 04:48:50 +01:00
if(_fix) {
p[i][0] *= _fixRef[0];
p[i][1] *= _fixRef[1];
} else {
p[i][0] = _area[0] + _area[2] * (p[i][0] * 2 - 1);
p[i][1] = _area[1] + _area[3] * (p[i][1] * 2 - 1);
}
2023-02-14 02:48:33 +01:00
array_push(pos, p[i]);
}
}
outputs[| 0].setValue(pos);
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_scatter_point, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}