Exemplo n.º 1
0
        private IVector[] GetVertexNormals()
        {
            if (null == mVertexPositions || null == FaceIndices)
            {
                return(null);
            }

            IPointEntity[] points = mVertexPositions.ConvertAll(GeometryExtension.ToEntity <Point, IPointEntity>);
            using (ISubDMeshEntity mesh = HostFactory.Factory.SubDMeshByVerticesFaceIndices(points, FaceIndices, 0))
            {
                return(mesh.GetVertexNormals());
            }
        }
Exemplo n.º 2
0
 protected TopologyMesh(SubDivisionMesh mesh, bool persist = true)
 {
     m_meshEntity = GeometryExtension.ToEntity(mesh) as ISubDMeshEntity;
     if (null != m_meshEntity)
     {
         ISurfaceEntity surface = m_meshEntity.ConvertToSurface(false);
         if (persist)
         {
             IPersistenceManager persistence_manager = persistence_manager_property.GetValue(null, null) as IPersistenceManager;
             if (null != surface && null != persistence_manager)
                 m_brep = persistence_manager.Persist(surface) as IBRepEntity;
         }
         else
         if (null != surface)
             m_brep = surface as IBRepEntity;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a SubDivisionMesh from Solid or Surface geometry by faceting
        /// the faces of Solid or Surface.
        /// </summary>
        /// <param name="context">Input geometry, Solid or Surface.</param>
        /// <param name="maxEdgeLength">Maximum allowed edge length
        /// to define coarseness of the mesh.</param>
        /// <returns>SubDivisionMesh</returns>
        public static DSSubDivisionMesh FromGeometry(DSGeometry context, double maxEdgeLength)
        {
            string kMethodName = "DSSubDivisionMesh.FromGeometry";

            if (null == context)
            {
                throw new System.ArgumentNullException("context");
            }

            ISubDMeshEntity entity = HostFactory.Factory.SubDMeshFromGeometry(context.GeomEntity, maxEdgeLength);

            if (null == entity)
            {
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            DSSubDivisionMesh mesh = new DSSubDivisionMesh(entity, true);

            mesh.Context          = context;
            mesh.SubDivisionLevel = 0;
            return(mesh);
        }
Exemplo n.º 4
0
        private static ISubDMeshEntity ByVerticesFaceIndicesCore(DSPoint[] vertices, int[][] faceIndices, int subDivisionLevel)
        {
            string kMethodName = "DSSubDivisionMesh.ByVerticesFaceIndices";

            if (subDivisionLevel < 0 || subDivisionLevel >= 5)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "subDivisionLevel", kMethodName));
            }

            IPointEntity[] points = vertices.ConvertAll(DSGeometryExtension.ToEntity <DSPoint, IPointEntity>);
            if (points.Length < 3 || points.ArePointsColinear())
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "vertices", kMethodName));
            }

            ISubDMeshEntity entity = HostFactory.Factory.SubDMeshByVerticesFaceIndices(points, faceIndices, subDivisionLevel);

            if (null == entity)
            {
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs a subdivision mesh by vertex shading, given an input
        /// array of vertex points and an input array of faces defined by a set
        /// of numbers, which are the indices of the vertices in the 'vertices'
        /// array making up the face.
        /// </summary>
        /// <param name="vertices">Input array of vertex points</param>
        /// <param name="faceIndices">Input array of faces indices for each
        /// vertex </param>
        /// <param name="vertexNormals">Input array of vertex normals</param>
        /// <param name="vertexColors">Input array of color assigned to each
        /// vertex </param>
        /// <param name="subDivisionLevel">Initial smoothness level, subDivisionLevel must
        /// have a value greater than or equal to 0 and less than 5.</param>
        /// <returns>SubDivisionMesh</returns>
        public static DSSubDivisionMesh ByVerticesFaceIndices(DSPoint[] vertices,
                                                              int[][] faceIndices, DSVector[] vertexNormals, DSColor[] vertexColors, int subDivisionLevel)
        {
            string kMethodName = "DSSubDivisionMesh.ByVerticesFaceIndices";

            if (subDivisionLevel < 0 || subDivisionLevel >= 5)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "subDivisionLevel", kMethodName));
            }

            IPointEntity[] points = vertices.ConvertAll(DSGeometryExtension.ToEntity <DSPoint, IPointEntity>);
            if (points.Length < 3 || points.ArePointsColinear())
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "vertices", kMethodName));
            }

            ISubDMeshEntity entity = HostFactory.Factory.SubDMeshByVerticesFaceIndices(points, faceIndices, subDivisionLevel);

            if (null == entity)
            {
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            DSSubDivisionMesh mesh = new DSSubDivisionMesh(entity, true);

            try
            {
                if (null != vertexNormals && vertexNormals.Length > 0)
                {
                    if (vertexNormals.Length != entity.GetNumVertices())
                    {
                        throw new System.ArgumentException(string.Format(Properties.Resources.NotEqual, "size of vertexNormals", "number of vertices"), "vertexNormals");
                    }

                    if (!entity.UpdateSubDMeshNormals(vertexNormals.ConvertAll((DSVector v) => v.IVector)))
                    {
                        throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
                    }
                }

                if (null != vertexColors && vertexColors.Length > 0)
                {
                    if (subDivisionLevel > 0)
                    {
                        throw new System.InvalidOperationException(Properties.Resources.VertexColorNotSupported);
                    }

                    if (vertexColors.Length != entity.GetNumVertices())
                    {
                        throw new System.ArgumentException(string.Format(Properties.Resources.NotEqual, "size of vertexColors", "number of vertices"), "vertexColors");
                    }

                    if (!entity.UpdateSubDMeshColors(vertexColors.ConvertAll((DSColor c) => c.IColor)))
                    {
                        throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
                    }
                }
            }
            catch (System.Exception ex)
            {
                mesh.Dispose();
                throw ex;
            }

            mesh.SubDivisionLevel = subDivisionLevel;
            return(mesh);
        }
Exemplo n.º 6
0
 private DSSubDivisionMesh(ISubDMeshEntity host, bool persist = false)
     : base(host, persist)
 {
     InitializeGuaranteedProperties();
 }
Exemplo n.º 7
0
 private DSSubDivisionMesh(ISubDMeshEntity host, bool persist = false)
     : base(host, persist)
 {
     InitializeGuaranteedProperties();
 }