mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +01:00
IK fix
This commit is contained in:
parent
14fab463f7
commit
7bfb368645
6 changed files with 60 additions and 31 deletions
|
@ -321,7 +321,7 @@ function __Bone(parent = noone, distance = 0, direction = 0, angle = 0, length =
|
|||
lengths[i] = point_distance(p0.x, p0.y, p1.x, p1.y);
|
||||
}
|
||||
|
||||
var p = parent.getPoint(0, 0);
|
||||
var p = parent.getPoint(0);
|
||||
p.x += lengthdir_x(distance, direction);
|
||||
p.y += lengthdir_y(distance, direction);
|
||||
|
||||
|
@ -334,7 +334,7 @@ function __Bone(parent = noone, distance = 0, direction = 0, angle = 0, length =
|
|||
|
||||
FABRIK_result = [];
|
||||
static FABRIK = function(bones, points, lengths, dx, dy) {
|
||||
var threshold = 0.1;
|
||||
var threshold = 0.01;
|
||||
var _bo = array_create(array_length(points));
|
||||
for( var i = 0, n = array_length(points); i < n; i++ )
|
||||
_bo[i] = { x: points[i].x, y: points[i].y };
|
||||
|
@ -354,7 +354,7 @@ function __Bone(parent = noone, distance = 0, direction = 0, angle = 0, length =
|
|||
}
|
||||
|
||||
_bo = _bn;
|
||||
if(++itr >= 32) break;
|
||||
if(++itr >= 64) break;
|
||||
} until(delta <= threshold);
|
||||
|
||||
for( var i = 0, n = array_length(points) - 1; i < n; i++ ) {
|
||||
|
@ -379,7 +379,7 @@ function __Bone(parent = noone, distance = 0, direction = 0, angle = 0, length =
|
|||
var p1 = points[i];
|
||||
var p0 = points[i - 1];
|
||||
var len = lengths[i - 1];
|
||||
var dir = point_direction(p0.x, p0.y, tx, ty);
|
||||
var dir = point_direction(tx, ty, p0.x, p0.y);
|
||||
|
||||
p1.x = tx;
|
||||
p1.y = ty;
|
||||
|
|
|
@ -13,10 +13,10 @@ function colorArrayFromReal(clr) {
|
|||
return [color_get_red(clr) / 255, color_get_green(clr) / 255, color_get_blue(clr) / 255 ];
|
||||
}
|
||||
|
||||
function colorBrightness(clr) {
|
||||
var r2 = color_get_red(clr) / 255;
|
||||
var g2 = color_get_green(clr) / 255;
|
||||
var b2 = color_get_blue(clr) / 255;
|
||||
function colorBrightness(clr, normalize = true) {
|
||||
var r2 = color_get_red(clr) / (normalize? 255 : 1);
|
||||
var g2 = color_get_green(clr) / (normalize? 255 : 1);
|
||||
var b2 = color_get_blue(clr) / (normalize? 255 : 1);
|
||||
return 0.299 * r2 + 0.587 * g2 + 0.224 * b2;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
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)) {
|
||||
TOOLTIP = "Apply scale";
|
||||
draw_sprite_ui(THEME.bone, 3, _x0, _y0,,,, cc, 0.75);
|
||||
|
||||
if(mouse_press(mb_left, _focus))
|
||||
|
@ -90,6 +91,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
_x0 += 20;
|
||||
var cc = bone.apply_rotation? COLORS._main_icon : COLORS._main_value_negative;
|
||||
if(point_in_circle(_m[0], _m[1], _x0, _y0, 16)) {
|
||||
TOOLTIP = "Apply rotation";
|
||||
draw_sprite_ui(THEME.bone, 4, _x0, _y0,,,, cc, 0.75);
|
||||
|
||||
if(mouse_press(mb_left, _focus))
|
||||
|
@ -270,7 +272,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
|
||||
var reachable = false;
|
||||
var _bone = ik_dragging.parent;
|
||||
var len = 1;
|
||||
var len = 0;
|
||||
|
||||
while(_bone != noone) {
|
||||
if(_bone == anc.parent) {
|
||||
|
@ -293,8 +295,8 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
|
||||
var IKbone = new __Bone(anc, _len, _ang, ik_dragging.angle + 90, 0, self);
|
||||
anc.addChild(IKbone);
|
||||
IKbone.IKlength = len;
|
||||
IKbone.IKTargetID = ik_dragging;
|
||||
IKbone.IKlength = len;
|
||||
IKbone.IKTargetID = ik_dragging.ID;
|
||||
|
||||
IKbone.name = "IK handle";
|
||||
IKbone.parent_anchor = false;
|
||||
|
@ -422,7 +424,8 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
}
|
||||
}
|
||||
} else if(isUsingTool("Add bones")) { // builder
|
||||
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
if(builder_bone == noone)
|
||||
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
|
||||
if(mouse_press(mb_left, active)) {
|
||||
if(anchor_selecting == noone) {
|
||||
|
@ -483,7 +486,8 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
if(anchor_selecting != noone)
|
||||
draw_sprite_ext(THEME.bone_tool_remove, 1, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
|
||||
} else if(isUsingTool("Detach bones")) { //detach
|
||||
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
if(builder_bone == noone)
|
||||
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
|
||||
if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
|
||||
builder_bone = anchor_selecting[0];
|
||||
|
@ -503,13 +507,15 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
|
|||
UNDO_HOLDING = true;
|
||||
}
|
||||
} else if(isUsingTool("IK")) { //IK
|
||||
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
if(ik_dragging == noone)
|
||||
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
|
||||
if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
|
||||
ik_dragging = anchor_selecting[0];
|
||||
}
|
||||
} else { //mover
|
||||
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
if(builder_bone == noone)
|
||||
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
|
||||
|
||||
if(anchor_selecting != noone && mouse_press(mb_left, active)) {
|
||||
builder_bone = anchor_selecting[0];
|
||||
|
|
|
@ -822,10 +822,10 @@ function Node_Armature_Bind(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
|
|||
_b = boneMap[? _b];
|
||||
|
||||
var _tran = use_data? _bind[i].transform : _data[datInd + 1];
|
||||
var _aang = _data[datInd + 2];
|
||||
var _pang = _data[datInd + 3];
|
||||
var _asca = _data[datInd + 4];
|
||||
var _psca = _data[datInd + 5];
|
||||
var _aang = use_data? _bind[i].applyRot : _data[datInd + 2];
|
||||
var _pang = use_data? _bind[i].applyRotl : _data[datInd + 3];
|
||||
var _asca = use_data? _bind[i].applySca : _data[datInd + 4];
|
||||
var _psca = use_data? _bind[i].applyScal : _data[datInd + 5];
|
||||
|
||||
var _rot = _aang * (_pang? _b.angle : _b.pose_local_angle) + _tran[TRANSFORM.rot];
|
||||
var _anc = _b.getPoint(0.5);
|
||||
|
@ -851,9 +851,13 @@ function Node_Armature_Bind(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
|
|||
|
||||
array_push(atlas_data, new SurfaceAtlas(_s, _pos, _rot, _sca));
|
||||
array_push(bind_data, {
|
||||
surface: new Surface(_s),
|
||||
bone: _b.ID,
|
||||
transform: _tran
|
||||
surface: new Surface(_s),
|
||||
bone: _b.ID,
|
||||
transform: _tran,
|
||||
applyRot: _aang,
|
||||
applyRotl: _pang,
|
||||
applySca: _asca,
|
||||
applyScal: _psca,
|
||||
});
|
||||
draw_surface_ext_safe(_s, _pos[0], _pos[1], _sca[0], _sca[1], _rot);
|
||||
}
|
||||
|
|
|
@ -14,11 +14,19 @@ function Node_Palette_Sort(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
|
||||
inputs[| 2] = nodeValue("Reverse", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
||||
|
||||
inputs[| 3] = nodeValue("Sort Order", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "RGB");
|
||||
inputs[| 3] = nodeValue("Sort Order", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "RGB", @"Compose sorting algorithm using string.
|
||||
- RGB: Red/Green/Blur channel
|
||||
- HSV: Hue/Saturation/Value
|
||||
- L: Brightness
|
||||
- Use small letter for ascending, capital letter for descending order.");
|
||||
|
||||
outputs[| 0] = nodeValue("Sorted palette", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, [])
|
||||
.setDisplay(VALUE_DISPLAY.palette);
|
||||
|
||||
input_display_list = [
|
||||
0, 1, 3, 2,
|
||||
]
|
||||
|
||||
static step = function() {
|
||||
var _typ = inputs[| 1].getValue();
|
||||
|
||||
|
@ -28,19 +36,29 @@ function Node_Palette_Sort(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
sort_string = "";
|
||||
static customSort = function(c) {
|
||||
var len = string_length(sort_string);
|
||||
var val = power(256, len);
|
||||
var val = power(256, len - 1);
|
||||
var res = 0;
|
||||
|
||||
for( var i = 1; i <= len; i++ ) {
|
||||
var ch = string_lower(string_char_at(sort_string, i));
|
||||
var ch = string_char_at(sort_string, i);
|
||||
var _v = 0;
|
||||
|
||||
switch(ch) {
|
||||
case "r" : return
|
||||
switch(string_lower(ch)) {
|
||||
case "r" : _v += color_get_red(c); break;
|
||||
case "g" : _v += color_get_green(c); break;
|
||||
case "b" : _v += color_get_blue(c); break;
|
||||
case "h" : _v += color_get_hue(c); break;
|
||||
case "s" : _v += color_get_saturation(c); break;
|
||||
case "v" : _v += color_get_value(c); break;
|
||||
case "l" : _v += colorBrightness(c, false); break;
|
||||
}
|
||||
|
||||
if(ord(ch) <= ord("Z")) res += _v * val;
|
||||
else res += (256 - _v) * val;
|
||||
val /= 256;
|
||||
}
|
||||
|
||||
return c;
|
||||
return res;
|
||||
}
|
||||
|
||||
static update = function(frame = PROJECT.animator.current_frame) {
|
||||
|
@ -63,7 +81,7 @@ function Node_Palette_Sort(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
case 7 : array_sort(_pal, __sortGreen); break;
|
||||
case 8 : array_sort(_pal, __sortBlue); break;
|
||||
|
||||
case 10 : array_sort(_pal, function(c1, c2) { return customSort(c1) - customSort(c2); }); break;
|
||||
case 10 : array_sort(_pal, function(c1, c2) { return customSort(c2) - customSort(c1); }); break;
|
||||
}
|
||||
|
||||
if(_rev) _pal = array_reverse(_pal);
|
||||
|
|
|
@ -12,6 +12,7 @@ function struct_override(original, override) {
|
|||
}
|
||||
|
||||
function struct_try_get(struct, key, def = 0) {
|
||||
gml_pragma("forceinline");
|
||||
if(struct[$ key] != undefined) return struct[$ key];
|
||||
|
||||
key = string_replace_all(key, "_", " ");
|
||||
|
|
Loading…
Reference in a new issue