Jump to content

loop in expression?


chiess

Recommended Posts

Hi,

The topic sounds pretty simple and I am sure a few others have asked the same question before, but somehow I couldn't find a proper thread for it.

Is it possible to use a loop in an expression? Hscript or Python, doesn't matter. It doesn't work for me at the moment.

For example: I have a transform sop and I want a rotation on the z axis, from 0 to 90, starting at a certain frame. I don't want to handanimate it, since the starting frame can be random.

for n in range(0, 90): ?

How does the syntax look like or how can I even use any form of a loop in an expression? I can't figure it out right now :(

Thank you!

Link to comment
Share on other sites

Doing a for loop in an expression would loop over some set of data, not so much over a couple of frames. What you could do is some linear interpolation between the frames. You could do this in a million ways, and this is one in HScript:

0 + (clamp($F - 10, 0, 10) / 10) * (90 - 0)

In psuedo code, this will be:

startRotation + (clamp($F - startFrame, 0, duration) / duration) * (endRotation - startRotation)

Link to comment
Share on other sites

Thanks a lot WesleyE!

I am not sure how to figure such calculations out... would take me ages I guess.

Thanks for the pseudo code, helped me a lot to understand it.

Unfortunately I have another question now:

How can I save the framenumber when a certain event happens. For example, a point gets the color red in frame 20. I want to save that value in an attrbiute or somewhere else now. Is that possible? $F or $FF don't work, since these would change the value every frame.

Link to comment
Share on other sites

you would need to use Solver SOP or Sop Solver DOP for that

or POPs or CHOPs

since pure SOPs are not simulation environment therefore they cannot remember values for next frame

you can find plenty of examples for any of methods I mentioned on the forums or in help

Link to comment
Share on other sites

Hi Tomas,

Thanks for your the quick answer. Yeah I thought so, I just started reading through the help documentation of the solver sop. It seems once I get used to it and understand how to work with it, it will solve many of my current "problems". It's been a while back since I worked with Houdini, thats why it takes me some time to get back into it... besides that, Houdini is anyway different than the other 3D packages :). I am slowly learning more and more everyday, but such expressions/calculations as WesleyE mentioned... I don't know how to "create/construct" such math-examples by myself. I probably would remember such calculations when using them many many times and of course start tweaking them for similar problems, but from scratch....

Anyway, thanks!

Link to comment
Share on other sites

Heh, to be honest, I always look up those kind of things myself. Linear interpolation is simply like having a 'slider' between two values where the frame number controls the slider, the clamp makes sure that it only starts 'sliding' between the start and end frames of the animation. The most important is to know what you want, the way you implement those things can be easily found on the net ;)

Link to comment
Share on other sites

and for many things you already have an expression so if you want just linear interpolation you can use fit()

ressions/fit'>www.sidefx.com/docs/houdini12.5/expressions/fit

for your case it would be

fit(currentFrame, startFrame, endFrame, startRotation, endRotation)[/CODE]

so like

[CODE]fit($FF,10,20,0,90)[/CODE]

Edited by anim
Link to comment
Share on other sites

Hey guys,

Thanks for your input!

I've tried to somehow store the framenumber now, but I am still struggling a lot with it. I don't know why I just can't get over it to fully understand that solver sop :(

I attached a very simple scene again. I basically just want to save the framenumber, as soon as the sphere goes higher than 4 on the z-axis.

I am using $F, but obviously it doesn't work with that variable.

Any quick hint would be helpful, thanks!

Chris

storeFramenumber.hip

Link to comment
Share on other sites

it's called startFrame and it stores the frame when each point first crossed 4 in Z (or whatever condition you want)

if you didn't want it per point but for whole sphere, you need to make clear what you mean by "as soon as the sphere goes higher than 4 on the z-axis." center of the sphere? all points of the sphere? etc

but principle is the same

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...