예제 #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Mesh;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select mesh to contour", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Mesh mesh = objref.Geometry() as Rhino.Geometry.Mesh;
            if (null == mesh)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.BoundingBox bbox     = mesh.GetBoundingBox(false);
            Rhino.Geometry.Point3d     start_pt = bbox.Corner(true, true, true);
            Rhino.Geometry.Point3d     end_pt   = bbox.Corner(false, true, true);
            double interval = start_pt.DistanceTo(end_pt) / 10;

            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Mesh.CreateContourCurves(mesh, start_pt, end_pt, interval);
            if (null != curves && curves.Length > 0)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
예제 #2
0
        //Convert a Rhino mesh to a Media 3d Model
        public static GeometryModel3D ToHelixModel(this Rhino.Geometry.Mesh input)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();

            input.Faces.ConvertQuadsToTriangles();
            foreach (Rhino.Geometry.Point3d pt in input.Vertices)
            {
                mesh.Positions.Add(pt.ToHelixPoint());
            }

            foreach (Rhino.Geometry.Vector3d vc in input.Normals)
            {
                mesh.Normals.Add(vc.ToHelixVector());
            }

            foreach (Rhino.Geometry.MeshFace face in input.Faces)
            {
                mesh.TriangleIndices.Add(face.A);
                mesh.TriangleIndices.Add(face.B);
                mesh.TriangleIndices.Add(face.C);
            }

            GeometryModel3D model = new GeometryModel3D();

            model.Geometry     = mesh;
            model.Material     = new DiffuseMaterial(new SolidColorBrush(Colors.LightGray));
            model.BackMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.LightGray));

            return(model);
        }
예제 #3
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Mesh mesh
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (mesh == null)
                {
                    throw new NullReferenceException($"Parameter '{Params.Input[0].Name}' not set to an instance of a Mesh.");
                }

                if (!mesh.IsValidWithLog(out var log))
                {
                    foreach (var line in log.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, line);
                    }

                    throw new Exception($"Parameter '{Params.Input[0].Name}' not set to a valid Mesh.");
                }

                var scaleFactor = 1.0 / Revit.ModelUnits;
                if (scaleFactor != 1.0)
                {
                    mesh.Scale(scaleFactor);
                }

                var shape = new List <GeometryObject>();

                foreach (var geometry in mesh.ToHost().SelectMany(x => x.ToDirectShapeGeometry()))
                {
                    // DirectShape only accepts those types and no nulls
                    switch (geometry)
                    {
                    case Point p: shape.Add(p); break;

                    case Curve c: shape.Add(c); break;

                    case Solid s: shape.Add(s); break;

                    case Mesh m: shape.Add(m); break;
                    }
                }

                var ds = element as DirectShape ?? CopyParametersFrom(DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)), element);
                ds.SetShape(shape);
                element = ds;

                ReplaceElement(doc, DA, Iteration, element);
            }
            catch (Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                ReplaceElement(doc, DA, Iteration, null);
            }
        }
예제 #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Geometry.Point3d[] corners;
            Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners);

            if (rc != Result.Success)
            {
                return(rc);
            }

            Rhino.Geometry.Plane    plane      = new Rhino.Geometry.Plane(corners[0], corners[1], corners[2]);
            Rhino.Geometry.Interval x_interval = new Rhino.Geometry.Interval(0, corners[0].DistanceTo(corners[1]));
            Rhino.Geometry.Interval y_interval = new Rhino.Geometry.Interval(0, corners[1].DistanceTo(corners[2]));

            Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromPlane(plane, x_interval, y_interval, 10, 10);
            //mesh.FaceNormals.ComputeFaceNormals();
            //mesh.Normals.ComputeNormals();

            SampleCsDrawMeshConduit conduit = new SampleCsDrawMeshConduit();

            conduit.Mesh    = mesh;
            conduit.Enabled = true;
            doc.Views.Redraw();

            string out_str = null;

            rc = Rhino.Input.RhinoGet.GetString("Press <Enter> to continue", true, ref out_str);

            conduit.Enabled = false;

            doc.Views.Redraw();

            return(Result.Success);
        }
예제 #5
0
        public GltfMeshHolder Convert()
        {
            GltfMeshHolder meshHolder = new GltfMeshHolder(converter, doc);

            foreach (var primitive in mesh.Primitives)
            {
                Rhino.Geometry.Mesh rhinoMesh = GetMesh(primitive);

                if (rhinoMesh == null)
                {
                    continue;
                }

                rhinoMesh.Weld(0.01);

                rhinoMesh.Compact();

                if (!rhinoMesh.IsValidWithLog(out string log))
                {
                    Rhino.RhinoApp.WriteLine(log);
                }

                meshHolder.AddPrimitive(rhinoMesh, primitive.Material, mesh.Name);
            }

            return(meshHolder);
        }
예제 #6
0
        void ReconstructDirectShapeByMesh
        (
            DB.Document doc,
            ref DB.DirectShape element,

            Rhino.Geometry.Mesh mesh
        )
        {
            if (!ThrowIfNotValid(nameof(mesh), mesh))
            {
                return;
            }

            if (element is DB.DirectShape ds)
            {
            }
            else
            {
                ds = DB.DirectShape.CreateElement(doc, new DB.ElementId(DB.BuiltInCategory.OST_GenericModel));
            }

            using (var ctx = GeometryEncoder.Context.Push(ds))
            {
                ctx.RuntimeMessage = (severity, message, invalidGeometry) =>
                                     AddGeometryConversionError((GH_RuntimeMessageLevel)severity, message, invalidGeometry);

                ds.SetShape(mesh.ToShape().OfType <DB.GeometryObject>().ToList());
            }

            ReplaceElement(ref element, ds);
        }
        protected static IndexBuffer ToWireframeBuffer(Rhino.Geometry.Mesh mesh, out int linesCount)
        {
            linesCount = (mesh.Faces.Count * 3) + mesh.Faces.QuadCount;
            if (linesCount > 0)
            {
                var ib = new IndexBuffer(linesCount * IndexLine.GetSizeInShortInts());
                ib.Map(linesCount * IndexLine.GetSizeInShortInts());

                using (var istream = ib.GetIndexStreamLine())
                {
                    foreach (var face in mesh.Faces)
                    {
                        istream.AddLine(new IndexLine(face.A, face.B));
                        istream.AddLine(new IndexLine(face.B, face.C));
                        istream.AddLine(new IndexLine(face.C, face.D));
                        if (face.IsQuad)
                        {
                            istream.AddLine(new IndexLine(face.D, face.A));
                        }
                    }
                }

                ib.Unmap();
                return(ib);
            }

            return(null);
        }
