Notifications
Clear all

[Closed] How rotate normal by specific axis?

num5Pos = getVert $ 5
num8Pos = getVert $ 8
num5Normal = getNormal $ 5
num8Normal = getNormal $ 8

axisY = normalize(num8Pos - num5Pos)
axisZ = normalize(num5Normal)
axisX = normalize(cross axisY axisZ)

theMatrix = matrix3 axisX axisY axisZ num5Pos

-- rotate transform to vertex 8 direction
preRotate theMatrix (eulertoquat (eulerAngles -90 0 0))
quatToEuler(theMatrix.rotationpart)

$.modifiers[#Edit_Normals].EditNormalsMod.rotate theMatrix.rotationpart

I created transform matrix which pointing vertex 8 from vertex 5. After that, I rotated the matrix -90 degree along x axis and applied the rotation to vertex 5’s normal. But the normal rotated to unexpected direction.

Is there a way to rotate normal’s direction by specific axis?

6 Replies

I’m not sure i understand – are you simply wanting the vert normal of vertex 5 to point towards vertex 8?

Yes, that’s it! That is what I want.

Is this what you wanted?

num5Pos = getVert $ 5
num8Pos = getVert $ 8
num5Normal = getNormal $ 5
num8Normal = getNormal $ 8

max modify mode --this is important

norm5 = #{} --array for all vert 5 normals, there can be more than 1
$.modifiers[#Edit_Normals].ConvertVertexSelection #{5} norm5 --append normals to array
norm5 = norm5 as array

for n in norm5 do
(
	$.modifiers[#Edit_Normals].setNormal n (normalize (num8Pos - num5Pos))
	$.modifiers[#Edit_Normals].EditNormalsMod.Select #{n}
	$.modifiers[#Edit_Normals].EditNormalsMod.MakeExplicit() --this is important
)
3 Replies
(@jalnaga)
Joined: 10 months ago

Posts: 0

Thank you, Tamyl. I appreciate to your interest.
Unfortunately, your code made same result what I did like this.

Actually, I found a solution. Using setNormal() in Mesh Vertex Methods not in Edit_Normals Modifier. As you know, getting a new normal direction of vertex 5 is very simple.

num5Pos = getVert $ 5
num8Pos = getVert $ 8
normalize(num8Pos - num5Pos)

So, I thought that simply applying new normal direction by EditNormal.setNormal(). But it made odd result. That is why I started digging about matrix3 things.

Solution was sooo simple. Just using setNormal() in Mesh Vertex Methods instead of EditNormal modifier like this:

num5Pos = getVert $ 5
num8Pos = getVert $ 8
newNormalDir = normalize(num8Pos - num5Pos)
setNormal $ 5 newNormalDir -- this is solution!

So, at this time, I have a question. Why EditNormal modifier makes wrong result?

(@denist)
Joined: 11 months ago

Posts: 0

try to update your mesh after you set a vertex normal and check what will happen (it will be rebuilt).
using the edit normals modifier you have a chance to make mesh normals specified, what you can’t do using only meshop or mesh methods.
why does the edit normals modifier not work right in the snippet above? because a normal has to be set in the world space. in the snippet above it set in edit normals modifier context which depends on object transform.

(@jalnaga)
Joined: 10 months ago

Posts: 0

Ah! Got it! I have to multiply inverse object transform to new normal vector.
It worked in Edit_Normal modifier. Thanks a lot denisT!