[Addon] Masked Smooth Normals (custom normals based on face selection)

Blender recently added support for custom vertex normals, although it doesn’t have a lot of good tools dedicated to editing them. I decided to make a tool that allows quick smoothing of vertex normals based on the current selection so that I can use it to improve the shading of my game models.


/uploads/default/original/4X/8/6/3/86301c4b4840fbf90199ef07948a9df597f04a2c.pngstc=1

version 0.0.4:

  • New smoothing algorithm. Face Weighted Normals - works on selections in edit mode and on everything in object mode.
  • Set Direction tool works properly on vertex and edge selections.
  • Set Direction tool now has an option to keep normals from splitting at selection edges.
  • Slight UI Panel cleanup

version 0.0.3:

  • Flip custom normals
  • Harden selected faces (edge and vertex harden to come later)
  • Set normals of selected faces using direction widget (in redo panel only for now… sorry)
  • mask by faces only disabled by default

version 0.0.2:

  • Automatically enable autosmooth
  • Never show when not in mesh edit mode
  • Can smooth by selected edges
  • Can smooth by selected vertices
  • Can set tool option to only use face selection regardless of selection mode
  • Small UI that appears in Tools > Shading / UVs in edit mode (not very useful currently…)
  • Code cleanup :smiley:

Download:
Available in a github repo: https://github.com/andyp123/blender_mesh_masked_smooth_normals
zip: https://github.com/andyp123/blender_mesh_masked_smooth_normals/archive/master.zip
extract the .py file from this zip and install using Blender’s addon install from script function.

Operation:

  1. With a mesh in edit mode select the faces that you’d like to smooth, making sure that any you don’t want to influence the result are not selected.
  2. Press [space] type in ‘masked soften normals’ and select it to run the script.
    Alternatively, open the Shading / UVs panel and there is a button that will do the same thing.

If you want to restore normal blobby smooth shading, then either select all faces and run the script as above, or disable autosmooth.

I hope this is of use to someone other than myself, and if so, I’ll try and fix any bugs that crop up, and maybe add some new features. Note that there are already a couple of more complex normal editing tools that are much better for people that want fine control over the normals. If these tools add a similar feature to Masked Smooth Normals, then I’ll probably stop working on it.

Attachments



Very cool job

Thank you. I’ve been needing this. I usually export the mesh and edit normals in another program and reimport. I hope this fixes my issues.

oh yes…really nice.
Thank you

Thank you, it targeted a missing feature in Blender; do you plan to develop it more like offering something like ‘smoothing groups’ in Max?
One of the reason I have to use Max near Blender is the handling of smoothing; it would be great to step over it. I would even donate some money for implementing it somehow.

Thanks

This is how it works in Max: https://youtu.be/-Iswm1xKtGs

Thanks for the comments. I will try and fix any problems you come across and have also done a little bit of work to improve the script today.

Small update to v0.0.2

  • Automatically enable autosmooth
  • Never show when not in mesh edit mode
  • Can smooth by selected edges
  • Can smooth by selected vertices
  • Can set tool option to only use face selection regardless of selection mode
  • Small UI that appears in Tools > Shading / UVs in edit mode (not very useful currently…)
  • Code cleanup :smiley:

To-Do:

  • Add soften based on sharp edges
  • Add harden by selected vertices
  • Add harden by selected edges
  • Add harden by selected faces
  • Clean up UI and unify language with Blender’s language (sharp/smooth?)
  • Make the only use face mask option available in the addon prefs?

Now available in a github repo: https://github.com/andyp123/blender_mesh_masked_smooth_normals
zip: https://github.com/andyp123/blender_mesh_masked_smooth_normals/archive/master.zip
extract the .py file from this zip and install using Blender’s addon install from script function.

Very nice work!
Is it possible to assign a hotkey by default (maybe with built-in custom assignment)? Thx.

AlmaTalp: I’m not going to attempt a Max style smoothing group editor, as I actually hated that system when using Max. Blender already has a Maya-style smooth face/edge/vertex feature that should work when autosmooth is enabled, although it doesn’t seem to work when you are using custom normals, so doesn’t play nice with my script. I will next try to modify my script so that it can smooth based on sharp edges set from the Blender Shading / UVs panel.

I see, thx. What do you think about a hotkey?

I’m not sure actually. I was thinking about trying to add it to the specials menu and see if I can figure out how to expose it to the user prefs so you can assign your own hotkey. Blender already uses a crazy number of shortcuts and I’d rather not add more by default if I can help it. Maybe I could enable the hotkey in the addon prefs. I’ll really have to have a think about how to do it.

To be honest the problem with the crazy amount of Blender hotkeys is that Blender uses hotkeys for unnecessary things in many cases (rarely used ones). Your add-on will be an ‘always used’ one for any proper modeling process. Also it is a problem that both Toolbox and Properties Menu represents a terrible GUI design concept which is everything but not not user-friendly/informative/fast to access anything.
So hotkeys would be an alternative solution; with customizing option it would allow to replace never used ones.

Another small update today. I really need to sit down and spend some time to polish this, as the way custom normals are implemented in Blender makes doing a lot of the stuff I’d like to do more fiddly than it needs to be (would be so easy if it was pure bmesh…) and so I don’t make much progress each time I work on it :confused: I also forgot how to write python code, so I’m doing a lot of looking at Python docs on top of the Blender API docs. Still, I’ll try and make this as usable as I can little by little :slight_smile:

Here’s what’s new in v0.0.3

  • Flip custom normals (based on sample code by mont29)
  • Harden selected faces (no edge/vertex harden atm, because it requires a lot of annoying mesh traversal I think)
  • Set normals of selected faces using direction widget (appears only in redo panel… sorry for being lame)

TODO:

  • improve functionality of harden
  • use hard edges to autosmooth
  • better control over setting specific normals
  • average merge split normals as average of existing custom normals (rather than just face normal average)
  • rename everything to make more sense and make sure language is consistent
  • shortcut support

Available in a github repo: https://github.com/andyp123/blender_…smooth_normals
zip: https://github.com/andyp123/blender_…ive/master.zip
extract the .py file from this zip and install using Blender’s addon install from script function.

Very usefull, thanks!

I was looking something like this to use after automatically weighting normals. Addon that can be used to manipulate, tweak and polish larger flat and curvy hard surface areas manually more faster at once, than go one face at the time.

Looking forward for next version.

Finally Blender starts to have nice combination of addons/tools to edit custom vertex normals for different situations.

just wanted to say thanks a lot for this script, and I’m looking forward to any additional development you might do on it!

I’m the sole artist on a team of 3 working on a game, I’m using blender for block-ins and retopo.

This script has allowed me to finally take advantage of better baking workflows for my assets, and now I can all kinds of nice things with my models without ruining how they interact with the normal maps! For example here’s some WIP shots of a tiling wooden plank I’m going to reuse all over the environment in different ways:




anyways, just wanted to say thanks, and let you know that I’m using this add-on with most models I’m creating for this game environment :slight_smile:

Although I haven’t added any of the items on my TODO list, I thought I would add the face weighted normals smoothing algorithm to make it easier to quickly get acceptable results with less manual effort. This uses the area of faces around a vertex to set the influence the face will have on the smoothed normal. This means that in many cases you can get a decent smoothing by simply selecting all faces and running the new ‘Face Weighted Normals’ operator. Because of this, I enabled its use in object mode as well as edit mode.

v.0.0.4 changes

  • New smoothing algorithm. Face weighted normals - works on selections in edit mode and on everything in object mode.
  • Set Direction tool works properly on vertex and edge selections.
  • Set Direction tool now has an option to keep normals from splitting at selection edges.
  • Slight UI Panel cleanup

Available in a github repo: https://github.com/andyp123/blender_…smooth_normals
zip: https://github.com/andyp123/blender_…ive/master.zip
extract the .py file from this zip and install using Blender’s addon install from script function.

Attachments


Thanks!!!

p2o, therealmarkehle, raziel_henzo: Glad you found some use for the tool. I really made it for myself so that I could effectively use Blender at work where we were making a game using cell shading outline effects so the normals could not be split, but it’s good that some others have been able to benefit from it.

If anyone has any feature requests or other suggestions, please let me know in this thread and I’ll think about doing them (I can’t guarantee anything of course, but I would like ideas for further development).

Damn. I left a really stupid bug in the script that is fixed now. I didn’t test it properly until today, so sorry if anyone was using it and was inconvenienced by this issue.