예제 #8
0
        public void AddInstance(Rhino.Geometry.Transform transform)
        {
            foreach (GltfMeshMaterialPair pair in  meshMaterialPairs)
            {
                Rhino.Geometry.Mesh rhinoMesh = pair.RhinoMesh.DuplicateMesh();

                rhinoMesh.Transform(GltfUtils.YupToZup * transform);

                rhinoMesh.TextureCoordinates.ReverseTextureCoordinates(1);

                Guid objectId = doc.Objects.AddMesh(rhinoMesh);

                Rhino.DocObjects.RhinoObject rhinoObject = doc.Objects.Find(objectId);

                Rhino.Render.RenderMaterial material = converter.GetMaterial(pair.MaterialIndex);

                if (rhinoObject != null && material != null)
                {
                    rhinoObject.RenderMaterial            = material;
                    rhinoObject.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                    rhinoObject.Attributes.Name           = pair.Name;

                    rhinoObject.CommitChanges();
                }
            }
        }
예제 #9
0
        void ReconstructDirectShapeByMesh
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Mesh mesh
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            ThrowIfNotValid(nameof(mesh), mesh);

            if (element is DirectShape ds)
            {
            }
            else
            {
                ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
            }

            var shape = mesh.
                        ToHostMultiple(scaleFactor).
                        SelectMany(x => x.ToDirectShapeGeometry());

            ds.SetShape(shape.ToList());

            ReplaceElement(ref element, ds);
        }
예제 #10
0
        public static Rhino.Geometry.Mesh ToRhino(this DMesh3 dMesh3)
        {
            Rhino.Geometry.Mesh            rhMs       = new Rhino.Geometry.Mesh();
            List <Rhino.Geometry.MeshFace> rhFaces    = new List <Rhino.Geometry.MeshFace>();
            List <Rhino.Geometry.Point3f>  rhVertices = new List <Rhino.Geometry.Point3f>();

            DMesh3 copy;

            if (!dMesh3.IsCompact)
            {
                copy = new DMesh3(dMesh3, true);
            }
            else
            {
                copy = dMesh3;
            }

            foreach (var tri in copy.Triangles())
            {
                rhMs.Faces.AddFace(new Rhino.Geometry.MeshFace(tri.a, tri.b, tri.c));
            }
            foreach (var vert in copy.Vertices())
            {
                rhMs.Vertices.Add((float)vert.x, (float)vert.y, (float)vert.z);
            }
            foreach (int ind in copy.VertexIndices())
            {
                Vector3f col = copy.GetVertexColor(ind);
                rhMs.VertexColors.Add((int)(col.x * 255), (int)(col.y * 255), (int)(col.z * 255));
            }

            return(rhMs);
        }
예제 #11
0
    public static Rhino.Commands.Result AddMesh(Rhino.RhinoDoc doc)
    {
        Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
        mesh.Vertices.Add(0.0, 0.0, 1.0); //0
        mesh.Vertices.Add(1.0, 0.0, 1.0); //1
        mesh.Vertices.Add(2.0, 0.0, 1.0); //2
        mesh.Vertices.Add(3.0, 0.0, 0.0); //3
        mesh.Vertices.Add(0.0, 1.0, 1.0); //4
        mesh.Vertices.Add(1.0, 1.0, 2.0); //5
        mesh.Vertices.Add(2.0, 1.0, 1.0); //6
        mesh.Vertices.Add(3.0, 1.0, 0.0); //7
        mesh.Vertices.Add(0.0, 2.0, 1.0); //8
        mesh.Vertices.Add(1.0, 2.0, 1.0); //9
        mesh.Vertices.Add(2.0, 2.0, 1.0); //10
        mesh.Vertices.Add(3.0, 2.0, 1.0); //11

        mesh.Faces.AddFace(0, 1, 5, 4);
        mesh.Faces.AddFace(1, 2, 6, 5);
        mesh.Faces.AddFace(2, 3, 7, 6);
        mesh.Faces.AddFace(4, 5, 9, 8);
        mesh.Faces.AddFace(5, 6, 10, 9);
        mesh.Faces.AddFace(6, 7, 11, 10);
        mesh.Normals.ComputeNormals();
        mesh.Compact();
        if (doc.Objects.AddMesh(mesh) != Guid.Empty)
        {
          doc.Views.Redraw();
          return Rhino.Commands.Result.Success;
        }
        return Rhino.Commands.Result.Failure;
    }
예제 #12
0
 public static Rhino.Geometry.Mesh MeshBox(double x, double y, double z)
 {
     Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
     mesh.Vertices.Add(0, 0, 0);
     mesh.Vertices.Add(x, 0, 0);
     mesh.Vertices.Add(x, y, 0);
     mesh.Vertices.Add(0, y, 0);
     mesh.Vertices.Add(0, 0, z);
     mesh.Vertices.Add(x, 0, z);
     mesh.Vertices.Add(x, y, z);
     mesh.Vertices.Add(0, y, z);
     mesh.Faces.AddFace(3, 2, 1, 0);
     mesh.Faces.AddFace(4, 5, 6, 7);
     mesh.Faces.AddFace(0, 1, 5, 4);
     mesh.Faces.AddFace(1, 2, 6, 5);
     mesh.Faces.AddFace(2, 3, 7, 6);
     mesh.Faces.AddFace(3, 0, 4, 7);
     mesh.Normals.ComputeNormals();
     mesh.Compact();
     if (mesh.IsValid)
     {
         return(mesh);
     }
     return(null);
 }
예제 #13
0
    public static Rhino.Commands.Result AddMesh(Rhino.RhinoDoc doc)
    {
        Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
        mesh.Vertices.Add(0.0, 0.0, 1.0); //0
        mesh.Vertices.Add(1.0, 0.0, 1.0); //1
        mesh.Vertices.Add(2.0, 0.0, 1.0); //2
        mesh.Vertices.Add(3.0, 0.0, 0.0); //3
        mesh.Vertices.Add(0.0, 1.0, 1.0); //4
        mesh.Vertices.Add(1.0, 1.0, 2.0); //5
        mesh.Vertices.Add(2.0, 1.0, 1.0); //6
        mesh.Vertices.Add(3.0, 1.0, 0.0); //7
        mesh.Vertices.Add(0.0, 2.0, 1.0); //8
        mesh.Vertices.Add(1.0, 2.0, 1.0); //9
        mesh.Vertices.Add(2.0, 2.0, 1.0); //10
        mesh.Vertices.Add(3.0, 2.0, 1.0); //11

        mesh.Faces.AddFace(0, 1, 5, 4);
        mesh.Faces.AddFace(1, 2, 6, 5);
        mesh.Faces.AddFace(2, 3, 7, 6);
        mesh.Faces.AddFace(4, 5, 9, 8);
        mesh.Faces.AddFace(5, 6, 10, 9);
        mesh.Faces.AddFace(6, 7, 11, 10);
        mesh.Normals.ComputeNormals();
        mesh.Compact();
        if (doc.Objects.AddMesh(mesh) != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
예제 #14
0
        public static DMesh3 ToDMesh3(this Rhino.Geometry.Mesh ms)
        {
            int numV = ms.Vertices.Count;
            int numF = ms.Faces.Count;
            int numC = ms.VertexColors.Count;

            List <Vector3f> Vertices  = new List <Vector3f>(numV);
            List <Vector3i> Triangles = new List <Vector3i>(numF);

            for (int i = 0; i < numV; i++)
            {
                Vertices.Add(ms.Vertices[i].ToVec3f());
            }

            for (int i = 0; i < numF; i++)
            {
                Triangles.Add(ms.Faces[i].ToVec3i());
            }

            DMesh3 dMs = DMesh3Builder.Build <Vector3f, Vector3i, Vector3f>(Vertices, Triangles);

            if (numV == numC)
            {
                dMs.EnableVertexColors(new Vector3f(0.5, 0.5, 0.5));

                for (int i = 0; i < numV; i++)
                {
                    dMs.SetVertexColor(i, new Vector3f((float)ms.VertexColors[i].R / 255, (float)ms.VertexColors[i].G / 255, (float)ms.VertexColors[i].B / 255));
                }
            }

            return(dMs);
        }
예제 #15
0
 public void AddPrimitive(Rhino.Geometry.Mesh rhinoMesh, int?materialIndex, string name)
 {
     meshMaterialPairs.Add(new GltfMeshMaterialPair()
     {
         RhinoMesh     = rhinoMesh,
         MaterialIndex = materialIndex,
         Name          = name,
     });
 }
예제 #16
0
        public Guid DrawObjectWithSpecificLayer(Rhino.Geometry.Mesh mesh, NamedLayer layername)
        {
            Rhino.RhinoDoc.ActiveDoc.Layers.SetCurrentLayerIndex(layerIndexes[(int)layername], false);

            var result = Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(mesh);

            Rhino.RhinoDoc.ActiveDoc.Layers.SetCurrentLayerIndex(0, false);
            return(result);
        }
예제 #17
0
        public void DoSomething()
        {
            var sphere = new Rhino.Geometry.Sphere(Rhino.Geometry.Point3d.Origin, 10);

            mesh = Rhino.Geometry.Mesh.CreateFromSphere(sphere, 10, 10);
            mesh.Faces.ConvertQuadsToTriangles();
            mesh.Flip(true, true, true);

            FMessage.Log(ELogVerbosity.Warning, "Created a mesh with " + mesh.Vertices.Count.ToString() + " vertices and " + mesh.Vertices.Count.ToString() + " Faces.");
        }
예제 #18
0
        public static Scene <Model> BuildScene(List <Rhino.Geometry.Mesh> meshes)
        {
            var merged_mesh = new Rhino.Geometry.Mesh();

            foreach (var m in meshes)
            {
                merged_mesh.Append(m);
            }
            return(BuildScene(merged_mesh));
        }
예제 #19
0
 public BakeGeometry GetBKGT(Rhino.Geometry.Mesh m)
 {
     return(new BakeGeometry((d, a, o) =>
     {
         Rhino.DocObjects.ObjectAttributes a2 = a.Duplicate();
         a2.LayerIndex = 1;
         Guid id = d.Objects.AddMesh(m, a2);
         o.Add(id);
     }));
 }
예제 #20
0
 // This function will be called from a component in Grasshopper
 void FromGrasshopper(object sender, Rhino.Runtime.NamedParametersEventArgs args)
 {
     Rhino.Geometry.GeometryBase[] values;
     if (args.TryGetGeometry("mesh", out values))
     {
         mesh = values[0] as Rhino.Geometry.Mesh;
         mesh.Faces.ConvertQuadsToTriangles();
         mesh.Flip(true, true, true);
     }
 }
예제 #21
0
        public static Rhino.Geometry.Mesh UnionMesh(List <Rhino.Geometry.Mesh> meshes)
        {
            Rhino.Geometry.Mesh outMesh = new Rhino.Geometry.Mesh();

            foreach (Rhino.Geometry.Mesh m in meshes)
            {
                outMesh.Append(m);
            }

            return(outMesh);
        }
예제 #22
0
        private bool HandleTriangleFanMode(Rhino.Geometry.Mesh rhinoMesh)
        {
            for (int i = 1; i < rhinoMesh.Vertices.Count - 1; i++)
            {
                Rhino.Geometry.MeshFace face = new Rhino.Geometry.MeshFace(0, i, i + 1);

                rhinoMesh.Faces.AddFace(face);
            }

            return(true);
        }
예제 #23
0
        private bool HandleTriangleStripMode(Rhino.Geometry.Mesh rhinoMesh)
        {
            for (int i = 0; i < rhinoMesh.Vertices.Count - 2; i++)
            {
                Rhino.Geometry.MeshFace face = new Rhino.Geometry.MeshFace(i, i + 1, i + 2);

                rhinoMesh.Faces.AddFace(face);
            }

            return(true);
        }
예제 #24
0
        void DrawData(Grasshopper.Kernel.Data.IGH_Structure volatileData, IGH_DocumentObject docObject)
        {
            if (!volatileData.IsEmpty)
            {
                foreach (var value in volatileData.AllData(true))
                {
                    // First check for IGH_PreviewData to discard no graphic elements like strings, doubles, vectors...
                    if (value is IGH_PreviewData)
                    {
                        switch (value.ScriptVariable())
                        {
                        case Rhino.Geometry.Point3d point:    primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.Point(point))); break;

                        case Rhino.Geometry.Line line:        primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.LineCurve(line))); break;

                        case Rhino.Geometry.Rectangle3d rect: primitives.Add(new ParamPrimitive(docObject, rect.ToNurbsCurve())); break;

                        case Rhino.Geometry.Arc arc:          primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.ArcCurve(arc))); break;

                        case Rhino.Geometry.Circle circle:    primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.ArcCurve(circle))); break;

                        case Rhino.Geometry.Ellipse ellipse:  primitives.Add(new ParamPrimitive(docObject, ellipse.ToNurbsCurve())); break;

                        case Rhino.Geometry.Curve curve:      primitives.Add(new ParamPrimitive(docObject, curve)); break;

                        case Rhino.Geometry.Mesh mesh:        primitives.Add(new ParamPrimitive(docObject, mesh)); break;

                        case Rhino.Geometry.Box box:
                        {
                            var boxMeshes = Rhino.Geometry.Mesh.CreateFromBox(box, 1, 1, 1);
                            if (boxMeshes != null)
                            {
                                primitives.Add(new ParamPrimitive(docObject, boxMeshes));
                            }
                        }
                        break;

                        case Rhino.Geometry.Brep brep:
                        {
                            var brepMeshes = Rhino.Geometry.Mesh.CreateFromBrep(brep, activeDefinition.PreviewCurrentMeshParameters());
                            if (brepMeshes != null)
                            {
                                var previewMesh = new Rhino.Geometry.Mesh();
                                previewMesh.Append(brepMeshes);

                                primitives.Add(new ParamPrimitive(docObject, previewMesh));
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
예제 #25
0
 public UpdateGeometry GetUPGR(Rhino.Geometry.Mesh m)
 {
     return(new UpdateGeometry((x, y, z) =>
     {
         m.Vertices.Clear();
         for (int i = 0; i < pS.Value.__N; i++)
         {
             m.Vertices.Add(pS.Value.particles[i, 0] + x, pS.Value.particles[i, 1] + y, pS.Value.particles[i, 2] + z);
         }
     }));
 }
        public Rhino.Geometry.Mesh Mesh(int index)
        {
            IntPtr pMesh = UnsafeNativeMethods.Rdk_CustomMeshes_Mesh(ConstPointer(), index);

            if (pMesh != IntPtr.Zero)
            {
                Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, null);
                mesh.DoNotDestructOnDispose();
                return(mesh);
            }
            return(null);
        }
예제 #27
0
    public static Rhino.Commands.Result UnrollSurface2(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;

        Rhino.DocObjects.ObjRef objref;
        Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Unroller unroll = null;
        Rhino.Geometry.Brep     brep   = objref.Brep();
        Rhino.Geometry.Mesh     mesh   = null;
        if (brep != null)
        {
            unroll = new Rhino.Geometry.Unroller(brep);
            mesh   = brep.Faces[0].GetMesh(Rhino.Geometry.MeshType.Render);
        }
        else
        {
            Rhino.Geometry.Surface srf = objref.Surface();
            if (srf != null)
            {
                unroll = new Rhino.Geometry.Unroller(srf);
            }
        }
        if (unroll == null || mesh == null)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        unroll.AddFollowingGeometry(mesh.Vertices.ToPoint3dArray());

        unroll.ExplodeOutput = false;
        Rhino.Geometry.Curve[]   curves;
        Rhino.Geometry.Point3d[] points;
        Rhino.Geometry.TextDot[] dots;
        unroll.PerformUnroll(out curves, out points, out dots);

        // change the mesh vertices to the flattened form and add it to the document
        if (points.Length == mesh.Vertices.Count)
        {
            for (int i = 0; i < points.Length; i++)
            {
                mesh.Vertices.SetVertex(i, points[i]);
            }
            mesh.Normals.ComputeNormals();
        }
        doc.Objects.AddMesh(mesh, objref.Object().Attributes);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
예제 #28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Mesh mesh = null;
            if (!DA.GetData("Mesh", ref mesh))
            {
                return;
            }

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, (Rhino.Geometry.Mesh)mesh?.DuplicateShallow()));
        }
