From 623574ffa23badf767d8a445f1c18aabdbd10e26 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 1 Nov 2018 15:20:31 +0100 Subject: Subdiv: Cleanup, de-duplicate some code --- source/blender/blenkernel/BKE_subdiv.h | 9 +++++ .../blender/blenkernel/intern/multires_reshape.c | 40 ++-------------------- source/blender/blenkernel/intern/subdiv_ccg_mask.c | 35 +------------------ .../intern/subdiv_displacement_multires.c | 35 +------------------ source/blender/blenkernel/intern/subdiv_inline.h | 30 ++++++++++++++++ 5 files changed, 44 insertions(+), 105 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_subdiv.h b/source/blender/blenkernel/BKE_subdiv.h index 715f82fac55..0a09d3528b4 100644 --- a/source/blender/blenkernel/BKE_subdiv.h +++ b/source/blender/blenkernel/BKE_subdiv.h @@ -223,6 +223,15 @@ BLI_INLINE void BKE_subdiv_ptex_face_uv_to_grid_uv( */ BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level); +/* Simplified version of mdisp_rot_face_to_crn, only handles quad and + * works in normalized coordinates. + * + * NOTE: Output coordinates are in ptex coordinates. + */ +BLI_INLINE int BKE_subdiv_rotate_quad_to_corner( + const float u, const float v, + float *r_u, float *r_v); + #endif /* __BKE_SUBDIV_H__ */ #include "intern/subdiv_inline.h" diff --git a/source/blender/blenkernel/intern/multires_reshape.c b/source/blender/blenkernel/intern/multires_reshape.c index 22605eb510a..3544fc33816 100644 --- a/source/blender/blenkernel/intern/multires_reshape.c +++ b/source/blender/blenkernel/intern/multires_reshape.c @@ -51,41 +51,6 @@ #include "DEG_depsgraph_query.h" -/* TODO(sergey): De-duplicate with subdiv_displacement_multires.c. */ - -/* Simplified version of mdisp_rot_face_to_crn, only handles quad and - * works in normalized coordinates. - * - * NOTE: Output coordinates are in ptex coordinates. - */ -BLI_INLINE int rotate_quad_to_corner(const float u, const float v, - float *r_u, float *r_v) -{ - int corner; - if (u <= 0.5f && v <= 0.5f) { - corner = 0; - *r_u = 2.0f * u; - *r_v = 2.0f * v; - } - else if (u > 0.5f && v <= 0.5f) { - corner = 1; - *r_u = 2.0f * v; - *r_v = 2.0f * (1.0f - u); - } - else if (u > 0.5f && v > 0.5f) { - corner = 2; - *r_u = 2.0f * (1.0f - u); - *r_v = 2.0f * (1.0f - v); - } - else { - BLI_assert(u <= 0.5f && v >= 0.5f); - corner = 3; - *r_u = 2.0f * (1.0f - v); - *r_v = 2.0f * u; - } - return corner; -} - static void multires_reshape_init_mmd( MultiresModifierData *reshape_mmd, const MultiresModifierData *mmd) @@ -314,7 +279,8 @@ static void multires_reshape_vertex_from_final_data( int grid_index; if (coarse_poly->totloop == 4) { float corner_u, corner_v; - face_corner = rotate_quad_to_corner(u, v, &corner_u, &corner_v); + face_corner = BKE_subdiv_rotate_quad_to_corner( + u, v, &corner_u, &corner_v); grid_corner = face_corner; grid_index = loop_index + face_corner; BKE_subdiv_ptex_face_uv_to_grid_uv( @@ -948,7 +914,7 @@ static void reshape_from_ccg_regular_face(ReshapeFromCCGTaskData *data, const float u = x * resolution_1_inv; float corner_u, corner_v; float grid_u, grid_v; - const int face_corner = rotate_quad_to_corner( + const int face_corner = BKE_subdiv_rotate_quad_to_corner( u, v, &corner_u, &corner_v); BKE_subdiv_ptex_face_uv_to_grid_uv( corner_u, corner_v, &grid_u, &grid_v); diff --git a/source/blender/blenkernel/intern/subdiv_ccg_mask.c b/source/blender/blenkernel/intern/subdiv_ccg_mask.c index 9cd7ed0a962..0da30fb1bf0 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg_mask.c +++ b/source/blender/blenkernel/intern/subdiv_ccg_mask.c @@ -60,39 +60,6 @@ typedef struct GridPaintMaskData { PolyCornerIndex *ptex_poly_corner; } GridPaintMaskData; -/* Simplified version of mdisp_rot_face_to_crn, only handles quad and - * works in normalized coordinates. - * - * NOTE: Output coordinates are in ptex coordinates. - */ -BLI_INLINE int rotate_quad_to_corner(const float u, const float v, - float *r_u, float *r_v) -{ - int corner; - if (u <= 0.5f && v <= 0.5f) { - corner = 0; - *r_u = 2.0f * u; - *r_v = 2.0f * v; - } - else if (u > 0.5f && v <= 0.5f) { - corner = 1; - *r_u = 2.0f * v; - *r_v = 2.0f * (1.0f - u); - } - else if (u > 0.5f && v > 0.5f) { - corner = 2; - *r_u = 2.0f * (1.0f - u); - *r_v = 2.0f * (1.0f - v); - } - else { - BLI_assert(u <= 0.5f && v >= 0.5f); - corner = 3; - *r_u = 2.0f * (1.0f - v); - *r_v = 2.0f * u; - } - return corner; -} - static int mask_get_grid_and_coord( SubdivCCGMask *mask_evaluator, const int ptex_face_index, const float u, const float v, @@ -107,7 +74,7 @@ static int mask_get_grid_and_coord( int corner = 0; if (poly->totloop == 4) { float corner_u, corner_v; - corner = rotate_quad_to_corner(u, v, &corner_u, &corner_v); + corner = BKE_subdiv_rotate_quad_to_corner(u, v, &corner_u, &corner_v); *r_mask_grid = &data->grid_paint_mask[start_grid_index + corner]; BKE_subdiv_ptex_face_uv_to_grid_uv(corner_u, corner_v, grid_u, grid_v); diff --git a/source/blender/blenkernel/intern/subdiv_displacement_multires.c b/source/blender/blenkernel/intern/subdiv_displacement_multires.c index bcb96ce8a66..5744ac3ca0d 100644 --- a/source/blender/blenkernel/intern/subdiv_displacement_multires.c +++ b/source/blender/blenkernel/intern/subdiv_displacement_multires.c @@ -70,39 +70,6 @@ typedef enum eAverageWith { AVERAGE_WITH_NEXT, } eAverageWith; -/* Simplified version of mdisp_rot_face_to_crn, only handles quad and - * works in normalized coordinates. - * - * NOTE: Output coordinates are in ptex coordinates. - */ -BLI_INLINE int rotate_quad_to_corner(const float u, const float v, - float *r_u, float *r_v) -{ - int corner; - if (u <= 0.5f && v <= 0.5f) { - corner = 0; - *r_u = 2.0f * u; - *r_v = 2.0f * v; - } - else if (u > 0.5f && v <= 0.5f) { - corner = 1; - *r_u = 2.0f * v; - *r_v = 2.0f * (1.0f - u); - } - else if (u > 0.5f && v > 0.5f) { - corner = 2; - *r_u = 2.0f * (1.0f - u); - *r_v = 2.0f * (1.0f - v); - } - else { - BLI_assert(u <= 0.5f && v >= 0.5f); - corner = 3; - *r_u = 2.0f * (1.0f - v); - *r_v = 2.0f * u; - } - return corner; -} - static int displacement_get_grid_and_coord( SubdivDisplacement *displacement, const int ptex_face_index, const float u, const float v, @@ -117,7 +84,7 @@ static int displacement_get_grid_and_coord( int corner = 0; if (poly->totloop == 4) { float corner_u, corner_v; - corner = rotate_quad_to_corner(u, v, &corner_u, &corner_v); + corner = BKE_subdiv_rotate_quad_to_corner(u, v, &corner_u, &corner_v); *r_displacement_grid = &data->mdisps[start_grid_index + corner]; BKE_subdiv_ptex_face_uv_to_grid_uv(corner_u, corner_v, grid_u, grid_v); } diff --git a/source/blender/blenkernel/intern/subdiv_inline.h b/source/blender/blenkernel/intern/subdiv_inline.h index c9e924ced82..0e715506ed3 100644 --- a/source/blender/blenkernel/intern/subdiv_inline.h +++ b/source/blender/blenkernel/intern/subdiv_inline.h @@ -31,6 +31,7 @@ #define __BKE_SUBDIV_INLINE_H__ #include "BKE_subdiv.h" +#include "BLI_utildefines.h" BLI_INLINE void BKE_subdiv_ptex_face_uv_to_grid_uv( const float ptex_u, const float ptex_v, @@ -45,4 +46,33 @@ BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level) return (1 << (level - 1)) + 1; } +BLI_INLINE int BKE_subdiv_rotate_quad_to_corner( + const float u, const float v, + float *r_u, float *r_v) +{ + int corner; + if (u <= 0.5f && v <= 0.5f) { + corner = 0; + *r_u = 2.0f * u; + *r_v = 2.0f * v; + } + else if (u > 0.5f && v <= 0.5f) { + corner = 1; + *r_u = 2.0f * v; + *r_v = 2.0f * (1.0f - u); + } + else if (u > 0.5f && v > 0.5f) { + corner = 2; + *r_u = 2.0f * (1.0f - u); + *r_v = 2.0f * (1.0f - v); + } + else { + BLI_assert(u <= 0.5f && v >= 0.5f); + corner = 3; + *r_u = 2.0f * (1.0f - v); + *r_v = 2.0f * u; + } + return corner; +} + #endif /* __BKE_SUBDIV_INLINE_H__ */ -- cgit v1.2.3