- Home /
Best Answer
Answer by liszto · Sep 04, 2012 at 11:53 AM
Ok I got an answer if some people are interesting to do this :
//Recursive function switch all uv2 of mesh to true
private void GenerateLightMapUV2( GameObject gameObject )
{
MeshFilter meshFilter = gameObject.GetComponent<MeshFilter>();
MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();
//Check if my mesh have and filter and a renderer so it's the final
if( meshFilter != null && meshRenderer != null )
{
//Take the mesh of the file
Mesh meshLightmapped = meshFilter.sharedMesh;
//Take the file's path and put it in a string
string path = AssetDatabase.GetAssetPath( meshLightmapped );
//Define a modelImporter to modify its importing settings
ModelImporter model = AssetImporter.GetAtPath( path ) as ModelImporter;
//Put the generateSecondaryUV field to true and GenerateUVSet for the mesh
model.generateSecondaryUV = true;
Unwrapping.GenerateSecondaryUVSet( meshLightmapped );
//Update the mesh setting in editor
AssetDatabase.ImportAsset( path );
}
//If the previous mesh don't have both so go in children
foreach( Transform t in gameObject.transform )
GenerateLightMapUV2( t.gameObject );
}
Your answer
Follow this Question
Related Questions
Lightmap Baking suddenly stops 0 Answers
Object odd light problem with mesh? 1 Answer
Automatically generate UVs for an imported mesh? 0 Answers
Mesh breaks apart when using vertex displacement with shadergraph. 3 Answers
Change uvs on texture packing 0 Answers