예제 #29
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!DA.GetData(1, ref v))
            {
                return;
            }

            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Mesh m = null;
                if (!DA.GetData(0, ref m))
                {
                    return;
                }
                newNodes.Clear();
                newNodes.AddRange(m.Vertices.ToPoint3dArray());
                int nNewNodes = newNodes.Count;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                }

                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                nF = new nodalForce(v.X, v.Y, v.Z);
                for (int i = 0; i < nNewNodes; i++)
                {
                    nF.addNode(lNodes[i]);
                }
                pS.Value.addObject(nF);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }
            else
            {
                nF.forceX = v.X;
                nF.forceY = v.Y;
                nF.forceZ = v.Z;
            }

            DA.SetData(0, pS);
        }
예제 #30
0
        public static Rhino.Geometry.Mesh ToRhinoMesh(this Mesh source)
        {
            // empty rhino mesh
            var rMesh = new Rhino.Geometry.Mesh();

            // add vertices
            foreach (var vertex in source.Vertices)
            {
                rMesh.Vertices.Add(vertex.Position.X, vertex.Position.Y, vertex.Position.Z);
            }

            // add faces
            foreach (var face in source.Faces)
            {
                switch (face.Vertices.Length)
                {
                case 3:
                    rMesh.Faces.AddFace(face.Vertices[0].Index, face.Vertices[1].Index, face.Vertices[2].Index);
                    break;

                case 4:
                    rMesh.Faces.AddFace(face.Vertices[0].Index, face.Vertices[1].Index, face.Vertices[2].Index, face.Vertices[3].Index);
                    break;

                default:
                    // triangulate about face center (fan)
                    var center = Vec3d.Average(face.Vertices.Select(v => v.Position).ToList()).ToPoint3d();
                    rMesh.Vertices.Add(center);

                    var faceIndices = new int[face.Vertices.Length];

                    for (int i = 0; i < face.Vertices.Length; i++)
                    {
                        faceIndices[i] =
                            rMesh.Faces
                            .AddFace(
                                face.Vertices[i].Index,
                                face.Vertices[(i + 1) % face.Vertices.Length].Index,
                                rMesh.Vertices.Count - 1);
                    }

                    rMesh.Ngons.AddNgon(Rhino.Geometry.MeshNgon.Create(face.Vertices.Select(v => v.Index).ToList(), faceIndices));
                    break;
                }
            }

            // clean up
            rMesh.Normals.ComputeNormals();
            return(rMesh);
        }
