/// <summary> /// Exports the combined meshes to the folder selected in the Editor Window /// </summary> /// <param name="realAssetPath">The real asset path to be used by System.IO</param> private void ExportMeshes(string realAssetPath) { foreach (MeshFilter mf in _hiddenCombinedObject.GetComponentsInChildren <MeshFilter>()) { MeshExporter.MeshToFile(mf.sharedMesh, realAssetPath + mf.name.Replace('.', '_') + ".obj"); AssetPostprocessor proc = new AssetPostprocessor(); AssetDatabase.Refresh(); proc.assetPath = AssetDatabase.GetAssetPath(_exportFolder) + "/" + mf.name.Replace('.', '_') + ".obj"; ModelImporter importer = proc.assetImporter as ModelImporter; importer.generateSecondaryUV = _isGeneratingLightmapUVs; importer.generateAnimations = ModelImporterGenerateAnimations.None; importer.optimizeMesh = true; importer.importMaterials = false; AssetDatabase.ImportAsset(_exportPath + mf.name.Replace('.', '_') + ".obj", ImportAssetOptions.ForceUpdate); mf.sharedMesh = (Mesh)AssetDatabase.LoadAssetAtPath(_exportPath + mf.name.Replace('.', '_') + ".obj", typeof(Mesh)); AssetDatabase.DeleteAsset(_exportPath + "/Materials/" + mf.sharedMesh.name); if (AssetDatabase.LoadAllAssetsAtPath(_exportPath + "/Materials/").Length == 0) { FileUtil.DeleteFileOrDirectory(_exportPath + "/Materials"); } } AssetDatabase.Refresh(); PrefabUtility.CreatePrefab(_exportPath + "CombinedObject.prefab", _hiddenCombinedObject, ReplacePrefabOptions.ConnectToPrefab); }
/// <summary> /// Exports the combined meshes to the folder selected in the Editor Window /// </summary> /// <param name="realAssetPath">The real asset path to be used by System.IO</param> private void ExportMeshes(string realAssetPath) { string materialsPath = Path.Combine(_exportPath, "Materials"); char[] invalidChars = Path.GetInvalidFileNameChars(); foreach (MeshFilter mf in _hiddenCombinedObject.GetComponentsInChildren <MeshFilter>()) { string filename = mf.name; foreach (char c in invalidChars) { filename.Replace(c, '_'); } filename += ".obj"; if (MeshExporter.MeshToFile(mf.sharedMesh, realAssetPath + filename)) { AssetPostprocessor proc = new AssetPostprocessor(); AssetDatabase.Refresh(); //even though it cant get here, should double check that export folder is null or not proc.assetPath = Path.Combine(AssetDatabase.GetAssetPath(_exportFolder), filename); ModelImporter importer = proc.assetImporter as ModelImporter; importer.generateSecondaryUV = _isGeneratingLightmapUVs; importer.generateAnimations = ModelImporterGenerateAnimations.None; importer.optimizeMesh = true; importer.importMaterials = false; AssetDatabase.ImportAsset(Path.Combine(_exportPath, filename), ImportAssetOptions.ForceUpdate); mf.sharedMesh = (Mesh)AssetDatabase.LoadAssetAtPath(Path.Combine(_exportPath, filename), typeof(Mesh)); AssetDatabase.DeleteAsset(Path.Combine(materialsPath, mf.sharedMesh.name)); if (AssetDatabase.LoadAllAssetsAtPath(materialsPath).Length == 0) { FileUtil.DeleteFileOrDirectory(materialsPath); } } else { Debug.LogError("There was an issue exporting the mesh to " + realAssetPath + filename + ". Please double check your paths, names, and files. If this occurs frequently, create an issue, or vote for the existing issue if it already exists at (https://bitbucket.org/purdyjo/draw-call-minimizer/issues) and please include all information related to this issue to make the repair as fast and seamless as possible"); } } AssetDatabase.Refresh(); PrefabUtility.CreatePrefab(_exportPath + "CombinedObject.prefab", _hiddenCombinedObject, ReplacePrefabOptions.ConnectToPrefab); }