diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-22 17:33:50 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-24 16:38:24 +0300 |
commit | fb2cb0324a391041db3fdc6c66ce992adf9598aa (patch) | |
tree | a472d1cce7a82923d8e4a1d8cc48730a4792edbd /source/blender/python/bmesh/bmesh_py_types.c | |
parent | b89437c27e4ce286d8f3525ade8d8d28c35d582f (diff) |
Fix T96308: Mesh to BMesh conversion doesn't calculate vertex normals
Currently there is a "calc_face_normal" argument to mesh to bmesh
conversion, but vertex normals had always implicitly inherited whatever
dirty state the mesh input's vertex normals were in. Probably they were
most often assumed to not be dirty, but this was never really correct in
the general case.
Ever since the refactor to move vertex normals out of mesh vertices,
cfa53e0fbeed7178c7, the copying logic has been explicit: copy the
normals when they are not dirty. But it turns out that more control is
needed, and sometimes normals should be calculated for the resulting
BMesh.
This commit adds an option to the conversion to calculate vertex
normals, true by default. In almost all places except the decimate
and edge split modifiers, I just copied the value of the
"calc_face_normals" argument.
Differential Revision: https://developer.blender.org/D14406
Diffstat (limited to 'source/blender/python/bmesh/bmesh_py_types.c')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 38ec242fa49..543094d9b8c 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -1066,7 +1066,8 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args) } PyDoc_STRVAR(bpy_bmesh_from_object_doc, - ".. method:: from_object(object, depsgraph, cage=False, face_normals=True)\n" + ".. method:: from_object(object, depsgraph, cage=False, face_normals=True, " + "vertex_normals=True)\n" "\n" " Initialize this bmesh from existing object data-block (only meshes are currently " "supported).\n" @@ -1076,10 +1077,12 @@ PyDoc_STRVAR(bpy_bmesh_from_object_doc, " :arg cage: Get the mesh as a deformed cage.\n" " :type cage: boolean\n" " :arg face_normals: Calculate face normals.\n" + " :arg vertex_normals: Calculate vertex normals.\n" " :type face_normals: boolean\n"); static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw) { - static const char *kwlist[] = {"object", "depsgraph", "cage", "face_normals", NULL}; + static const char *kwlist[] = { + "object", "depsgraph", "cage", "face_normals", "vertex_normals", NULL}; PyObject *py_object; PyObject *py_depsgraph; Object *ob, *ob_eval; @@ -1089,6 +1092,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject BMesh *bm; bool use_cage = false; bool use_fnorm = true; + bool use_vert_normal = true; const CustomData_MeshMasks data_masks = CD_MASK_BMESH; BPY_BM_CHECK_OBJ(self); @@ -1102,7 +1106,9 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject PyC_ParseBool, &use_cage, PyC_ParseBool, - &use_fnorm) || + &use_fnorm, + PyC_ParseBool, + &use_vert_normal) || !(ob = PyC_RNA_AsPointer(py_object, "Object")) || !(depsgraph = PyC_RNA_AsPointer(py_depsgraph, "Depsgraph"))) { return NULL; @@ -1153,6 +1159,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject me_eval, (&(struct BMeshFromMeshParams){ .calc_face_normal = use_fnorm, + .calc_vert_normal = use_vert_normal, })); if (need_free) { @@ -1164,7 +1171,8 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject PyDoc_STRVAR( bpy_bmesh_from_mesh_doc, - ".. method:: from_mesh(mesh, face_normals=True, use_shape_key=False, shape_key_index=0)\n" + ".. method:: from_mesh(mesh, face_normals=True, vertex_normals=True, use_shape_key=False, " + "shape_key_index=0)\n" "\n" " Initialize this bmesh from existing mesh datablock.\n" "\n" @@ -1184,11 +1192,13 @@ PyDoc_STRVAR( "mesh won't be added.\n"); static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw) { - static const char *kwlist[] = {"mesh", "face_normals", "use_shape_key", "shape_key_index", NULL}; + static const char *kwlist[] = { + "mesh", "face_normals", "vertex_normals", "use_shape_key", "shape_key_index", NULL}; BMesh *bm; PyObject *py_mesh; Mesh *me; bool use_fnorm = true; + bool use_vert_normal = true; bool use_shape_key = false; int shape_key_index = 0; @@ -1202,6 +1212,8 @@ static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject * PyC_ParseBool, &use_fnorm, PyC_ParseBool, + &use_vert_normal, + PyC_ParseBool, &use_shape_key, &shape_key_index) || !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) { @@ -1214,6 +1226,7 @@ static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject * me, (&(struct BMeshFromMeshParams){ .calc_face_normal = use_fnorm, + .calc_vert_normal = use_vert_normal, .use_shapekey = use_shape_key, .active_shapekey = shape_key_index + 1, })); |