@tool
class_name BoneToFlatten
extends Resource

@export var bone_names: PackedStringArray = []
@export var amount_by_pitch_curve: Curve = Curve.new()
@export var amount_by_yaw_curve: Curve = Curve.new()
@export var consider_side: bool = false
@export var yaw_fraction: float = 1

@export_group("Position")
@export var do_position: bool = false
@export var position_x_amount: float

@export_group("Rotation")
@export var do_rotation: bool = false
@export var rotation_x_amount: float
@export var rotation_x_curve: Curve
@export var mirror_rot_x: bool = false
@export var consider_side_rot_x: bool = false
@export var rotation_y_amount: float
@export var rotation_y_curve: Curve
@export var mirror_rot_y: bool = false
@export var consider_side_rot_y: bool = false
@export var rotation_z_amount: float
@export var rotation_z_curve: Curve
@export var mirror_rot_z: bool = false
@export var consider_side_rot_z: bool = false

@export_group("Scale")
@export var do_scale: bool = false


func get_angle_normalized(angle: Vector3) -> Vector3:
	var normalized := Vector3.ZERO
	normalized.y = angle.y / (PI / yaw_fraction)
	normalized.x = angle.x / (PI / 2)
	return normalized


func get_amount(angle: Vector3) -> float:
	if amount_by_pitch_curve == null or amount_by_yaw_curve == null:
		return 0

	var normalized := get_angle_normalized(angle)
	var amount_by_yaw := amount_by_yaw_curve.sample(absf(normalized.y))
	var amount := amount_by_pitch_curve.sample(absf(normalized.x)) * amount_by_yaw
	if consider_side:
		amount *= -signf(normalized.y)
	return amount
