Pixel-Composer/scripts/node_armature_path/node_armature_path.gml

117 lines
3.4 KiB
Text
Raw Normal View History

2023-07-05 15:09:52 +02:00
function Node_Armature_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2024-03-28 14:18:02 +01:00
name = "Armature Path";
setDimension(96, 72);
2023-07-05 15:09:52 +02:00
inputs[| 0] = nodeValue("Armature", self, JUNCTION_CONNECT.input, VALUE_TYPE.armature, noone)
.setVisible(true, true)
.rejectArray();
outputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
lines = [];
current_length = 0;
boundary = new BoundingBox();
2023-09-14 16:29:39 +02:00
#region ++++ attributes ++++
2023-07-05 15:09:52 +02:00
attributes.display_name = true;
attributes.display_bone = 0;
array_push(attributeEditors, "Display");
2023-07-14 20:34:35 +02:00
array_push(attributeEditors, ["Display name", function() { return attributes.display_name; },
2023-07-05 15:09:52 +02:00
new checkBox(function() {
attributes.display_name = !attributes.display_name;
})]);
2023-07-14 20:34:35 +02:00
array_push(attributeEditors, ["Display bone", function() { return attributes.display_bone; },
2023-07-05 15:09:52 +02:00
new scrollBox(["Octahedral", "Stick"], function(ind) {
attributes.display_bone = ind;
})]);
2023-09-14 16:29:39 +02:00
#endregion
2023-07-05 15:09:52 +02:00
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
var _b = getInputData(0);
2023-07-05 15:09:52 +02:00
if(_b == noone) return;
_b.draw(attributes, false, _x, _y, _s, _mx, _my);
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-05 15:09:52 +02:00
static getBoundary = function() { return boundary; }
static getLineCount = function() { return array_length(lines); }
static getSegmentCount = function() { return 1; }
static getLength = function() { return current_length; }
static getAccuLength = function() { return [ 0, current_length ]; }
2023-09-14 16:29:39 +02:00
static getWeightDistance = function (_dist, _ind = 0) { #region
2023-07-05 15:09:52 +02:00
return getWeightRatio(_dist / current_length, _ind);
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-05 15:09:52 +02:00
2023-09-14 16:29:39 +02:00
static getWeightRatio = function (_rat, _ind = 0) { #region
2023-07-05 15:09:52 +02:00
var _p0 = lines[_ind][0];
var _p1 = lines[_ind][1];
if(!is_array(_p0) || array_length(_p0) < 3) return 1;
if(!is_array(_p1) || array_length(_p1) < 3) return 1;
return lerp(_p0[2], _p1[2], _rat);
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-05 15:09:52 +02:00
2023-10-29 06:29:10 +01:00
static getPointDistance = function(_dist, _ind = 0, out = undefined) { return getPointRatio(_dist / current_length, _ind, out); }
2023-07-05 15:09:52 +02:00
2023-10-29 06:29:10 +01:00
static getPointRatio = function(_rat, _ind = 0, out = undefined) { #region
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
2023-07-05 15:09:52 +02:00
var _p0 = lines[_ind][0];
var _p1 = lines[_ind][1];
2023-10-29 06:29:10 +01:00
if(!is_array(_p0) || array_length(_p0) < 2) return out;
if(!is_array(_p1) || array_length(_p1) < 2) return out;
2023-07-05 15:09:52 +02:00
2023-10-29 06:29:10 +01:00
out.x = lerp(_p0[0], _p1[0], _rat);
out.y = lerp(_p0[1], _p1[1], _rat);
2023-07-05 15:09:52 +02:00
2023-10-29 06:29:10 +01:00
return out;
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-05 15:09:52 +02:00
2023-09-26 14:35:25 +02:00
static update = function() { #region
var _bone = getInputData(0);
2023-07-05 15:09:52 +02:00
if(_bone == noone) return;
lines = [];
current_length = 0;
var _bst = ds_stack_create();
ds_stack_push(_bst, _bone);
while(!ds_stack_empty(_bst)) {
var bone = ds_stack_pop(_bst);
if(bone.IKlength) continue;
if(!bone.is_main) {
var _p0 = bone.getPoint(0);
var _p1 = bone.getPoint(1);
array_push(lines, [
[_p0.x, _p0.y, 1],
[_p1.x, _p1.y, 1],
]);
current_length += point_distance(_p0.x, _p0.y, _p1.x, _p1.y);
}
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(bone.childs); i < n; i++ ) {
2023-07-05 15:09:52 +02:00
var child_bone = bone.childs[i];
ds_stack_push(_bst, child_bone);
}
}
ds_stack_destroy(_bst);
outputs[| 0].setValue(self);
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-05 15:09:52 +02:00
2023-09-14 16:29:39 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-07-05 15:09:52 +02:00
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_armature_path, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-05 15:09:52 +02:00
}