Toribash
Original Post
[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()
Attached Images
test1.jpg (14.3 KB, 223 views)
test2.jpg (14.6 KB, 192 views)
Hmm...
your conversion is fine, as this pic shows:

drawn using:
add_hook("draw3d","test",
    function()
        set_color(0,0,0,1)
        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)
            
            draw_sphere(joint_pos.x-3,joint_pos.y,joint_pos.z,radius)
            draw_sphere(joint_pos.x+3,joint_pos.y,joint_pos.z,radius)
        end
        
        for body_index = 0,20 do
            body_info = get_body_info (player_index, body_index)
                
             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
            
            set_color(1,0,0,1)
            if(body_index == 0) then
                draw_sphere(body_info.pos.x-3,body_info.pos.y,body_info.pos.z,body_info.sides.x)
                draw_sphere(body_info.pos.x+3,body_info.pos.y,body_info.pos.z,body_info.sides.x)

            elseif(body_index > 0 and body_index < 15) or (body_index > 18) then
                draw_box(body_info.pos.x-3,body_info.pos.y,body_info.pos.z,body_info.sides.x,body_info.sides.y,body_info.sides.z,angle_x,angle_y,angle_z)
                draw_box_m(body_info.pos.x+3,body_info.pos.y,body_info.pos.z,body_info.sides.x,body_info.sides.y,body_info.sides.z,body_info.rot)
            else --Legs are odd..
                draw_capsule(body_info.pos.x-3,body_info.pos.y,body_info.pos.z,body_info.sides.x+0.2,body_info.sides.y-0.17,angle_x,angle_y,angle_z)
                draw_capsule_m(body_info.pos.x+3,body_info.pos.y,body_info.pos.z,body_info.sides.x+0.2,body_info.sides.y-0.17,body_info.rot)
            end
            
        end
        
    end
)
So idk, it must be a problem to do with either the creation of the mod file, or the way mods work?
:D
thumbing through the bands I be playin' with the check, keep it real 'til I die, put it on my set Tapion's Avatar
4th Dan Black Belt
Join Date: Jul 2008
Posts: 2,373
I can try to look over the mod file or something and check if I see something suspisios. rawr. But ye. Lua people should look further into this ofc.

EDIT: is that code you posted blam the lua code?
Sigma | Gata
Lost pet looking for home
OMG, thanks so much melmoth. now hampa dosent have to put in starting stances into toribash (well not yet anyway) we just did it for him

*gives tampion a lolcookie*

so to test it i just copy the script and put it in my scrpits folder? and then you lcick on the scrpt ingame.... and hten you get the file from the mod folder? is that right?
- its been a while
Originally Posted by Tapion View Post
I can try to look over the mod file or something and check if I see something suspisios. rawr. But ye. Lua people should look further into this ofc.

EDIT: is that code you posted blam the lua code?

code I posted was just to check for any really obvious errors.
:D
can you make it prompt for a filename and then save in mod folder? im not really sure what to do with it. i just loaded it ingame with /ls stance.lua and i have no idea what it did.
- its been a while
makes a mod file in data/scripts/ called !test.tbm
:D
ahhh thank you. im going off to make some stance mods....

wait nvm... still cant find it. i think i might be a problem with on how i load the script. does it automaticly make the file once i load it or do i have to press something?
Last edited by blkk; Feb 21, 2009 at 06:23 PM.
- its been a while
thumbing through the bands I be playin' with the check, keep it real 'til I die, put it on my set Tapion's Avatar
4th Dan Black Belt
Join Date: Jul 2008
Posts: 2,373
The stance gets a bit off. the only think that goes right here, is the body parts. All the joints go abit off. The knee joint goes too much off so...
Sigma | Gata
Lost pet looking for home