Showing posts with label switch. Show all posts
Showing posts with label switch. Show all posts

Monday 30 September 2024

solver storing the frame when attribute changes

 


Say you're transferring an attribute to an object. Eg. a sphere going along a curve and making it red.

Now you might want to store the frame that the curve receives the red attribute and use that information later - eg. do an attribute fade, so the attrib only starts fading when we reach the stored frame.

What you want to do is plug things into a solver, as above (just one input) and then....



in a wrangle-

vector newCd=point(1,"Cd",@ptnum);


if(@Cd!=newCd){

    if(@change_frame==0){

    @change_frame=@Frame;

    //i@changed += 1; //debugging

    }

    

}


What does this mean? Well, the Prev Frame is typically on the first input of point wrangles when in a solver... you are generally "adding" onto whatever was in the previous frame. (I always think about it the other way, but there you go). So we check to see what the "new" (or current frame) Cd value is.. And compare it to the existing (previous frame) value. If it is not the same, that means a change has occurred.

Now we check to see if the @change_frame value has been altered from zero or not. If it hasn't and is still zero, then we now make it equal to the current frame value.

Wednesday 3 November 2021

switch node or blending transforms at object level

If you need to switch or blend between two (or more) null transforms, eg to parent an object use the BLEND OBJECT. Kinda simple, goes to show how much I work at SOP level ha.

You'll probably want to use the Sequence mode, with "Shortest Path Rotation Blending" ticked, to avoid weird flipping (depending on what and how you're blending stuff)

Thursday 18 April 2019

Copying different objects to points

Sometimes you need to copy a bunch of different objects to points. Eg. You have 5 variations of wood splinters and you're emitting them from a snapping plank.
Instead of using the slower copy stamp with random point values, you can use a ForEach loop and a Switch node..and of course a point wrangle.

Connect the objects to the Switch node. In a point wrangle, give each point an (random) integer value (eg "instanceID") ranging from 0 to the number of objects you have.
Make a ForEach network and connect the Point wrangle into the top. Create a null node directly after the start of the Foreach Begin. This will be a "temporary holder" node. It will carry the instanceID value to the Switch node. I've called it PT
The clever bit happens in the Switch node. In the parameter window, click on the cog wheel and add a Spare Input. This will create a new dialog box called Spare Input 0. Type in:

../PT

This will point the spare input to our temporary null & its instanceID value.
In the Select Input dialog box, type

point(-1, 0, "instanceID", 0)

here we are telling the Switch node to get a point attribute from input -1 (which is the spare dialog....which is pointing to the PT temporary null..). The attribute in question is instanceID.. NICE.
A purple arrow going from PT to Switch should have appeared now. This represents that link we've just made.

All that is left to do is to create a Copy To Points node & put the Switch output into the objects input & plug PT into the points input. Finally plug the output of all of that into the Foreach End.

Thursday 9 November 2017

alternative to copy stamping

Copy Stamping is a bit slow, here's another way of copying things using point attributes.
EG - a bunch of points comprising of cubes, spheres and donuts.


  1. get a bunch of points!
  2. give them an id attribute eg 1,2,3,4..which will represent cube,sphere,donut. The attribute randomise node is quite good for this. There is a setting called Discrete Values which you can tweak with weighting. Eg. 20% value 1, 40%value 2, 40% value 3. Lets call the attribute ID
  3. Create a For-Each-Loop network. Set the mode to "points". By default it is set to process "pieces". Uncheck the use "name" bit. This is to do with the fracturing rigid body workflow.
  4. Connect the cube, sphere and donut to a switch node. In the index box type: point("../foreach1/",0,"ID",0)    this references the current point being processed by the foreach loop and reads it's corresponding ID value.
  5. Inside the foreach loop add a "copy to points" node. Connect the switch node to this.
  6. This should all work now!