예제 #31
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Mesh mesh
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (mesh == null || !mesh.IsValid)
                {
                    throw new Exception(string.Format("Parameter '{0}' must be valid Mesh.", Params.Input[0].Name));
                }

                var scaleFactor = 1.0 / Revit.ModelUnits;
                if (scaleFactor != 1.0)
                {
                    mesh.Scale(scaleFactor);
                }

                var shape = new List <GeometryObject>();

                foreach (var geometry in mesh.ToHost().SelectMany(x => x.ToDirectShapeGeometry()))
                {
                    // DirectShape only accepts those types and no nulls
                    switch (geometry)
                    {
                    case Point p: shape.Add(p); break;

                    case Curve c: shape.Add(c); break;

                    case Solid s: shape.Add(s); break;

                    case Mesh m: shape.Add(m); break;
                    }
                }

                var ds = element as DirectShape ?? CopyParametersFrom(DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)), element);
                ds.SetShape(shape);
                element = ds;

                ReplaceElement(doc, DA, Iteration, element);
            }
            catch (Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                ReplaceElement(doc, DA, Iteration, null);
            }
        }
 public static Rhino.Geometry.Mesh MeshBox(double x, double y, double z)
 {
   Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
   mesh.Vertices.Add(0, 0, 0);
   mesh.Vertices.Add(x, 0, 0);
   mesh.Vertices.Add(x, y, 0);
   mesh.Vertices.Add(0, y, 0);
   mesh.Vertices.Add(0, 0, z);
   mesh.Vertices.Add(x, 0, z);
   mesh.Vertices.Add(x, y, z);
   mesh.Vertices.Add(0, y, z);
   mesh.Faces.AddFace(3, 2, 1, 0);
   mesh.Faces.AddFace(4, 5, 6, 7);
   mesh.Faces.AddFace(0, 1, 5, 4);
   mesh.Faces.AddFace(1, 2, 6, 5);
   mesh.Faces.AddFace(2, 3, 7, 6);
   mesh.Faces.AddFace(3, 0, 4, 7);
   mesh.Normals.ComputeNormals();
   mesh.Compact();
   if (mesh.IsValid)
     return mesh;
   return null;
 }
예제 #33
0
    static int OnReturnBoolGeneralCallback(int serial_number, int iVirtualFunction, IntPtr pObj, IntPtr pMat, IntPtr pMesh)
    {
      try
      {
        RenderPipeline pipe = RenderPipeline.FromSerialNumber(serial_number);
        if (pipe != null)
        {
          switch ((VirtualFunctions)iVirtualFunction)
          {
            case VirtualFunctions.StartRendering:
              return pipe.StartRendering() ? 1 : 0;
            case VirtualFunctions.StopRendering:
              pipe.StopRendering();
              return 1;
            case VirtualFunctions.NeedToProcessGeometryTable:
              return pipe.NeedToProcessGeometryTable() ? 1 : 0;
            case VirtualFunctions.NeedToProcessLightTable:
              return pipe.NeedToProcessLightTable() ? 1 : 0;
            case VirtualFunctions.RenderSceneWithNoMeshes:
              return pipe.RenderSceneWithNoMeshes() ? 1 : 0;
            case VirtualFunctions.RenderPreCreateWindow:
              return pipe.RenderPreCreateWindow() ? 1:0;
            case VirtualFunctions.RenderEnterModalLoop:
              return pipe.RenderEnterModalLoop() ? 1 : 0;
            case VirtualFunctions.RenderExitModalLoop:
              return pipe.RenderExitModalLoop() ? 1 : 0;
            case VirtualFunctions.RenderContinueModal:
              return pipe.RenderContinueModal() ? 1 : 0;

            case VirtualFunctions.IgnoreRhinoObject:
              {
                if (pObj != IntPtr.Zero)
                {
                  Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj);
                  if (obj != null)
                    return pipe.IgnoreRhinoObject(obj) ? 1 : 0;
                }
              }
              return 0;
            case VirtualFunctions.AddLightToScene:
              {
                if (pObj != IntPtr.Zero)
                {
                  Rhino.DocObjects.LightObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj) as Rhino.DocObjects.LightObject;
                  if (obj != null)
                    return pipe.AddLightToScene(obj) ? 1 : 0;
                }
              }
              return 0;
            case VirtualFunctions.AddRenderMeshToScene:
              {
                if (pObj != IntPtr.Zero && pMat != IntPtr.Zero && pMesh != IntPtr.Zero)
                {
                  Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj);
                  Rhino.DocObjects.Material mat = Rhino.DocObjects.Material.NewTemporaryMaterial(pMat);

                  //Steve....you need to look at this
                  Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, obj);

                  return pipe.AddRenderMeshToScene(obj, mat, mesh) ? 1:0;
                }
              }
              return 0;
          }          
        }
      }
      catch (Exception ex)
      {
        Rhino.Runtime.HostUtils.ExceptionReport(ex);
      }

      Debug.Assert(false);
      return 0;
    }
