Created
April 4, 2015 10:35
-
-
Save sugi-cho/3acacf4f9564a6126da1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
public class BakeTransformToMesh | |
{ | |
[MenuItem("sugi.cho/Mesh/Bake Transform")] | |
public static void BakeTransform () | |
{ | |
var targetGo = Selection.activeGameObject; | |
if (targetGo == null || targetGo.GetComponent<MeshFilter> () == null) | |
return; | |
var targetMesh = targetGo.GetComponent<MeshFilter> ().sharedMesh; | |
if (targetMesh == null) | |
return; | |
var mesh = new Mesh (); | |
var ci = new CombineInstance (); | |
ci.mesh = targetMesh; | |
ci.transform = targetGo.transform.localToWorldMatrix; | |
mesh.CombineMeshes (new CombineInstance[]{ci}); | |
mesh.RecalculateNormals (); | |
mesh.RecalculateBounds (); | |
AssetDatabase.CreateAsset (mesh, "Assets/" + targetGo.name + "_BakeTransform" + ".asset"); | |
AssetDatabase.SaveAssets (); | |
AssetDatabase.Refresh (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment