how to add new keyframe to bezier curve based on when a condition is met.

how to add new keyframe to bezier curve based on when a condition is met.

Anonymous
Not applicable
871 Views
4 Replies
Message 1 of 5

how to add new keyframe to bezier curve based on when a condition is met.

Anonymous
Not applicable
--question.  How can I add a frame to the bezier controller named "garb" and change value of light multiplyer to 75 when the height value of box becomes 202.9631958008 (b.height  = 202.9631958008)   over the course of the animation 0 to 100
--I realize I can do it like "at time # animate on d.multiplier = 75" however my question is mainly about how to add keyframes to a bezier controller for my light multiplier value that
--changes the multiplyer value based when a certain condition that is met during the course of an animation namely when box height = 202.9631958008

--later I have to switch out the conditional with something more than just a height change of a box but I am trying to learn basics  of adding keyframes to bezier curves based on a condition. The condition of a box determines when my new keyframe is placed with regard to my light. My current script below
--thanks


clearListener() ResetMaxFile #noPrompt units.displayType = #metric units.MetricType = #Kilometers units.systemType = #kilometers units.systemScale = 1 b = box name:"dodo" height:10 pos:[0,100,0]--create box d = omnilight name:"****" rgb:[0,230,89] pos:[0,0,0] multiplier:59 --create light whos multiplyer value changes at time 0 animate on b.height=0 at time 100 animate on b.height=300 at time 0 animate on d.multiplier = 0 at time 100 animate on d.multiplier = 50 d.multiplier.controller = bezier_float name:"garb" --creates a multiplyer bezier curve for curve editor for omnilight displaymulitplyerkeys = d.multiplier.controller.keys addnewkey d.multiplier.controller 64 ---this line adds keyframe along the curve at frame 64 but doesnt dosnt change the multiplyer value and its placement is not based on a condition. So this doesnt answer my question. --if (b.height = 202.9631958008) == true do ---LINE DOES NOT WORK --then --( --d.multiplier = 75 ---LINE DOES NOT WORK --)

 

0 Likes
Accepted solutions (1)
872 Views
4 Replies
Replies (4)
Message 2 of 5

Steve_Curley
Mentor
Mentor
--if (b.height = 202.9631958008) == true do ---LINE DOES NOT WORK
Test is incorrect - if b.height == 202.9631958008 do
Use either do or then, but not both.

Even written correctly that will never work. Max is simply not that accurate (and never has been). Single Precision floating point maths simply cannot accurately store a value with that many decimal places.
Consider using the close_enough function - Search the Maxscript help for it - it's on the Number Values page.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 5

Anonymous
Not applicable

I should add more clarification although the close_enough function is something I should check out. The problem is more about how to create/add a keyframe on my bezier_float curve for my light multiplyer. In my rewritten example below I was expecting multiple keyframes added to my light multiplyer curve setting the multiplyer value to 75  anytime the height of my box was greater than 200. How can I do this?

 

clearListener()
ResetMaxFile #noPrompt
units.displayType = #metric      
units.MetricType = #Kilometers  
units.systemType = #kilometers 
units.systemScale = 1              


b = box name:"dodo" height:10 pos:[0,100,0]           --create box
d = omnilight name:"woops" rgb:[0,230,89] pos:[0,0,0] --create light whos multiplyer value changes


at time 0 animate on b.height=0
at time 100 animate on b.height=300
	
at time 0 animate on d.multiplier = 0
at time 100 animate on d.multiplier = 50
d.multiplier.controller = bezier_float name:"garb" ---------  creates a multiplyer bezier curve for curve editor for omnilight
displaymulitplyerkeys = d.multiplier.controller.keys  

if (b.height > 202.0)  then
(

at time --wrong
d.multiplier = 75  ---LINE DOES NOT add as a new keyframe
addnewkey d.multiplier.controller 64 ---this line adds keyframe along the curve at frame 64 but doesnt change multiplyer val and its placement is not based on a condition. So this is wrong.
)

 

0 Likes
Message 4 of 5

Steve_Curley
Mentor
Mentor
Accepted solution
(
clearListener()
ResetMaxFile #noPrompt
units.displayType = #metric      
units.MetricType = #Kilometers  
units.systemType = #kilometers 
units.systemScale = 1              

b = box name:"dodo" height:10 pos:[0,100,0]           --create box
d = omnilight name:"woops" rgb:[0,230,89] pos:[0,0,0] --create light whos multiplyer value changes

with animate on
	(
	at time 0  b.height=0
	at time 100 b.height=300
	
	at time 0 d.multiplier = 0
	at time 100 d.multiplier = 50
	)
	
d.multiplier.controller = bezier_float name:"garb" ---------  creates a multiplyer bezier curve for curve editor for omnilight
displaymulitplyerkeys = d.multiplier.controller.keys  

for fr = 0 to 100 do
	(
	sliderTime = fr
	if (b.height > 202.0)  then
		(
		newKey = addNewKey d.multiplier.controller fr
		newKey.value = 64
		)
	)

)
However, there are some "gotcha"s with this. The new key will be the key type determined by the current setting of the Default Tangent Type flyout button (next to the Set Key button at the bottom of the UI). Auto Tangent might be the best choice. Also, this method will set a key on every frame which passes the test - in this case all frames from 62 to 100 inclusive. That's a lot of unnecessary keys.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 5

Anonymous
Not applicable
thanks! Perfect!
0 Likes