예제 #34
0
    void Initialize()
    {
      IntPtr pSceneServer = m_pSceneServer;

      if (pSceneServer != IntPtr.Zero)
      {
        //Pull in the list of objects
        m_scene_objects = new List<SceneObject>();

        UnsafeNativeMethods.Rdk_SceneServer_ResetObjectEnum(pSceneServer);

        IntPtr pObject = UnsafeNativeMethods.Rdk_SceneServer_NextObject(pSceneServer);
        while (pObject != IntPtr.Zero)
        {
          Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();

          IntPtr pMaterial = UnsafeNativeMethods.Rdk_SceneServer_ObjectDetails(pObject, mesh.NonConstPointer());
          if (pMaterial != IntPtr.Zero)
          {
            SceneObject o = new SceneObject(mesh, RenderContent.FromPointer(pMaterial) as RenderMaterial);
            m_scene_objects.Add(o);
          }

          pObject = UnsafeNativeMethods.Rdk_SceneServer_NextObject(pSceneServer);
        }

        //Now get the lights
        m_scene_lights = new List<Rhino.Geometry.Light>();

        UnsafeNativeMethods.Rdk_SceneServer_ResetLightEnum(pSceneServer);

        IntPtr pLight = UnsafeNativeMethods.Rdk_SceneServer_NextLight(pSceneServer);
        while (pLight != IntPtr.Zero)
        {
          Rhino.Geometry.Light light = new Rhino.Geometry.Light();
          UnsafeNativeMethods.Rdk_SceneServer_LightDetails(pLight, light.NonConstPointer());

          m_scene_lights.Add(light);

          pLight = UnsafeNativeMethods.Rdk_SceneServer_NextLight(pSceneServer);
        }

        //And then fill in the blanks
        IntPtr pEnvironment = UnsafeNativeMethods.Rdk_SceneServer_Environment(pSceneServer);
        if (pEnvironment != IntPtr.Zero)
        {
          m_environment = RenderContent.FromPointer(pEnvironment) as RenderEnvironment;
        }
        else
        {
          m_environment = null;
        }

        m_content_instance_id = UnsafeNativeMethods.Rdk_SceneServer_InstanceId(pSceneServer);
        m_sig = UnsafeNativeMethods.Rdk_SceneServer_Signature(pSceneServer);

        //Just the view left...

        m_viewport = new Rhino.DocObjects.ViewportInfo();
        UnsafeNativeMethods.Rdk_SceneServer_View(pSceneServer, m_viewport.NonConstPointer());
      }

      m_pSceneServer = IntPtr.Zero;
    }
예제 #35
0
        public static void OptToRhino(OptFile opt, string rhinoPath, bool scale)
        {
            if (opt == null)
            {
                throw new ArgumentNullException("opt");
            }

            string rhinoDirectory = Path.GetDirectoryName(rhinoPath);
            string rhinoName = Path.GetFileNameWithoutExtension(rhinoPath);

            var distances = opt.Meshes
                .SelectMany(t => t.Lods)
                .Select(t => t.Distance)
                .Distinct()
                .OrderByDescending(t => t)
                .ToArray();

            for (int distance = 0; distance < distances.Length; distance++)
            {
                using (var file = new Rhino.FileIO.File3dm())
                {
                    file.Settings.ModelUnitSystem = Rhino.UnitSystem.Meters;

                    int objectsIndex = 0;
                    List<string> textureNames = new List<string>();

                    foreach (var mesh in opt.Meshes)
                    {
                        var lod = mesh.Lods.FirstOrDefault(t => t.Distance <= distances[distance]);

                        if (lod == null)
                        {
                            continue;
                        }

                        foreach (var textureName in lod.FaceGroups
                            .Where(t => t.Textures.Count > 0)
                            .Select(t => t.Textures[0]))
                        {
                            if (!textureNames.Contains(textureName))
                            {
                                textureNames.Add(textureName);
                            }
                        }

                        string meshName = string.Format(CultureInfo.InvariantCulture, "{0}.{1:D3}", mesh.Descriptor.MeshType, objectsIndex);

                        using (var layer = new Rhino.DocObjects.Layer())
                        {
                            layer.Name = meshName;

                            file.Layers.Add(layer);
                        }

                        foreach (var faceGroup in lod.FaceGroups)
                        {
                            using (var rhinoMesh = new Rhino.Geometry.Mesh())
                            using (var rhinoAttributes = new Rhino.DocObjects.ObjectAttributes())
                            {
                                rhinoAttributes.Name = meshName;
                                rhinoAttributes.LayerIndex = objectsIndex;

                                if (faceGroup.Textures.Count > 0)
                                {
                                    rhinoAttributes.MaterialIndex = textureNames.IndexOf(faceGroup.Textures[0]);
                                }

                                Action<Vector> addVertex;

                                if (scale)
                                {
                                    addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X * OptFile.ScaleFactor, vertex.Y * OptFile.ScaleFactor, vertex.Z * OptFile.ScaleFactor);
                                }
                                else
                                {
                                    addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X, vertex.Y, vertex.Z);
                                }

                                Action<TextureCoordinates> addTexCoords = texCoords => rhinoMesh.TextureCoordinates.Add(texCoords.U, -texCoords.V);

                                Action<Vector> addNormal = normal => rhinoMesh.Normals.Add(normal.X, normal.Y, normal.Z);

                                int facesIndex = 0;

                                foreach (var face in faceGroup.Faces)
                                {
                                    var verticesIndex = face.VerticesIndex;
                                    var texCoordsIndex = face.TextureCoordinatesIndex;
                                    var normalsIndex = face.VertexNormalsIndex;

                                    addVertex(mesh.Vertices[verticesIndex.A]);
                                    addTexCoords(mesh.TextureCoordinates[texCoordsIndex.A]);
                                    addNormal(mesh.VertexNormals[normalsIndex.A]);
                                    facesIndex++;

                                    addVertex(mesh.Vertices[verticesIndex.B]);
                                    addTexCoords(mesh.TextureCoordinates[texCoordsIndex.B]);
                                    addNormal(mesh.VertexNormals[normalsIndex.B]);
                                    facesIndex++;

                                    addVertex(mesh.Vertices[verticesIndex.C]);
                                    addTexCoords(mesh.TextureCoordinates[texCoordsIndex.C]);
                                    addNormal(mesh.VertexNormals[normalsIndex.C]);
                                    facesIndex++;

                                    if (verticesIndex.D >= 0)
                                    {
                                        addVertex(mesh.Vertices[verticesIndex.D]);
                                        addTexCoords(mesh.TextureCoordinates[texCoordsIndex.D]);
                                        addNormal(mesh.VertexNormals[normalsIndex.D]);
                                        facesIndex++;
                                    }

                                    if (verticesIndex.D < 0)
                                    {
                                        rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3);
                                    }
                                    else
                                    {
                                        rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3, facesIndex - 4);
                                    }
                                }

                                rhinoMesh.Compact();

                                file.Objects.AddMesh(rhinoMesh, rhinoAttributes);
                            }
                        }

                        objectsIndex++;
                    }

                    foreach (var textureName in textureNames)
                    {
                        Texture texture;
                        opt.Textures.TryGetValue(textureName, out texture);

                        using (var material = new Rhino.DocObjects.Material())
                        {
                            material.Name = textureName;

                            if (texture == null)
                            {
                                material.DiffuseColor = System.Drawing.Color.White;
                            }
                            else
                            {
                                texture.Save(Path.Combine(rhinoDirectory, textureName + ".png"));
                                material.SetBitmapTexture(textureName + ".png");

                                if (texture.HasAlpha)
                                {
                                    texture.SaveAlphaMap(Path.Combine(rhinoDirectory, textureName + "_alpha.png"));
                                    material.SetTransparencyTexture(textureName + "_alpha.png");
                                }
                            }

                            file.Materials.Add(material);
                        }
                    }

                    file.Write(Path.Combine(rhinoDirectory, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.3dm", rhinoName, distance)), 4);
                }
            }
        }
                private void Build_Mesh_Sections()
                {
                    int ct = -1;
                    m_templateX = new Rhino.Geometry.Mesh[2];
                    m_templateX[0] = new Rhino.Geometry.Mesh();
                    m_templateX[1] = new Rhino.Geometry.Mesh();
                    m_templateY = new Rhino.Geometry.Mesh[2];
                    m_templateY[0] = new Rhino.Geometry.Mesh();
                    m_templateY[1] = new Rhino.Geometry.Mesh();
                    m_templateZ = new Rhino.Geometry.Mesh[2];
                    m_templateZ[0] = new Rhino.Geometry.Mesh();
                    m_templateZ[1] = new Rhino.Geometry.Mesh();

                    double rt2 = Math.Sqrt(2);

                    for (int i = 0; i < 2; i++)
                    {
                        ct = -1;
                        for (int y = 0; y < PFrame[i].Length; y++)
                        {
                            for (int z = 0; z < PFrame[i][y].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(PFrame[0][0][0].Pt.x, PFrame[i][y][z].Pt.y, PFrame[i][y][z].Pt.z);
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, dz)));
                                int ct4 = ct * 4;
                                m_templateX[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int z = 0; z < PFrame[x][i].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(PFrame[x][i][z].Pt.x, PFrame[0][0][0].Pt.y, PFrame[x][i][z].Pt.z);
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(2 * dx / rt2, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, -dz)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(2 * -dx / rt2, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, dz)));
                                int ct4 = ct * 4;
                                m_templateY[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int y = 0; y < PFrame[x].Length; y++)
                            {
                                ct++;

                                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(PFrame[x][y][i].Pt.x, PFrame[x][y][i].Pt.y, PFrame[0][0][0].Pt.z);

                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(2 * dx / rt2, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, -dy, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(-2 * dx / rt2, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, dy, 0)));
                                int ct4 = ct * 4;
                                m_templateZ[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        m_templateX[i].Normals.ComputeNormals();
                        m_templateX[i].FaceNormals.ComputeFaceNormals();
                        m_templateY[i].Normals.ComputeNormals();
                        m_templateY[i].FaceNormals.ComputeFaceNormals();
                        m_templateZ[i].Normals.ComputeNormals();
                        m_templateZ[i].FaceNormals.ComputeFaceNormals();
                    }
                }
 public Rhino.Geometry.Mesh Mesh(int index)
 {
   IntPtr pMesh = UnsafeNativeMethods.Rdk_CustomMeshes_Mesh(ConstPointer(), index);
   if (pMesh != IntPtr.Zero)
   {
     Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, null);
     mesh.DoNotDestructOnDispose();
     return mesh;
   }
   return null;
 }
