Re: [script] Creating relative values fcurve

Date : Mon, 30 Apr 2007 21:59:19 -0700
To : XSI(at)Softimage.COM
From : javier <javier.vdp(at)gmail.com>
Subject : Re: [script] Creating relative values fcurve
Bernard, you are quite right. addkey method does not work as it should in my books either. It makes an honest attempt but it fell short of target, I think.

I would suggest that you build your own addkey function by parsing the keys and tangents  from FCurve.Keys, rebuilding the arrays and setting the keys using Parameter.AddFcurve2([Keytime value array]) and  Fcurve.SetKeyTangents([tan array]) methods
The only thing that you have to make sure that your tangents do not result in invalid values, that is added tangent lengths overlap cannot add up to more than ~125% of the distance between two keys, Keytime value array must be correctly ordered in time,  tangent array must be divisible by 4 and twice the length of key time array. . Sure it is a pain in the arse and you would think that .addkey should work, but it has some some behavioural issues; you could do a few things. Scream and kick maybe someone will listen although i doubt it, pray to the Lord 3d, maybe you will hit the narrow behaviour that the designer of that method envisioned, or rebuild your own fcurve environment. I would say with your knowledge of the sdk the easiest would be the latter.




On 4/30/07, Bernard Lebel <3dbernard(at)gmail.com> wrote:
Your script works perfectly, Kim. For "typlical" fcurves (that is, on transformations) I never had a problem creating those by script. But now I'm trying to create the fcurve of a link with _expression_ that connects the shapes (in the mixer) with cpset parameters.


Below is a script that re-produces my problem. The first part does like when I create the relative values manually. The second parts uses the SetKeys() method. The third one is the for loop we've been trying.

With second and last approach I'm getting exactly the same results. The first keyframe is 0/0, and the second one is 0.24/6.


Cheers
Bernard




NewScene( null, false );

// Create primitives
var oSphere = activesceneroot.addgeometry( "Sphere", "MeshSurface" );
var >


var oSphereParam = oSphere.kinematics.local.posy;
var >

var aParams = new Array( oSphereParam.fullname, oNullParam.fullname );
var sParams = aParams.join( "," );


var sExpression = "l_fcv( ".concat(oNullParam.fullname, " )")

// Create the link with _expression_
oSphereParam.addexpression( sExpression );

SetRelativeValues( oSphereParam.fullname );

// Move the null and sphere away, set a new relative value
oSphereParam.value = 6;
oNullParam.value = 6;

SetRelativeValues( oSphereParam.fullname );



/////////////////////////////////////////////////////////////



// Remove _expression_
oSphereParam.disconnect();

// Recreate the _expression_
oExpression = oSphereParam.addexpression( sExpression );

var aFcurveKeys = new Array( 0, 0, 6, 6 );

// Get the _expression_ object
var oExpression = oSphereParam.source ;

// Get the _expression_ fcurve for relative value
var oFcurveParam = oExpression.nestedobjects( "l_fcv" );
var oFcurve = oFcurveParam.source;

// DOESN'T RESULT IN PROPER FCURVE -> [0, 0, 0.24, 6]
oFcurve.setkeys( aFcurveKeys );




/////////////////////////////////////////////////////////////



// Remove keys
oFcurve.removekeys( 1, 100, true );


// Create keyframes via a for loop

oFcurve.beginedit();

iLength = aFcurveKeys.length;

var fTime, fValue;
for( var i = 0; i < iLength; i=i+2 )
{
    fTime = aFcurveKeys[i];
    fValue = aFcurveKeys[i+1];
    oFcurve.addkey( fTime, fValue, 0, true );
}

oFcurve.endedit();

// DOESN'T RESULT IN PROPER FCURVE -> [0, 0, 0.24, 6]









On 4/30/07, kim aldis < kim.aldis(at)gmail.com> wrote:
> Just for the pure pendency of it Bernard, try just cutting the script out of
> my  mail and pasting from one of these mails into a new xsi at your end, see
> what happens. You never know.


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.