Example #1
0
        public IMesh Triangulated()
        {
            // test whether the mesh contains triangles only
            if (!ContainsQuads)
            {
                return(this);
            }

            var nmesh = new Rhino.Geometry.Mesh();

            nmesh.CopyFrom(mesh);
            for (int face_ind = 0; face_ind < nmesh.Faces.Count; ++face_ind)
            {
                var face = nmesh.Faces[face_ind];
                if (face.IsQuad)
                {
                    var l_ac = nmesh.Vertices[face.A].DistanceTo(nmesh.Vertices[face.C]);
                    var l_bd = nmesh.Vertices[face.B].DistanceTo(nmesh.Vertices[face.D]);
                    Rhino.Geometry.MeshFace face1, face2;
                    if (l_ac < l_bd)
                    {
                        face1 = new Rhino.Geometry.MeshFace(face.A, face.B, face.C);
                        face2 = new Rhino.Geometry.MeshFace(face.A, face.C, face.D);
                    }
                    else
                    {
                        face1 = new Rhino.Geometry.MeshFace(face.A, face.B, face.D);
                        face2 = new Rhino.Geometry.MeshFace(face.B, face.C, face.D);
                    }
                    nmesh.Faces.SetFace(face_ind, face1);
                    nmesh.Faces.AddFace(face2);
                }
            }
            return(new RhinoMesh(nmesh));
        }
Example #2
0
        /// <summary>
        /// Convert a Rhino mesh to a Nucleus one
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static Mesh Convert(RC.Mesh mesh)
        {
            if (mesh == null)
            {
                return(null);
            }
            Mesh result = new Mesh();

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                result.AddVertex(Convert(mesh.Vertices[i]));
                // TODO: Vertex colours?
            }
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                RC.MeshFace mF = mesh.Faces[i];
                if (mF.IsTriangle)
                {
                    result.AddFace(mF.A, mF.B, mF.C);
                }
                else
                {
                    result.AddFace(mF.A, mF.B, mF.C, mF.D);
                }
            }
            return(result);
        }
Example #3
0
        /***************************************************/

        public static BHG.Face FromRhino(this RHG.MeshFace rFace)
        {
            BHG.Face face = new BHG.Face
            {
                A = rFace.A,
                B = rFace.B,
                C = rFace.C
            };

            if (rFace.IsQuad)
            {
                face.D = rFace.D;
            }

            return(face);
        }
 public MeshSimplify_Face(int a, int b, int c)
 {
     this.face = new MeshFace(a, b, c);
 }
 public MeshSimplify_Face(MeshFace f)
 {
     this.face = f;
 }
Example #6
0
 public static Karamba.Geometry.Face3 Convert(this Rhino.Geometry.MeshFace face)
 {
     return(new Face3(face.A, face.B, face.C, face.D));
 }
Example #7
0
        /// <summary>
        /// Converts a Rhino.Geometry.Mesh object to a UnityEngine.Mesh object, and assigns it to an existing reference.
        /// </summary>
        /// <param name="rhinoMesh"> The Rhino.Geometry.Mesh to convert.</param>
        /// <param name="unityMesh"> The reference to an existing UnityEngine.Mesh instance.</param>
        /// <returns>A new instance of a UnityEngine.Mesh object.</returns>
        public static void ToUnityMesh(this Rhino.Geometry.Mesh rhinoMesh, ref UnityEngine.Mesh unityMesh, UnityEngine.Transform _transform)
        {
            int vertexCount = rhinoMesh.Vertices.Count;
            int faceCount   = rhinoMesh.Faces.Count;
            int normalCount = rhinoMesh.Normals.Count;
            int uvCount     = rhinoMesh.TextureCoordinates.Count;
            int colorCount  = rhinoMesh.VertexColors.Count;

            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();
            List <Vector3> normals   = new List <Vector3>();
            List <Vector2> uvs       = new List <Vector2>();
            List <Color>   colors    = new List <Color>();

            #region Convert Vertices

            for (int i = 0; i < vertexCount; i++)
            {
                vertices.Add(_transform.InverseTransformPoint(rhinoMesh.Vertices[i].ToUnityVector()));
            }

            unityMesh.SetVertices(vertices);

            #endregion

            #region Convert Faces

            for (int i = 0; i < faceCount; i++)
            {
                Rhino.Geometry.MeshFace face = rhinoMesh.Faces[i];

                if (face.IsTriangle)
                {
                    triangles.Add(face.A);
                    triangles.Add(face.C);
                    triangles.Add(face.B);
                }
                else
                {
                    triangles.Add(face.A);
                    triangles.Add(face.D);
                    triangles.Add(face.B);

                    triangles.Add(face.B);
                    triangles.Add(face.D);
                    triangles.Add(face.C);
                }
            }

            unityMesh.SetTriangles(triangles, 0);

            #endregion

            /*
             #region Convert Normals
             *
             * if (normalCount > 0)
             * {
             *  for (int i = 0; i < normalCount; i++)
             *  {
             *      normals.Add(rhinoMesh.Normals[i].ToUnityVector());
             *  }
             * }
             * else
             * {
             *  unityMesh.RecalculateNormals();
             * }
             *
             *
             *
             #endregion
             */
            #region Convert UVs

            if (uvCount > 0)
            {
                for (int i = 0; i < uvCount; i++)
                {
                    uvs.Add(rhinoMesh.TextureCoordinates[i].ToUnityVector());
                }
            }

            #endregion

            #region Convert Colors
            if (colorCount > 0)
            {
                for (int i = 0; i < colorCount; i++)
                {
                    colors.Add(rhinoMesh.VertexColors[i].ToUnityColor());
                }
            }

            unityMesh.SetColors(colors);

            #endregion

            unityMesh.RecalculateNormals();
            unityMesh.RecalculateTangents();
            unityMesh.RecalculateBounds();
        }
Example #8
0
 public MeshSimplify_Face(int a, int b, int c)
 {
     this.face = new MeshFace(a, b, c);
 }
Example #9
0
 public MeshSimplify_Face(MeshFace f)
 {
     this.face = f;
 }