View Full Version : Question about Hair Dynamics Expression

10 October 2009, 04:51 AM
Hi all:
I have been reverse engineering a Dynamic Bones script by Wade Ryer (
Its a rig in which a bone chain is partially controlled by a dynamic hair curve.
Its a cool setup and I have it all figured out except this expression which controls the Hair System:
////// Live Update Expression /////////////////////
disconnectAttr time1.outTime (""+$SetUpName+"_HairSystemShape.currentTime");
string $DynUpdExp = (
"if (frame > "+$SetUpName+"_HairSystemShape.startFrame) { "+$SetUpName+"_HairSystemShape.currentTime += 1; float $refresh = "+$SetUpName+"MainDynLocUpdate.translateX;}\n"
+"else "+$SetUpName+"_HairSystemShape.currentTime = "+$SetUpName+"_HairSystemShape.startFrame;"

expression -n "DynamicUpdateExpr" -s $DynUpdExp;
I haven't worked with expressions too much, but it appears to me that the expression does the following:
1) Disconnects the Hair System from the Main timeline.
2) Set the currentTime of the HairSystem to be one frame less than the main timeline.
3) $refresh does not appear to be used.
4) Rewind the Hair System when the current time is set to 0.

2 Questions:
1. Is my analysis correct?
2. What is the purpose of the expression?


10 October 2009, 05:19 AM
I just love talking to myself late at nite...
So I see that this expression does what it says - it makes the chain interactive by divorcing the hair system from the main time. Dragging it around on any frame above 0 forces the hair system to update interactively, which is pretty cool. I've also discovered that the $refresh var is necessary, else it doesn't work. I assume it forces a refresh, but all it is doing is grabbing the XTran of a locator which is pointConstrained within the rig, so how does that force a refresh?
if (frame > TEST_HairSystemShape.startFrame) { TEST_HairSystemShape.currentTime += 1; float $refresh = TESTMainDynLocUpdate.translateX;}
else TEST_HairSystemShape.currentTime = TEST_HairSystemShape.startFrame;
// Fails:
if (frame > TEST_HairSystemShape.startFrame) { TEST_HairSystemShape.currentTime += 1;}
else TEST_HairSystemShape.currentTime = TEST_HairSystemShape.startFrame;

10 October 2009, 08:47 AM
I'm not sure I'm right, but it seems to me that the $refresh forces the re-evaluation of the expression in order for the $refresh = loc.tx to be exact all the time even if there's already a connection on the translate.
BTW the pointConstraint actually changes the value of the translate as opposed to a simple parent/child relation, so it would be good to know if this trick works with a parent instead of the pointConstraint.

Hope that helps,


PS: sorry for my english.

10 October 2009, 03:57 PM
I don't think that's quite right. I think the expression will eval on every frame by default.
A bit more analysis:
The TESTMainDynLocUpdate locator is pointConstrained to 5 other "DynLocUpdate" locators, each of which is pointConstrained to an FK joint in the rig (the rig is driven by the FK joints). So by grabbing it's XTrans, I'd assume that the location of each of the other "DynLocUpdate" locators is also queried.
The screen grab below shows the connection between TESTMainDynLocUpdate and the expression and the HairSystem and also the HG w/the DynLocUpdate removed from the expression. I don't see why it is necessary to force the Hair System to update.

CGTalk Moderation
10 October 2009, 03:57 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.