Animation. Linear Interpolation

Is there a way to tell Daz that every existing key and every future key in every existing and future property of every existing key frame and every future key frame should use linear interpolation by default?

Comments

  • WendyLuvsCatzWendyLuvsCatz Posts: 38,302

    there is a script Richard posted but I cannot figure out how to use it

    I saved it as a dsa but it doesn't seem to do anything

    Scene.setDefaultKeyInterpolationType( DzProperty.InterpLinear );

  • Richard HaseltineRichard Haseltine Posts: 101,422
    edited November 9

    I moved the cube up and down at frames 5, 10, and 15. Then I ran the script. The I moved the cube and frames 20, 25, and 30 - the keys created seem to have switched from TCB to Linear as they should.

    Default keyframe type.jpg
    1874 x 376 - 81K
    Post edited by Richard Haseltine on
  • jmucchiellojmucchiello Posts: 137

    It works. It just doesn't affect existing keys. So I've added it to the script loaded when a scene loads.

    (function(){	Scene.setDefaultKeyInterpolationType(DzProperty.Linear);})()

    Thanks for remembering the script existed.

  • Richard HaseltineRichard Haseltine Posts: 101,422

    Right, it chnages the default (the kind of key created when a new key is created after running the script - note that this seems to affect the outgoing behaviour, as you can see in my screenshot above the line graph line coming into the Linear key iss till curved from the preceeding TCB key, so you won't see the difference on the first new key created at the end of a run of previously created keys.

  • jmucchiellojmucchiello Posts: 137
    edited November 9

    Next is the script to change existing keys. But I can't seem to find a script api that enumerates or list all frames of an animation. Or all frame keys attached to nodes. (Which is the ridiculous method of where stuff is saved in scene file.)

     

    Post edited by jmucchiello on
  • Richard HaseltineRichard Haseltine Posts: 101,422

    You'd have to iterate over properties on nodes with DzProperty.hasKeys() I think

  • jmucchiellojmucchiello Posts: 137

    So it's bunch of nested loops? Will this hit all keys at all times in the animation?

    Scene.getNodeList().foreach(func(node){    node.getPropertyList().foreach(func2(prop){        if (prop.hasKeys()) {             for (var idx = 0; idx < prop.getNumKeys();++idx)                  prop.SetKeyInterpolationType(idx, DzProperty.InterpLinear);        }    })})

     

  • Is that your own work or AI generated? It's not an approach I have seen before, and the lop opening have mis-matched parentheses. I don't see foreach in the reference docs.

  • jmucchiellojmucchiello Posts: 137
    edited November 10

    [Boo to] AI.

    I wrote it from the docs.

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/array#a_1a50bc05836f5d6592feeda8c3a2d61377

    As for mismatched parentheses. I do that all the time. I typed the code here, not in Daz. (I'm in the middle of a render.) Apparently I misspelled forEach as foreach.

    Post edited by Richard Haseltine on
  • It's weird. The loops work. But the interpolation type isn't changing. These are all store assets: the g9 character, the animation. It plainly shows it found all the keys at all the time offsets. But, I've run the script several times, the interpolations types remain TCB. Only takes 14 seconds to run.

    // DAZ Studio version 4.22.0.19 filetype DAZ Script(function allLinear(){	Scene.getNodeList().forEach(		function(node){			print(node.assetId + ' has ' + node.getNumProperties().toString() + ' properties.');			node.getPropertyList().forEach(				function(prop){					if (prop.hasKeys()) {						var end = prop.getNumKeys();						print('    ' + prop.assetId + ' has ' + end.toString() + ' keys.');						for (var idx = 0; idx < end; ++idx) {							print('        key time ' + prop.getKeyTime(idx).valueOf().toString()								         + ' interp type ' + prop.getKeyInterpolationType(idx).toString()								);							prop.setKeyInterpolationType(idx, DzProperty.InterpLinear);						}			        }			    }			)		}	);})();

     

    Untitled.png
    1500 x 976 - 127K
  • Sorry, I looked for foreach in the general control statements rather than in Array.

    Your script looks plausible, I don't know why it isn't working.

  • Would a bug report be of use? I am running 4.22 still.

  • I would at least wait a bit to see if soemone else can spot a logic flaw.

  • If I instead get the current key value and time and set them using the new interpolation type that does work:

    // DAZ Studio version 4.22.0.19 filetype DAZ Script

     

    var nPropT, nPropV;

    (function allLinear(){

    Scene.getNodeList().forEach(

    function(node){

    print(node.assetId + ' has ' + node.getNumProperties().toString() + ' properties.');

    node.getPropertyList().forEach(

    function(prop){

    if (prop.hasKeys()) {

    var end = prop.getNumKeys();

    print(' ' + prop.assetId + ' has ' + end.toString() + ' keys.');

    for (var idx = 0; idx < end; ++idx) {

    print(' key time ' + prop.getKeyTime(idx).valueOf().toString() + ' interp type ' + prop.getKeyInterpolationType(idx).toString() );

    nPropT = prop.getKeyTime( idx );

    nPropV = prop.getValue( idx ):

    prop.setValue(nPropT, nPropV , DzFloatProperty.LINEAR_INTERP );

    print(' key time ' + prop.getKeyTime(idx).valueOf().toString() + ' interp type ' + prop.getKeyInterpolationType(idx).toString() );

    }

    }

    }

    )

    }

    );

    }

    )();

    DzFloatProperty does have a different enumeration for the types, but substituting for that didn't seem to help.

  • The thing I don't want to try is deleting the key and rebuilding it from scratch. That seems both time consuming and error prone.

  • Well, the script does the work for you - it isn't a manual copy and redo. It does suggest that there may be a bug, unless there is an extra step that we are both missing.

  • The call to setKeyInterpolationType doesn't do anything. I wouldn't call that "working."

    A missing step seems a possibility but who knows what?

  • For sweeping through keys in an existing scene, I've always used mCasual's SetInterpolation script, which still works as of 4.22.   It appears to use a different constant ( DzFloatProperty.LINEAR_INTERP ) than what's referenced above.  

    https://sites.google.com/site/mcasualsdazscripts/setinterpolation-for-ds2-3

     

Sign In or Register to comment.