PDA

View Full Version : Editing vertex normals in Max, got scripts?


rasmus
08-11-2010, 03:15 AM
Hey folks,

Now that UDK started supporting custom vertex normals I'm struggling with the archaic Edit Normals modifier in Max and since Google fails me, I'm wondering if anyone has any nice tools or scripts to edit normals in Max in ways that are actually practical. Something like this script for Maya would be great!
http://migugi.net/mel/normalTools/

Specifically all I'm really interested in doing is this, as taken from the script above:
http://migugi.net/mel/normalTools/fig_fillet_3.png

(forcing the connected vertex normals of a certain face to redirect along the face normal)

Much love as always.

Bal
08-11-2010, 03:31 AM
Yeah, I'm interested in this for the same reasons, now that I can use edited vertex normals in UDK, I'm doing it all over the place.
But yeah, Max really isn't so hot for working with them, not only is the Edit Normals modifier kind of shitty, but max tends to mess up the edited normals alot depending on what you do to your model (like attaching stuff, or making other changes to the model).

The only script I have at the moment is one made by Zoffty (I can post it if someone is interested), it just averages the normals of your selected face when you run it, that works in many cases (in your example for instance Rasmus, it would work), but idealy it should align them to the face normal instead.

Ark
08-11-2010, 03:31 AM
Theres a couple of threads with some scripts and info:

http://www.polycount.com/forum/showthread.php?p=1149155#post1149155

http://www.polycount.com/forum/showthread.php?p=1152529#post1152529

Theres also some good stuff on the wiki under 'Environment Foilage' : http://wiki.polycount.com/CategoryEnvironment

rasmus
08-11-2010, 04:13 AM
Bal: Cool, mind posting it?

Ark: Thanks for the info - don't see exactly what I'm looking for but NormalThief looks useful.

I have a feeling this would be a breeze to whip up for anyone versed in MaxScript... I can promise big wet internet kisses to any and all takers :P Can't believe there aren't better tools for doing these things tbh, sort of like the same lack of quality tools when it comes to vertex colors.

Bal
08-11-2010, 04:32 AM
Here's the one I have rasmus, as I said, it's only really useful in some specific situations.


