public async Task <RhinoComputeExampleOutputs> Handler(RhinoComputeExampleInputs args, ILambdaContext context) { if (this.store == null) { // Preload the dependencies (if they exist), // so that they are available during model deserialization. var asmLocation = this.GetType().Assembly.Location; var asmDir = Path.GetDirectoryName(asmLocation); var asmName = Path.GetFileNameWithoutExtension(asmLocation); var depPath = Path.Combine(asmDir, $"{asmName}.Dependencies.dll"); if (File.Exists(depPath)) { Console.WriteLine($"Loading dependencies from assembly: {depPath}..."); Assembly.LoadFrom(depPath); Console.WriteLine("Dependencies assembly loaded."); } this.store = new S3ModelStore <RhinoComputeExampleInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <RhinoComputeExampleInputs, RhinoComputeExampleOutputs>(store, RhinoComputeExample.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// The RhinoComputeExample function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A RhinoComputeExampleOutputs instance containing computed results and the model with any new elements.</returns> public static RhinoComputeExampleOutputs Execute(Dictionary <string, Model> inputModels, RhinoComputeExampleInputs input) { // set up a model to hold elements var model = new Model(); // Call rhino methods with regular rhino calls, or Rhino.Compute calls if required methods are unavailable var box1 = rg.Brep.CreateFromBox(new rg.BoundingBox(new rg.Point3d(0, 0, 0), new rg.Point3d(input.Radius, input.Radius, input.Radius))); var box2 = rg.Brep.CreateFromBox(new rg.BoundingBox(new rg.Point3d(input.Radius * 0.5, input.Radius * 0.5, input.Radius * 0.5), new rg.Point3d(input.Radius * 1.5, input.Radius * 1.5, input.Radius * 1.5))); var booleanDiff = Rhino.Compute.BrepCompute.CreateBooleanDifference(box1, box2, 0.1).First(); var boundaryCurves = booleanDiff.Faces.Select(f => f.OuterLoop.To3dCurve()); // Use conversion extension methods from HyRhi / Conversion.cs var elementsSphereMesh = booleanDiff.ToMesh(); var elementsCrvs = boundaryCurves.Select(c => c.ToPolygon()); // create Hypar Elements from resulting geometry var meshElement = new MeshElement(elementsSphereMesh, BuiltInMaterials.Glass); var curveElements = elementsCrvs.Select(c => new ModelCurve(c)); // add elements to model model.AddElement(meshElement); model.AddElements(curveElements); // construct output object var output = new RhinoComputeExampleOutputs(); // add model to output output.Model = model; // return output return(output); }