algorithmic modeling for Rhino
This can be tricky. I don't know exactly how Daniel solves it, but there's two main approaches you can take:
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.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by