Home Technical Talk

Maxscript distance help

polycounter lvl 8
Offline / Send Message
jfeez polycounter lvl 8
So im new to maxscript (grand total of 3days :poly124:) and i decided to throw myself in the deep end by making an autorigger. So far its been pretty simple, used some functions to make a dummy rig that can be adjusted and add bones that align to them etc. but now i want to make twist links. So what i want to be able to do is take the position of two point helpers (eg elbow and wrist, i also make the elbow lookat the wrist so the relationship between bones is easier to see)) get the distance and be able to set the number of bones it places between them 2 points through i spinner, which i have failed at so far..

i have a hacky way to do it (just make 2 point helps called testdummy_01 and testdummy_02)
fn makebone1 pos1 pos2 bname=(
	local newbone
	newbone= bonesys.createbone pos1 pos2 (pos2 - pos1)
	newbone.name = bname
	return newbone
)

rollout test "test" width:238 height:114
(
	button makebonetest "makebone" pos:[34,20] width:135 height:46
	on makebonetest pressed do
	(
		makebone1 $testdummy_01.pos (($testdummy_02.pos+$testdummy_01.pos)/2) "testbone"
		$testbone.transform=$testdummy_01.transform
		makebone1 (($testdummy_02.pos+$testdummy_01.pos)/2) $testdummy_02.pos "testbone2"
		$testbone2.parent=$testbone
	)
)
createdialog test

problem with this method is i have there is no exposed control for the number of bones which i want(use a spiner to select number of bones). i know id probs have to use an array for this, but so far i haven't got anywhere

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    My friend, this is not the deep end, this is open waters.

    Comments in the code below:
    rollout test "test" width:238 height:114
    (
    	--ADD A SPINNER
    	button makebonetest "makebone" pos:[34,20] width:135 height:46
    	spinner spnTwist "Twist Count" type:#integer range:[1,10,2]
    	
    	--MOVED THE FUNCTION INSIDE THE ROLLOUT
    	fn makebone1 pos1 pos2 UpVector BoneLength =
    	(
    		local newbone
    		newbone= bonesys.createbone pos1 pos2 UpVector
    		newbone.length = BoneLength
    		return newbone
    	)
    	
    	on makebonetest pressed do
    	(
    		--GET SOME INFO NEEDED TO CREATE THE BONES
    		StartPos = selection[1].pos
    		EndPos = selection[2].pos
    		--THE UpVector IS USED TO MATCH THE ROTATION OF THE START BONE
    		--WE ASSUME WE ARE WORKING WITH BONES, SO WE USE THE Y AXIS
    		UpVector = in coordsys selection[1] (selection[1].pos + [0,1,0])
    		BoneCount = spnTwist.value
    		BoneLength = (distance StartPos EndPos) / BoneCount
    		
    		--INIT THE ARRAY OF TWISTBONES
    		newBones = #()
    		
    		dir = (EndPos - StartPos) / length (EndPos - StartPos)
    		
    		for i = 0 to BoneCount-1 do
    		(
    			--ADJUST THE START POS FOR EACH TWIST BONE
    			--THE END POS IS THE SAME, BUT WE CHANGE IT'S LENGTH AFTER CREATION, KEEPS THE LOOP SIMPLIER
    			newStartPos = StartPos + (dir * i * BoneLength)
    			append newBones (makebone1 newStartPos EndPos UpVector BoneLength)
    		)
    		
    		--MAKE A LOOP THAT PARENTS THE TWIST BONES
    		--blah blah blah
    	)
    )
    createdialog test
    
  • jfeez
    Options
    Offline / Send Message
    jfeez polycounter lvl 8
    oh man, that makes alot of sense *bashes head against wall* alot of simple things i should have already got clicked straight away. many thanks =)
Sign In or Register to comment.