Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/DerivedMesh.cc
| Show First 20 Lines • Show All 992 Lines • ▼ Show 20 Lines | |||||
| /* Evaluate modifiers up to certain index to get the mesh cage. */ | /* Evaluate modifiers up to certain index to get the mesh cage. */ | ||||
| int cageIndex = BKE_modifiers_get_cage_index(scene, ob, nullptr, true); | int cageIndex = BKE_modifiers_get_cage_index(scene, ob, nullptr, true); | ||||
| if (r_cage && cageIndex == -1) { | if (r_cage && cageIndex == -1) { | ||||
| mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords( | mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords( | ||||
| em_input, &final_datamask, nullptr, mesh_input); | em_input, &final_datamask, nullptr, mesh_input); | ||||
| } | } | ||||
| /* The mesh from edit mode should not have any original index layers already, since those | |||||
| * are added during evaluation when necessary and are redundant on an original mesh. */ | |||||
| BLI_assert(CustomData_get_layer(&em_input->bm->pdata, CD_ORIGINDEX) == nullptr && | |||||
| CustomData_get_layer(&em_input->bm->edata, CD_ORIGINDEX) == nullptr && | |||||
| CustomData_get_layer(&em_input->bm->pdata, CD_ORIGINDEX) == nullptr); | |||||
| /* Clear errors before evaluation. */ | /* Clear errors before evaluation. */ | ||||
| BKE_modifiers_clear_errors(ob); | BKE_modifiers_clear_errors(ob); | ||||
| for (int i = 0; md; i++, md = md->next, md_datamask = md_datamask->next) { | for (int i = 0; md; i++, md = md->next, md_datamask = md_datamask->next) { | ||||
| const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md->type); | const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md->type); | ||||
| if (!editbmesh_modifier_is_enabled(scene, ob, md, mesh_final != nullptr)) { | if (!editbmesh_modifier_is_enabled(scene, ob, md, mesh_final != nullptr)) { | ||||
| continue; | continue; | ||||
| Show All 22 Lines | |||||
| } | } | ||||
| else { | else { | ||||
| deformed_verts = editbmesh_vert_coords_alloc(em_input, &num_deformed_verts); | deformed_verts = editbmesh_vert_coords_alloc(em_input, &num_deformed_verts); | ||||
| } | } | ||||
| } | } | ||||
| else if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) { | else if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) { | ||||
| if (mesh_final == nullptr) { | if (mesh_final == nullptr) { | ||||
| mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, nullptr, mesh_input); | mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, nullptr, mesh_input); | ||||
| BKE_mesh_ensure_default_orig_index_layers(mesh_final); | |||||
| ASSERT_IS_VALID_MESH(mesh_final); | ASSERT_IS_VALID_MESH(mesh_final); | ||||
| } | } | ||||
| BLI_assert(deformed_verts != nullptr); | BLI_assert(deformed_verts != nullptr); | ||||
| BKE_mesh_vert_coords_apply(mesh_final, deformed_verts); | BKE_mesh_vert_coords_apply(mesh_final, deformed_verts); | ||||
| } | } | ||||
| if (mti->deformVertsEM) { | if (mti->deformVertsEM) { | ||||
| BKE_modifier_deform_vertsEM( | BKE_modifier_deform_vertsEM( | ||||
| Show All 9 Lines | |||||
| if (deformed_verts) { | if (deformed_verts) { | ||||
| Mesh *mesh_tmp = BKE_mesh_copy_for_eval(mesh_final, false); | Mesh *mesh_tmp = BKE_mesh_copy_for_eval(mesh_final, false); | ||||
| if (mesh_final != mesh_cage) { | if (mesh_final != mesh_cage) { | ||||
| BKE_id_free(nullptr, mesh_final); | BKE_id_free(nullptr, mesh_final); | ||||
| } | } | ||||
| mesh_final = mesh_tmp; | mesh_final = mesh_tmp; | ||||
| BKE_mesh_vert_coords_apply(mesh_final, deformed_verts); | BKE_mesh_vert_coords_apply(mesh_final, deformed_verts); | ||||
| } | } | ||||
| else if (mesh_final == mesh_cage) { | else if (mesh_final == mesh_cage) { | ||||
| /* 'me' may be changed by this modifier, so we need to copy it. */ | /* 'me' may be changed by this modifier, so we need to copy it. */ | ||||
sergey: Why there is no need to ensure origindex here? | |||||
Done Inline ActionsWell, original index layers weren't added here before this patch, since this is just creating a wrapper of the BMesh. HooglyBoogly: Well, original index layers weren't added here before this patch, since this is just creating a… | |||||
| mesh_final = BKE_mesh_copy_for_eval(mesh_final, false); | mesh_final = BKE_mesh_copy_for_eval(mesh_final, false); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| mesh_final = BKE_mesh_wrapper_from_editmesh_with_coords( | mesh_final = BKE_mesh_wrapper_from_editmesh_with_coords( | ||||
| em_input, nullptr, deformed_verts, mesh_input); | em_input, nullptr, deformed_verts, mesh_input); | ||||
| deformed_verts = nullptr; | deformed_verts = nullptr; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| mesh_cage = BKE_mesh_copy_for_eval(mesh_final, false); | mesh_cage = BKE_mesh_copy_for_eval(mesh_final, false); | ||||
| BKE_mesh_vert_coords_apply(mesh_cage, deformed_verts); | BKE_mesh_vert_coords_apply(mesh_cage, deformed_verts); | ||||
| } | } | ||||
| else if (mesh_final) { | else if (mesh_final) { | ||||
| mesh_cage = mesh_final; | mesh_cage = mesh_final; | ||||
| } | } | ||||
| else { | else { | ||||
| Mesh *me_orig = mesh_input; | Mesh *me_orig = mesh_input; | ||||
| if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) { | if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) { | ||||
Done Inline ActionsSame as above sergey: Same as above | |||||
| if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) { | if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) { | ||||
| BKE_mesh_runtime_reset_edit_data(me_orig); | BKE_mesh_runtime_reset_edit_data(me_orig); | ||||
| } | } | ||||
| me_orig->runtime.edit_data->vertexCos = (const float(*)[3])MEM_dupallocN(deformed_verts); | me_orig->runtime.edit_data->vertexCos = (const float(*)[3])MEM_dupallocN(deformed_verts); | ||||
| } | } | ||||
| mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords( | mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords( | ||||
| em_input, | em_input, | ||||
| &final_datamask, | &final_datamask, | ||||
| Show All 28 Lines | |||||
| /* this is just a copy of the editmesh, no need to calc normals */ | /* this is just a copy of the editmesh, no need to calc normals */ | ||||
| mesh_final = BKE_mesh_wrapper_from_editmesh_with_coords( | mesh_final = BKE_mesh_wrapper_from_editmesh_with_coords( | ||||
| em_input, &final_datamask, deformed_verts, mesh_input); | em_input, &final_datamask, deformed_verts, mesh_input); | ||||
| deformed_verts = nullptr; | deformed_verts = nullptr; | ||||
| } | } | ||||
| if (deformed_verts) { | if (deformed_verts) { | ||||
| MEM_freeN(deformed_verts); | MEM_freeN(deformed_verts); | ||||
| } | } | ||||
Done Inline ActionsWhy this is needed? As in, why the origindex was not ensured when the mesh_final was created from bmesh in the evaluation loop above? sergey: Why this is needed? As in, why the origindex was not ensured when the `mesh_final` was created… | |||||
Done Inline ActionsYou're right. It will be done by the mesh wrapper when necessary anyway. HooglyBoogly: You're right. It will be done by the mesh wrapper when necessary anyway. | |||||
| /* Add orco coordinates to final and deformed mesh if requested. */ | /* Add orco coordinates to final and deformed mesh if requested. */ | ||||
| if (final_datamask.vmask & CD_MASK_ORCO) { | if (final_datamask.vmask & CD_MASK_ORCO) { | ||||
| /* FIXME(Campbell): avoid the need to convert to mesh data just to add an orco layer. */ | /* FIXME(Campbell): avoid the need to convert to mesh data just to add an orco layer. */ | ||||
| BKE_mesh_wrapper_ensure_mdata(mesh_final); | BKE_mesh_wrapper_ensure_mdata(mesh_final); | ||||
| add_orco_mesh(ob, em_input, mesh_final, mesh_orco, CD_ORCO); | add_orco_mesh(ob, em_input, mesh_final, mesh_orco, CD_ORCO); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 484 Lines • Show Last 20 Lines | |||||
Why there is no need to ensure origindex here?