[WIP+REL] Stance Maker
Hey,
I've started a stance maker for toribash modding.
Contrary to what one might think, I have no problem with the rotation angles, but I have a lot of problem to understand how position works.
See by yourself :
First screenshot : i make my pose in game, and i launch the script
Second screenshot : i load the generated tbm file... as you can see, there are some glitches with the position of the joints and bodyparts.
If somebody (Blam ?) could fix that for me...
Anyway, here's the code :
local player_index = 0
local body_index
local body_info
local angle_x, angle_y, angle_z
local trx, try
local file = io.open("!test.tbm","w")
file:write ("# mod automatically generated by Melmoth's Stance Maker\n\n")
for joint_index = 0,19 do
joint_info = get_joint_info (player_index, joint_index)
joint_pos = get_joint_pos2 (player_index, joint_index)
local radius = get_joint_radius (player_index, joint_index)
local jointname = string.lower(joint_info.name)
jointname,_ = jointname:gsub("right ", "r_")
jointname,_ = jointname:gsub("left ", "l_")
file:write ("joint " .. string.lower(jointname) .. "\n")
file:write ("\tradius " .. radius .. "\n")
file:write ("\tpos " .. joint_pos.x .. " " .. (0.45 + joint_pos.y) .. " " .. (0.06 + joint_pos.z) .. "\n")
end
file:write ("\n")
for body_index = 0,20 do
body_info = get_body_info (player_index, body_index)
local bodyname = body_info.name
if (bodyname == "THORAX") then
bodyname = "groin"
end
angle_y = math.asin(body_info.rot.r2) -- Calculate Y-axis angle
C = math.cos(angle_y)
angle_y = -(angle_y * 180) / math.pi
if ( math.abs( C ) > 0.005 ) then
-- no Gimball lock, so get X-axis angle
trx = body_info.rot.r10 / C
try = -(body_info.rot.r6 / C)
angle_x = -(math.atan2( try, trx ) * 180) / math.pi
trx = body_info.rot.r0 / C -- Get Z-axis angle
try = -(body_info.rot.r1 / C)
angle_z = -(math.atan2( try, trx ) * 180) / math.pi
else
-- Gimball lock has occurred
angle_x = 0 -- Set X-axis angle to zero
trx = body_info.rot.r5 -- And calculate Z-axis angle
try = body_info.rot.r4;
angle_z = -(math.atan2( try, trx ) * 180) / math.pi
end
file:write ("body " .. string.lower(bodyname) .. "\n")
file:write ("\tsides " .. body_info.sides.x .. " " .. body_info.sides.y .. " " .. body_info.sides.z .. "\n")
file:write ("\tpos " .. body_info.pos.x .. " " .. (0.45 + body_info.pos.y) .. " " .. (0.06 + body_info.pos.z) .. "\n")
file:write ("\trot " .. angle_x .. " " .. angle_y .. " " .. angle_z .. "\n")
file:write ("\n")
end
file:close()