Subdiv: Cleanup, de-duplicate some code

This commit is contained in:
Sergey Sharybin
2018-11-01 15:20:31 +01:00
parent d710cb91b9
commit 623574ffa2
5 changed files with 44 additions and 105 deletions

View File

@@ -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"

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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__ */