├── LICENSE ├── MeshSaver-screenshot.png ├── MeshSaver ├── Editor.meta └── Editor │ ├── MeshSaverEditor.cs │ └── MeshSaverEditor.cs.meta └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 John 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MeshSaver-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pharan/Unity-MeshSaver/e6025eaca3203baf2427de873863c2d5904a1cc6/MeshSaver-screenshot.png -------------------------------------------------------------------------------- /MeshSaver/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c49dd254a322f1a4b96a3b39bf78bb7e 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /MeshSaver/Editor/MeshSaverEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | 3 | using UnityEngine; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | public static class MeshSaverEditor { 8 | 9 | [MenuItem("CONTEXT/MeshFilter/Save Mesh...")] 10 | public static void SaveMeshInPlace (MenuCommand menuCommand) { 11 | MeshFilter mf = menuCommand.context as MeshFilter; 12 | Mesh m = mf.sharedMesh; 13 | SaveMesh(m, m.name, false, true); 14 | } 15 | 16 | [MenuItem("CONTEXT/MeshFilter/Save Mesh As New Instance...")] 17 | public static void SaveMeshNewInstanceItem (MenuCommand menuCommand) { 18 | MeshFilter mf = menuCommand.context as MeshFilter; 19 | Mesh m = mf.sharedMesh; 20 | SaveMesh(m, m.name, true, true); 21 | } 22 | 23 | public static void SaveMesh (Mesh mesh, string name, bool makeNewInstance, bool optimizeMesh) { 24 | string path = EditorUtility.SaveFilePanel("Save Separate Mesh Asset", "Assets/", name, "asset"); 25 | if (string.IsNullOrEmpty(path)) return; 26 | 27 | path = FileUtil.GetProjectRelativePath(path); 28 | 29 | Mesh meshToSave = (makeNewInstance) ? Object.Instantiate(mesh) as Mesh : mesh; 30 | 31 | if (optimizeMesh) 32 | MeshUtility.Optimize(meshToSave); 33 | 34 | AssetDatabase.CreateAsset(meshToSave, path); 35 | AssetDatabase.SaveAssets(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /MeshSaver/Editor/MeshSaverEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7030626f9649cdd42865be1523f381b4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity-MeshSaver 2 | Save your Mesh as an asset file. 3 | 4 | This UnityEditor script adds context menu items to your MeshFilter component, allowing you to save its UnityEngine.Mesh object as a .asset file that you can then reuse in your project. 5 | 6 | This is great for saving procedurally generated meshes that may be too resource-intensive to generate at runtime. 7 | 8 | # How to Install 9 | Just copy the folder called MeshSaver into your project's Assets folder, or drag it into Unity's project panel. 10 | 11 | # How to Use 12 | ![](MeshSaver-screenshot.png) 13 | 14 | 1. Right click on a MeshFilter component's label or click on its gear icon to open up its context menu. 15 | 2. Then select either "Save Mesh..." or "Save Mesh As New Instance...". 16 | 17 | **Save Mesh...** will save the current shared mesh as an asset file. 18 | **Save Mesh As New Instance...** will save a copy of the current mesh. 19 | 20 | Note that "Save Mesh..." will not work if the mesh comes from an imported 3D asset/prefab. 21 | --------------------------------------------------------------------------------