예제 #38
0
    static int OnReturnBoolGeneralCallback(int serial_number, int iVirtualFunction, IntPtr pObj, IntPtr pMat, IntPtr pMesh, IntPtr pView, int rectLeft, int rectTop, int rectRight, int rectBottom)
    {
      try
      {
        RenderPipeline pipe = RenderPipeline.FromSerialNumber(serial_number);
        if (pipe != null)
        {
          switch ((VirtualFunctions)iVirtualFunction)
          {
            case VirtualFunctions.StartRendering:
              return pipe.OnRenderBegin() ? 1 : 0;
            case VirtualFunctions.StartRenderingInWindow:
              {
                Rhino.Display.RhinoView view = Rhino.Display.RhinoView.FromIntPtr(pView);
                System.Drawing.Rectangle rect = System.Drawing.Rectangle.FromLTRB(rectLeft, rectTop, rectRight, rectBottom);
                return pipe.OnRenderWindowBegin(view, rect) ? 1 : 0;
              }
            case VirtualFunctions.StopRendering:
              pipe.OnRenderEnd(new RenderEndEventArgs());
              return 1;
            case VirtualFunctions.NeedToProcessGeometryTable:
              return pipe.NeedToProcessGeometryTable() ? 1 : 0;
            case VirtualFunctions.NeedToProcessLightTable:
              return pipe.NeedToProcessLightTable() ? 1 : 0;
            case VirtualFunctions.RenderSceneWithNoMeshes:
              return pipe.RenderSceneWithNoMeshes() ? 1 : 0;
            case VirtualFunctions.RenderPreCreateWindow:
              return pipe.RenderPreCreateWindow() ? 1:0;
            case VirtualFunctions.RenderEnterModalLoop:
              return pipe.RenderEnterModalLoop() ? 1 : 0;
            case VirtualFunctions.RenderExitModalLoop:
              return pipe.RenderExitModalLoop() ? 1 : 0;
            case VirtualFunctions.RenderContinueModal:
              return pipe.ContinueModal() ? 1 : 0;

            case VirtualFunctions.IgnoreRhinoObject:
              {
                if (pObj != IntPtr.Zero)
                {
                  Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj);
                  if (obj != null)
                    return pipe.IgnoreRhinoObject(obj) ? 1 : 0;
                }
              }
              return 0;
            case VirtualFunctions.AddLightToScene:
              {
                if (pObj != IntPtr.Zero)
                {
                  Rhino.DocObjects.LightObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj) as Rhino.DocObjects.LightObject;
                  if (obj != null)
                    return pipe.AddLightToScene(obj) ? 1 : 0;
                }
              }
              return 0;
            case VirtualFunctions.AddRenderMeshToScene:
              {
                if (pObj != IntPtr.Zero && pMat != IntPtr.Zero && pMesh != IntPtr.Zero)
                {
                  Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj);
                  Rhino.DocObjects.Material mat = Rhino.DocObjects.Material.NewTemporaryMaterial(pMat);

                  //Steve....you need to look at this
                  Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, obj);

                  return pipe.AddRenderMeshToScene(obj, mat, mesh) ? 1:0;
                }
              }
              return 0;
          }          
        }
      }
      catch (Exception ex)
      {
        Rhino.Runtime.HostUtils.ExceptionReport(ex);
      }

      Debug.Assert(false);
      return 0;
    }
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(out Mapping.PachMapReceiver[] Map)
            {
                System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();
                of.DefaultExt = ".pachm";
                of.AddExtension = true;
                of.Filter = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
                if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    Map = null;
                    return false;
                }
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(of.FileName, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();
                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir") throw new Exception("Map Data File Expected");
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct=1;
                Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
                Map = new Mapping.PachMapReceiver[1];
                //Map[0] = new Pach_Map_Receiver();
                //double[] Rho_C = null;
                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                        case "Version":
                            //Pach1.7 = Versioning functionality added.
                            string v = sr.ReadString();
                            version = double.Parse(v.Substring(0, 3));
                            rev = int.Parse(v.Split(new char[1] { '.' })[3]);
                            break;
                        case "Mesh Information":
                            //6. Announce Mesh Vertices (string)
                            //Write the number of vertices & faces (int) (int)
                            if (sr.ReadString() != "Mesh Vertices") throw new Exception("Mesh Vertices Expected");

                            int VC = (int)sr.ReadUInt32();
                            int FC = (int)sr.ReadUInt32();
                            for (int i = 0; i < VC; i++)
                            {
                                //Write Vertex: (double) (double) (double)
                                Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                            }

                            //7. Announce Mesh Faces (string)
                            if (sr.ReadString() != "Mesh Faces") throw new Exception("Mesh Faces Expected");

                            for (int i = 0; i < FC; i++)
                            {
                                // Write mesh vertex indices: (int) (int) (int) (int)
                                Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
                            }
                            break;
                        case "Sources":
                            //7.5: Announce the number of sources.
                            s_ct = sr.ReadInt32();
                            delay = new double[s_ct];
                            Map = new Mapping.PachMapReceiver[s_ct];
                            //7.5a Announce the type of source.

                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s] = new Mapping.PachMapReceiver();
                                Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                                Map[s].SampleCT = SampleCT;
                                Map[s].SampleRate = SampleRate;
                                Map[s].Map_Mesh = Map_Mesh;
                                Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[s].SrcType = sr.ReadString();
                                //4.4 Source delay (ms)
                                if (version > 2.0 || (version == 2.0 && rev >= 1))
                                {
                                    delay[s] = sr.ReadDouble();
                                }
                            }
                            break;
                        case "SourceswLoc":
                            //7.5: Announce the number of sources.
                            s_ct = sr.ReadInt32();
                            delay = new double[s_ct];
                            Map = new Mapping.PachMapReceiver[s_ct];
                            //7.5a Announce the type of source.

                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s] = new Mapping.PachMapReceiver();
                                Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                                Map[s].SampleCT = SampleCT;
                                Map[s].SampleRate = SampleRate;
                                Map[s].Map_Mesh = Map_Mesh;
                                Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[s].Src = new Rhino.Geometry.Point3d(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                                Map[s].SrcType = sr.ReadString();
                                //4.4 Source delay (ms)
                                if (version > 2.0 || (version == 2.0 && rev >= 1))
                                {
                                    delay[s] = sr.ReadDouble();
                                }
                            }
                            break;
                        case "Receiver Hit Data":
                            if (Map[0] == null)
                            {
                                Map = new Mapping.PachMapReceiver[1];
                                Map[0] = new Mapping.PachMapReceiver();
                                Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                                Map[0].SampleRate = SampleRate;
                                Map[0].SampleCT = SampleCT;
                                Map[0].Map_Mesh = Map_Mesh;
                                Map[0].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[0].SrcType = "Geodesic";
                            }

                            //8. Announce that the following data pertains to the receiver histograms (string)
                            //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                            bool vert_Receiver = sr.ReadBoolean();
                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s].Rec_Vertex = vert_Receiver;
                                for (int i = 0; i < Map[s].Rec_List.Length; i++)
                                {
                                    //for version 1.7 and up, write direct sound arrival time.
                                    //Write Receiver Index (int)
                                    int j = (int)sr.ReadUInt32();
                                    //Write Direct Sound Arrival Time.
                                    double Direct_Time;
                                    if (version >= 1.7) Direct_Time = sr.ReadDouble(); else Direct_Time = (Utilities.PachTools.RPttoHPt(Map[s].Src) - Map[s].Rec_List[i].H_Origin).Length() / 343f;
                                    //Write Impedance of Air
                                    double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                    if (vert_Receiver)
                                    {
                                        Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(Map_Mesh.Vertices[i], new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                    }
                                    else
                                    {
                                        Rhino.Geometry.Point3d RecLoc = Map_Mesh.Faces.GetFaceCenter(i);
                                        Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(new Rhino.Geometry.Point3f((float)RecLoc.X, (float)RecLoc.Y, (float)RecLoc.Z), new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                    }

                                    for (int Octave = 0; Octave < 8; Octave++)
                                    {
                                        //Write Octave (int)
                                        int Oct_out = (int)sr.ReadUInt32();
                                        if (Oct_out != Octave) throw new Exception(string.Format("Octave {0} Expected", Octave));
                                        double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                        if (Directional)
                                        {
                                            if (version < 1.7)
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                            else
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            if (version < 1.7)
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                            else
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0,0,0), Octave);
                                            }
                                        }
                                    }
                                    if (sr.ReadString() != "End_Receiver_Hits") throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                            break;
                        case "End_of_File":
                            sr.Close();
                            return true;
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }