unity3d-jp/MeshSync

MeshSync UV0 Green Channel Flip Issue

martin-mikulic opened this issue · 2 comments

MeshSync UV0 Green Channel Flip Issue

When importing meshes with MeshSync, UV0 has the green channel flipped, while UV1 appears duplicated UV0 but with correct green channel.
When i switch material to use UV1 it looks correct as the default unity plane

I tested this also importing from 3ds max 2023, 2022, and blender and it behaves the same.
I tested it with auto exported meshes -||-
When I export .fbx from max this doesn't happen.

I don't want to switch all of my many unity materials to use UV1 as a base.
I am saying "green channel flip" because when i use the swizzle for the normal map green channel to "1-G" material shows correctly on meshsync meshes but then it's wrong on every other fbx mesh

Is there a way to make meshsync swap those two channels on import
Thanks

Unity version: Unity 2023.3.12f1
Unity version: Unity 2022

MeshSync version: MeshSync 0.16
MeshSync version: MeshSync 0.17.3
Operating system: Windows 10

meshsync-bug

I found a possible solution.
This could be caused by a tangent inversion of the model when importing model from dcc.
Try reversing the tangent with the following code.

    public MeshSyncServer target;
------
    void Reverse(NetworkMessageType t)
    {
        foreach(MeshFilter filter in target.transform.GetComponentsInChildren<MeshFilter>())
        {
            if (filter != null)
            {
                Mesh mesh = filter.sharedMesh;
            
                Vector4[] tangents = mesh.tangents;
                for (int i = 0; i < tangents.Length; i++)
                {
                    tangents[i] = new Vector4(tangents[i].x, tangents[i].y, tangents[i].z, -1);
                }
                mesh.tangents = tangents;
            }
        }
    }    
------
    //When OnEnable()
    target = GameObject.FindObjectOfType<MeshSyncServer>();
    target.OnPostRecvMessageCallback += Reverse;