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 25 Lines | |||||
| deformed_verts = nullptr; | deformed_verts = nullptr; | ||||
| } | } | ||||
| /* create an orco derivedmesh in parallel */ | /* create an orco derivedmesh in parallel */ | ||||
| CustomData_MeshMasks mask = md_datamask->mask; | CustomData_MeshMasks mask = md_datamask->mask; | ||||
| if (mask.vmask & CD_MASK_ORCO) { | if (mask.vmask & CD_MASK_ORCO) { | ||||
| if (!mesh_orco) { | if (!mesh_orco) { | ||||
| mesh_orco = create_orco_mesh(ob, mesh_input, em_input, CD_ORCO); | mesh_orco = create_orco_mesh(ob, mesh_input, em_input, CD_ORCO); | ||||
| } | } | ||||
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… | |||||
| mask.vmask &= ~CD_MASK_ORCO; | mask.vmask &= ~CD_MASK_ORCO; | ||||
| mask.vmask |= CD_MASK_ORIGINDEX; | mask.vmask |= CD_MASK_ORIGINDEX; | ||||
| mask.emask |= CD_MASK_ORIGINDEX; | mask.emask |= CD_MASK_ORIGINDEX; | ||||
| mask.pmask |= CD_MASK_ORIGINDEX; | mask.pmask |= CD_MASK_ORIGINDEX; | ||||
| mesh_set_only_copy(mesh_orco, &mask); | mesh_set_only_copy(mesh_orco, &mask); | ||||
| Mesh *mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco); | Mesh *mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco); | ||||
| ASSERT_IS_VALID_MESH(mesh_next); | ASSERT_IS_VALID_MESH(mesh_next); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| &final_datamask, | &final_datamask, | ||||
| deformed_verts ? (const float(*)[3])MEM_dupallocN(deformed_verts) : nullptr, | deformed_verts ? (const float(*)[3])MEM_dupallocN(deformed_verts) : nullptr, | ||||
| mesh_input); | mesh_input); | ||||
| } | } | ||||
| } | } | ||||
| isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform); | isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform); | ||||
| } | } | ||||
Done Inline ActionsSame as above sergey: Same as above | |||||
| BLI_linklist_free((LinkNode *)datamasks, nullptr); | BLI_linklist_free((LinkNode *)datamasks, nullptr); | ||||
| /* Yay, we are done. If we have a DerivedMesh and deformed vertices need | /* Yay, we are done. If we have a DerivedMesh and deformed vertices need | ||||
| * to apply these back onto the DerivedMesh. If we have no DerivedMesh | * to apply these back onto the DerivedMesh. If we have no DerivedMesh | ||||
| * then we need to build one. */ | * then we need to build one. */ | ||||
| if (mesh_final) { | if (mesh_final) { | ||||
| 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); | ||||
| Show All 28 Lines | |||||
| } | } | ||||
| if (mesh_orco) { | if (mesh_orco) { | ||||
| BKE_id_free(nullptr, mesh_orco); | BKE_id_free(nullptr, mesh_orco); | ||||
| } | } | ||||
| /* Compute normals. */ | /* Compute normals. */ | ||||
| editbmesh_calc_modifier_final_normals(mesh_final, &final_datamask); | editbmesh_calc_modifier_final_normals(mesh_final, &final_datamask); | ||||
| if (mesh_cage && (mesh_cage != mesh_final)) { | if (mesh_cage && (mesh_cage != mesh_final)) { | ||||
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. | |||||
| editbmesh_calc_modifier_final_normals(mesh_cage, &final_datamask); | editbmesh_calc_modifier_final_normals(mesh_cage, &final_datamask); | ||||
| } | } | ||||
| /* Return final mesh. */ | /* Return final mesh. */ | ||||
| *r_final = mesh_final; | *r_final = mesh_final; | ||||
| if (r_cage) { | if (r_cage) { | ||||
| *r_cage = mesh_cage; | *r_cage = mesh_cage; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 468 Lines • Show Last 20 Lines | |||||
Why there is no need to ensure origindex here?