Notifications
Clear all

[Closed] Edit_Normals() – vert pos in vert normal?

hey –
I can’t seem to get a correct relationship between a vertices position and its normal through using the Edit_Normals modifier.

What I am wanting to do is ‘explode’ all normals away from the averaged center (some foliage lighting experiment)… I noticed the standalone command setNormal[font=Courier New] <mesh> <vert_index_integer> <point3> [font=Verdana]does not appear to change any normals? [/font][/font]

So – I figured I’d try the Edit_Normals modifier… this at least yeilds modified normals when I change them. For what I’m trying to achieve, I need to have the position of the vertex that this normal is attached to… but there isn’t a correlation between EditNormalsMod.GetNormal() (which needs a NormalID) and EditNormalsMod.GetVertex()(which needs a VertexID)… how can I get the relationship?

…another oddity:
If I set the normal to be the position of the vertex of the same ID in MaxScriptListener I get correct results. That is, each vertex ‘explodes’ away from the center as expected.

 
obj=$ -- this is usually an EditMesh object
obj.modifiers[#Edit_Normals].EditNormalsMod.setNormal 2 (obj.modifiers[#Edit_Normals].GetVertex(3))

But if I use this exact same code (literally copy pasted) in my script, it will modify a different vertex! What’s going on!

Thanks!

7 Replies

First, you have to understand that any vertex can have as many normals as many faces using this vertex. So, normal ID doesn’t correspond to vertex ID. If you want to get all normals corresponding to vertex id you have to use ConvertVertexSelection (check Edit Normals help), or GetNormalID and GetVertexID by face and by corner.


node = <your node>
modi = <Edit_Normals Modifier>
[color=white][/color]
norms = #{}
modi.ConvertVertexSelection #{vert_id} norms node:node -- it returns norms as a bitarray of normal ids

Second, you have use average normal for every vertex:


av_norm = [0,0,0]
for n in norms do av_norm += modi.GetNormal n node:node
av_norm /= norms.numberset
av_norm = normalize av_norm -- average normal

PS. Using Edit_Normals modifier in your case is the absolutely right solution.

thanks for the reply… keen to try it out, but again, stuck on MaxScript not executing code in the script, but it will in the Listener.

Now I’m trying to expand the Edit Normals modifer to select all verts.


addModifier obj (EditNormals()) ui:on   
obj.modifiers[#Edit_Normals].displayLength = 150  
modPanel.setCurrentObject obj.modifiers[#Edit_Normals]
subobjectlevel = 1   
obj.modifiers[#Edit_Normals].EditNormalsMod.SetSelection #{1..vertCount}

this works perfectly if executed line by line in the listener… but the exact same code will not work in a running script!

Why is this?! I’ve come accross this in other scripts as well!

here is a snippet that shows how apply and edit Edit_Normals modifier:


try(destroydialog testRol) catch()
rollout testRol "Edit Normals by denisT" 
(
 button create "Create" width:180 offset:[0,4]
 
 on create pressed do undo "Create" on 
 (
  try (delete objects) catch()
  obj = sphere name:"testNormals" isSelected:on
  modi = EditNormals name:"_enormal" displayLength:150 
  addModifier obj modi ui:on   
  if getCommandPanelTaskMode() != #modify do setCommandPanelTaskMode mode:#modify
  modi.SetSelection #{1..50} node:obj  
 )
)
createdialog testRol width:200 height:40

cool, creating the modifier like that did the trick…
thanks for the help!

btw – why is it that some commands (even sequences of) can be executed without a problem in listener, but they simply will not work in a script? They run with no errors… they just don’t do anything! Such as my example above.

Cheers!

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

to make Edit_Normals working you have to set Edit_Normals modifier as current object of modpanel and modpanel has to be opened

hmm, i just noted that if you conver to an edit poly or editable poly it destroys anything the edit_normals modifier did, converting to edit_mesh, editable_mesh is fine though!

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

When any node converts to editable poly it recomputes all normals. That means all results of normal editing will be lost. There is no way prevent it