Skip to content

Flipping all mesh normals in the positive direction #3309

Answered by Grantim
aseglorstw asked this question in Q&A
Discussion options

You must be logged in to vote

Hello!

We have flipOrientation function to do it:

import meshlib.mrmeshpy as mr

mesh = mr.loadMesh(path_to_mesh)) 

# check if it is needed to flip
avgNorm = mr.Vector3f()
for v in mesh.topology.getValidVerts():
    avgNorm = avgNorm   mesh.normal(v)

avgNorm = avgNorm / mesh.topology.getValidVerts().count()
if ( mr.dot( avgNorm, mr.Vector3f(0,0,1) ) < 0 ): # assume that you want your normals to look in positive Z direction
    mesh.topology.flipOrientation() # flip all normals

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@aseglorstw
Comment options

@Grantim
Comment options

Answer selected by aseglorstw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants