Pixel-Composer/scripts/node_armature/node_armature.gml

621 lines
19 KiB
Plaintext
Raw Normal View History

2023-06-17 14:30:49 +02:00
function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Armature Create";
2024-03-28 14:18:02 +01:00
setDimension(96, 72);
2023-06-25 20:12:17 +02:00
2024-08-18 06:16:20 +02:00
//newInput(0, nodeValue_Int("Axis", self, 0));
2023-06-17 14:30:49 +02:00
2023-09-14 16:29:39 +02:00
bone_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
2023-06-21 20:36:53 +02:00
var _b = attributes.bones;
2023-06-25 20:12:17 +02:00
if(_b == noone) return 0;
2023-06-21 20:36:53 +02:00
var amo = _b.childCount();
2023-06-25 20:12:17 +02:00
var _hh = ui(28);
var bh = ui(32 + 16) + amo * _hh;
var ty = _y;
2023-06-21 20:36:53 +02:00
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
draw_text_add(_x + ui(16), ty + ui(4), __txt("Bones"));
2023-06-25 20:12:17 +02:00
ty += ui(32);
2023-06-21 20:36:53 +02:00
2023-06-25 20:12:17 +02:00
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, ty, _w, bh - ui(32), COLORS.node_composite_bg_blend, 1);
2023-06-21 20:36:53 +02:00
draw_set_color(COLORS.node_composite_separator);
2023-06-25 20:12:17 +02:00
draw_line(_x + 16, ty + ui(8), _x + _w - 16, ty + ui(8));
2023-06-21 20:36:53 +02:00
2023-06-25 20:12:17 +02:00
ty += ui(8);
2023-06-21 20:36:53 +02:00
2023-06-25 20:12:17 +02:00
var hovering = noone;
var _bst = ds_stack_create();
ds_stack_push(_bst, [ _b, _x, _w ]);
2023-07-14 20:34:35 +02:00
var bone_remove = noone;
2023-06-25 20:12:17 +02:00
while(!ds_stack_empty(_bst)) {
var _st = ds_stack_pop(_bst);
var bone = _st[0];
var __x = _st[1];
var __w = _st[2];
2023-07-14 20:34:35 +02:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(bone.childs); i < n; i++ )
2023-07-14 20:34:35 +02:00
ds_stack_push(_bst, [ bone.childs[i], __x + 16, __w - 16 ]);
2023-06-25 20:12:17 +02:00
2023-07-14 20:34:35 +02:00
if(bone.is_main) continue;
if(bone.parent_anchor)
draw_sprite_ui(THEME.bone, 1, __x + 12, ty + 14,,,, COLORS._main_icon);
else if(bone.IKlength)
draw_sprite_ui(THEME.bone, 2, __x + 12, ty + 14,,,, COLORS._main_icon);
else {
if(_hover && point_in_circle(_m[0], _m[1], __x + 12, ty + 12, 12)) {
draw_sprite_ui(THEME.bone, 0, __x + 12, ty + 14,,,, COLORS._main_icon_light);
if(mouse_press(mb_left, _focus))
bone_dragging = bone;
} else
draw_sprite_ui(THEME.bone, 0, __x + 12, ty + 14,,,, COLORS._main_icon);
}
2023-06-26 18:55:41 +02:00
2023-07-14 20:34:35 +02:00
if(point_in_rectangle(_m[0], _m[1], __x + 24, ty + 3, __x + __w, ty + _hh - 3))
anchor_selecting = [ bone, 2 ];
var bx = __x + __w - 24;
var by = ty + _hh / 2;
if(point_in_circle(_m[0], _m[1], bx, by, 16)) {
draw_sprite_ui_uniform(THEME.icon_delete, 3, bx, by, 1, COLORS._main_value_negative);
2023-07-05 15:09:52 +02:00
2023-07-14 20:34:35 +02:00
if(mouse_press(mb_left, _focus))
bone_remove = bone;
} else
draw_sprite_ui_uniform(THEME.icon_delete, 3, bx, by, 1, COLORS._main_icon);
2023-08-01 19:21:51 +02:00
draw_set_font(f_p2);
var ww = string_width(bone.name);
2023-07-14 20:34:35 +02:00
bone.tb_name.setFocusHover(_focus, _hover);
2023-08-01 19:21:51 +02:00
bone.tb_name.draw(__x + 24, ty + 3, ww + 16, _hh - 6, bone.name, _m);
var _x0 = __x + 24 + ww + 32;
2023-08-02 19:11:57 +02:00
var _y0 = ty + 14;
var cc = bone.apply_scale? COLORS._main_icon : COLORS._main_value_negative;
if(point_in_circle(_m[0], _m[1], _x0, _y0, 16)) {
2023-08-09 15:41:35 +02:00
TOOLTIP = "Apply scale";
2023-08-02 19:11:57 +02:00
draw_sprite_ui(THEME.bone, 3, _x0, _y0,,,, cc, 0.75);
if(mouse_press(mb_left, _focus))
bone.apply_scale = !bone.apply_scale;
} else
draw_sprite_ui(THEME.bone, 3, _x0, _y0,,,, cc, 0.5);
2023-08-01 19:21:51 +02:00
_x0 += 20;
2023-08-02 19:11:57 +02:00
var cc = bone.apply_rotation? COLORS._main_icon : COLORS._main_value_negative;
if(point_in_circle(_m[0], _m[1], _x0, _y0, 16)) {
2023-08-09 15:41:35 +02:00
TOOLTIP = "Apply rotation";
2023-08-02 19:11:57 +02:00
draw_sprite_ui(THEME.bone, 4, _x0, _y0,,,, cc, 0.75);
if(mouse_press(mb_left, _focus))
bone.apply_rotation = !bone.apply_rotation;
} else
draw_sprite_ui(THEME.bone, 4, _x0, _y0,,,, cc, 0.5);
2023-08-01 19:21:51 +02:00
2023-07-14 20:34:35 +02:00
ty += _hh;
2023-06-25 20:12:17 +02:00
2023-07-14 20:34:35 +02:00
draw_set_color(COLORS.node_composite_separator);
draw_line(_x + 16, ty, _x + _w - 16, ty);
2023-06-21 20:36:53 +02:00
}
2023-06-25 20:12:17 +02:00
ds_stack_destroy(_bst);
if(bone_dragging && mouse_release(mb_left))
bone_dragging = noone;
2023-07-14 20:34:35 +02:00
if(bone_remove != noone) {
var _par = bone_remove.parent;
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-07-14 20:34:35 +02:00
array_remove(_par.childs, bone_remove);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(bone_remove.childs); i < n; i++ ) {
2023-07-14 20:34:35 +02:00
var _ch = bone_remove.childs[i];
_par.addChild(_ch);
_ch.parent_anchor = bone_remove.parent_anchor;
}
}
2023-06-25 20:12:17 +02:00
return bh;
2023-09-14 16:29:39 +02:00
}); #endregion
2023-06-21 20:36:53 +02:00
input_display_list = [
bone_renderer,
];
2023-09-14 16:29:39 +02:00
static createBone = function(parent, distance, direction) { #region
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-07-05 15:09:52 +02:00
var bone = new __Bone(parent, distance, direction,,, self);
2023-06-17 14:30:49 +02:00
parent.addChild(bone);
if(parent == attributes.bones)
bone.parent_anchor = false;
return bone;
2023-09-14 16:29:39 +02:00
} #endregion
2023-06-17 14:30:49 +02:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Armature", self, VALUE_TYPE.armature, noone));
2023-06-17 14:30:49 +02:00
2023-09-14 16:29:39 +02:00
#region ++++ attributes ++++
2023-07-05 15:09:52 +02:00
attributes.bones = new __Bone(,,,,, self);
2023-06-21 20:36:53 +02:00
attributes.bones.name = "Main";
2023-06-17 14:30:49 +02:00
attributes.bones.is_main = true;
2023-06-25 20:12:17 +02:00
attributes.bones.node = self;
2023-06-21 20:36:53 +02:00
attributes.display_name = true;
2023-07-05 15:09:52 +02:00
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-06-21 20:36:53 +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-06-17 14:30:49 +02:00
tools = [
2023-07-15 20:01:29 +02:00
new NodeTool( [ "Move", "Scale" ], [ THEME.bone_tool_move, THEME.bone_tool_scale ] ),
2023-06-23 15:39:24 +02:00
new NodeTool( "Add bones", THEME.bone_tool_add ),
new NodeTool( "Remove bones", THEME.bone_tool_remove ),
new NodeTool( "Detach bones", THEME.bone_tool_detach ),
2023-06-26 18:55:41 +02:00
new NodeTool( "IK", THEME.bone_tool_IK ),
2023-06-17 14:30:49 +02:00
];
anchor_selecting = noone;
builder_bone = noone;
builder_type = 0;
builder_sx = 0;
builder_sy = 0;
builder_mx = 0;
builder_my = 0;
2023-07-15 20:01:29 +02:00
builder_moving = false;
builder_scaling = false;
2023-06-25 20:12:17 +02:00
bone_dragging = noone;
2023-06-26 18:55:41 +02:00
ik_dragging = noone;
2023-06-25 20:12:17 +02:00
2023-06-23 15:39:24 +02:00
moving = false;
scaling = false;
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
2023-06-17 14:30:49 +02:00
var mx = (_mx - _x) / _s;
var my = (_my - _y) / _s;
2023-08-01 19:21:51 +02:00
var smx = value_snap(mx, _snx);
var smy = value_snap(my, _sny);
2023-06-26 18:55:41 +02:00
var _b = attributes.bones;
2023-06-23 15:39:24 +02:00
2023-09-14 16:29:39 +02:00
if(builder_bone != noone) { #region
2023-07-05 15:09:52 +02:00
anchor_selecting = _b.draw(attributes, false, _x, _y, _s, _mx, _my, anchor_selecting);
2023-06-26 18:55:41 +02:00
2023-08-01 19:21:51 +02:00
var dir = point_direction(builder_sx, builder_sy, smx, smy);
var dis = point_distance(builder_sx, builder_sy, smx, smy);
2023-06-17 14:30:49 +02:00
2023-06-19 20:28:30 +02:00
if(builder_type == 2) {
2023-08-01 19:21:51 +02:00
var bx = builder_sx + (smx - builder_mx);
var by = builder_sy + (smy - builder_my);
2023-06-19 20:28:30 +02:00
if(!builder_bone.parent_anchor) {
builder_bone.direction = point_direction(0, 0, bx, by);
builder_bone.distance = point_distance( 0, 0, bx, by);
}
} else if(key_mod_press(ALT)) {
2023-06-17 14:30:49 +02:00
if(builder_type == 0) {
2023-06-25 20:12:17 +02:00
var bo = builder_bone.getPoint(1);
2023-06-17 14:30:49 +02:00
builder_bone.direction = dir;
builder_bone.distance = dis;
2023-06-25 20:12:17 +02:00
var bn = builder_bone.getPoint(0);
2023-06-17 14:30:49 +02:00
2023-06-19 20:28:30 +02:00
builder_bone.angle = point_direction(bn.x, bn.y, bo.x, bo.y);
builder_bone.length = point_distance( bn.x, bn.y, bo.x, bo.y);
2023-06-17 14:30:49 +02:00
} else if(builder_type == 1) {
var chs = [];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(builder_bone.childs); i < n; i++ ) {
2023-06-17 14:30:49 +02:00
var ch = builder_bone.childs[i];
2023-06-25 20:12:17 +02:00
chs[i] = ch.getPoint(1);
2023-06-17 14:30:49 +02:00
}
builder_bone.angle = dir;
builder_bone.length = dis;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(builder_bone.childs); i < n; i++ ) {
2023-06-17 14:30:49 +02:00
var ch = builder_bone.childs[i];
2023-06-25 20:12:17 +02:00
var c0 = ch.getPoint(0);
2023-06-17 14:30:49 +02:00
ch.angle = point_direction(c0.x, c0.y, chs[i].x, chs[i].y);
ch.length = point_distance( c0.x, c0.y, chs[i].x, chs[i].y);
}
}
} else {
if(builder_type == 0) {
builder_bone.direction = dir;
builder_bone.distance = dis;
2023-06-25 20:12:17 +02:00
if(builder_bone.parent) {
var par_anc = builder_bone.parent.getPoint(1);
par_anc.x = _x + par_anc.x * _s;
par_anc.y = _y + par_anc.y * _s;
2023-06-26 18:55:41 +02:00
var inRange = point_in_circle(_mx, _my, par_anc.x, par_anc.y, 16) && mouse_release(mb_left);
if(!builder_bone.parent.is_main && builder_bone.IKlength > 0 && inRange)
2023-06-25 20:12:17 +02:00
builder_bone.parent_anchor = true;
}
2023-06-17 14:30:49 +02:00
} else if(builder_type == 1) {
builder_bone.angle = dir;
builder_bone.length = dis;
}
}
2023-06-21 20:36:53 +02:00
if(mouse_release(mb_left)) {
2023-06-17 14:30:49 +02:00
builder_bone = noone;
2023-06-21 20:36:53 +02:00
UNDO_HOLDING = false;
}
2023-06-25 20:12:17 +02:00
triggerRender();
2023-09-14 16:29:39 +02:00
#endregion
} else if(ik_dragging != noone) { #region
2023-07-05 15:09:52 +02:00
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting, ik_dragging);
2023-06-26 18:55:41 +02:00
if(anchor_selecting != noone && anchor_selecting[1] == 2) {
var anc = anchor_selecting[0];
var reachable = false;
var _bone = ik_dragging.parent;
2023-08-09 15:41:35 +02:00
var len = 0;
2023-06-26 18:55:41 +02:00
while(_bone != noone) {
2023-07-05 15:09:52 +02:00
if(_bone == anc.parent) {
2023-06-26 18:55:41 +02:00
reachable = true;
break;
}
len++;
_bone = _bone.parent;
}
if(reachable && mouse_release(mb_left)) {
var p1 = ik_dragging.getPoint(1);
var p0 = anc.getPoint(0);
var _len = point_distance(p0.x, p0.y, p1.x, p1.y);
var _ang = point_direction(p0.x, p0.y, p1.x, p1.y);
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-07-05 15:09:52 +02:00
var IKbone = new __Bone(anc, _len, _ang, ik_dragging.angle + 90, 0, self);
2023-06-26 18:55:41 +02:00
anc.addChild(IKbone);
2023-08-09 15:41:35 +02:00
IKbone.IKlength = len;
IKbone.IKTargetID = ik_dragging.ID;
2023-06-26 18:55:41 +02:00
IKbone.name = "IK handle";
IKbone.parent_anchor = false;
}
}
if(mouse_release(mb_left)) {
ik_dragging = noone;
UNDO_HOLDING = false;
}
triggerRender();
2023-09-14 16:29:39 +02:00
#endregion
2023-07-15 20:01:29 +02:00
}
2023-09-14 16:29:39 +02:00
if(isUsingTool("Move")) { #region
2023-07-15 20:01:29 +02:00
_b.draw(attributes, false, _x, _y, _s, _mx, _my);
var bbox = _b.bbox();
var x0 = _x + bbox[0] * _s;
var y0 = _y + bbox[1] * _s;
var x1 = _x + bbox[2] * _s;
var y1 = _y + bbox[3] * _s;
if(builder_moving) {
var dx = (mx - builder_mx) / _s;
var dy = (my - builder_my) / _s;
builder_mx = mx;
builder_my = my;
var _bx = lengthdir_x(_b.distance, _b.direction) + dx;
var _by = lengthdir_y(_b.distance, _b.direction) + dy;
_b.distance = point_distance(0, 0, _bx, _by);
_b.direction = point_direction(0, 0, _bx, _by);
2023-08-08 18:45:00 +02:00
if(mouse_release(mb_left)) {
2023-07-15 20:01:29 +02:00
builder_moving = false;
2023-08-08 18:45:00 +02:00
UNDO_HOLDING = false;
}
2023-07-15 20:01:29 +02:00
draw_set_color(COLORS._main_accent);
draw_rectangle(x0, y0, x1, y1, true);
} else {
if(point_in_rectangle(_mx, _my, x0, y0, x1, y1)) {
draw_set_color(COLORS._main_accent);
if(mouse_press(mb_left, active)) {
builder_moving = true;
builder_mx = mx;
builder_my = my;
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-07-15 20:01:29 +02:00
}
} else
draw_set_color(c_white);
draw_set_alpha(0.5);
draw_rectangle(x0, y0, x1, y1, true);
draw_set_alpha(1);
}
2023-09-14 16:29:39 +02:00
#endregion
} else if(isUsingTool("Scale")) { #region
2023-07-15 20:01:29 +02:00
_b.draw(attributes, false, _x, _y, _s, _mx, _my);
var bbox = _b.bbox();
var x0 = _x + bbox[0] * _s;
var y0 = _y + bbox[1] * _s;
var x1 = _x + bbox[2] * _s;
var y1 = _y + bbox[3] * _s;
draw_set_color(c_white);
draw_set_alpha(0.5);
draw_rectangle(x0, y0, x1, y1, true);
draw_set_alpha(1);
var cx = (x0 + x1) / 2;
var cy = (y0 + y1) / 2;
draw_set_color(COLORS._main_accent);
draw_set_alpha(0.5 + builder_scaling * 0.5);
draw_line(cx, cy, _mx, _my);
draw_set_alpha(1);
if(builder_scaling) {
var _so = point_distance(cx, cy, builder_mx, builder_my);
var _sn = point_distance(cx, cy, _mx, _my);
var _ss = 1 + (_sn - _so) / max(_so, 8);
builder_mx = _mx;
builder_my = _my;
var _bst = ds_stack_create();
ds_stack_push(_bst, _b);
while(!ds_stack_empty(_bst)) {
var __b = ds_stack_pop(_bst);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(__b.childs); i < n; i++ )
2023-07-15 20:01:29 +02:00
ds_stack_push(_bst, __b.childs[i]);
__b.distance *= _ss;
__b.length *= _ss;
}
ds_stack_destroy(_bst);
var bbox_n = _b.bbox();
var _ox = (bbox[0] + bbox[2]) / 2 - (bbox_n[0] + bbox_n[2]) / 2;
var _oy = (bbox[1] + bbox[3]) / 2 - (bbox_n[1] + bbox_n[3]) / 2;
var _bx = lengthdir_x(_b.distance, _b.direction) + _ox;
var _by = lengthdir_y(_b.distance, _b.direction) + _oy;
_b.distance = point_distance(0, 0, _bx, _by);
_b.direction = point_direction(0, 0, _bx, _by);
2023-08-08 18:45:00 +02:00
if(mouse_release(mb_left)) {
2023-07-15 20:01:29 +02:00
builder_scaling = false;
2023-08-08 18:45:00 +02:00
}
2023-07-15 20:01:29 +02:00
} else {
if(mouse_press(mb_left, active)) {
builder_scaling = true;
builder_mx = _mx;
builder_my = _my;
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-07-15 20:01:29 +02:00
}
}
2023-09-14 16:29:39 +02:00
#endregion
} else if(isUsingTool("Add bones")) { #region // builder
2023-08-09 15:41:35 +02:00
if(builder_bone == noone)
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
2023-06-17 14:30:49 +02:00
if(mouse_press(mb_left, active)) {
if(anchor_selecting == noone) {
2023-08-01 19:21:51 +02:00
builder_bone = createBone(attributes.bones, point_distance(0, 0, smx, smy), point_direction(0, 0, smx, smy));
2023-06-17 14:30:49 +02:00
builder_type = 1;
2023-08-01 19:21:51 +02:00
builder_sx = smx;
builder_sy = smy;
2023-06-21 20:36:53 +02:00
UNDO_HOLDING = true;
2024-04-01 11:10:01 +02:00
2023-06-17 14:30:49 +02:00
} else if(anchor_selecting[1] == 1) {
builder_bone = createBone(anchor_selecting[0], 0, 0);
builder_type = 1;
2023-08-01 19:21:51 +02:00
builder_sx = smx;
builder_sy = smy;
2023-06-21 20:36:53 +02:00
UNDO_HOLDING = true;
2024-04-01 11:10:01 +02:00
2023-06-19 20:28:30 +02:00
} else if(anchor_selecting[1] == 2) {
var _pr = anchor_selecting[0];
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-07-05 15:09:52 +02:00
var _md = new __Bone(noone, 0, 0, _pr.angle, _pr.length / 2, self);
2023-06-19 20:28:30 +02:00
_pr.length = _md.length;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_pr.childs); i < n; i++ )
2023-06-19 20:28:30 +02:00
_md.addChild(_pr.childs[i]);
_pr.childs = [];
_pr.addChild(_md);
2023-06-21 20:36:53 +02:00
UNDO_HOLDING = true;
2024-04-01 11:10:01 +02:00
triggerRender();
2023-06-17 14:30:49 +02:00
}
}
2023-06-25 20:12:17 +02:00
if(anchor_selecting == noone)
draw_sprite_ext(THEME.bone_tool_add, 1, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
else if(anchor_selecting[1] == 1) {
draw_sprite_ext(THEME.bone_tool_add, 0, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
draw_sprite_ext(THEME.bone_tool_add, 1, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
} else if(anchor_selecting[1] == 2)
draw_sprite_ext(THEME.bone_tool_add, 0, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
2023-09-14 16:29:39 +02:00
#endregion
} else if(isUsingTool("Remove bones")) { #region //remover
2023-07-05 15:09:52 +02:00
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
2023-06-26 18:55:41 +02:00
if(anchor_selecting != noone && anchor_selecting[1] == 2 && anchor_selecting[0].parent != noone && mouse_press(mb_left, active)) {
2023-06-19 20:28:30 +02:00
var _bone = anchor_selecting[0];
var _par = _bone.parent;
2023-06-26 18:55:41 +02:00
array_remove(_par.childs, _bone);
2023-06-19 20:28:30 +02:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_bone.childs); i < n; i++ ) {
2023-06-26 18:55:41 +02:00
var _ch = _bone.childs[i];
_par.addChild(_ch);
2023-06-25 20:12:17 +02:00
2023-06-26 18:55:41 +02:00
_ch.parent_anchor = _bone.parent_anchor;
2023-06-19 20:28:30 +02:00
}
2023-06-26 18:55:41 +02:00
triggerRender();
2023-06-19 20:28:30 +02:00
}
2023-06-25 20:12:17 +02:00
if(anchor_selecting != noone)
draw_sprite_ext(THEME.bone_tool_remove, 1, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
2023-09-14 16:29:39 +02:00
#endregion
} else if(isUsingTool("Detach bones")) { #region //detach
2023-08-09 15:41:35 +02:00
if(builder_bone == noone)
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
2023-06-26 18:55:41 +02:00
2023-06-25 20:12:17 +02:00
if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
2023-06-19 20:28:30 +02:00
builder_bone = anchor_selecting[0];
builder_type = anchor_selecting[1];
var par = builder_bone.parent;
2023-06-25 20:12:17 +02:00
if(builder_bone.parent_anchor) {
builder_bone.distance = par.length;
builder_bone.direction = par.angle;
}
2023-06-19 20:28:30 +02:00
builder_bone.parent_anchor = false;
2023-06-25 20:12:17 +02:00
builder_sx = lengthdir_x(builder_bone.distance, builder_bone.direction);
builder_sy = lengthdir_y(builder_bone.distance, builder_bone.direction);
2023-06-19 20:28:30 +02:00
builder_mx = mx;
builder_my = my;
2023-06-21 20:36:53 +02:00
UNDO_HOLDING = true;
2023-06-19 20:28:30 +02:00
}
2023-09-14 16:29:39 +02:00
#endregion
} else if(isUsingTool("IK")) { #region //IK
2023-08-09 15:41:35 +02:00
if(ik_dragging == noone)
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
2023-06-26 18:55:41 +02:00
if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
ik_dragging = anchor_selecting[0];
}
2023-09-14 16:29:39 +02:00
#endregion
} else { #region //mover
2023-08-09 15:41:35 +02:00
if(builder_bone == noone)
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
2023-06-25 20:12:17 +02:00
2023-06-17 14:30:49 +02:00
if(anchor_selecting != noone && mouse_press(mb_left, active)) {
builder_bone = anchor_selecting[0];
builder_type = anchor_selecting[1];
2023-08-08 18:45:00 +02:00
recordAction(ACTION_TYPE.struct_modify, attributes.bones, attributes.bones.serialize());
2023-06-17 14:30:49 +02:00
if(builder_type == 0) {
2023-06-25 20:12:17 +02:00
var orig = builder_bone.parent.getPoint(0);
2023-06-17 14:30:49 +02:00
builder_sx = orig.x;
builder_sy = orig.y;
} else if(builder_type == 1) {
2023-06-25 20:12:17 +02:00
var orig = builder_bone.getPoint(0);
2023-06-17 14:30:49 +02:00
builder_sx = orig.x;
builder_sy = orig.y;
} else if(builder_type == 2) {
2023-06-19 20:28:30 +02:00
if(builder_bone.parent_anchor) {
builder_bone = noone;
} else {
var par = builder_bone.parent;
builder_sx = lengthdir_x(builder_bone.distance, builder_bone.direction);
builder_sy = lengthdir_y(builder_bone.distance, builder_bone.direction);
builder_mx = mx;
builder_my = my;
}
2023-06-17 14:30:49 +02:00
}
2023-06-21 20:36:53 +02:00
UNDO_HOLDING = true;
2023-06-17 14:30:49 +02:00
}
2023-09-14 16:29:39 +02:00
#endregion
2023-06-17 14:30:49 +02:00
}
2023-09-14 16:29:39 +02:00
} #endregion
2023-06-17 14:30:49 +02:00
2023-11-20 13:21:50 +01:00
static step = function() {}
2023-06-21 20:36:53 +02:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { #region
2024-08-08 06:57:51 +02:00
outputs[0].setValue(attributes.bones);
2023-09-14 16:29:39 +02:00
} #endregion
2023-06-17 14:30:49 +02:00
2023-09-14 16:29:39 +02:00
static getPreviewBoundingBox = function() { #region
2023-07-10 20:14:10 +02:00
var minx = 9999999;
var miny = 9999999;
var maxx = -9999999;
var maxy = -9999999;
var _b = attributes.bones;
var _bst = ds_stack_create();
ds_stack_push(_bst, _b);
while(!ds_stack_empty(_bst)) {
var __b = ds_stack_pop(_bst);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(__b.childs); i < n; i++ ) {
2023-07-10 20:14:10 +02:00
var p0 = __b.childs[i].getPoint(0);
var p1 = __b.childs[i].getPoint(1);
minx = min(minx, p0.x); miny = min(miny, p0.y);
maxx = max(maxx, p0.x); maxy = max(maxy, p0.y);
minx = min(minx, p1.x); miny = min(miny, p1.y);
maxx = max(maxx, p1.x); maxy = max(maxy, p1.y);
ds_stack_push(_bst, __b.childs[i]);
}
}
ds_stack_destroy(_bst);
if(minx == 9999999) return noone;
return BBOX().fromPoints(minx, miny, maxx, maxy);
2023-09-14 16:29:39 +02:00
} #endregion
2023-07-10 20:14:10 +02:00
2023-06-25 20:12:17 +02:00
static attributeSerialize = function() { return {}; }
static attributeDeserialize = function(attr) {}
2023-09-14 16:29:39 +02:00
static doSerialize = function(_map) { #region
2023-06-23 15:39:24 +02:00
_map.bones = attributes.bones.serialize();
2023-09-14 16:29:39 +02:00
} #endregion
2023-09-14 16:29:39 +02:00
static postDeserialize = function() { #region
2023-06-23 15:39:24 +02:00
if(!struct_has(load_map, "bones")) return;
2023-07-05 15:09:52 +02:00
attributes.bones = new __Bone(,,,,, self);
attributes.bones.deserialize(load_map.bones, self);
2023-06-26 18:55:41 +02:00
attributes.bones.connect();
2023-09-14 16:29:39 +02:00
} #endregion
2023-06-25 20:12:17 +02:00
2023-09-14 16:29:39 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-06-25 20:12:17 +02:00
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_armature_create, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-09-14 16:29:39 +02:00
} #endregion
2023-06-17 14:30:49 +02:00
}