Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/subdiv_mesh.c
| Show All 38 Lines | typedef struct SubdivMeshContext { | ||||
| /* Cached custom data arrays for faster access. */ | /* Cached custom data arrays for faster access. */ | ||||
| int *vert_origindex; | int *vert_origindex; | ||||
| int *edge_origindex; | int *edge_origindex; | ||||
| int *loop_origindex; | int *loop_origindex; | ||||
| int *poly_origindex; | int *poly_origindex; | ||||
| /* UV layers interpolation. */ | /* UV layers interpolation. */ | ||||
| int num_uv_layers; | int num_uv_layers; | ||||
| MLoopUV *uv_layers[MAX_MTFACE]; | MLoopUV *uv_layers[MAX_MTFACE]; | ||||
| /* Orco interpolation. */ | |||||
| float (*orco)[3]; | |||||
| float (*cloth_orco)[3]; | |||||
| /* Per-subdivided vertex counter of averaged values. */ | /* Per-subdivided vertex counter of averaged values. */ | ||||
| int *accumulated_counters; | int *accumulated_counters; | ||||
| bool have_displacement; | bool have_displacement; | ||||
| } SubdivMeshContext; | } SubdivMeshContext; | ||||
| static void subdiv_mesh_ctx_cache_uv_layers(SubdivMeshContext *ctx) | static void subdiv_mesh_ctx_cache_uv_layers(SubdivMeshContext *ctx) | ||||
| { | { | ||||
| Mesh *subdiv_mesh = ctx->subdiv_mesh; | Mesh *subdiv_mesh = ctx->subdiv_mesh; | ||||
| Show All 9 Lines | static void subdiv_mesh_ctx_cache_custom_data_layers(SubdivMeshContext *ctx) | ||||
| Mesh *subdiv_mesh = ctx->subdiv_mesh; | Mesh *subdiv_mesh = ctx->subdiv_mesh; | ||||
| /* Pointers to original indices layers. */ | /* Pointers to original indices layers. */ | ||||
| ctx->vert_origindex = CustomData_get_layer(&subdiv_mesh->vdata, CD_ORIGINDEX); | ctx->vert_origindex = CustomData_get_layer(&subdiv_mesh->vdata, CD_ORIGINDEX); | ||||
| ctx->edge_origindex = CustomData_get_layer(&subdiv_mesh->edata, CD_ORIGINDEX); | ctx->edge_origindex = CustomData_get_layer(&subdiv_mesh->edata, CD_ORIGINDEX); | ||||
| ctx->loop_origindex = CustomData_get_layer(&subdiv_mesh->ldata, CD_ORIGINDEX); | ctx->loop_origindex = CustomData_get_layer(&subdiv_mesh->ldata, CD_ORIGINDEX); | ||||
| ctx->poly_origindex = CustomData_get_layer(&subdiv_mesh->pdata, CD_ORIGINDEX); | ctx->poly_origindex = CustomData_get_layer(&subdiv_mesh->pdata, CD_ORIGINDEX); | ||||
| /* UV layers interpolation. */ | /* UV layers interpolation. */ | ||||
| subdiv_mesh_ctx_cache_uv_layers(ctx); | subdiv_mesh_ctx_cache_uv_layers(ctx); | ||||
| /* Orco interpolation. */ | |||||
| ctx->orco = CustomData_get_layer(&subdiv_mesh->vdata, CD_ORCO); | |||||
| ctx->cloth_orco = CustomData_get_layer(&subdiv_mesh->vdata, CD_CLOTH_ORCO); | |||||
| } | } | ||||
| static void subdiv_mesh_prepare_accumulator(SubdivMeshContext *ctx, int num_vertices) | static void subdiv_mesh_prepare_accumulator(SubdivMeshContext *ctx, int num_vertices) | ||||
| { | { | ||||
| if (!ctx->have_displacement) { | if (!ctx->have_displacement) { | ||||
| return; | return; | ||||
| } | } | ||||
| ctx->accumulated_counters = MEM_calloc_arrayN( | ctx->accumulated_counters = MEM_calloc_arrayN( | ||||
| ▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | static void subdiv_mesh_tls_free(void *tls_v) | ||||
| if (tls->loop_interpolation_initialized) { | if (tls->loop_interpolation_initialized) { | ||||
| loop_interpolation_end(&tls->loop_interpolation); | loop_interpolation_end(&tls->loop_interpolation); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Evaluation helper functions | |||||
| * \{ */ | |||||
| static void subdiv_vertex_orco_evaluate(const SubdivMeshContext *ctx, | |||||
| const int ptex_face_index, | |||||
| const float u, | |||||
| const float v, | |||||
| const int subdiv_vertex_index) | |||||
| { | |||||
| if (ctx->orco || ctx->cloth_orco) { | |||||
| float vertex_data[6]; | |||||
| BKE_subdiv_eval_vertex_data(ctx->subdiv, ptex_face_index, u, v, vertex_data); | |||||
| if (ctx->orco) { | |||||
| copy_v3_v3(ctx->orco[subdiv_vertex_index], vertex_data); | |||||
| if (ctx->cloth_orco) { | |||||
| copy_v3_v3(ctx->orco[subdiv_vertex_index], vertex_data + 3); | |||||
| } | |||||
| } | |||||
| else if (ctx->cloth_orco) { | |||||
| copy_v3_v3(ctx->orco[subdiv_vertex_index], vertex_data); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Accumulation helpers | /** \name Accumulation helpers | ||||
| * \{ */ | * \{ */ | ||||
| static void subdiv_accumulate_vertex_displacement(SubdivMeshContext *ctx, | static void subdiv_accumulate_vertex_displacement(SubdivMeshContext *ctx, | ||||
| const int ptex_face_index, | const int ptex_face_index, | ||||
| const float u, | const float u, | ||||
| const float v, | const float v, | ||||
| MVert *subdiv_vert) | MVert *subdiv_vert) | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | if (ctx->have_displacement) { | ||||
| copy_v3_v3(D, subdiv_vert->co); | copy_v3_v3(D, subdiv_vert->co); | ||||
| mul_v3_fl(D, inv_num_accumulated); | mul_v3_fl(D, inv_num_accumulated); | ||||
| } | } | ||||
| /* Copy custom data and evaluate position. */ | /* Copy custom data and evaluate position. */ | ||||
| subdiv_vertex_data_copy(ctx, coarse_vert, subdiv_vert); | subdiv_vertex_data_copy(ctx, coarse_vert, subdiv_vert); | ||||
| BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_vert->co); | BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_vert->co); | ||||
| /* Apply displacement. */ | /* Apply displacement. */ | ||||
| add_v3_v3(subdiv_vert->co, D); | add_v3_v3(subdiv_vert->co, D); | ||||
| /* Evaluate undeformed texture coordinate. */ | |||||
| subdiv_vertex_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vertex_index); | |||||
| /* Remove facedot flag. This can happen if there is more than one subsurf modifier. */ | /* Remove facedot flag. This can happen if there is more than one subsurf modifier. */ | ||||
| BLI_BITMAP_DISABLE(ctx->subdiv_mesh->runtime.subsurf_face_dot_tags, subdiv_vertex_index); | BLI_BITMAP_DISABLE(ctx->subdiv_mesh->runtime.subsurf_face_dot_tags, subdiv_vertex_index); | ||||
| } | } | ||||
| static void evaluate_vertex_and_apply_displacement_interpolate( | static void evaluate_vertex_and_apply_displacement_interpolate( | ||||
| const SubdivMeshContext *ctx, | const SubdivMeshContext *ctx, | ||||
| const int ptex_face_index, | const int ptex_face_index, | ||||
| const float u, | const float u, | ||||
| Show All 10 Lines | if (ctx->have_displacement) { | ||||
| copy_v3_v3(D, subdiv_vert->co); | copy_v3_v3(D, subdiv_vert->co); | ||||
| mul_v3_fl(D, inv_num_accumulated); | mul_v3_fl(D, inv_num_accumulated); | ||||
| } | } | ||||
| /* Interpolate custom data and evaluate position. */ | /* Interpolate custom data and evaluate position. */ | ||||
| subdiv_vertex_data_interpolate(ctx, subdiv_vert, vertex_interpolation, u, v); | subdiv_vertex_data_interpolate(ctx, subdiv_vert, vertex_interpolation, u, v); | ||||
| BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_vert->co); | BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_vert->co); | ||||
| /* Apply displacement. */ | /* Apply displacement. */ | ||||
| add_v3_v3(subdiv_vert->co, D); | add_v3_v3(subdiv_vert->co, D); | ||||
| /* Evaluate undeformed texture coordinate. */ | |||||
| subdiv_vertex_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vertex_index); | |||||
| } | } | ||||
| static void subdiv_mesh_vertex_displacement_every_corner_or_edge( | static void subdiv_mesh_vertex_displacement_every_corner_or_edge( | ||||
| const SubdivForeachContext *foreach_context, | const SubdivForeachContext *foreach_context, | ||||
| void *UNUSED(tls), | void *UNUSED(tls), | ||||
| const int ptex_face_index, | const int ptex_face_index, | ||||
| const float u, | const float u, | ||||
| const float v, | const float v, | ||||
| ▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | static void subdiv_mesh_vertex_inner(const SubdivForeachContext *foreach_context, | ||||
| const MPoly *coarse_poly = &coarse_mpoly[coarse_poly_index]; | const MPoly *coarse_poly = &coarse_mpoly[coarse_poly_index]; | ||||
| Mesh *subdiv_mesh = ctx->subdiv_mesh; | Mesh *subdiv_mesh = ctx->subdiv_mesh; | ||||
| MVert *subdiv_mvert = subdiv_mesh->mvert; | MVert *subdiv_mvert = subdiv_mesh->mvert; | ||||
| MVert *subdiv_vert = &subdiv_mvert[subdiv_vertex_index]; | MVert *subdiv_vert = &subdiv_mvert[subdiv_vertex_index]; | ||||
| subdiv_mesh_ensure_vertex_interpolation(ctx, tls, coarse_poly, coarse_corner); | subdiv_mesh_ensure_vertex_interpolation(ctx, tls, coarse_poly, coarse_corner); | ||||
| subdiv_vertex_data_interpolate(ctx, subdiv_vert, &tls->vertex_interpolation, u, v); | subdiv_vertex_data_interpolate(ctx, subdiv_vert, &tls->vertex_interpolation, u, v); | ||||
| BKE_subdiv_eval_final_point(subdiv, ptex_face_index, u, v, subdiv_vert->co); | BKE_subdiv_eval_final_point(subdiv, ptex_face_index, u, v, subdiv_vert->co); | ||||
| subdiv_mesh_tag_center_vertex(coarse_poly, subdiv_vertex_index, u, v, subdiv_mesh); | subdiv_mesh_tag_center_vertex(coarse_poly, subdiv_vertex_index, u, v, subdiv_mesh); | ||||
| subdiv_vertex_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vertex_index); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Edge subdivision process | /** \name Edge subdivision process | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 431 Lines • Show Last 20 Lines | |||||