Notifications
Clear all

[Closed] Edge Normal Issues

Hello,

I thought I had this solved, and in most cases, it is. However, I noticed an issue with my code when trying to get Edge Normals. In some cases, for some reason, my Normal Dir that is computed comes up at an odd angle from what you’d expect.

In my current test, I have a ribbon type mesh, and all edges work fine, except for the edges facing in -Z. When I try to compute those normals, my final Normal is rotated around 45 degrees from what it should be.

I think it’s how I am calculating my Edge Normal from the Vert Normals. Should I be adding them up then normalizing at the end, or is that completely wrong?

 (
   	local theVertNormal = [0,0,0]
   	local theVerts = polyop.getVertsUsingEdge Selection[1] #{218}
   	local theMesh = snapshotasmesh selection[1]
   
   	for vert in theVerts do 
   	(
   		theVertNormal += (getNormal theMesh vert)
   	)
   
   	vertNormal = Normalize theVertNormal
   	--$Teapot02.dir =  vertNormal
   	
   	delete theMesh
   )
4 Replies

Hm… I’m realizing, maybe I should get the faces from the Edge, then get the Average Normal from those?

I figured it out. This seems to work just fine.


 local faceUsingEdge = polyop.getFacesUsingEdge
 	local getSmoothing = polyop.getFaceSmoothGroup
 	local theNormal = polyop.getFaceNormal
 	
 	local theFaces = faceUsingEdge obj edge
 	local averageNormal = [0,0,0]
 	local faceArray = theFaces as Array
 
 	if (faceArray.count > 1) then
 	(
 		--Check Smoothing Groups to see if we are using the same or not (Hard Edge Check)
 		if ((getSmoothing obj faceArray[1]) == (getSmoothing obj faceArray[2])) do
 		(
 			averageNormal += faceNormal obj faceArray[1]
 			averageNormal += faceNormal obj faceArray[2]
 		)
 	)
 	else
 	(
 		averageNormal = faceNormal obj faceArray[1]
 	)
 
    edgeNormal = normalize averageNormal --Normalize theVertNormal

actually this is not correct… you have to compare not just SmGroup values but also their bits:


(bit.and sm_gr1 sm_gr2) != 0

Hm… so it would be

if (bit.and (getSmoothing obj faceArray[1]) (getSmoothing obj faceArray[2])) != 0 do..