Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/bmesh/bmesh_py_types.c
| Show First 20 Lines • Show All 1,117 Lines • ▼ Show 20 Lines | if (ob->type != OB_MESH) { | ||||
| PyErr_SetString(PyExc_ValueError, | PyErr_SetString(PyExc_ValueError, | ||||
| "from_object(...): currently only mesh objects are supported"); | "from_object(...): currently only mesh objects are supported"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| const bool use_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER; | const bool use_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER; | ||||
| scene_eval = DEG_get_evaluated_scene(depsgraph); | scene_eval = DEG_get_evaluated_scene(depsgraph); | ||||
| ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| bool need_free = false; | |||||
| /* Write the display mesh into the dummy mesh */ | /* Write the display mesh into the dummy mesh */ | ||||
| if (use_deform) { | if (use_deform) { | ||||
| if (use_render) { | if (use_render) { | ||||
| if (use_cage) { | if (use_cage) { | ||||
| PyErr_SetString(PyExc_ValueError, | PyErr_SetString(PyExc_ValueError, | ||||
| "from_object(...): cage arg is unsupported when dependency graph " | "from_object(...): cage arg is unsupported when dependency graph " | ||||
| "evaluation mode is RENDER"); | "evaluation mode is RENDER"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| me_eval = mesh_create_eval_final(depsgraph, scene_eval, ob_eval, &data_masks); | me_eval = BKE_mesh_new_from_object(depsgraph, ob_eval, true); | ||||
| need_free = true; | |||||
brecht: An unevaluated object should not be used for modifier evaluation, it will not generally give… | |||||
| } | } | ||||
| else { | else { | ||||
| if (use_cage) { | if (use_cage) { | ||||
| me_eval = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &data_masks); | me_eval = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &data_masks); | ||||
| } | } | ||||
| else { | else { | ||||
| me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &data_masks); | me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &data_masks); | ||||
| } | } | ||||
| Show All 24 Lines | static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw) | ||||
| bm = self->bm; | bm = self->bm; | ||||
| BM_mesh_bm_from_me(bm, | BM_mesh_bm_from_me(bm, | ||||
| me_eval, | me_eval, | ||||
| (&(struct BMeshFromMeshParams){ | (&(struct BMeshFromMeshParams){ | ||||
| .calc_face_normal = use_fnorm, | .calc_face_normal = use_fnorm, | ||||
| })); | })); | ||||
| if (need_free) { | |||||
| BKE_id_free(NULL, me_eval); | |||||
| } | |||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| PyDoc_STRVAR( | PyDoc_STRVAR( | ||||
| bpy_bmesh_from_mesh_doc, | 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, use_shape_key=False, shape_key_index=0)\n" | ||||
| "\n" | "\n" | ||||
| " Initialize this bmesh from existing mesh datablock.\n" | " Initialize this bmesh from existing mesh datablock.\n" | ||||
| ▲ Show 20 Lines • Show All 3,114 Lines • Show Last 20 Lines | |||||
An unevaluated object should not be used for modifier evaluation, it will not generally give the correct result when there are e.g. constraints, animation or drivers.
I think you can use BKE_mesh_new_from_object instead and pass it the evaluated object. That's what is used for object.to_mesh() in the Python API. Note that the returned mesh needs to be freed.