Skip to content

Instantly share code, notes, and snippets.

@pearswj
Created February 10, 2021 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pearswj/bb23284e557ab29ccfaad2273b73999b to your computer and use it in GitHub Desktop.
Save pearswj/bb23284e557ab29ccfaad2273b73999b to your computer and use it in GitHub Desktop.
A simple dotnet console app to hammer a Rhino Compute server
using Rhino.Compute;
using System;
using System.Threading.Tasks;
namespace hammertime
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
ComputeServer.WebAddress = "http://localhost:5000";
// create a couple of dense mesh spheres and intersect them
var density = 700;
var pt = Rhino.Geometry.Point3d.Origin;
var vec = Rhino.Geometry.Vector3d.ZAxis;
vec.Unitize();
var sp1 = new Rhino.Geometry.Sphere(pt, 12);
var msp1 = Rhino.Compute.MeshCompute.CreateFromSphere(sp1, density, density);
var msp2 = msp1.DuplicateMesh();
msp2.Translate(new Rhino.Geometry.Vector3d(10, 10, 10));
var watch = System.Diagnostics.Stopwatch.StartNew();
var count = 2;
var tasks = new Task[count];
for (int i = 0; i < count; i++)
{
var t = Task.Run(() => {
_ = Rhino.Compute.MeshCompute.CreateBooleanIntersection(
new Rhino.Geometry.Mesh[] { msp1 },
new Rhino.Geometry.Mesh[] { msp2 }
);
});
tasks[i] = t;
}
Console.WriteLine("Go!");
while (!System.Threading.Tasks.Task.WaitAll(tasks, 250))
{
Console.WriteLine($"Running for {watch.Elapsed.TotalSeconds}s...");
}
Console.WriteLine($"Done in {watch.Elapsed.TotalSeconds}s!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment