Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/DerivedMesh.cc
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_mesh_runtime.h" | #include "BKE_mesh_runtime.h" | ||||
| #include "BKE_mesh_tangent.h" | #include "BKE_mesh_tangent.h" | ||||
| #include "BKE_mesh_wrapper.h" | #include "BKE_mesh_wrapper.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_multires.h" | #include "BKE_multires.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_object_deform.h" | #include "BKE_object_deform.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_subdiv_modifier.h" | |||||
| #include "BLI_sys_types.h" /* for intptr_t support */ | #include "BLI_sys_types.h" /* for intptr_t support */ | ||||
| #include "BKE_shrinkwrap.h" | #include "BKE_shrinkwrap.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "CLG_log.h" | #include "CLG_log.h" | ||||
| ▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | |||||
| static bool mesh_has_modifier_final_normals(const Mesh *mesh_input, | static bool mesh_has_modifier_final_normals(const Mesh *mesh_input, | ||||
| const CustomData_MeshMasks *final_datamask, | const CustomData_MeshMasks *final_datamask, | ||||
| Mesh *mesh_final) | Mesh *mesh_final) | ||||
| { | { | ||||
| /* Test if mesh has the required loop normals, in case an additional modifier | /* Test if mesh has the required loop normals, in case an additional modifier | ||||
| * evaluation from another instance or from an operator requests it but the | * evaluation from another instance or from an operator requests it but the | ||||
| * initial normals were not loop normals. */ | * initial normals were not loop normals. */ | ||||
| const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 || | const bool calc_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 || | ||||
| (final_datamask->lmask & CD_MASK_NORMAL) != 0); | (final_datamask->lmask & CD_MASK_NORMAL) != 0); | ||||
| return (!do_loop_normals || CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)); | return (!calc_loop_normals || CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)); | ||||
| } | } | ||||
| static void mesh_calc_modifier_final_normals(const Mesh *mesh_input, | static void mesh_calc_modifier_final_normals(const Mesh *mesh_input, | ||||
| const CustomData_MeshMasks *final_datamask, | const CustomData_MeshMasks *final_datamask, | ||||
| const bool sculpt_dyntopo, | const bool sculpt_dyntopo, | ||||
| Mesh *mesh_final) | Mesh *mesh_final) | ||||
| { | { | ||||
| /* Compute normals. */ | /* Compute normals. */ | ||||
| const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 || | const bool calc_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 || | ||||
| (final_datamask->lmask & CD_MASK_NORMAL) != 0); | (final_datamask->lmask & CD_MASK_NORMAL) != 0); | ||||
| /* Needed as `final_datamask` is not preserved outside modifier stack evaluation. */ | /* Needed as `final_datamask` is not preserved outside modifier stack evaluation. */ | ||||
| mesh_final->runtime.subsurf_do_loop_normals = do_loop_normals; | SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime.subsurf_runtime_data; | ||||
| if (subsurf_runtime_data) { | |||||
| subsurf_runtime_data->calc_loop_normals = calc_loop_normals; | |||||
| } | |||||
| if (do_loop_normals) { | if (calc_loop_normals) { | ||||
| /* Compute loop normals (NOTE: will compute poly and vert normals as well, if needed!). In case | /* Compute loop normals (NOTE: will compute poly and vert normals as well, if needed!). In case | ||||
| * of deferred CPU subdivision, this will be computed when the wrapper is generated. */ | * of deferred CPU subdivision, this will be computed when the wrapper is generated. */ | ||||
| if (mesh_final->runtime.subsurf_resolution == 0) { | if (subsurf_runtime_data && subsurf_runtime_data->resolution == 0) { | ||||
| BKE_mesh_calc_normals_split(mesh_final); | BKE_mesh_calc_normals_split(mesh_final); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (sculpt_dyntopo == false) { | if (sculpt_dyntopo == false) { | ||||
| /* without this, drawing ngon tri's faces will show ugly tessellated face | /* without this, drawing ngon tri's faces will show ugly tessellated face | ||||
| * normals and will also have to calculate normals on the fly, try avoid | * normals and will also have to calculate normals on the fly, try avoid | ||||
| * this where possible since calculating polygon normals isn't fast, | * this where possible since calculating polygon normals isn't fast, | ||||
| ▲ Show 20 Lines • Show All 630 Lines • ▼ Show 20 Lines | static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final, | ||||
| const CustomData_MeshMasks *final_datamask) | const CustomData_MeshMasks *final_datamask) | ||||
| { | { | ||||
| if (mesh_final->runtime.wrapper_type != ME_WRAPPER_TYPE_MDATA) { | if (mesh_final->runtime.wrapper_type != ME_WRAPPER_TYPE_MDATA) { | ||||
| /* Generated at draw time. */ | /* Generated at draw time. */ | ||||
| mesh_final->runtime.wrapper_type_finalize = (1 << mesh_final->runtime.wrapper_type); | mesh_final->runtime.wrapper_type_finalize = (1 << mesh_final->runtime.wrapper_type); | ||||
| return; | return; | ||||
| } | } | ||||
| const bool do_loop_normals = ((mesh_final->flag & ME_AUTOSMOOTH) != 0 || | const bool calc_loop_normals = ((mesh_final->flag & ME_AUTOSMOOTH) != 0 || | ||||
| (final_datamask->lmask & CD_MASK_NORMAL) != 0); | (final_datamask->lmask & CD_MASK_NORMAL) != 0); | ||||
| mesh_final->runtime.subsurf_do_loop_normals = do_loop_normals; | SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime.subsurf_runtime_data; | ||||
| if (subsurf_runtime_data) { | |||||
| subsurf_runtime_data->calc_loop_normals = calc_loop_normals; | |||||
| } | |||||
| if (do_loop_normals) { | if (calc_loop_normals) { | ||||
| /* Compute loop normals. In case of deferred CPU subdivision, this will be computed when the | /* Compute loop normals. In case of deferred CPU subdivision, this will be computed when the | ||||
| * wrapper is generated. */ | * wrapper is generated. */ | ||||
| if (mesh_final->runtime.subsurf_resolution == 0) { | if (subsurf_runtime_data && subsurf_runtime_data->resolution == 0) { | ||||
| BKE_mesh_calc_normals_split(mesh_final); | BKE_mesh_calc_normals_split(mesh_final); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Same as mesh_calc_modifiers. If using loop normals, poly nors have already been computed. */ | /* Same as mesh_calc_modifiers. If using loop normals, poly nors have already been computed. */ | ||||
| BKE_mesh_ensure_normals_for_display(mesh_final); | BKE_mesh_ensure_normals_for_display(mesh_final); | ||||
| /* Some modifiers, like data-transfer, may generate those data, we do not want to keep them, | /* Some modifiers, like data-transfer, may generate those data, we do not want to keep them, | ||||
| ▲ Show 20 Lines • Show All 762 Lines • Show Last 20 Lines | |||||