stepped mode keys

stepped mode keys

silentboof
Advocate Advocate
3,014 Views
14 Replies
Message 1 of 15

stepped mode keys

silentboof
Advocate
Advocate

super noob alert :))

 

Hi

 

I was wondering how I can make an objects to get always "stepped" type key. Let me explain more; As you know there are number of controller floats, bezier float, noise float, linear float, etc and for example if you assign a linear float to something it will always have linear keys no matter what. Now is there any way to define a stepped float?

and one more question... what's the syntax for changing all the keys to stepped mode. Let's say I have an animated box with smooth keys and I don't want to go to curve editor and select all the keys and set them to stepped; I just want to select the object and enter a syntax in listener and do all that in on go. (apparantly macro recorder does not get you such things)

 

 

0 Likes
Accepted solutions (1)
3,015 Views
14 Replies
Replies (14)
Message 2 of 15

har1sf0x
Advocate
Advocate

Hello there,

 

  As far as it concerns your first question you could either script a custom step controller or change the 'Default In/Out Tangents for New Keys' to Step next to the 'Set Key' button. (That will work only with controllers that support tangents)

 

  Now for your second question you could see the example script below to get a first impression. It depends on the controller though. Most of the times for position we use position_xyz which has 3 sub-anim (bezier float) controllers. (if you have position_list you have to search deeper). The following code works with bezier float since if not mistaken is the only one which has tangents (it will not work with linear float controllers).

try(delete obj)catch()
obj = teapot()
with animate on
(
  for i = 1 to 3 do for k in obj.pos.controller[i].controller.keys do
  (
    k.inTangentType = #step
    k.outTangentType = #step
  )
)

  You could also check the 'Bezier Controller Keys' in the maxscript help.

 

Enjoy,

har1sf0x

Message 3 of 15

denisT.MaxDoctor
Advisor
Advisor

@har1sf0x wrote:

Hello there,

 

  As far as it concerns your first question you could either script a custom step controller...


It would very interesting to see your implementation of a custom step controller

0 Likes
Message 4 of 15

silentboof
Advocate
Advocate

Tnx for the reply. I animated a teapot and used ur code but it didn't work. However I changed it and it works fine in most situations. I just need to select any animated object and run this in listener.

(
	$.pos.controller[1].controller.keys.inTangentType = #step
	$.pos.controller[2].controller.keys.inTangentType = #step
	$.pos.controller[3].controller.keys.inTangentType = #step
	$.pos.controller[1].controller.keys.outTangentType = #step
	$.pos.controller[2].controller.keys.outTangentType = #step
	$.pos.controller[3].controller.keys.outTangentType = #step
)

but when I try to get a for loop code based on that, it gives me error. This is the troublesome code:

 

for i in 1 to 3 do
(
	$.pos.controller[i].controller.keys.inTangentType = #step
	$.pos.controller[i].controller.keys.outTangentType = #step
)

 Still I'm looking for something better.

You know the procedure is really simple:

 

  • You select one or objects
  • Select the keys in time line
  • Open up curve editor
  • Click the stepped mode tangent

 

And done!!! (even if you have thousands of controllers in list controller it still works fine!!!

 

Should it be that hard to automated this procedure and assign it lets say to  a button in attribute holder??!!!

Man I hate scripting!!! :))

0 Likes
Message 5 of 15

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
for node in selection do
(
	cc = getclassinstances bezier_float target:node
	for c in cc do c.keys.inTangentType = c.keys.outTangentType = #step 
)
Message 6 of 15

har1sf0x
Advocate
Advocate

Hello,

 

  WOW!!!! I think that my whole time studying maxscript might have been in vain and i feel so little. (if not bothering you denisT, except here and cgsociety is there somewhere else that you post code or any tutorials so as to learn some stuff?)

  The only 'plus' in my effort, if you could say that it is a plus, is that you can exclude the custom attributes controllers.

 

--contro must be a controller type
--if caBool affect controllers of custom attributes as well
fn allKeysStep contro caBool:true =
(
  if classof contro == bezier_float do
  (
--the for loop could be replaced by:
--contro.keys.inTangentType = contro.keys.outTangentType = #step --since keys seams mappable for key in contro.keys do ( key.inTangentType = key.outTangentType = #step ) ) if contro != undefined and contro.numSubs > 0 do ( for i = 1 to contro.numSubs do ( if (getSubAnim contro i).controller != undefined then ( allKeysStep (getSubAnim contro i).controller ) else if (getSubAnim contro i).numSubs > 0 do ( for j = 1 to (getSubAnim contro i).numSubs do ( allKeysStep (getSubAnim (getSubAnim contro i) j).controller ) ) ) ) -- change controllers of custom attributes as well if caBool and contro != undefined and (custAttributes.count contro > 0) do ( for i = 1 to (custAttributes.count contro) do ( if (temp = custAttributes.get contro i).numSubs > 0 do ( for j = 1 to temp.numSubs do ( allKeysStep (getSubAnim temp j).controller ) ) ) ) true ) -- for obj in selection do allKeysStep obj.transform.controller

 

 Enjoy,

har1sf0x

 

p.s. in my previous post it seams that i have copied something wrong because i clearly remember that in the animate on block in my machine i had code for animating the position of the teapot and not for changing the tangents. i apologise 😞

Message 7 of 15

silentboof
Advocate
Advocate

Simple, efficient AND PERFECT...thanks a lot 🙂

0 Likes
Message 8 of 15

silentboof
Advocate
Advocate

Tnx for your time. This code seems to be awesome. But when I use it in listener it  doesn't do anything.Then I used it a scripted float controller and it generated error. It showed "can't convert to float" or something like that. I'm not sure how to implement the code. can you please explain on how to use it. it seems like a new controller which can be pretty cool. Thank you

0 Likes
Message 9 of 15

har1sf0x
Advocate
Advocate

Hello there,

 

  My code is not awesome, it is just a very ugly way of almost what @denisT.MaxDoctor wrote (for instance my code does not check the parameters of the object base, e.g. the radius of a sphere). It is based in the idea that every controller may have sub-controllers (subAnims). A transform.controller most of the times has a position_xyz subanim (which has its controller), an euler_xyz and a bezier_scale. Each of them has its own subanims and so one. If the controller class is bezier_float and it has keys then you can modify the tangent of these keys. It looks odd though that it crashed with the script controller or that it couldn't work in the listener. If you evaluate it a function is created (allKeysStep(controller)) where you can invoke it passing a controller (preferably the controller of which the subanims you want to change)

  I have some liability until Tuesday and hopefully on Wednesday i will put my effort on scripting my first controller (a step controller). I'll post my progress here. Since then if you want for some reason to use my ugly code and you need more info please contact me (an attached file of the problem occurred may be helpful)

 

Enjoy,

har1sf0x

Message 10 of 15

denisT.MaxDoctor
Advisor
Advisor

here is way how to force a bezier float controller stay all the time #step...

 

mapped fn setStepFloat sub = if iscontroller sub and iskindof sub Bezier_Float do
(
	replaceinstances sub (c = Float_List())
	c.available.controller = sub
	s = c.available.controller = Float_Script()
	s.addobject "control" sub
	s.setexpression "control.keys.intangenttype = control.keys.outtangenttype = #step\n0"
)
delete objects
b = box isselected:on
--setStepFloat $.position.controller[#x_position].controller -- only specified controller
setStepFloat (getclassinstances Bezier_Float target:$.pos.controller) -- all position float controllers
--setStepFloat (getclassinstances Bezier_Float target:$.controller) -- all transform float controllers
--setStepFloat (getclassinstances Bezier_Float target:$) -- all node float controllers

it works, but i would not use it in general for myself. there are several reasons to not use this solution and there are some situations where this solution might fail (not crash, but might work as not as expected). but it's a subject for another thread.

 

 

for a position controllers the solution is pretty safe at least if you not have a long animation with large number of keys.

Message 11 of 15

denisT.MaxDoctor
Advisor
Advisor

a custom step controller is the solution. but the example code will be too complicated for this thread to be shown and discussed.

 

0 Likes
Message 12 of 15

har1sf0x
Advocate
Advocate

Hello,

 

  As far as it concerns the custom stepController i took the first (extend) example from here (float controller) and in the on getValue do block i added:

if value.controller != undefined do for f in value.controller.keys do f.inTangentType = f.outTangentType = #step

It works even though probably not the most elegant way. I also commented all the format lines and changed the definition at the start to says stepController etc. I am sure that it could be modified to the sorter version as well but i didn't :D.

 

Enjoy,

har1sf0x

 

p.s. i hope that some day i will create an sdk step controller 😉

0 Likes
Message 13 of 15

denisT.MaxDoctor
Advisor
Advisor

 

 

  As far as it concerns the custom stepController i took the first (extend) example from here (float controller) and in the on getValue do block i added:

if value.controller != undefined do for f in value.controller.keys do f.inTangentType = f.outTangentType = #step

It works even though probably not the most elegant way. I also commented all the format lines and changed the definition at the start to says stepController etc. I am sure that it could be modified to the sorter version as well but i didn't :D.

 


what's the difference with what i showed above?

0 Likes
Message 14 of 15

har1sf0x
Advocate
Advocate

sorry, duplicate problem...

0 Likes
Message 15 of 15

har1sf0x
Advocate
Advocate

Hello,

 

 What do you mean? It's the same basic idea implemented on a scripted plugin floatController that you can reuse without re-running a script. I also tried an other approach iterating the keys (with index) of the value.controller and checking if key.time == currentTime then value = key.value else if key.time > currentTime then value = peviousKey.value but since it was creating some issues in the graph editor, was adding more keys by its own and couldn't find a solution i took the first approach.

 I was looking in the sdk help and i maybe managed to understand that you probably need too create an other interpolator (besides TCB, bezier and linear) in order to create a genuine step controller not based in bezier float but you might need to be a registered developer in order to get access to the interpolator implementations to get some ideas, and i am not :D.

 

Enjoy,

har1sf0x

0 Likes