internal override DSGeometry TransformBy(ICoordinateSystemEntity csEntity)
        {
            DSSubDivisionMesh mesh = base.TransformBy(csEntity) as DSSubDivisionMesh;

            mesh.SubDivisionLevel = this.SubDivisionLevel;
            return(mesh);
        }
        protected override DSGeometry Translate(DSVector offset)
        {
            DSSubDivisionMesh mesh = base.Translate(offset) as DSSubDivisionMesh;

            if (null != mesh)
            {
                mesh.SubDivisionLevel = SubDivisionLevel;
            }

            return(mesh);
        }
Example #3
0
        public IContextData[] ImportData(Dictionary <string, object> connectionParameters)
        {
            List <DSGeometry> geometryList = new List <DSGeometry>();

            DSGeometry[] geometry = null;
            foreach (var param in connectionParameters)
            {
                switch (param.Key)
                {
                case "OBJ":
                    geometry = DSSubDivisionMesh.ImportFromOBJ(Convert.ToString(param.Value));
                    break;

                case "SAT":
                    geometry = DSGeometry.ImportFromSAT(Convert.ToString(param.Value));
                    break;

                default:
                    if (param.Value.GetType().IsArray)
                    {
                        Array data = param.Value as Array;
                        geometry = GeometryDataSerializer.CreateGeometryFromData(param.Key, data);
                    }
                    break;
                }
                if (null != geometry && geometry.Length > 0)
                {
                    geometryList.AddRange(geometry);
                }
            }

            int nItems = geometryList.Count;

            if (nItems == 0)
            {
                return(null);
            }

            IContextData[] contextData = new IContextData[nItems];
            for (int i = 0; i < nItems; ++i)
            {
                contextData[i] = new GeometryData("ImportData", geometryList[i], this);
            }
            return(contextData);
        }
        /// <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);
        }
        /// <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);
        }
Example #6
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;
        }
Example #7
0
 /// <summary>
 /// Exports the SubDivision meshes provided by the user to an .Obj file. Each Subvision Mesh
 /// is represented by a group. Groups are automatically named.
 /// </summary>
 /// <param name="mesh">The SubDivision Mesh array to be exported in one file</param>
 /// <param name="filePath">The meshes are exported to this file Path, or the active directory if only file name is provided</param>
 /// <returns></returns>
 public static bool ExportToOBJ(DSSubDivisionMesh[] mesh, string filePath)
 {
     if (mesh == null || mesh.Length == 0)
         throw new System.ArgumentNullException("mesh");
     if (string.IsNullOrWhiteSpace(filePath))
         throw new System.ArgumentNullException("filePath");
     DSMeshData meshData = new DSMeshData();
     for (int i = 0; i < mesh.Length; ++i)
     {
         meshData.AddGroup("Group_" + i);
         foreach (var vertices in mesh[i].FaceIndices)
         {
             for (int j = 0; j < vertices.Length; ++j)
                 vertices[j] += meshData.Vertices.Count + 1;
             meshData.Groups[i].AddFace(vertices);
         }
         meshData.Vertices.AddRange(mesh[i].Vertices);
     }
     if (!filePath.EndsWith(".obj"))
         filePath += ".obj";
     if (!Path.IsPathRooted(filePath))
     {
         string foldername = Path.GetDirectoryName(DSGeometrySettings.RootModulePath);
         filePath = Path.Combine(foldername, filePath);
     }
     return ObjHandler.Export(meshData, filePath);
 }
Example #8
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;
        }