New drivers function
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from mathutils import *
|
||||
# from mathutils import *
|
||||
from math import *
|
||||
import bpy
|
||||
|
||||
@@ -38,43 +38,36 @@ def half_angle_to_length(angle: float, target: float = 1.0) -> float:
|
||||
return (side * sin(angle)) / sin((pi - angle) * 0.5)
|
||||
|
||||
|
||||
def angle_compensation(angle: float) -> float:
|
||||
side_len = sqrt(pow(pi * 0.5, 2) * 0.5) # Length of imaginary triangle's side
|
||||
distance = 0.5 # Distance to which move bone to
|
||||
|
||||
angle = abs(pi - angle)
|
||||
|
||||
# Compensate non-linear input angle
|
||||
if angle > 0:
|
||||
comp_angle = (side_len * 0.5 * sin(angle)) / sin(angle * 0.5)
|
||||
else:
|
||||
comp_angle = side_len
|
||||
|
||||
return (sqrt(pow(tan(comp_angle), 2) + 1) - 1) * distance
|
||||
|
||||
|
||||
def half_angle_compensation(angle: float) -> float:
|
||||
def half_elbow_compensation(angle: float) -> float:
|
||||
side = sqrt(pow(pi * 0.25, 2) * 0.5) # Length of imaginary triangle's side
|
||||
angle = abs(angle)
|
||||
final_angle = (side * sin(angle)) / sin((pi - angle) * 0.5) # Width of imaginary triangle's base
|
||||
return sqrt(pow(tan(final_angle), 2) + 1) - 1 # What the fuck??
|
||||
|
||||
|
||||
def test_compensation(angle: float) -> float:
|
||||
side = sqrt(pow(pi * 0.5, 2) * 0.5) # Triangle's side is now a desired output angle in radians
|
||||
angle = abs(pi - angle) # Rotate default angle to 180deg
|
||||
return angle_to_length(angle, side)
|
||||
def compensated_elbow_corner(frame: float, offset: float = 0.125) -> float:
|
||||
# min(0.125, 0.125 * tan(acos(1 - frame / 180)))
|
||||
c_angle = acos(1 - frame / 180)
|
||||
return min(offset, offset * tan(c_angle))
|
||||
|
||||
|
||||
def test_half_compensation(angle: float) -> float:
|
||||
side = pi * 0.25
|
||||
angle = abs(pi * 0.5 + angle) # Rotate default angle to 90deg
|
||||
return half_angle_to_length(angle, side)
|
||||
def compensated_elbow_crease(frame: float, offset_1: float = 0.0625, offset_2: float = 0.125) -> float:
|
||||
# min(0.0625, 0.0625 * tan(acos(1 - frame / 180))) + 0.125 * tan(max(acos(1 - frame / 180) - pi / 4, 0))
|
||||
c_angle = acos(1 - frame / 180)
|
||||
first_stage = min(offset_1, offset_1 * tan(c_angle))
|
||||
second_stage = (tan(max(c_angle - pi / 4, 0)) * offset_2)
|
||||
return first_stage + second_stage
|
||||
|
||||
|
||||
def compensated_elbow_corner_2(frame: float, offset: float = 0.125) -> float:
|
||||
# 0.125 * (sqrt(pow(tan(acos(1 - frame / 180)), 2) + 1) - 1)
|
||||
c_angle = acos(1 - frame / 180)
|
||||
return offset * (sqrt(pow(tan(c_angle), 2) + 1) - 1)
|
||||
|
||||
|
||||
bpy.app.driver_namespace["angle_to_length"] = angle_to_length
|
||||
bpy.app.driver_namespace["half_angle_to_length"] = half_angle_to_length
|
||||
bpy.app.driver_namespace["angle_compensation"] = angle_compensation
|
||||
bpy.app.driver_namespace["half_angle_compensation"] = half_angle_compensation
|
||||
bpy.app.driver_namespace["test_compensation"] = test_compensation
|
||||
bpy.app.driver_namespace["test_half_compensation"] = test_half_compensation
|
||||
bpy.app.driver_namespace["half_elbow_compensation"] = half_elbow_compensation
|
||||
bpy.app.driver_namespace["compensated_elbow_corner"] = compensated_elbow_corner
|
||||
bpy.app.driver_namespace["compensated_elbow_corner_2"] = compensated_elbow_corner_2
|
||||
bpy.app.driver_namespace["compensated_elbow_crease"] = compensated_elbow_crease
|
||||
|
||||
Reference in New Issue
Block a user