macroScript AverageNormal category:"zOffTy Tools" tooltip:" AverageNormal " buttonText: "AverageNormal"(
--================================================== ================================================== =======================
clearListener()
disableSceneRedraw()
---array pour stoker la face selectionné, et la futur conversion en normal
my_face = #{} --array pour la face selectionné
my_normals = #{} --array du resultat de la face

---defini la face selectionné
my_face = $.EditablePoly.GetSelection #Face

---rajoute un edit normal
modPanel.addModToSelection (Edit_Normals ()) ui:on
---passe en mode face
$.modifiers[#Edit_Normals].selectBy = 3
---clear les selections precedente
$.modifiers[#Edit_Normals].EditNormalsMod.SetSelection #{}
---converti la face en normal
$.Edit_Normals.ConvertFaceSelection &my_face &my_normals
$.modifiers[#Edit_Normals].EditNormalsMod.Select my_normals

---fait un reset de la face au cas ou elle serait déja normalisé
$.modifiers[#Edit_Normals].EditNormalsMod.Reset ()
--- fait l'average avec le thresold off
$.modifiers[#Edit_Normals].EditNormalsMod.Average useThresh:off threshold:0.1

---collapse le merdier et retour sous edit poly
maxOps.CollapseNodeTo $ 1 off
enableSceneRedraw()
subobjectLevel = 4
)--end macro

Eric Chadwick
08-11-2010, 06:53 AM
Here's a quicker version of the NormalThief script (copies normals from one object to another) http://www.polycount.com/forum/showthread.php?p=1178203#post1178203
Doesn't do exactly what you want tho.

The mig Normal Tools look great.

Eric Chadwick
08-11-2010, 07:36 AM
But yeah, Max really isn't so hot for working with them, not only is the Edit Normals modifier kind of shitty, but max tends to mess up the edited normals alot depending on what you do to your model (like attaching stuff, or making other changes to the model).

I looked into this awhile back, here are the (hidden) rules I uncovered.
http://wiki.polycount.com/VertexNormal#Editing_Normals_in_3ds_Max

Bal
08-11-2010, 12:08 PM
Cool, thanks Eric, I'd learnt most of this by trial and error, but never took the time to really try out what exactly works or doesn't work.

Eric Chadwick
08-11-2010, 02:02 PM
What's weird is they kind of fixed some of worser bits in 2010, but left the other problems in.

rasmus
08-19-2010, 08:38 AM
Hmm I'm stumped guys - can I implore someone out there to take a look at writing a quick script that does what my first post describes? It could be as simple as the script posted by Bal, anything would be really appreciated. By now a lot of people use UDK and MAX and the complete lack of adequate handling of vertex normals is making me a sad puppy... SyncView? Render? All you other wizards?

Basically what I'm imagining is:

1. Make a face selection.
2. Run script.
3. Vertices connected to the selected face have their normals realigned to this face normal.
4. Happy puppyness.

Neox
08-19-2010, 09:06 AM
isn't select faces and avarage selected doing pretty much this?

http://www.polyphobia.de/public/advices/normals.jpg

Eric Chadwick
08-19-2010, 09:18 AM
I think it is, as long as you do it on one polygon at a time. The normals for the faces at the far left in your example don't seem to be pointing along their face normals.

SyncViewS
08-19-2010, 09:30 AM
I'm on it, trying something simple to begin with, then add functionalities as needed. It will require an Edit Normals Modifier though. I'm starting with support for Editable Poly Object only, eventually extend to modifiers.

I take that selected contiguous faces keep the normals averaged between their normals. It implies that on a multiple face selection only the selection border vertexes get their normals reoriented. Is it right?

Neox
08-19-2010, 09:44 AM
yeah a bit bad example as its curved in space, on a flat plane it will do the normal you want, otherwise you'll have to do it on a per face level

Bal
08-19-2010, 10:56 AM
Neox, no doing average just averages the normals, if the angles of the neighboring faces are different, the resulting vector won't always be perpendicular to the face (which is what we want).

Idealy I'd like a script that takes all my selected faces one by one, and aligns the vertex normals so they are perpendicular to their face. Order doesn't really matter, as usually you'll always have either unselected faces between your selected one, or the faces are coplanar to begin with, so it's not an issue.
Maybe a box with x -x y -y z -z buttons as presets for vertex normals could come in handy too.

rasmus, did the script not work for you? It's not ideal but it still saves me some boring Edit Normals modifier work most of the time.

Eric Chadwick
08-19-2010, 12:07 PM
Idealy I'd like a script that takes all my selected faces one by one, and aligns the vertex normals so they are perpendicular to their face. Don't need a script for this really. Select your faces, add a Smooth modifier, collapse the stack, done.

SyncViewS
08-19-2010, 12:31 PM
Hi guys, I put together a fast script that should do the trick, it should be like the migNormalTools "Fillet Outside".

The script works on Editable Poly Objects only, and it must be the active object in the stack. If not present, the script adds an Edit Normals Modifier right above the base object. Just go into Face sub-object level, make a face selection and run the script.

Get the script here (http://dl.dropbox.com/u/1397854/polycount/stash/SetNormals_01.zip), and find it under Category: Rasmus Tools, Set Normals (sorry, this evening I'm running out of fantasy).

Bal
08-19-2010, 01:34 PM
SyncViews, this is great! Exactly what I wanted, now I just need to set it up so it auto collapses the Edit Normals afterwards (I never need to keep it around). Thanks alot.

Don't need a script for this really. Select your faces, add a Smooth modifier, collapse the stack, done.
What? I didn't know about the smooth modifier, but I really don't see how it helps here... It just seems to be reassigning smoothing groups, it's not affecting the vertex normals at all?

SyncViewS
08-19-2010, 01:44 PM
Hi Bal, I'm glad you like it. It is not super tested, so let me know about any issue.

If you want to collapse the Edit Normal modifier, just substitute line 81:

from
modPanel.setCurrentObject theEditObj
with
maxOps.collapseNodeTo theNode theNode.modifiers.count true

Eric Chadwick
08-19-2010, 01:52 PM
Smoothing groups do in fact edit the vertex normals. But I think it's not what you want anyhow, since it breaks the vertex normals on the edge of the selection, instead of just bending them.

Bal
08-19-2010, 01:57 PM
Eric, yeah I think you misunderstood what I wanted (or I didn't explain it clearly enough :). Had me worried there, thought for a second there was a modifier already present in max to do what I wanted all along, heh.

SyncViewS, works perfectly, you rock. Will tell you if I come across any problems.

rasmus
08-19-2010, 07:11 PM
Wow, now that's what I'm talking about! Works like a dream :) Thanks a million SyncView, you do indeed rock!

http://2.bp.blogspot.com/_SiVeRUcT19c/SGOOnRajRZI/AAAAAAAAAac/_5L6S4wfgpo/s400/puppy.jpg

Bal: Yeah I did get the script running (thanks) but I don't really see the use for the "Average"-function - to me this should be the same as just uniting the smoothing groups *opens can of worms* ;)

zOffTy
08-20-2010, 01:28 AM
yeah!
great tools
works better than mine !! :)

You can add a subobjectLevel = 4 to return in Face selection mod :p

Thanks a lot ;) !

Bal
08-20-2010, 01:33 AM
Ok, found a bug, or at least something unwanted I think.
If I apply the script on a face, that has a neighboring face on a separate smoothgroup, it's gonna edit the vertex normals of the neighboring face, aligning them with the ones from the selected faces, instead of just leaving them alone, fixable?

rasmus
08-20-2010, 01:38 AM
Bal: I think that's a matter of preference :) I'd have to test it some more, but from what I could see nothing happens to faces that don't share smoothing (unlike Maya, where editing normals naturally forces smoothing across the affected faces). What I'm saying is, I wish it did what you describe :) I had to set a common smoothing for the affected faces first, then run the script to see the effect (Max 2010 x64).

Bal
08-20-2010, 01:48 AM
Eh? Weird, I've tested it out in multiple cases, and it always changes the vertex normals of neighboring faces, even if they are in a different smooth group (so initially broken vertex normals). I'm using Max 2009, 32bit.

I don't really see the advantage of it doing this, can't imagine a situation where I'd want to. If I have a face on a different smoothing group, it's that I want that hard edge to stay.

rasmus
08-20-2010, 01:51 AM
Sure - I don't really mind it this way or that, but a bit odd that we get differences. Oh well.

SyncViewS
08-20-2010, 02:49 AM
Hi guys, Bal is right, before realigning normals, each vertex normals set is reset to one, so it does a sort of "unify" smoothing groups. I did it because it doesn't makes a lot of sense -just in my mind- to realign a splitted normal set, as it should already be perpendicular to the face normal. Anyway I already see a way to do that, it is only slightly longer to code. If you want it, just ask, I'll patch it as soon as possible.

Bal
08-20-2010, 03:07 AM
Yeah i definitely want it! I often have this kind of situation appear, where I have a neighboring face on a different smooth group, because of how I set up my modular normals.
Maybe both commands could be present in the script? I'm surprised it's not doing the same thing for Rasmus, Zoffty tells me he has the same as me on max 2010 64bit.

Thanks again!

rasmus
08-20-2010, 03:11 AM
Hehe, maybe I'm just delirious :) Like I said, I don't mind it either way - doing it your way Bal I suppose just means that smoothing groups have to be united manually before the script will have any visible changes, right? My line of thought was the same as SyncViews, but I'm easy - I guess your way won't be destructive for anyone.

Eric Chadwick
08-20-2010, 04:26 AM
Yeah, I would think if you have a hard edge, then you don't want the script to merge the edge normals (killing the hard edge), instead I would want just the selected faces' normals to be adjusted.

SyncViewS
08-20-2010, 07:09 AM
Hi guys, here (http://dl.dropbox.com/u/1397854/polycount/stash/SetNormals_02.zip) is a new script version. It is a completely different algorithm and should not mess with Smoothing Groups at all. Let me know if it works as is meant. Keep in mind that every time a normal is modified by the script, is made Explicit to retain the modifications. If you want to revert it back to the original status, geometry dependent, you need to do it manually by resetting it through an Edit Normals Modifier.
You can simply download the script and overwrite the previous one. Enjoy :)

Bal
08-20-2010, 07:19 AM
Works great, does exactly what I want anyways. Will keep testing it to see if I see if I come across any other problems, but I've tried most of the possibilities I can think of and it always does what I want it to for now.
Thanks again!

Eric Chadwick
08-20-2010, 07:30 AM
Added to the wiki
http://wiki.polycount.com/VertexNormal#SetNormals_MAXScript

SyncViewS
08-20-2010, 07:33 AM
Hi Bal, that's good to hear. One of the differences of this new version is that it works on face selection border vertexes but doesn't reset the normals of the internal selection vertexes. Is it good, or is it better to reset inner vertexes selection normals?

To make an example to be sure to make it clear. Imagine to have four faces selected in a 2x2 way. There are 8 vertexes on the perimeter and 1 inner vertex, shared by all faces. The current script set all normals along the perimeter but doesn't reset the inner one. Which means it would be averaged among all shared faces, or if there is a split in smoothing groups, each face normal would be realigned to its face normal.

I couldn't really decide on this, but preferred to leave the inner vertexes unchanged to avoid "undoing" normals modifications inadvertently. Is it good as is right now, or need a change? It would be a matter of a couple of lines of code.

Edit: Thanks Eric, but maybe it would be better to name this script in a more meaningful way before adding it to the wiki. I didn't put a reference in the code either. Since it could still change, maybe you could link the thread only.

rasmus
08-20-2010, 07:43 AM
I think this is where we come into multiple uses and you start seeing a need to expand it into a Vertex Normal Toolbox of some kind to allow the user to modify this on a case-by-case basis, but at the moment I'm happy with it changing every vertex connected to the selected faces - bordervert or not - and I can't really see the need to do anything else quite yet. Will keep testing and keep you posted.

Again, thanks a million for spending the time on this, SyncView!

Bal
08-20-2010, 07:56 AM
Yeah, same as rasmus, by default I'd expect it to change all the vertex normals of the selected faces, would be more consistent I think.
In practice though, I wouldn't notice the difference very often at all. When I have multiple neighboring faces selected like that, they are usually coplanar anyways, so one way or the other it wouldn't make a difference.

As rasmus said, at this point maybe it'd be interesting to expand it to an UI, or multiple commands, but personally the function you've made is the only one I really need for now, so not sure if it'd be worth it (that and surprisingly enough, not many people seem to mess with vertex normals much, especially max users).

SyncViewS
08-20-2010, 07:57 AM
Hi Rasmus, I'm glad you liked it, and you're right, a further development would see a small panel with preferences and different options. If I see interest I could go on with it.

Here (http://dl.dropbox.com/u/1397854/polycount/stash/GetVertNormalsFromFace_0_1.zip) is the same second release with some more meaningful names and "signed" by me in the code.

Category: Normal Tools
Action: Get Vert Normals from Faces

rasmus
08-20-2010, 08:45 AM
Great :)

Bal: Not many people touch it probably because up until today it was useless :P Now we only need someone to take a look at multiple UV channel editing and some decent vertex color tools and Max is without blemishes for UDK folks! *hint hint*

Eric Chadwick
08-20-2010, 09:23 AM
Thanks Eric, but maybe it would be better to name this script in a more meaningful way before adding it to the wiki. I didn't put a reference in the code either. Since it could still change, maybe you could link the thread only.
I updated the wiki everytime you made a change. Feel free to update the wiki too if you like, by getting a wiki account (http://wiki.polycount.com/HowToContribute).

SyncViewS
08-21-2010, 01:36 AM
Hi guys, I just updated the script a bit. It now sets every normal from vertexes in the face selection and makes them explicit. Previous version has some glitches related to normals ID change when made explicit. The script now always switches back to Base Object level and Face sub-object level as expected, even when other modifiers are stacked on top of it.

Get the new version here (http://dl.dropbox.com/u/1397854/polycount/stash/GetVertNormalsFromFace_0_2.zip).

Bal
08-21-2010, 02:37 AM
Cool, seems to work fine, now if only max didn't blow up the normals on most modifiers anyways. :)

Thanksa again! (To Eric too, for taking care of the Wiki so well ;)

RexM
12-16-2010, 12:15 AM
Are there any comparable scripts for XSI?

Trying to get better lighting for my vegetation... even though it's not bad right now, it would really help make the vegetation look way more natural further away when shadows are not hitting it.

Working in Cryengine 2.

Somehow, if a script could be made to make normals like this, vegetation would be perfectly lit.

The examples in here explain:

http://wypierpapier.blogspot.com/2010_02_01_archive.html

16bit
08-01-2011, 04:10 PM
Can I get some help with this script? I'm using 2012 and I select the polygons whose normals I want to change, and run the script but nothing happens? I'm a little confused on how to get it to work.