Exemple #1
0
        public void CanCreateFromRhinoMesh()
        {
            // 1. get/create rhino mesh

            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();

            // 2. call BmMesh(Mesh) constructor

            Mesh polymesh = new Mesh(mesh);

            // 3. compare number of vertex/face elements
            // 4. compare number of halfedges against no. required for no. faces
        }
Exemple #2
0
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            // Cast from Buckminster.Mesh
            if (typeof(Mesh).IsAssignableFrom(source.GetType()))
            {
                Value = (Mesh)source;
                return(true);
            }

            // Cast from Rhino.Geometry.Mesh
            Rhino.Geometry.Mesh mesh = null;
            if (GH_Convert.ToMesh(source, ref mesh, GH_Conversion.Primary))
            {
                Value = new Mesh(mesh);
                return(true);
            }

            // Ah well, at least we tried...
            return(false);
        }
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            // Cast from Molecular
            if (typeof(Molecular).IsAssignableFrom(source.GetType()))
            {
                Value = (Molecular)source;
                return(true);
            }

            // Cast from Buckminster.Mesh
            if (typeof(Mesh).IsAssignableFrom(source.GetType()))
            {
                Value = ((Mesh)source).ToMolecular();
                return(true);
            }

            // Cast from GH_GeometricGoo<Buckminster.Mesh>
            if (typeof(MeshGoo).IsAssignableFrom(source.GetType()))
            {
                var target = (MeshGoo)source;
                Value = target.Value.ToMolecular();
                return(true);
            }

            // Cast from Rhino.Geometry.Mesh
            Rhino.Geometry.Mesh rmesh = null;
            if (GH_Convert.ToMesh(source, ref rmesh, GH_Conversion.Primary))
            {
                var target = new Molecular(rmesh.Vertices.Count);

                // add nodes
                foreach (var pt in rmesh.TopologyVertices)
                {
                    target.Add(pt.X, pt.Y, pt.Z);
                }

                // add bars (use edges from mesh)
                for (int i = 0; i < rmesh.TopologyEdges.Count; i++)
                {
                    var edge = rmesh.TopologyEdges.GetTopologyVertices(i);
                    target.Add(edge.I, edge.J);
                }

                Value = target;
                return(true);
            }

            // Ah well, at least we tried...
            return(false);
        }