Пример #1
0
        public async Task <RhinoHeadOutputs> Handler(RhinoHeadInputs 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 <RhinoHeadInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <RhinoHeadInputs, RhinoHeadOutputs>(store, RhinoHead.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
Пример #2
0
        /// <summary>
        /// The RhinoHead function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A RhinoHeadOutputs instance containing computed results and the model with any new elements.</returns>
        public static RhinoHeadOutputs Execute(Dictionary <string, Model> inputModels, RhinoHeadInputs input)
        {
            var doc = File3dm.Read("hello_mesh.3dm");
            //var doc = File3dm.Read("/home/ec2-user/hypar_test/StarterFunction/models/hello_mesh.3dm");

            var meshes = new List <MeshElement>();

            foreach (var obj in doc.Objects)
            {
                if (!(obj.Geometry is Rhino.Geometry.Mesh m))
                {
                    continue;
                }

                m.Compact(); // remove any unreferenced vertices

                var mesh = new Mesh();

                foreach (var v in m.Vertices)
                {
                    var x = (double)v.X;
                    var y = (double)v.Y;
                    var z = (double)v.Z;
                    mesh.AddVertex(new Vector3(x, y, z));
                }

                foreach (var f in m.Faces)
                {
                    if (f.IsTriangle)
                    {
                        mesh.AddTriangle(mesh.Vertices[f.A], mesh.Vertices[f.B], mesh.Vertices[f.C]);
                    }
                    else
                    {
                        mesh.AddTriangle(mesh.Vertices[f.A], mesh.Vertices[f.B], mesh.Vertices[f.C]);
                        mesh.AddTriangle(mesh.Vertices[f.C], mesh.Vertices[f.D], mesh.Vertices[f.A]);
                    }
                }

                mesh.ComputeNormals();
                var shiny = new Material("shiny", Colors.Red, 1.0, 0.9);
                meshes.Add(new MeshElement(mesh, shiny));
            }

            var output = new RhinoHeadOutputs((double)doc.Objects.Count);

            output.Model.AddElements(meshes);
            return(output);
        }