This commit is contained in:
Tanasart 2023-08-09 15:41:35 +02:00
parent 14fab463f7
commit 7bfb368645
6 changed files with 60 additions and 31 deletions

View file

@ -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); 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.x += lengthdir_x(distance, direction);
p.y += lengthdir_y(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 = []; FABRIK_result = [];
static FABRIK = function(bones, points, lengths, dx, dy) { static FABRIK = function(bones, points, lengths, dx, dy) {
var threshold = 0.1; var threshold = 0.01;
var _bo = array_create(array_length(points)); var _bo = array_create(array_length(points));
for( var i = 0, n = array_length(points); i < n; i++ ) for( var i = 0, n = array_length(points); i < n; i++ )
_bo[i] = { x: points[i].x, y: points[i].y }; _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; _bo = _bn;
if(++itr >= 32) break; if(++itr >= 64) break;
} until(delta <= threshold); } until(delta <= threshold);
for( var i = 0, n = array_length(points) - 1; i < n; i++ ) { 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 p1 = points[i];
var p0 = points[i - 1]; var p0 = points[i - 1];
var len = lengths[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.x = tx;
p1.y = ty; p1.y = ty;

View file

@ -13,10 +13,10 @@ function colorArrayFromReal(clr) {
return [color_get_red(clr) / 255, color_get_green(clr) / 255, color_get_blue(clr) / 255 ]; return [color_get_red(clr) / 255, color_get_green(clr) / 255, color_get_blue(clr) / 255 ];
} }
function colorBrightness(clr) { function colorBrightness(clr, normalize = true) {
var r2 = color_get_red(clr) / 255; var r2 = color_get_red(clr) / (normalize? 255 : 1);
var g2 = color_get_green(clr) / 255; var g2 = color_get_green(clr) / (normalize? 255 : 1);
var b2 = color_get_blue(clr) / 255; var b2 = color_get_blue(clr) / (normalize? 255 : 1);
return 0.299 * r2 + 0.587 * g2 + 0.224 * b2; return 0.299 * r2 + 0.587 * g2 + 0.224 * b2;
} }

View file

@ -80,6 +80,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
var _y0 = ty + 14; var _y0 = ty + 14;
var cc = bone.apply_scale? COLORS._main_icon : COLORS._main_value_negative; var cc = bone.apply_scale? COLORS._main_icon : COLORS._main_value_negative;
if(point_in_circle(_m[0], _m[1], _x0, _y0, 16)) { 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); draw_sprite_ui(THEME.bone, 3, _x0, _y0,,,, cc, 0.75);
if(mouse_press(mb_left, _focus)) if(mouse_press(mb_left, _focus))
@ -90,6 +91,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
_x0 += 20; _x0 += 20;
var cc = bone.apply_rotation? COLORS._main_icon : COLORS._main_value_negative; var cc = bone.apply_rotation? COLORS._main_icon : COLORS._main_value_negative;
if(point_in_circle(_m[0], _m[1], _x0, _y0, 16)) { 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); draw_sprite_ui(THEME.bone, 4, _x0, _y0,,,, cc, 0.75);
if(mouse_press(mb_left, _focus)) 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 reachable = false;
var _bone = ik_dragging.parent; var _bone = ik_dragging.parent;
var len = 1; var len = 0;
while(_bone != noone) { while(_bone != noone) {
if(_bone == anc.parent) { if(_bone == anc.parent) {
@ -294,7 +296,7 @@ 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); var IKbone = new __Bone(anc, _len, _ang, ik_dragging.angle + 90, 0, self);
anc.addChild(IKbone); anc.addChild(IKbone);
IKbone.IKlength = len; IKbone.IKlength = len;
IKbone.IKTargetID = ik_dragging; IKbone.IKTargetID = ik_dragging.ID;
IKbone.name = "IK handle"; IKbone.name = "IK handle";
IKbone.parent_anchor = false; IKbone.parent_anchor = false;
@ -422,6 +424,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
} }
} }
} else if(isUsingTool("Add bones")) { // builder } else if(isUsingTool("Add bones")) { // builder
if(builder_bone == noone)
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting); anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
if(mouse_press(mb_left, active)) { if(mouse_press(mb_left, active)) {
@ -483,6 +486,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
if(anchor_selecting != noone) if(anchor_selecting != noone)
draw_sprite_ext(THEME.bone_tool_remove, 1, _mx + 24, _my + 24, 1, 1, 0, c_white, 1); draw_sprite_ext(THEME.bone_tool_remove, 1, _mx + 24, _my + 24, 1, 1, 0, c_white, 1);
} else if(isUsingTool("Detach bones")) { //detach } else if(isUsingTool("Detach bones")) { //detach
if(builder_bone == noone)
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting); 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)) { if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
@ -503,12 +507,14 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
UNDO_HOLDING = true; UNDO_HOLDING = true;
} }
} else if(isUsingTool("IK")) { //IK } else if(isUsingTool("IK")) { //IK
if(ik_dragging == noone)
anchor_selecting = _b.draw(attributes, active * 0b100, _x, _y, _s, _mx, _my, anchor_selecting); 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)) { if(anchor_selecting != noone && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
ik_dragging = anchor_selecting[0]; ik_dragging = anchor_selecting[0];
} }
} else { //mover } else { //mover
if(builder_bone == noone)
anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting); anchor_selecting = _b.draw(attributes, active * 0b111, _x, _y, _s, _mx, _my, anchor_selecting);
if(anchor_selecting != noone && mouse_press(mb_left, active)) { if(anchor_selecting != noone && mouse_press(mb_left, active)) {

View file

@ -822,10 +822,10 @@ function Node_Armature_Bind(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
_b = boneMap[? _b]; _b = boneMap[? _b];
var _tran = use_data? _bind[i].transform : _data[datInd + 1]; var _tran = use_data? _bind[i].transform : _data[datInd + 1];
var _aang = _data[datInd + 2]; var _aang = use_data? _bind[i].applyRot : _data[datInd + 2];
var _pang = _data[datInd + 3]; var _pang = use_data? _bind[i].applyRotl : _data[datInd + 3];
var _asca = _data[datInd + 4]; var _asca = use_data? _bind[i].applySca : _data[datInd + 4];
var _psca = _data[datInd + 5]; var _psca = use_data? _bind[i].applyScal : _data[datInd + 5];
var _rot = _aang * (_pang? _b.angle : _b.pose_local_angle) + _tran[TRANSFORM.rot]; var _rot = _aang * (_pang? _b.angle : _b.pose_local_angle) + _tran[TRANSFORM.rot];
var _anc = _b.getPoint(0.5); var _anc = _b.getPoint(0.5);
@ -853,7 +853,11 @@ function Node_Armature_Bind(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
array_push(bind_data, { array_push(bind_data, {
surface: new Surface(_s), surface: new Surface(_s),
bone: _b.ID, bone: _b.ID,
transform: _tran transform: _tran,
applyRot: _aang,
applyRotl: _pang,
applySca: _asca,
applyScal: _psca,
}); });
draw_surface_ext_safe(_s, _pos[0], _pos[1], _sca[0], _sca[1], _rot); draw_surface_ext_safe(_s, _pos[0], _pos[1], _sca[0], _sca[1], _rot);
} }

View file

@ -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[| 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, []) outputs[| 0] = nodeValue("Sorted palette", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, [])
.setDisplay(VALUE_DISPLAY.palette); .setDisplay(VALUE_DISPLAY.palette);
input_display_list = [
0, 1, 3, 2,
]
static step = function() { static step = function() {
var _typ = inputs[| 1].getValue(); var _typ = inputs[| 1].getValue();
@ -28,19 +36,29 @@ function Node_Palette_Sort(_x, _y, _group = noone) : Node(_x, _y, _group) constr
sort_string = ""; sort_string = "";
static customSort = function(c) { static customSort = function(c) {
var len = string_length(sort_string); 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++ ) { 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) { switch(string_lower(ch)) {
case "r" : return 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; val /= 256;
} }
return c; return res;
} }
static update = function(frame = PROJECT.animator.current_frame) { 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 7 : array_sort(_pal, __sortGreen); break;
case 8 : array_sort(_pal, __sortBlue); 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); if(_rev) _pal = array_reverse(_pal);

View file

@ -12,6 +12,7 @@ function struct_override(original, override) {
} }
function struct_try_get(struct, key, def = 0) { function struct_try_get(struct, key, def = 0) {
gml_pragma("forceinline");
if(struct[$ key] != undefined) return struct[$ key]; if(struct[$ key] != undefined) return struct[$ key];
key = string_replace_all(key, "_", " "); key = string_replace_all(key, "_", " ");