Grasshopper

algorithmic modeling for Rhino

Hi all

I have a simple loop with some sort of particle movement. In the end I've got only the final position of particles. But how do I see every iteration of that loop? I want to have some kind of animation like in Daniel Piker's kangaroo.

Views: 2315

Replies to This Discussion

This can be tricky. I don't know exactly how Daniel solves it, but there's two main approaches you can take:

  1. Don't loop internally, keep completing solutions for every iteration. This way Grasshopper draws your previews for you. You will of course have to trigger new solutions at the end of each (or every Nth) iteration.
  2. Keep looping internally, but draw your intermediate solutions yourself. This may be problematic for two reasons. One, if you start redrawing the Rhino viewports in the middle of a GH solution, the rest of the Grasshopper preview may go missing. Two, I'm not even sure it is reliably possible to redraw Rhino viewports from within a tight loop. It may be that all you can do is trigger a redraw in the future, which won't actually happen until Rhino feels the time is right.

HI!You can do like this way.

Attachments:

A hybrid approach could be to run your simulation asynchronously in another thread and have it constantly update a field in the scripting component. Parallel to this, expire the scripting component in regular intervals or whenever it can and have it output the value of this field.

I am not sure of all the performance and synchronisation implications of having a thread constantly writing a field and another constantly reading it. There are compiler optimizations that can make the local cache of each core have different values (but gh scripting components have these disabled) and probably other unintended consequences i'm not aware about.

But the following works:

private void RunScript(object x, object y, ref object A)
{
if (task == null || task.IsCompleted)
{
task = System.Threading.Tasks.Task.Run(() => Animation());
}

Component.ExpireSolution(true);

A = point;
}

// <Custom additional code>
System.Threading.Tasks.Task task = null;
Point3d point;


void Animation()
{
for(int i = 0;i < 1000;i++)
{
point = new Point3d(i, 0, 0);
System.Threading.Thread.Sleep(1);
}
}
// </Custom additional code>
}

You could also use a timer component to update, rather the Component.Expiresolution.

If you want to draw every single iteration you can put the Component.ExpireSolution(true) line inside the for loop.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service