Search Unity

Wrong baking after Unwrapping.GenerateSecondaryUVSet()

Discussion in 'Global Illumination' started by tokareuv, Sep 7, 2017.

  1. tokareuv

    tokareuv

    Joined:
    Sep 28, 2016
    Posts:
    6
    I've met a problem with generating UV2 field for generated meshes using Unwrapping.GenerateSecondaryUVSet(). I thought this problem is somehow related to the way I've created these meshes, though it happens even for standard Unity objects.
    Suppose we have these lighting setting
    upload_2017-9-7_8-3-44.png
    and settings for directional light
    upload_2017-9-7_8-5-29.png
    Now for the lone object we have this code:
    Code (CSharp):
    1.     static public void GenerateSecUV()
    2.     {
    3.         var currentScene = EditorSceneManager.GetActiveScene ();
    4.         Transform selection = Selection.GetTransforms (SelectionMode.Editable | SelectionMode.ExcludePrefab)[0];
    5.         var meshF = selection.GetComponent<MeshFilter> ()ж
    6.         Mesh mesh = mesh.sharedMesh;
    7.         Unwrapping.GenerateSecondaryUVSet (mesh);
    8.         EditorSceneManager.MarkSceneDirty(currentScene);
    9.         EditorSceneManager.SaveScene (currentScene);
    10.     }
    Now let us have standard Unity cube, use beforementioned code, nake him static and bake with these parameters.
    upload_2017-9-7_8-14-5.png
    Now we have some creepy thing. Looking at baked UV we can see this:
    upload_2017-9-7_8-15-39.png
    upload_2017-9-7_8-15-55.png
    The same thing happen when I tried to bake my own generated object (sofa). It was like baking happened at the right places (where UV coords are) but with wrong light and not "complete".

    I have new Unity 2017.1.1f1. I've had the same problem with Unity 5 and thought it's some bag of Unity. It seems it is not the case...
     
    Last edited: Sep 7, 2017
  2. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377
    It is very dangerous to use
    Unwrapping.GenerateSecondaryUVSet()
    on generated meshes. It will change your mesh data, including uv, indices and even vertices!

    You can compare the mesh data before and after calling
    Unwrapping.GenerateSecondaryUVSet()
    to inspect that.