Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Mirror a 3d model?

Discussion in 'Scripting' started by jessee03, Sep 26, 2022.

  1. jessee03

    jessee03

    Joined:
    Apr 27, 2011
    Posts:
    729
    Is it possible to mirror a 3d model through code? Want to do this for shoulder armor equipment prefab without needing to create two separate 3d models.
     
  2. mopthrow

    mopthrow

    Joined:
    May 8, 2020
    Posts:
    348
    One way would be to set the scale to -1 in the axis you'd like to mirror.
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,070
    Yes, it is possible. There are three approaches I can think of.

    The most obvious one is already mentioned, but there might be issues with this approach. Rendering may be broken in some cases, or there might be glitches due to lighting or because how colliders work.

    The other is a visual one, where you mirror the thing in the shader. However there are so many edge-cases to consider if you intend this mesh to live together with non-flipped ones. It's an ok solution for a UI, for example, when the mesh lives in isolation, but if not you need to be able to work with shaders to pull this off, and it's not worth the effort.

    The third solution is to basically recreate the mesh fully in code, but then you have to pay attention to how triangles are flipped (but also UVs and normals to match everything), which isn't hard if you know how to work with meshes in Unity C#, but at this point it's worth asking yourself, why not do it in Blender properly?
     
    Last edited: Sep 26, 2022
    AnimalMan likes this.
  4. jessee03

    jessee03

    Joined:
    Apr 27, 2011
    Posts:
    729
    Looks like this is a working solution. Hopefully won't notice any graphical issues