Last active
December 14, 2015 19:39
-
-
Save RodGreen/5138155 to your computer and use it in GitHub Desktop.
Unity - PostProcess Model - Swap UVs
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
#define DEBUG_ON | |
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class SwapUVs : AssetPostprocessor | |
{ | |
const string CLabel = "pp_swapuvs"; // Asset needs to have this label to be processed | |
void OnPostprocessModel (GameObject g) | |
{ | |
Apply (g.transform); | |
} | |
void Apply (Transform transform) | |
{ | |
var assetLabels = new List<string> (AssetDatabase.GetLabels (assetImporter)); | |
if (!assetLabels.Contains (CLabel)) // Contains label? | |
return; | |
var thisMeshFilter = transform.GetComponent<MeshFilter> (); | |
if (thisMeshFilter == null) | |
return; | |
var thisMesh = thisMeshFilter.sharedMesh; | |
if (thisMesh == null) | |
return; | |
if (thisMesh.uv2 == null) // Not sure if it's possible for this to return null, but JIC | |
return; | |
var uv1 = thisMesh.uv; | |
thisMesh.uv = thisMesh.uv2; | |
thisMesh.uv2 = uv1; | |
#if DEBUG_ON | |
Debug.Log (string.Format ("Swapped UVs for {0}", transform.name)); | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment