Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Syntax for using pointOnCurve in an expression?

Syntax for using pointOnCurve in an expression?

mostly_human
Advocate Advocate
418 Views
3 Replies
Message 1 of 4

Syntax for using pointOnCurve in an expression?

mostly_human
Advocate
Advocate

I am trying to use pointOnCurve in an expression but cant figure out the syntax or is it even possible?  

 

I have tried these ideas among others:

float $weightValue = `pointOnCurve -pr "facs_MouthPucker_curve"`;

float $weightValue = `pointOnCurve -pr facs_MouthPucker_curve`;

 

These work fine in a regular mel script but struggling getting it to work in an expression.

 

Thank you for any help!

0 Likes
419 Views
3 Replies
Replies (3)
Message 2 of 4

Kahylan
Advisor
Advisor

Hi!

 

The parameter flag (-pr) always needs to be used in conjunction with a float value that specifies the parameter at which the positional value should be read out.

This worked for me:

float $weightValue[] = `pointOnCurve -pr 0.0 "curve"`;

But I have to admit, that when I tried to use the value further in a little constrainttest maya slowed down to a crawl with this expression.

So I wanted to ask what exactly you are planing to do with this, because there is probably an easier and more stable way than using pointOnCurve in an expression to achieve what you want.

 

I hope it helps!

 

0 Likes
Message 3 of 4

mostly_human
Advocate
Advocate

I need to create an expression for a blendshape target that will control the weight of a second blendshape target using a TCB curve.  The curve in my first test case has 3 keyframes set  at time 0 it will be 0, at time 0.7 it will be zero and then scale to time 1 where it will be 1.  Instead of time it will use the weight slider value of the other blendshape target weight.

 

I will have anywhere from 100-200 of these that are being exported out of a c# program i wrote that is pulling the data from json files in another application. The app generates the mel scripts which contain mel to automate the creation of the curves and their keyframes, as well as create an expression for each.   

 

A lot of the JSON definitions have shape targets linearly driving other targets at a 1:1 and I have had all that working smoothly and it is performant, but trying to implement a way for shapes to control shapes based on a TCB curve has been a struggle 😕  I am completely open to ideas and am very grateful for your help the past couple of days!

 

Example of what I am thinking (the expression creation syntax isnt correct yet but you get the idea):

float $timeValue = `getAttr BlendShapes.weight[1]`;
float $weightValue = `pointOnCurve -pr facs_cbs_MouthPuckerDetails_div2_curve $timeValue`;

 

expression -s (("float " + $weightValue + " = `pointOnCurve -pr " + $curveName + "BlendShapes.weight[" + $driverIndex + "]`;\nBlendShapes.facs_cbs_MouthPuckerDetails_div2 = `pointOnCurve -pr " + $curveName + "BlendShapes.weight[" + $driverIndex + "]`;")") -o "" -n ("MouthPuckerDetails" + "_Limiter") -ae 1 -uc all;

 

0 Likes
Message 4 of 4

Kahylan
Advisor
Advisor

I don't think I fully understand the setup you have in mind, so I'm not sure if this is a stupid question. Also I'm sadly not too familiar with TCB curves.
But if you have one target that needs to drive another target on a curve, why aren't you converting your curve into a set driven key animation curve when the curve is read into maya? Do you need live feedback when the TCB curve is manipulated?

Because otherwise, what you can do is just use a set driven key, the time value is the Targetweight of your blendShape A and the value of your blenshape B is defined by the vertical value of your curve.

something like this:

global proc convertCurveToSDK(string $blendA,string $blendB, string $TCMcrv, float $drvRangeStart, float $drvRangeEnd, float $step){
    float $weightValue[];
    for($i=$drvRangeStart; $i <= ($drvRangeEnd + $step); $i= $i + $step ){
        $weightValue = `pointOnCurve -pr $i $TCMcrv`;
        setAttr $blendA $i;
        setDrivenKeyframe -cd $blendA -v $weightValue[1] $blendB;
    }
}
convertCurveToSDK("blendShape1.w[0]","blendShape2.w[0]", "curve", 0.0, 1.0, 0.01);

The last line is an example of how the procedure could be called.


Basically this would turn your TCM curve into an animation curve that takes the first target value as time and sets the value of the second target to the Y-value of your curve at the parametervalue of the time.

This has the upside that it is a lot faster than an expression since the connection between the two targets is baked, and once the baking is finished the curve is no longer needed and can be deleted.
It obviously has the downside that the curve is not directly connected to the targets and therefore can't be used to manually change their relationship afterwards, but what you are describing doesn't sound like that feature is intended.

I hope it helps!

 

0 Likes