Пример #1
0
        /// <summary>
        /// Creates an array of Sub Division Mesh from the .Obj file given by the user.
        /// Each Group within the .Obj file is represented by one SubDivsion Mesh.
        /// </summary>
        /// <param name="filePath">The file to be imported</param>
        /// <returns></returns>
        public static DSSubDivisionMesh[] ImportFromOBJ(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new System.ArgumentNullException("filePath");
            }
            filePath = DSGeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }
            DSMeshData result = ObjHandler.Import(filePath);

            return(result.ConvertToSubDivisionMesh());
        }
Пример #2
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));
        }