2023-06-17 14:30:49 +02:00
|
|
|
function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|
|
|
name = "Armature Create";
|
2024-11-29 06:18:28 +01:00
|
|
|
setDimension(96, 96);
|
|
|
|
draw_padding = 8;
|
2023-06-25 20:12:17 +02:00
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
bone_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
2024-11-07 07:59:04 +01:00
|
|
|
var _b = 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;
|
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
|
2023-09-28 15:10:41 +02:00
|
|
|
draw_text_add(_x + ui(16), ty + ui(4), __txt("Bones"));
|
2024-11-07 07:59:04 +01:00
|
|
|
ty += ui(28);
|
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);
|
|
|
|
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);
|
2024-11-07 07:59:04 +01:00
|
|
|
|
2023-07-14 20:34:35 +02:00
|
|
|
else if(bone.IKlength)
|
|
|
|
draw_sprite_ui(THEME.bone, 2, __x + 12, ty + 14,,,, COLORS._main_icon);
|
2024-11-07 07:59:04 +01:00
|
|
|
|
2023-07-14 20:34:35 +02:00
|
|
|
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
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
if(!ds_stack_empty(_bst)) {
|
|
|
|
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;
|
2024-11-07 07:59:04 +01:00
|
|
|
recordAction(ACTION_TYPE.struct_modify, bones, 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;
|
2024-10-29 03:03:29 +01:00
|
|
|
});
|
2023-06-21 20:36:53 +02:00
|
|
|
|
|
|
|
input_display_list = [
|
|
|
|
bone_renderer,
|
|
|
|
];
|
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
static createBone = function(parent, distance, direction) {
|
2024-11-07 07:59:04 +01:00
|
|
|
recordAction(ACTION_TYPE.struct_modify, bones, bones.serialize());
|
2023-08-08 18:45:00 +02:00
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
var bone = new __Bone(parent, distance, direction, 0, 0, self);
|
2023-06-17 14:30:49 +02:00
|
|
|
parent.addChild(bone);
|
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
if(parent == bones)
|
|
|
|
bone.parent_anchor = false;
|
|
|
|
|
|
|
|
bone.distance = distance;
|
|
|
|
bone.direction = direction;
|
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
return bone;
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
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 ++++
|
2024-11-26 11:28:04 +01:00
|
|
|
bones = new __Bone(,,,,, self);
|
|
|
|
bones.name = "Main";
|
2024-11-07 07:59:04 +01:00
|
|
|
bones.is_main = true;
|
2024-11-26 11:28:04 +01:00
|
|
|
bones.node = self;
|
2024-10-29 03:03:29 +01:00
|
|
|
|
|
|
|
attributes.display_name = true;
|
|
|
|
attributes.display_bone = 0;
|
|
|
|
|
|
|
|
array_push(attributeEditors, "Display");
|
2024-11-26 11:28:04 +01:00
|
|
|
array_push(attributeEditors, ["Display name", function() /*=>*/ {return attributes.display_name}, new checkBox(function() /*=>*/ { attributes.display_name = !attributes.display_name; })]);
|
|
|
|
array_push(attributeEditors, ["Display bone", function() /*=>*/ {return attributes.display_bone}, 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 = [
|
2024-11-27 09:03:12 +01:00
|
|
|
new NodeTool( "Transform", THEME.bone_tool_move ),
|
|
|
|
new NodeTool( [ "Add bones", "Mirror bones"], [ THEME.bone_tool_add, THEME.bone_tool_mirror ]),
|
|
|
|
new NodeTool( "Remove bones", THEME.bone_tool_remove ),
|
|
|
|
new NodeTool( "Detach bones", THEME.bone_tool_detach ),
|
|
|
|
new NodeTool( "IK", THEME.bone_tool_IK ),
|
2023-06-17 14:30:49 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
anchor_selecting = noone;
|
|
|
|
builder_bone = noone;
|
|
|
|
builder_type = 0;
|
2024-11-26 11:28:04 +01:00
|
|
|
builder_sv = 0;
|
2024-11-10 05:17:30 +01:00
|
|
|
builder_sx = 0;
|
|
|
|
builder_sy = 0;
|
|
|
|
builder_mx = 0;
|
|
|
|
builder_my = 0;
|
2023-06-17 14:30:49 +02:00
|
|
|
|
2023-06-25 20:12:17 +02:00
|
|
|
bone_dragging = noone;
|
2024-11-10 05:17:30 +01:00
|
|
|
ik_dragging = noone;
|
2023-06-25 20:12:17 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
moving = false;
|
2023-06-23 15:39:24 +02:00
|
|
|
scaling = false;
|
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
bone_arr = [];
|
|
|
|
bone_point_maps = [];
|
|
|
|
bone_point_mape = [];
|
|
|
|
|
2024-11-29 06:18:28 +01:00
|
|
|
bone_bbox = undefined;
|
2024-11-26 11:28:04 +01:00
|
|
|
bone_transform_bbox = -1;
|
|
|
|
bone_transform_type = -1;
|
|
|
|
|
2024-11-27 08:33:49 +01:00
|
|
|
mirroring_bone = noone;
|
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny, _panel) {
|
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);
|
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
var _b = bones;
|
2023-06-23 15:39:24 +02:00
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
if(builder_bone != noone) {
|
|
|
|
gpu_set_texfilter(true);
|
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
anchor_selecting = _b.draw(attributes, false, _x, _y, _s, _mx, _my, anchor_selecting, builder_bone);
|
2024-11-27 05:32:43 +01:00
|
|
|
_b.drawControl(attributes);
|
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) {
|
2024-11-26 11:28:04 +01:00
|
|
|
var an = point_direction(builder_sx, builder_sy, mx, my);
|
|
|
|
builder_bone.angle += angle_difference(an, builder_sv);
|
|
|
|
builder_sv = an;
|
2023-06-19 20:28:30 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
var _rx = _x + _s * builder_sx;
|
|
|
|
var _ry = _y + _s * builder_sy;
|
|
|
|
draw_sprite_ext(s_bone_rotate, 0, _rx, _ry, 1, 1, builder_bone.angle, COLORS._main_value_positive, 1);
|
|
|
|
|
|
|
|
} else if(builder_type == 3) {
|
2024-11-10 05:17:30 +01:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
builder_bone.length = point_distance(builder_sx, builder_sy, mx, my) / builder_sv;
|
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
orig = builder_bone.getPoint(0.8);
|
2024-11-26 11:28:04 +01:00
|
|
|
var _rx = _x + _s * orig.x;
|
|
|
|
var _ry = _y + _s * orig.y;
|
|
|
|
draw_sprite_ext(s_bone_scale, 0, _rx, _ry, 1, 1, builder_bone.angle, COLORS._main_value_positive, 1);
|
|
|
|
|
2023-06-19 20:28:30 +02:00
|
|
|
} else if(key_mod_press(ALT)) {
|
2023-06-17 14:30:49 +02:00
|
|
|
if(builder_type == 0) {
|
2024-11-10 05:17:30 +01:00
|
|
|
var bo = builder_bone.getTail();
|
2023-06-17 14:30:49 +02:00
|
|
|
|
|
|
|
builder_bone.direction = dir;
|
|
|
|
builder_bone.distance = dis;
|
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
var bn = builder_bone.getHead();
|
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);
|
2024-11-10 05:17:30 +01:00
|
|
|
|
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];
|
2024-11-10 05:17:30 +01:00
|
|
|
chs[i] = ch.getTail();
|
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];
|
2024-11-10 05:17:30 +01:00
|
|
|
var c0 = ch.getHead();
|
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) {
|
2024-11-10 05:17:30 +01:00
|
|
|
var par_anc = builder_bone.parent.getTail();
|
|
|
|
var par_ancx = _x + par_anc.x * _s;
|
|
|
|
var par_ancy = _y + par_anc.y * _s;
|
2023-06-25 20:12:17 +02:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
var inRange = point_in_circle(_mx, _my, par_ancx, par_ancy, 16) && mouse_release(mb_left);
|
2023-06-26 18:55:41 +02:00
|
|
|
if(!builder_bone.parent.is_main && builder_bone.IKlength > 0 && inRange)
|
2023-06-25 20:12:17 +02:00
|
|
|
builder_bone.parent_anchor = true;
|
2024-11-26 11:28:04 +01:00
|
|
|
|
2023-06-25 20:12:17 +02:00
|
|
|
}
|
2024-11-26 11:28:04 +01:00
|
|
|
|
|
|
|
orig = builder_bone.getHead();
|
|
|
|
var _rx = _x + _s * orig.x;
|
|
|
|
var _ry = _y + _s * orig.y;
|
|
|
|
draw_sprite_ext(s_bone_move, 0, _rx, _ry, 1, 1, 0, COLORS._main_value_positive, 1);
|
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
} else if(builder_type == 1) {
|
|
|
|
builder_bone.angle = dir;
|
|
|
|
builder_bone.length = dis;
|
2024-11-26 11:28:04 +01:00
|
|
|
|
|
|
|
orig = builder_bone.getTail();
|
|
|
|
var _rx = _x + _s * orig.x;
|
|
|
|
var _ry = _y + _s * orig.y;
|
|
|
|
draw_sprite_ext(s_bone_move, 0, _rx, _ry, 1, 1, 0, COLORS._main_value_positive, 1);
|
2023-06-17 14:30:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
gpu_set_texfilter(false);
|
2023-06-25 20:12:17 +02:00
|
|
|
triggerRender();
|
2024-11-27 05:32:43 +01:00
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
} else if(ik_dragging != noone) {
|
2023-07-05 15:09:52 +02:00
|
|
|
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting, ik_dragging);
|
2024-11-27 05:32:43 +01:00
|
|
|
_b.drawControl(attributes);
|
2023-06-26 18:55:41 +02:00
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
var _bone = ik_dragging;
|
2024-11-10 05:17:30 +01:00
|
|
|
var p1 = ik_dragging.getTail();
|
|
|
|
var p1x = _x + p1.x * _s;
|
|
|
|
var p1y = _y + p1.y * _s;
|
2023-06-26 18:55:41 +02:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
if(anchor_selecting != noone && anchor_selecting[1] == 2) {
|
|
|
|
var anc = anchor_selecting[0];
|
2024-11-27 05:32:43 +01:00
|
|
|
var bne = anc;
|
2024-11-10 05:17:30 +01:00
|
|
|
var _reach = false;
|
|
|
|
var _blen = 0;
|
2023-06-26 18:55:41 +02:00
|
|
|
|
|
|
|
while(_bone != noone) {
|
2024-11-27 05:32:43 +01:00
|
|
|
_blen++;
|
|
|
|
_bone = _bone.parent;
|
|
|
|
|
2023-07-05 15:09:52 +02:00
|
|
|
if(_bone == anc.parent) {
|
2024-11-10 05:17:30 +01:00
|
|
|
_reach = true;
|
2024-11-27 05:32:43 +01:00
|
|
|
bne = anc;
|
|
|
|
anc = anc.parent;
|
2023-06-26 18:55:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
if(_reach) {
|
|
|
|
var p0 = anc.getHead();
|
2024-11-27 05:32:43 +01:00
|
|
|
var p0t = bne.getHead();
|
2024-11-10 05:17:30 +01:00
|
|
|
var _px = _x + p0t.x * _s;
|
|
|
|
var _py = _y + p0t.y * _s;
|
2024-11-12 01:41:42 +01:00
|
|
|
draw_line_dashed(_px, _py, p1x, p1y, 2, 8);
|
|
|
|
draw_sprite_ui(THEME.preview_bone_IK, 1, _px, _py, 1, 1, 0, COLORS._main_accent, 1);
|
2023-06-26 18:55:41 +02:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
var _len = point_distance(p0.x, p0.y, p1.x, p1.y);
|
|
|
|
var _ang = point_direction(p0.x, p0.y, p1.x, p1.y);
|
|
|
|
|
|
|
|
recordAction(ACTION_TYPE.struct_modify, bones, bones.serialize());
|
|
|
|
|
|
|
|
var IKbone = new __Bone(anc, _len, _ang, ik_dragging.angle + 90, 0, self);
|
|
|
|
anc.addChild(IKbone);
|
2024-11-27 05:32:43 +01:00
|
|
|
|
|
|
|
IKbone.direction = _ang;
|
|
|
|
IKbone.distance = _len;
|
2024-11-10 05:17:30 +01:00
|
|
|
IKbone.IKlength = _blen;
|
|
|
|
IKbone.IKTargetID = ik_dragging.ID;
|
|
|
|
|
|
|
|
IKbone.name = "IK handle";
|
|
|
|
IKbone.parent_anchor = false;
|
|
|
|
|
|
|
|
bones.setPosition();
|
|
|
|
}
|
2023-06-26 18:55:41 +02:00
|
|
|
}
|
2024-11-10 05:17:30 +01:00
|
|
|
|
2024-11-12 01:41:42 +01:00
|
|
|
draw_sprite_ui(THEME.preview_bone_IK, 0, p1x, p1y, 1, 1, 0, _reach? COLORS._main_value_positive : COLORS._main_accent, 1);
|
2024-11-10 05:17:30 +01:00
|
|
|
|
|
|
|
} else
|
2024-11-12 01:41:42 +01:00
|
|
|
draw_sprite_ui(THEME.preview_bone_IK, 0, p1x, p1y, 1, 1, 0, COLORS._main_accent, 0.5);
|
2023-06-26 18:55:41 +02:00
|
|
|
|
|
|
|
if(mouse_release(mb_left)) {
|
2024-11-10 05:17:30 +01:00
|
|
|
ik_dragging = noone;
|
2023-06-26 18:55:41 +02:00
|
|
|
UNDO_HOLDING = false;
|
2024-11-10 05:17:30 +01:00
|
|
|
bones.setPosition();
|
2023-06-26 18:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
triggerRender();
|
2024-10-29 03:03:29 +01:00
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
}
|
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
if(isUsingTool("Transform")) {
|
2023-07-15 20:01:29 +02:00
|
|
|
_b.draw(attributes, false, _x, _y, _s, _mx, _my);
|
|
|
|
|
|
|
|
var bbox = _b.bbox();
|
2024-11-26 11:28:04 +01:00
|
|
|
if(!is_array(bbox)) return;
|
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
var x0 = _x + bbox[0] * _s;
|
|
|
|
var y0 = _y + bbox[1] * _s;
|
2024-11-26 11:28:04 +01:00
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
var x1 = _x + bbox[2] * _s;
|
|
|
|
var y1 = _y + bbox[3] * _s;
|
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
if(bone_transform_type >= 0) {
|
|
|
|
var dx = mx - builder_mx;
|
|
|
|
var dy = my - builder_my;
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
var ox0 = bone_transform_bbox[0], oy0 = bone_transform_bbox[1];
|
|
|
|
var ox1 = bone_transform_bbox[2], oy1 = bone_transform_bbox[3];
|
|
|
|
var ow = ox1 - ox0;
|
|
|
|
var oh = oy1 - oy0;
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
var nx0 = ox0, ny0 = oy0;
|
|
|
|
var nx1 = ox1, ny1 = oy1;
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
switch(bone_transform_type) { // transform
|
|
|
|
case 0 :
|
|
|
|
nx0 = ox0 + dx;
|
|
|
|
ny0 = oy0 + dy;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1 :
|
|
|
|
nx1 = ox1 + dx;
|
|
|
|
ny0 = oy0 + dy;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2 :
|
|
|
|
nx0 = ox0 + dx;
|
|
|
|
ny1 = oy1 + dy;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3 :
|
|
|
|
nx1 = ox1 + dx;
|
|
|
|
ny1 = oy1 + dy;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4 :
|
|
|
|
nx0 = ox0 + dx;
|
|
|
|
ny0 = oy0 + dy;
|
|
|
|
nx1 = ox1 + dx;
|
|
|
|
ny1 = oy1 + dy;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var nw = nx1 - nx0;
|
|
|
|
var nh = ny1 - ny0;
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(bone_point_maps); i < n; i++ ) {
|
|
|
|
var _bmap = bone_point_maps[i];
|
|
|
|
var _emap = bone_point_mape[i];
|
|
|
|
|
|
|
|
_emap[0].x = (_bmap[0].x - ox0) / ow * nw + nx0;
|
|
|
|
_emap[0].y = (_bmap[0].y - oy0) / oh * nh + ny0;
|
|
|
|
|
|
|
|
_emap[1].x = (_bmap[1].x - ox0) / ow * nw + nx0;
|
|
|
|
_emap[1].y = (_bmap[1].y - oy0) / oh * nh + ny0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(bone_arr); i < n; i++ ) {
|
|
|
|
var _bone = bone_arr[i];
|
|
|
|
var _emap = bone_point_mape[i];
|
|
|
|
|
|
|
|
var _h = _emap[0];
|
|
|
|
var _t = _emap[1];
|
|
|
|
|
|
|
|
if(!_bone.parent_anchor) {
|
|
|
|
var _ox = 0;
|
|
|
|
var _oy = 0;
|
|
|
|
|
|
|
|
if(_bone.parent) {
|
|
|
|
var _ph = _bone.parent.getHead();
|
|
|
|
_ox = _ph.x;
|
|
|
|
_oy = _ph.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
_bone.distance = point_distance( _ox, _oy, _h.x, _h.y );
|
|
|
|
_bone.direction = point_direction( _ox, _oy, _h.x, _h.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
_bone.length = point_distance(_h.x, _h.y, _t.x, _t.y);
|
|
|
|
_bone.angle = point_direction(_h.x, _h.y, _t.x, _t.y);
|
|
|
|
|
|
|
|
_bone.__setPosition();
|
|
|
|
}
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2023-08-08 18:45:00 +02:00
|
|
|
if(mouse_release(mb_left)) {
|
2024-11-26 11:28:04 +01:00
|
|
|
bone_transform_type = -1;
|
2024-11-10 05:17:30 +01:00
|
|
|
UNDO_HOLDING = false;
|
2023-08-08 18:45:00 +02:00
|
|
|
}
|
2024-11-26 11:28:04 +01:00
|
|
|
|
|
|
|
triggerRender();
|
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_rectangle(x0, y0, x1, y1, true);
|
2024-11-26 11:28:04 +01:00
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
} else {
|
2024-11-26 11:28:04 +01:00
|
|
|
var _hov_type = -1;
|
|
|
|
var _r = 8;
|
|
|
|
|
|
|
|
if(point_in_circle(_mx, _my, x0, y0, _r + 2)) _hov_type = 0;
|
|
|
|
else if(point_in_circle(_mx, _my, x1, y0, _r + 2)) _hov_type = 1;
|
|
|
|
else if(point_in_circle(_mx, _my, x0, y1, _r + 2)) _hov_type = 2;
|
|
|
|
else if(point_in_circle(_mx, _my, x1, y1, _r + 2)) _hov_type = 3;
|
|
|
|
else if(point_in_rectangle(_mx, _my, x0, y0, x1, y1)) _hov_type = 4;
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
draw_set_color(_hov_type == 4? COLORS._main_accent : c_white);
|
2023-07-15 20:01:29 +02:00
|
|
|
draw_set_alpha(0.5);
|
|
|
|
draw_rectangle(x0, y0, x1, y1, true);
|
|
|
|
draw_set_alpha(1);
|
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
draw_anchor(_hov_type == 0, x0, y0, _r);
|
|
|
|
draw_anchor(_hov_type == 1, x1, y0, _r);
|
|
|
|
draw_anchor(_hov_type == 2, x0, y1, _r);
|
|
|
|
draw_anchor(_hov_type == 3, x1, y1, _r);
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
if(_hov_type >= -1 && mouse_press(mb_left, active)) {
|
|
|
|
bone_arr = _b.toArray();
|
|
|
|
for( var i = 0, n = array_length(bone_arr); i < n; i++ ) {
|
|
|
|
var _h = bone_arr[i].getHead();
|
|
|
|
var _t = bone_arr[i].getTail();
|
|
|
|
|
|
|
|
bone_point_maps[i] = [ _h, _t ];
|
|
|
|
bone_point_mape[i] = [ _h.clone(), _t.clone() ];
|
|
|
|
}
|
2023-07-15 20:01:29 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
bone_transform_type = _hov_type;
|
|
|
|
bone_transform_bbox = _b.bbox();
|
|
|
|
builder_mx = mx;
|
|
|
|
builder_my = my;
|
2023-08-08 18:45:00 +02:00
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
recordAction(ACTION_TYPE.struct_modify, bones, bones.serialize());
|
2023-07-15 20:01:29 +02:00
|
|
|
}
|
|
|
|
}
|
2024-10-29 03:03:29 +01:00
|
|
|
|
|
|
|
} else if(isUsingTool("Add bones")) { // builder
|
2024-11-27 05:32:43 +01:00
|
|
|
if(builder_bone == noone) {
|
2023-08-09 15:41:35 +02:00
|
|
|
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
2024-11-27 05:32:43 +01:00
|
|
|
_b.drawControl(attributes);
|
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
|
|
|
|
if(mouse_press(mb_left, active)) {
|
2024-11-27 05:32:43 +01:00
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
if(anchor_selecting == noone) {
|
2024-11-07 07:59:04 +01:00
|
|
|
builder_bone = createBone(bones, point_distance(0, 0, smx, smy), point_direction(0, 0, smx, smy));
|
2023-06-17 14:30:49 +02:00
|
|
|
builder_type = 1;
|
2024-11-27 05:32:43 +01:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
builder_sx = smx;
|
|
|
|
builder_sy = smy;
|
2023-06-21 20:36:53 +02:00
|
|
|
UNDO_HOLDING = true;
|
2024-11-10 05:17:30 +01:00
|
|
|
bones.setPosition();
|
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;
|
2024-11-27 05:32:43 +01:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
builder_sx = smx;
|
|
|
|
builder_sy = smy;
|
2023-06-21 20:36:53 +02:00
|
|
|
UNDO_HOLDING = true;
|
2024-11-10 05:17:30 +01:00
|
|
|
bones.setPosition();
|
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];
|
2024-11-07 07:59:04 +01:00
|
|
|
recordAction(ACTION_TYPE.struct_modify, bones, bones.serialize());
|
2023-08-08 18:45:00 +02:00
|
|
|
|
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)
|
2024-11-07 07:59:04 +01:00
|
|
|
draw_sprite_ext(THEME.bone_tool_add, 1, _mx + 16, _my + 16, 1, 1, 0, c_white, 1);
|
2024-11-10 05:17:30 +01:00
|
|
|
|
2023-06-25 20:12:17 +02:00
|
|
|
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);
|
2024-11-10 05:17:30 +01:00
|
|
|
|
2023-06-25 20:12:17 +02:00
|
|
|
} else if(anchor_selecting[1] == 2)
|
|
|
|
draw_sprite_ext(THEME.bone_tool_add, 0, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
|
2024-10-29 03:03:29 +01:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
} else if(isUsingTool("Remove bones")) { //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);
|
2024-10-29 03:03:29 +01:00
|
|
|
|
2024-11-10 05:17:30 +01:00
|
|
|
} else if(isUsingTool("Detach bones")) { //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)) {
|
2024-11-26 11:28:04 +01:00
|
|
|
var detach_bone = anchor_selecting[0];
|
2023-06-19 20:28:30 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
var par = detach_bone.parent;
|
|
|
|
if(detach_bone.parent_anchor) {
|
|
|
|
detach_bone.distance = par.length;
|
|
|
|
detach_bone.direction = par.angle;
|
2023-06-25 20:12:17 +02:00
|
|
|
}
|
2024-11-26 11:28:04 +01:00
|
|
|
detach_bone.parent_anchor = false;
|
|
|
|
|
|
|
|
builder_bone = detach_bone;
|
|
|
|
builder_type = 0;
|
2023-06-19 20:28:30 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
var head = par.getHead();
|
2024-11-27 05:32:43 +01:00
|
|
|
builder_sx = head.x;
|
|
|
|
builder_sy = head.y;
|
|
|
|
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
|
|
|
}
|
2024-10-29 03:03:29 +01:00
|
|
|
|
|
|
|
} else if(isUsingTool("IK")) { //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
|
|
|
|
2024-11-27 08:33:49 +01:00
|
|
|
if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active))
|
2023-06-26 18:55:41 +02:00
|
|
|
ik_dragging = anchor_selecting[0];
|
2024-11-27 08:33:49 +01:00
|
|
|
|
|
|
|
} else if(isUsingTool("Mirror bones")) {
|
|
|
|
if(builder_bone == noone)
|
|
|
|
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
|
|
|
|
|
|
|
if(mirroring_bone != noone) {
|
|
|
|
var _maxis = anchor_selecting == noone || anchor_selecting[0] == mirroring_bone? mirroring_bone.parent.angle : anchor_selecting[0].angle;
|
|
|
|
var _ori = mirroring_bone.getHead();
|
|
|
|
|
|
|
|
var _ox = _x + _ori.x * _s;
|
|
|
|
var _oy = _y + _ori.y * _s;
|
|
|
|
|
|
|
|
var _x0 = _ox + lengthdir_x(64, _maxis);
|
|
|
|
var _y0 = _oy + lengthdir_y(64, _maxis);
|
|
|
|
var _x1 = _ox - lengthdir_x(64, _maxis);
|
|
|
|
var _y1 = _oy - lengthdir_y(64, _maxis);
|
|
|
|
|
|
|
|
BLEND_ADD
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_line_dashed(_x0, _y0, _x1, _y1, 3);
|
|
|
|
BLEND_NORMAL
|
|
|
|
|
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
var _mirrored = mirroring_bone.clone();
|
|
|
|
var _mirArr = _mirrored.toArray();
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(_mirArr); i < n; i++ ) {
|
|
|
|
var _bm = _mirArr[i];
|
|
|
|
_bm.ID = UUID_generate();
|
|
|
|
|
|
|
|
if(string_pos(" L", _bm.name)) _bm.name = string_replace(_bm.name, " L", " R");
|
|
|
|
else if(string_pos(" R", _bm.name)) _bm.name = string_replace(_bm.name, " R", " L");
|
|
|
|
|
|
|
|
_bm.angle = _maxis + angle_difference(_maxis, _bm.angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
mirroring_bone.parent.addChild(_mirrored);
|
|
|
|
mirroring_bone = noone;
|
|
|
|
|
|
|
|
triggerRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(anchor_selecting != noone) {
|
|
|
|
var _bne = anchor_selecting[0];
|
|
|
|
var _typ = anchor_selecting[1];
|
|
|
|
|
|
|
|
if(_bne.parent && mouse_press(mb_left, active))
|
|
|
|
mirroring_bone = _bne;
|
2023-06-26 18:55:41 +02:00
|
|
|
}
|
2024-11-27 08:33:49 +01:00
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
} else { // move tools
|
|
|
|
if(builder_bone == noone) {
|
2023-08-09 15:41:35 +02:00
|
|
|
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
2024-11-27 05:32:43 +01:00
|
|
|
_b.drawControl(attributes);
|
|
|
|
}
|
2023-06-25 20:12:17 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
if(anchor_selecting != noone) {
|
|
|
|
var _bne = anchor_selecting[0];
|
|
|
|
var _typ = anchor_selecting[1];
|
2023-06-17 14:30:49 +02:00
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
if(_bne.IKlength) _typ = 0;
|
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
gpu_set_texfilter(true);
|
2023-08-08 18:45:00 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
if(_typ == 0) { // free move
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getHead();
|
2024-11-26 11:28:04 +01:00
|
|
|
draw_sprite_ext(s_bone_move, 0, _x + _s * orig.x, _y + _s * orig.y, 1, 1, 0, COLORS._main_accent, 1);
|
2024-11-10 05:17:30 +01:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
} else if(_typ == 1) { // bone move
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getTail();
|
2024-11-26 11:28:04 +01:00
|
|
|
draw_sprite_ext(s_bone_move, 0, _x + _s * orig.x, _y + _s * orig.y, 1, 1, 0, COLORS._main_accent, 1);
|
2024-11-10 05:17:30 +01:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
} else if(_typ == 2) { // bone rotate
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getHead();
|
2024-11-26 11:28:04 +01:00
|
|
|
var _rx = _x + _s * orig.x;
|
|
|
|
var _ry = _y + _s * orig.y;
|
|
|
|
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getPoint(0.8);
|
2024-11-26 11:28:04 +01:00
|
|
|
var _sx = _x + _s * orig.x;
|
|
|
|
var _sy = _y + _s * orig.y;
|
|
|
|
|
|
|
|
if(point_in_circle(_mx, _my, _sx, _sy, 12)) {
|
|
|
|
draw_sprite_ext(s_bone_scale, 0, _sx, _sy, 1, 1, _bne.angle, COLORS._main_accent, 1);
|
|
|
|
draw_sprite_ext(s_bone_rotate, 0, _rx, _ry, 1, 1, _bne.angle, c_white, 1);
|
|
|
|
_typ = 3;
|
|
|
|
|
2023-06-19 20:28:30 +02:00
|
|
|
} else {
|
2024-11-26 11:28:04 +01:00
|
|
|
draw_sprite_ext(s_bone_scale, 0, _sx, _sy, 1, 1, _bne.angle, c_white, 1);
|
|
|
|
draw_sprite_ext(s_bone_rotate, 0, _rx, _ry, 1, 1, _bne.angle, COLORS._main_accent, 1);
|
|
|
|
_typ = 2;
|
2023-06-19 20:28:30 +02:00
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
}
|
2023-06-21 20:36:53 +02:00
|
|
|
|
2024-11-26 11:28:04 +01:00
|
|
|
gpu_set_texfilter(false);
|
|
|
|
|
|
|
|
if(mouse_press(mb_left, active)) {
|
|
|
|
builder_bone = _bne;
|
|
|
|
builder_type = _typ;
|
|
|
|
|
|
|
|
recordAction(ACTION_TYPE.struct_modify, bones, bones.serialize());
|
|
|
|
|
|
|
|
if(_typ == 0) {
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.parent.getHead();
|
2024-11-26 11:28:04 +01:00
|
|
|
builder_sx = orig.x;
|
|
|
|
builder_sy = orig.y;
|
|
|
|
|
|
|
|
} else if(_typ == 1) {
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getHead();
|
2024-11-26 11:28:04 +01:00
|
|
|
builder_sx = orig.x;
|
|
|
|
builder_sy = orig.y;
|
|
|
|
|
|
|
|
} else if(_typ == 2) {
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getHead();
|
2024-11-26 11:28:04 +01:00
|
|
|
builder_sv = point_direction(orig.x, orig.y, mx, my);
|
|
|
|
builder_sx = orig.x;
|
|
|
|
builder_sy = orig.y;
|
|
|
|
builder_mx = mx;
|
|
|
|
builder_my = my;
|
|
|
|
|
|
|
|
} else if(_typ == 3) {
|
2024-11-27 05:32:43 +01:00
|
|
|
var orig = _bne.getHead();
|
2024-11-26 11:28:04 +01:00
|
|
|
builder_sv = point_distance(orig.x, orig.y, mx, my) / _bne.length;
|
|
|
|
builder_sx = orig.x;
|
|
|
|
builder_sy = orig.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNDO_HOLDING = true;
|
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
}
|
|
|
|
}
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
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
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
static update = function(frame = CURRENT_FRAME) {
|
2024-11-27 05:32:43 +01:00
|
|
|
bones.resetPose()
|
|
|
|
.setPosition();
|
2024-11-29 06:18:28 +01:00
|
|
|
bone_bbox = bones.bbox();
|
2024-11-27 05:32:43 +01:00
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
outputs[0].setValue(bones);
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
static getPreviewBoundingBox = function() {
|
2023-07-10 20:14:10 +02:00
|
|
|
var minx = 9999999;
|
|
|
|
var miny = 9999999;
|
|
|
|
var maxx = -9999999;
|
|
|
|
var maxy = -9999999;
|
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
var _b = bones;
|
2023-07-10 20:14:10 +02:00
|
|
|
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++ ) {
|
2024-11-10 05:17:30 +01:00
|
|
|
var p0 = __b.childs[i].getHead();
|
|
|
|
var p1 = __b.childs[i].getTail();
|
2023-07-10 20:14:10 +02:00
|
|
|
|
|
|
|
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);
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
2023-07-10 20:14:10 +02:00
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
static doSerialize = function(_map) {
|
2024-11-07 07:59:04 +01:00
|
|
|
_map.bones = bones.serialize();
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static postDeserialize = function() {
|
2024-11-07 07:59:04 +01:00
|
|
|
if(struct_has(attributes, "bones")) struct_remove(attributes, "bones");
|
2023-06-23 15:39:24 +02:00
|
|
|
if(!struct_has(load_map, "bones")) return;
|
2024-11-26 11:28:04 +01:00
|
|
|
|
2024-11-07 07:59:04 +01:00
|
|
|
bones = new __Bone(,,,,, self);
|
|
|
|
bones.deserialize(load_map.bones, self);
|
|
|
|
bones.connect();
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
2023-06-25 20:12:17 +02:00
|
|
|
|
2024-10-29 03:03:29 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-06-25 20:12:17 +02:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
2024-11-29 06:18:28 +01:00
|
|
|
|
|
|
|
var _ss = _s * .5;
|
|
|
|
gpu_set_tex_filter(1);
|
|
|
|
draw_sprite_ext(s_node_armature_create, 0, bbox.x0 + 24 * _ss, bbox.y1 - 24 * _ss, _ss, _ss, 0, c_white, 0.5);
|
|
|
|
gpu_set_tex_filter(0);
|
|
|
|
|
|
|
|
bones.drawThumbnail(_s, bbox, bone_bbox);
|
2024-10-29 03:03:29 +01:00
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
}
|
|
|
|
|