Notifications
Clear all

[Closed] Wheel Rotation Script

Sorry to bother people with this problem again, seems there are so many threads about it, but none with a reel solution.

I have a car that I animated over a spline with a simpel car-rig.
I found a script to make the wheels spin, as they where driving on a road.

http://forums.cgsociety.org/showthr…=wheel+rotation

script works like a charms, exept for the fact that I can’t render a sequence. It’s an old archived thread so I can’t comment on it. Maybe there is a way to ‘bake’ the scripted animation or someone has a better script.

using MAX 2010 or 2009.

thanks…

7 Replies
 eek

You should make it a fn, so people dont need to rename there stuff plus if dummy01 exists in the scene there screwed. Also using nurbs splines is not good for big scenes – dont know if max has fixed the messages bug.

 struct wheelroll 
(
 
fn wheelpath path wheel =
(
 
p = point() 
p.name = (uniquename + (wheel.name as string + "_point" ))
p.pos = [0,0,0]
 
wheelTemp = circle radius:20 pos:[0,0,0] name: (uniquename + wheel.name as string)
rotate WheelTemp (angleaxis -90 [0,1,0])
 
wheelTemp.parent = p
 
p.pos.controller = position_list()
p.pos.controller.avaliable.controller = path_constraint()
p.pos.controller.path_constraint.controller.appendTarget path
 
p.pos.controller.path_constraint.controller.follow = on
p.pos.controller.Path_Constraint.controller.constantVel = off
 
rotate wheeltemp (angleaxis 90 [0,0,1])
 
 
p.pos.controller.Path_Constraint.controller.percent.controller = bezier_float ()
paramWire.connect p.pos.controller.Path_Constraint.controller[#Percent] wheelTemp.rotation.controller[#Y_Rotation] "(Percent)*(((curveLength $" + path.name as string + " )/(2*PI*$" + WheelTemp as string + ".radius))*360)/(360/(2*PI))" 
 
)
 
 
 
 
 
 
 
)

now call the struct to make it an instance:

wheelroll_c = wheelroll()

Then wheelroll_c.wheelPath $curve01 $wheel01

Something like that anyway – havent tested it. I love structs!

edit cant remember if you have to add “”” to the being of the wireparam, to encapsulate the quotes.

Hi Charles,

I too have just started to use data structures and i’m finding the ability to access scene aspects in a more organised way very interesting. I hadn’t thought about placing a function inside a struct and it is a really nice way of accessing it. I guess If you had a longer script you could group similar functions into a struct this way, and help with the organisation of things.
Although i use functions a lot, i sometimes find they are all bundled in the start of the script in no particular order and it makes navigating more dificult. This way you could have a separate struct for each type of function set and call it in the way that you have detailed. Thanks a lot.

 eek

Bingo, thats exactly what i do. I have a struct with a ton of fns inside it, i can call it in additional scripts, you can even can fns with fn in a struct:

struct test

(
fn test1 a b = ( return (a+b)),
fn test2 c =( return (test.test1 + c))
)
struct instancing is very powerful, because variables inside, become unique – you dont need globals, which arent that good to use. Virtually any container in max can hold virtually anything. Ive used CA blocks to hold fns, that variables outside in script controllers access. Fns can be embedded virtually anywhere in a scene and outside too. And most of my scripts are just fns calls returning vals going into more fns.

great stuff Charles, very interesting. Thanks for your input.

here is a simple bake animation function:


fn bakeAnimation obj =
(
	local transformArray = for i = animationrange.start to animationrange.end collect 
		at time i obj.transform
	obj.transform.controller = transform_script()
	obj.transform.controller = prs()
	obj.parent = undefined
	undo "Bake Animation" on
		with animate on
			for i = 1 to transformArray.count do 
				at time (i + animationrange.start - 1) obj.transform = transformArray[i]
)


I had try wheel rotational script above, but can we make it realtime as you move the Dummy,
the wheel rotate even AutoKey OFF?
What i mean, can we achieve rotation like MakeRoll function in MEL script?

I remember this one being pretty good:

http://forums.cgsociety.org/showthread.php?p=4713871