Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeshSync UV0 Green Channel Flip Issue #940

Open
minirebel3 opened this issue Nov 2, 2023 · 2 comments
Open

MeshSync UV0 Green Channel Flip Issue #940

minirebel3 opened this issue Nov 2, 2023 · 2 comments

Comments

@minirebel3
Copy link

minirebel3 commented Nov 2, 2023

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

@K4N114
Copy link

K4N114 commented Aug 26, 2024

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;

@minirebel3
Copy link
Author

Thank you @K4N114 for your suggestion, when I find the time to start using MeshSync again, I will try to check this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants