Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_wrapper.cc
| Show First 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | static Mesh *mesh_wrapper_ensure_subdivision(const Object *ob, Mesh *me) | ||||
| SubsurfRuntimeData *runtime_data = BKE_subsurf_modifier_ensure_runtime(smd); | SubsurfRuntimeData *runtime_data = BKE_subsurf_modifier_ensure_runtime(smd); | ||||
| Subdiv *subdiv = BKE_subsurf_modifier_subdiv_descriptor_ensure(smd, &subdiv_settings, me, false); | Subdiv *subdiv = BKE_subsurf_modifier_subdiv_descriptor_ensure(smd, &subdiv_settings, me, false); | ||||
| if (subdiv == nullptr) { | if (subdiv == nullptr) { | ||||
| /* Happens on bad topology, but also on empty input mesh. */ | /* Happens on bad topology, but also on empty input mesh. */ | ||||
| return me; | return me; | ||||
| } | } | ||||
| const bool use_clnors = BKE_subsurf_modifier_use_custom_loop_normals(smd, me); | |||||
| if (use_clnors) { | |||||
| /* If custom normals are present and the option is turned on calculate the split | |||||
| * normals and clear flag so the normals get interpolated to the result mesh. */ | |||||
| BKE_mesh_calc_normals_split(me); | |||||
| CustomData_clear_layer_flag(&me->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | |||||
| } | |||||
| Mesh *subdiv_mesh = BKE_subdiv_to_mesh(subdiv, &mesh_settings, me); | Mesh *subdiv_mesh = BKE_subdiv_to_mesh(subdiv, &mesh_settings, me); | ||||
| if (use_clnors) { | |||||
| float(*lnors)[3] = static_cast<float(*)[3]>( | |||||
| CustomData_get_layer(&subdiv_mesh->ldata, CD_NORMAL)); | |||||
| BLI_assert(lnors != NULL); | |||||
| BKE_mesh_set_custom_normals(subdiv_mesh, lnors); | |||||
| CustomData_set_layer_flag(&me->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | |||||
| CustomData_set_layer_flag(&subdiv_mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | |||||
| } | |||||
| else if (me->runtime.subsurf_do_loop_normals) { | |||||
| BKE_mesh_calc_normals_split(subdiv_mesh); | |||||
| } | |||||
| if (subdiv != runtime_data->subdiv) { | if (subdiv != runtime_data->subdiv) { | ||||
| BKE_subdiv_free(subdiv); | BKE_subdiv_free(subdiv); | ||||
| } | } | ||||
| if (subdiv_mesh != me) { | if (subdiv_mesh != me) { | ||||
| if (me->runtime.mesh_eval != nullptr) { | if (me->runtime.mesh_eval != nullptr) { | ||||
| BKE_id_free(nullptr, me->runtime.mesh_eval); | BKE_id_free(nullptr, me->runtime.mesh_eval); | ||||
| } | } | ||||
| Show All 27 Lines | |||||