Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/subdiv_mesh.cc
| Show All 10 Lines | |||||
| #include "DNA_key_types.h" | #include "DNA_key_types.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "BLI_array.hh" | #include "BLI_array.hh" | ||||
| #include "BLI_bitmap.h" | #include "BLI_bitmap.h" | ||||
| #include "BLI_math_vector.h" | #include "BLI_math_vector.h" | ||||
| #include "BLI_math_vector_types.hh" | |||||
| #include "BKE_customdata.h" | #include "BKE_customdata.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_mapping.h" | #include "BKE_mesh_mapping.h" | ||||
| #include "BKE_subdiv.h" | #include "BKE_subdiv.h" | ||||
| #include "BKE_subdiv_eval.h" | #include "BKE_subdiv_eval.h" | ||||
| #include "BKE_subdiv_foreach.h" | #include "BKE_subdiv_foreach.h" | ||||
| #include "BKE_subdiv_mesh.h" | #include "BKE_subdiv_mesh.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| using blender::float2; | |||||
| using blender::float3; | using blender::float3; | ||||
| using blender::Span; | using blender::Span; | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Subdivision Context | /** \name Subdivision Context | ||||
| * \{ */ | * \{ */ | ||||
| struct SubdivMeshContext { | struct SubdivMeshContext { | ||||
| Show All 13 Lines | 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]; | float2 *uv_layers[MAX_MTFACE]; | ||||
| /* Original coordinates (ORCO) interpolation. */ | /* Original coordinates (ORCO) interpolation. */ | ||||
| float (*orco)[3]; | float (*orco)[3]; | ||||
| float (*cloth_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; | ||||
| /* Lazily initialize a map from vertices to connected edges. */ | /* Lazily initialize a map from vertices to connected edges. */ | ||||
| std::mutex vert_to_edge_map_mutex; | std::mutex vert_to_edge_map_mutex; | ||||
| int *vert_to_edge_buffer; | int *vert_to_edge_buffer; | ||||
| MeshElemMap *vert_to_edge_map; | MeshElemMap *vert_to_edge_map; | ||||
| }; | }; | ||||
| 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; | ||||
| ctx->num_uv_layers = CustomData_number_of_layers(&subdiv_mesh->ldata, CD_MLOOPUV); | ctx->num_uv_layers = CustomData_number_of_layers(&subdiv_mesh->ldata, CD_PROP_FLOAT2); | ||||
| for (int layer_index = 0; layer_index < ctx->num_uv_layers; layer_index++) { | for (int layer_index = 0; layer_index < ctx->num_uv_layers; layer_index++) { | ||||
| ctx->uv_layers[layer_index] = static_cast<MLoopUV *>( | ctx->uv_layers[layer_index] = static_cast<float2 *>( | ||||
| CustomData_get_layer_n(&subdiv_mesh->ldata, CD_MLOOPUV, layer_index)); | CustomData_get_layer_n(&subdiv_mesh->ldata, CD_PROP_FLOAT2, layer_index)); | ||||
| } | } | ||||
| } | } | ||||
| static void subdiv_mesh_ctx_cache_custom_data_layers(SubdivMeshContext *ctx) | static void subdiv_mesh_ctx_cache_custom_data_layers(SubdivMeshContext *ctx) | ||||
| { | { | ||||
| Mesh *subdiv_mesh = ctx->subdiv_mesh; | Mesh *subdiv_mesh = ctx->subdiv_mesh; | ||||
| ctx->subdiv_positions = subdiv_mesh->vert_positions_for_write().data(); | ctx->subdiv_positions = subdiv_mesh->vert_positions_for_write().data(); | ||||
| ctx->subdiv_edges = BKE_mesh_edges_for_write(subdiv_mesh); | ctx->subdiv_edges = BKE_mesh_edges_for_write(subdiv_mesh); | ||||
| ▲ Show 20 Lines • Show All 764 Lines • ▼ Show 20 Lines | static void subdiv_eval_uv_layer(SubdivMeshContext *ctx, | ||||
| const float v) | const float v) | ||||
| { | { | ||||
| if (ctx->num_uv_layers == 0) { | if (ctx->num_uv_layers == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| Subdiv *subdiv = ctx->subdiv; | Subdiv *subdiv = ctx->subdiv; | ||||
| const int mloop_index = subdiv_loop - ctx->subdiv_loops; | const int mloop_index = subdiv_loop - ctx->subdiv_loops; | ||||
| for (int layer_index = 0; layer_index < ctx->num_uv_layers; layer_index++) { | for (int layer_index = 0; layer_index < ctx->num_uv_layers; layer_index++) { | ||||
| MLoopUV *subdiv_loopuv = &ctx->uv_layers[layer_index][mloop_index]; | BKE_subdiv_eval_face_varying( | ||||
| BKE_subdiv_eval_face_varying(subdiv, layer_index, ptex_face_index, u, v, subdiv_loopuv->uv); | subdiv, layer_index, ptex_face_index, u, v, ctx->uv_layers[layer_index][mloop_index]); | ||||
| } | } | ||||
| } | } | ||||
| static void subdiv_mesh_ensure_loop_interpolation(SubdivMeshContext *ctx, | static void subdiv_mesh_ensure_loop_interpolation(SubdivMeshContext *ctx, | ||||
| SubdivMeshTLS *tls, | SubdivMeshTLS *tls, | ||||
| const MPoly *coarse_poly, | const MPoly *coarse_poly, | ||||
| const int coarse_corner) | const int coarse_corner) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines | |||||