Home Technical Talk

Blender - Mirroring Custom Normals

Hello everyone!

First time asking a question on here, I have scoured the internet and found truly no answers on this problem.

I have a gun that has custom vertex normals using the addon yavne. The custom normals are there so I can get a clean bake. I quickly learned it seems impossible to mirror custom normals... I have seen others with this issue and people just responded with "You can't mirror custom normals."

My first thought was: "NO! This makes custom normals impossible with Blender then... I mean it is possible but if it can't be mirrored then what's the point?"

It seems like my only solution is to export my model to 3DS Max or Maya then bring it back...

I did find this: https://developer.blender.org/T47041

It is a known issue but after 3 years it still has not been solved...

Blender is my favorite modelling tool but I have used many others. Every now and then I run into an issue like this with Blender that just makes it seem like a "game over" situation...

I just don't know what to do and if I can't figure out something I can't complete the project...

Thanks in advance.

Replies

  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    Yea custom normals have very limited support in Blender (same goes for 3DSMax). Best solution is to just leave the normals alone until you're done with your model, and customize them on the otherwise finished piece. Customizing normals while still working on the model is a bad idea.
  • RN
    Options
    Offline / Send Message
    RN sublime tool
    Yavne writes custom normals for vertices. So it's possible to set an arbitrary normal on a given vertex.

    If you know what "mirroring custom normals" means then it might be possible to write a script that does that.

    Say, the mesh is centred at the world origin, you have two vertices, one is opposite to the other based on a world axis. On either of the vertices, you take the normal of the other one, flip that normal on that axis and then use it as its own normal? Is this what normal mirroring is?
  • keegankeene
    Options
    Offline / Send Message
    PolyHertz said:
    Yea custom normals have very limited support in Blender (same goes for 3DSMax). Best solution is to just leave the normals alone until you're done with your model, and customize them on the otherwise finished piece. Customizing normals while still working on the model is a bad idea.
    The modelling is all done. The model is perfectly symmetrical so I decided it would be twice as fast if I edited the normals on one half then just mirrored. Had no clue it would not mirror... It take hours to get all the normals edited. I had edit some vertices to very specific values so if I already have the model mirrored and have to manually copy the values by hand I would die for exhaustion.

    RN said:
    Yavne writes custom normals for vertices. So it's possible to set an arbitrary normal on a given vertex.

    If you know what "mirroring custom normals" means then it might be possible to write a script that does that.

    Say, the mesh is centred at the world origin, you have two vertices, one is opposite to the other based on a world axis. On either of the vertices, you take the normal of the other one, flip that normal on that axis and then use it as its own normal? Is this what normal mirroring is?
    Yeah... I keep telling myself I need to learn how to code... 


    I guess I have no choice but to mirror then edit both sides at the same time and die from boredom... I feel like thousands of people would be complaining about this issue but a lot of people I talked to had no clue why someone would want to edit the normals to improve the bake... I did not either for a long time though.

    Well, I guess I know what to do now, unless there is some answer elsewhere but it seems unlikely. Maybe yavne will get a mirror normals feature. Maybe I should mention that to the dev.

    Thanks!
  • thomasp
    Options
    Offline / Send Message
    thomasp hero character
    have you tried the data transfer modifier?

    - duplicate mesh-half with custom normals, mirror on X axis and leave as is
    - duplicate from same source, mirror, clear out the stack and then apply transforms/reset xform
    (at that stage any custom normals are likely gone - no experience with YAVNE here though)
    - apply data transfer modifier on that second object, set the first one containing the normals you want as the source
    - activate 'face corner data' and 'custom normals'. set to 'nearest corner of nearest face'
    - apply modifier

    quick test here suggests this will work. you might still end up with a visible seam down the mirror center which will need manual attention.

  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    One other thing you might try is the "GSoC 2017 - Normal Editing Tools" branch of blender: https://blenderartists.org/forum/showthread.php?427746-GSoC-2017-Normal-Editing-Tools"

    I tried creating custom normals in that version on a simple model using the built in tools and using mirror, and other then needing to clean up normals along the seam it worked ok.
  • keegankeene
    Options
    Offline / Send Message
    thomasp said:
    have you tried the data transfer modifier?

    - duplicate mesh-half with custom normals, mirror on X axis and leave as is
    - duplicate from same source, mirror, clear out the stack and then apply transforms/reset xform
    (at that stage any custom normals are likely gone - no experience with YAVNE here though)
    - apply data transfer modifier on that second object, set the first one containing the normals you want as the source
    - activate 'face corner data' and 'custom normals'. set to 'nearest corner of nearest face'
    - apply modifier

    quick test here suggests this will work. you might still end up with a visible seam down the mirror center which will need manual attention.

    THIS WORKED! I tried doing this but with yavne transfer normals. Did not work as well as the data transfer modifier.

    PolyHertz said:
    One other thing you might try is the "GSoC 2017 - Normal Editing Tools" branch of blender: https://blenderartists.org/forum/showthread.php?427746-GSoC-2017-Normal-Editing-Tools"

    I tried creating custom normals in that version on a simple model using the built in tools and using mirror, and other then needing to clean up normals along the seam it worked ok.
    Have not tried this but if it worked for you then it will probably work for me.


    Thanks everyone! Maybe I should ask questions more often.


    Edit: Actually... upon further inspection the normals are better but they are still looking a bit off... I also can't edit any normals after doing this or else the half that was duplicated breaks its normals...

    Will post back later with better details. Gotta go to work.
  • MACHIN3
    Options
    Offline / Send Message
    MACHIN3 sublime tool
    RN said:
    If you know what "mirroring custom normals" means then it might be possible to write a script that does that.
    Mirroring normals is very simple. If you want to mirror across x in either direction, in blender you just do:

    mirror_normal = orig_normal.reflect(1, 0, 0)
    The harder part is associating the loops(which is where the per face vertex normals sit) on the mirrored geometry to the loops on the original geometry.

    Happy to say, that I managed to do that :)



  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    Hello @MACHIN3 -
    Could you explain a bit more what is happening in this video - basically, what is being transferred to what ?

    I understand the end result but I am having trouble visualizing the input and conditions. Looks like the normals of the outer edges of the selection "islands" are being transferred to anything else strictly within that area (excluding the border itself of course) ?

    (In any case that looks pretty damn great - I am just trying to understand a bit more what's going on to see if it could be applied to some of things I am thinking of working on next)
  • MACHIN3
    Options
    Offline / Send Message
    MACHIN3 sublime tool
    Watch closely when I start the tool. The mesh wire disappears and a low opacity white wireframe appears.

    This is the wireframe of a "stash", which is a duplicate of the mesh made before the detail was cut in.  An object can have many stashes and you can scroll though them to select which one you use. You can stash the active mesh or you can stash an object to another one.
    The stash is used as the source for the normals by the Normal Transfer tool. You can also use them as just backups.

    The selection masks where the transfered normals are applied. Usually the border edges/verts of the details are sufficient, but it was much simpler to select the faces here.
  • RN
    Options
    Offline / Send Message
    RN sublime tool
    MACHIN3 said:
    The harder part is associating the loops(which is where the per face vertex normals sit) on the mirrored geometry to the loops on the original geometry.

    Happy to say, that I managed to do that :)
    Woh, that's a doozy. In Blender it seems to match vertices either by location or by similarity in edge count (the "Use Topolgy" option). The code that finds symmetrical vertices is this: https://github.com/dfelinto/blender/blob/master/source/blender/editors/mesh/mesh_mirror.c#L175
    Is that what you meant?
  • MACHIN3
    Options
    Offline / Send Message
    MACHIN3 sublime tool
    No,  not quite. Pairing vertices is only the first step. You can do it even by index(after a symmetrize op), but I also have a location based method as a fall back. You'll then also need to pair the faces and only once you have both - vert pairs and face pairs - can you uniquely identify and pair the per face vertex loops, which hold the normals you want to mirror.
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    Thank you for the breakdown ! Makes sense.
  • MACHIN3
    Options
    Offline / Send Message
    MACHIN3 sublime tool
    More mirror related custom normal stuff:

    I've been working on a tool to turn mirror mods into real geometry, with proper origins and orientations and proper custom normals.
    This tool is also essential if you are doing object space texturing, as the mirror mod in blender messes with this as well (understandably) as shown in the second part of the video.


    What's interesting is, unlike for  the symmetrize tool,  I didn't have to reflect the loop normals across the mirror axis, but across themselves instead.
    I'm not sure I fully grasp why yet, but I guess it makes sense in a way, as the face normals had to be flipped as well after the mirror(neg scale) was applied.

    Glad to have this sorted now.

    edit:
    in the above video you can see I've got an orientation inversion, where z is down where the original is up. Initially I thought this was unavoidable and result of maintaining axis order in the coordinate system, but it  was actually just  a 180° rotation, ha.
    I have now applied that rotation as well, and interestingly it required me to also change how the mirror normals are created. I now need to reflect the original normals across the mirror axis, which I had expected to be required at the very beginning. No more reflecting across itself. I stiil don't fully grasp why that was required before, but it's all working perfectly now with better orientation even.


Sign In or Register to comment.