Showing posts with label spring. Show all posts
Showing posts with label spring. Show all posts

Wednesday, 28 August 2024

mark fancher mograph video notes

 some mark fancher youtube vex tidbits-

//in a rig attrib wrangle, to rotate joints - take into account parenting!-

vector axis={1,0,0};

prerotate(4@localtransform, chf("angle"),axis);

-----------------------------------------------------------------------------------------

//in a rig attrib wrangle,to scale joints - take into account parenting-

prescale(4@localtransform, chf("scale"));



--------------------------------------------------------------------------------------------------------

//point wrangle, after a distance along geometry - nice rampable normalised mask

float map=f@map;

float p=chf("position");

float t=chf("transition");

t=max(t,0.0001); //clamps down value

p=fit01(p,-t,1); //makes mask zero when t at low values and p at zero

float mask=fit(map,p,p+t,1,0);

mask=chramp("ramp",mask);

f@mask=mask;

--------------------------------------------------------------------------------------------

how to store activation frame based on a threshold of something

in a point wrangle

if(@value>chf("threshold")){

i@group_active=1;

}

inside a solver...connect prev_frame to input 2 and input 1 to 1 of a point wrangle..

int prev_active=inpointgroup(1,"active",@ptnum); //check if previous frame was active

//if group active and NOT previously active then give active_frame value of current frame

if(i@group_active==1 && prev_active==0){

f@active_frame=@Frame;

}


float activationFramePrevious=point(1,"active_frame",@ptnum);

f@active_frame=max(activationFramePrevious, @active_frame);



simple spring solver - prev frame into input 1, input 1 into 2nd input of wrangle

based on F=-kx -bv

where F is force, k is the spring coefficient (stiffness), x is the distance, b is the damping and v is velocity. We also use F=ma to calculate acceleration (and use that for velocity, which ultimately gets added to Position)

float m=chf("mass");

float k=chf("stiffness");//stiffness coefficient

float b=chf("damping");//damping coefficient


vector p2=point(1,"P",@ptnum);//position of point on "current" frame

vector x=@P-p2; //distance between previous and current

vector f=-k*x -b*v@_v;//calculate force using damped harmonic motion equation


vector a =f/m; //get acceleration from f=ma to then find...

v@_v+=a;//velocity

v@P+=v@_v;//new position is calculated by adding velocity vector to current pos

Friday, 26 February 2021

CHOPS basics!

CHOPS.

Say you have a moving box. Make a null name it OUT_BOX (or something), for easy access.

Now create a chop network.

In here, make a Geometry node. Set the attribute you want to process. Maybe it's the P (for position).. or N (for normal). Set the Method to Animated if it's animated...

Add whatever effects you want. Eg. Lag, Spring.

And finally add an Output  node and set the relevant export flags.

Like this -

Now back at SOP level, add a Channel sop to follow on from your OUT_BOX (or whatever)

 and set the Attribute Scope to whatever you're processing. I was tweaking N, so that's what I've used!



You could add a Channel node elsewhere and apply the same values to a P, or Cd if you wanted!
That concludes CHOPS basics!

Bonus
in a parameter... you can use this expression to access the 0th value from chopnet1, every $F frames-
chopcf("../chopnet1/output0/",0,$F)