2
$\begingroup$

I'm working on an addon to distort the backsides of a mesh along a direction. I'm using a dot product with each vertex's normal to determine whether or not that vertex should or should not be affected, and by how much. This works 100% perfectly if you only move or scale the object, but if you rotate it without applying the rotation, there are issues with the direction not changing.

Here is my code for getting the normals

def global_verts(_obj):

    out_verts = []
    out_norms = []
  
    mat = _obj.matrix_world

    depsgraph = bpy.context.evaluated_depsgraph_get()
    mesh = _obj.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph)

    for vert in mesh.vertices:
        out_norms.append(vert.normal)
        out_verts.append(mat @ vert.co)

    return np.array(out_verts), np.array(out_norms)

This should give me the updated mesh, but when I test if these normals are equal to the original object, it returns as true. So far I have tried multiplying the normals by matrix_world, matrix_local, and matrix_basis, using multiple different methods of getting the mesh, and setting the mesh vertices to world space and then getting the normals, none of which have worked. Is there any way that I could get the applied normals for a mesh, not just for rotates objects but also for rigged ones as well?

Thanks!

$\endgroup$
  • $\begingroup$ I might be missing something, but in your script you're never changing, e.g. rotating the normals, so naturally they would be the same in the comparison. The normals in out_norms are identical to the original ones (with the exception of e.g. modifiers because the evaluated depsgraph is used). $\endgroup$ – Robert Gützkow Sep 5 at 22:46
  • $\begingroup$ That might be the case. Any way that you know of that I could fix it? $\endgroup$ – Andrew Combs Sep 5 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.