Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_multires.c
| Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | static Mesh *multires_as_ccg(MultiresModifierData *mmd, | ||||
| Mesh *result = mesh; | Mesh *result = mesh; | ||||
| SubdivToCCGSettings ccg_settings; | SubdivToCCGSettings ccg_settings; | ||||
| multires_ccg_settings_init(&ccg_settings, mmd, ctx, mesh); | multires_ccg_settings_init(&ccg_settings, mmd, ctx, mesh); | ||||
| if (ccg_settings.resolution < 3) { | if (ccg_settings.resolution < 3) { | ||||
| return result; | return result; | ||||
| } | } | ||||
| BKE_subdiv_displacement_attach_from_multires(subdiv, mesh, mmd); | BKE_subdiv_displacement_attach_from_multires(subdiv, mesh, mmd); | ||||
| result = BKE_subdiv_to_ccg_mesh(subdiv, &ccg_settings, mesh); | result = BKE_subdiv_to_ccg_mesh(subdiv, &ccg_settings, mesh); | ||||
| /* NOTE: CCG becomes an owner of Subdiv descriptor, so can not share | |||||
| * this pointer. Not sure if it's needed, but might have a second look | |||||
| * on the ownership model here. */ | |||||
| MultiresRuntimeData *runtime_data = mmd->modifier.runtime; | |||||
| runtime_data->subdiv = NULL; | |||||
| return result; | return result; | ||||
| } | } | ||||
| static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) | static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) | ||||
| { | { | ||||
| Mesh *result = mesh; | Mesh *result = mesh; | ||||
| #if !defined(WITH_OPENSUBDIV) | #if !defined(WITH_OPENSUBDIV) | ||||
| BKE_modifier_set_error(md, "Disabled, built without OpenSubdiv"); | BKE_modifier_set_error(md, "Disabled, built without OpenSubdiv"); | ||||
| Show All 40 Lines | if (ctx->object->sculpt != NULL) { | ||||
| sculpt_session->multires.modifier = mmd; | sculpt_session->multires.modifier = mmd; | ||||
| sculpt_session->multires.level = mmd->sculptlvl; | sculpt_session->multires.level = mmd->sculptlvl; | ||||
| sculpt_session->totvert = mesh->totvert; | sculpt_session->totvert = mesh->totvert; | ||||
| sculpt_session->totpoly = mesh->totpoly; | sculpt_session->totpoly = mesh->totpoly; | ||||
| sculpt_session->mvert = NULL; | sculpt_session->mvert = NULL; | ||||
| sculpt_session->mpoly = NULL; | sculpt_session->mpoly = NULL; | ||||
| sculpt_session->mloop = NULL; | sculpt_session->mloop = NULL; | ||||
| } | } | ||||
| /* NOTE: CCG becomes an owner of Subdiv descriptor, so can not share | |||||
| * this pointer. Not sure if it's needed, but might have a second look | |||||
| * on the ownership model here. */ | |||||
| runtime_data->subdiv = NULL; | |||||
| // BKE_subdiv_stats_print(&subdiv->stats); | // BKE_subdiv_stats_print(&subdiv->stats); | ||||
| } | } | ||||
| else { | else { | ||||
| if (use_clnors) { | if (use_clnors) { | ||||
| /* If custom normals are present and the option is turned on calculate the split | /* 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. */ | * normals and clear flag so the normals get interpolated to the result mesh. */ | ||||
| BKE_mesh_calc_normals_split(mesh); | BKE_mesh_calc_normals_split(mesh); | ||||
| CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | ||||
| Show All 12 Lines | else { | ||||
| if (subdiv != runtime_data->subdiv) { | if (subdiv != runtime_data->subdiv) { | ||||
| BKE_subdiv_free(subdiv); | BKE_subdiv_free(subdiv); | ||||
| } | } | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| static void deformMatrices(ModifierData *md, | static void deformMatrices(ModifierData *md, | ||||
| const ModifierEvalContext *UNUSED(ctx), | const ModifierEvalContext *ctx, | ||||
| Mesh *mesh, | Mesh *mesh, | ||||
| float (*vertex_cos)[3], | float (*vertex_cos)[3], | ||||
| float (*deform_matrices)[3][3], | float (*deform_matrices)[3][3], | ||||
| int num_verts) | int num_verts) | ||||
| { | { | ||||
| #if !defined(WITH_OPENSUBDIV) | #if !defined(WITH_OPENSUBDIV) | ||||
| BKE_modifier_set_error(md, "Disabled, built without OpenSubdiv"); | BKE_modifier_set_error(md, "Disabled, built without OpenSubdiv"); | ||||
| return; | return; | ||||
| #endif | #endif | ||||
| /* Subsurf does not require extra space mapping, keep matrices as is. */ | /* Subsurf does not require extra space mapping, keep matrices as is. */ | ||||
| (void)deform_matrices; | (void)deform_matrices; | ||||
| MultiresModifierData *mmd = (MultiresModifierData *)md; | MultiresModifierData *mmd = (MultiresModifierData *)md; | ||||
| SubdivSettings subdiv_settings; | SubdivSettings subdiv_settings; | ||||
| BKE_multires_subdiv_settings_init(&subdiv_settings, mmd); | BKE_multires_subdiv_settings_init(&subdiv_settings, mmd); | ||||
| if (subdiv_settings.level == 0) { | if (subdiv_settings.level == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| SubdivToCCGSettings ccg_settings; | |||||
| multires_ccg_settings_init(&ccg_settings, mmd, ctx, mesh); | |||||
| if (ccg_settings.resolution < 3) { | |||||
| return; | |||||
| } | |||||
| BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh); | BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh); | ||||
| MultiresRuntimeData *runtime_data = multires_ensure_runtime(mmd); | MultiresRuntimeData *runtime_data = multires_ensure_runtime(mmd); | ||||
| Subdiv *subdiv = subdiv_descriptor_ensure(mmd, &subdiv_settings, mesh); | Subdiv *subdiv = subdiv_descriptor_ensure(mmd, &subdiv_settings, mesh); | ||||
| if (subdiv == NULL) { | if (subdiv == NULL) { | ||||
| /* Happens on bad topology, ut also on empty input mesh. */ | /* Happens on bad topology, ut also on empty input mesh. */ | ||||
| return; | return; | ||||
| } | } | ||||
| BKE_subdiv_displacement_attach_from_multires(subdiv, mesh, mmd); | BKE_subdiv_displacement_attach_from_multires(subdiv, mesh, mmd); | ||||
| ▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines | |||||