diff options
Diffstat (limited to 'source/blender/blenkernel/intern/subdiv_ccg.c')
-rw-r--r-- | source/blender/blenkernel/intern/subdiv_ccg.c | 73 |
1 files changed, 58 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index bc1b79f62c5..0997b42a19f 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -85,7 +85,7 @@ static int element_size_bytes_get(const SubdivCCG *subdiv_ccg) static void subdiv_ccg_init_layers(SubdivCCG *subdiv_ccg, const SubdivToCCGSettings *settings) { /* CCG always contains coordinates. Rest of layers are coming after them. */ - int layer_offset = sizeof(float) * 3; + int layer_offset = sizeof(float[3]); /* Mask. */ if (settings->need_mask) { subdiv_ccg->has_mask = true; @@ -103,7 +103,7 @@ static void subdiv_ccg_init_layers(SubdivCCG *subdiv_ccg, const SubdivToCCGSetti if (settings->need_normal) { subdiv_ccg->has_normal = true; subdiv_ccg->normal_offset = layer_offset; - layer_offset += sizeof(float) * 3; + layer_offset += sizeof(float[3]); } else { subdiv_ccg->has_normal = false; @@ -234,7 +234,7 @@ static void subdiv_ccg_eval_regular_grid(CCGEvalGridsData *data, const int face_ SubdivCCG *subdiv_ccg = data->subdiv_ccg; const int ptex_face_index = data->face_ptex_offset[face_index]; const int grid_size = subdiv_ccg->grid_size; - const float grid_size_1_inv = 1.0f / (float)(grid_size - 1); + const float grid_size_1_inv = 1.0f / (grid_size - 1); const int element_size = element_size_bytes_get(subdiv_ccg); SubdivCCGFace *faces = subdiv_ccg->faces; SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces; @@ -243,9 +243,9 @@ static void subdiv_ccg_eval_regular_grid(CCGEvalGridsData *data, const int face_ const int grid_index = face->start_grid_index + corner; unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index]; for (int y = 0; y < grid_size; y++) { - const float grid_v = (float)y * grid_size_1_inv; + const float grid_v = y * grid_size_1_inv; for (int x = 0; x < grid_size; x++) { - const float grid_u = (float)x * grid_size_1_inv; + const float grid_u = x * grid_size_1_inv; float u, v; BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, &u, &v); const size_t grid_element_index = (size_t)y * grid_size + x; @@ -265,7 +265,7 @@ static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_ { SubdivCCG *subdiv_ccg = data->subdiv_ccg; const int grid_size = subdiv_ccg->grid_size; - const float grid_size_1_inv = 1.0f / (float)(grid_size - 1); + const float grid_size_1_inv = 1.0f / (grid_size - 1); const int element_size = element_size_bytes_get(subdiv_ccg); SubdivCCGFace *faces = subdiv_ccg->faces; SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces; @@ -275,9 +275,9 @@ static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_ const int ptex_face_index = data->face_ptex_offset[face_index] + corner; unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index]; for (int y = 0; y < grid_size; y++) { - const float u = 1.0f - ((float)y * grid_size_1_inv); + const float u = 1.0f - (y * grid_size_1_inv); for (int x = 0; x < grid_size; x++) { - const float v = 1.0f - ((float)x * grid_size_1_inv); + const float v = 1.0f - (x * grid_size_1_inv); const size_t grid_element_index = (size_t)y * grid_size + x; const size_t grid_element_offset = grid_element_index * element_size; subdiv_ccg_eval_grid_element(data, ptex_face_index, u, v, &grid[grid_element_offset]); @@ -709,7 +709,7 @@ static void subdiv_ccg_recalc_inner_face_normals(SubdivCCG *subdiv_ccg, CCGElem *grid = subdiv_ccg->grids[grid_index]; if (tls->face_normals == NULL) { tls->face_normals = MEM_malloc_arrayN( - grid_size_1 * grid_size_1, 3 * sizeof(float), "CCG TLS normals"); + grid_size_1 * grid_size_1, sizeof(float[3]), "CCG TLS normals"); } for (int y = 0; y < grid_size - 1; y++) { for (int x = 0; x < grid_size - 1; x++) { @@ -766,7 +766,7 @@ static void subdiv_ccg_average_inner_face_normals(SubdivCCG *subdiv_ccg, counter++; } /* Normalize and store. */ - mul_v3_v3fl(CCG_grid_elem_no(key, grid, x, y), normal_acc, 1.0f / (float)counter); + mul_v3_v3fl(CCG_grid_elem_no(key, grid, x, y), normal_acc, 1.0f / counter); } } } @@ -1009,7 +1009,7 @@ static void subdiv_ccg_average_inner_face_grids(SubdivCCG *subdiv_ccg, CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0); element_accumulator_add(¢er_accumulator, subdiv_ccg, key, grid_center_element); } - element_accumulator_mul_fl(¢er_accumulator, 1.0f / (float)num_face_grids); + element_accumulator_mul_fl(¢er_accumulator, 1.0f / num_face_grids); for (int corner = 0; corner < num_face_grids; corner++) { CCGElem *grid = grids[face->start_grid_index + corner]; CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0); @@ -1066,7 +1066,7 @@ static void subdiv_ccg_average_grids_boundary(SubdivCCG *subdiv_ccg, } } for (int i = 1; i < grid_size2 - 1; i++) { - element_accumulator_mul_fl(&tls->accumulators[i], 1.0f / (float)num_adjacent_faces); + element_accumulator_mul_fl(&tls->accumulators[i], 1.0f / num_adjacent_faces); } /* Copy averaged value to all the other faces. */ for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { @@ -1118,7 +1118,7 @@ static void subdiv_ccg_average_grids_corners(SubdivCCG *subdiv_ccg, key, subdiv_ccg, &adjacent_vertex->corner_coords[face_index]); element_accumulator_add(&accumulator, subdiv_ccg, key, grid_element); } - element_accumulator_mul_fl(&accumulator, 1.0f / (float)num_adjacent_faces); + element_accumulator_mul_fl(&accumulator, 1.0f / num_adjacent_faces); /* Copy averaged value to all the other faces. */ for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { CCGElem *grid_element = subdiv_ccg_coord_to_elem( @@ -1618,7 +1618,7 @@ static int prev_adjacent_edge_point_index(const SubdivCCG *subdiv_ccg, const int return point_index - 1; } -/* When the point index corresponds to a grid corner, returs the point index which corresponds to +/* When the point index corresponds to a grid corner, returns the point index which corresponds to * the corner of the adjacent grid, as the adjacent edge has two separate points for each grid * corner at the middle of the edge. */ static int adjacent_grid_corner_point_index_on_edge(const SubdivCCG *subdiv_ccg, @@ -1650,7 +1650,7 @@ static void neighbor_coords_edge_get(const SubdivCCG *subdiv_ccg, if (include_duplicates) { num_duplicates += num_adjacent_faces - 1; if (is_corner) { - /* When the coord is a grid corner, add an extra duplicate per adajacent grid in all adjacent + /* When the coord is a grid corner, add an extra duplicate per adjacent grid in all adjacent * faces to the edge. */ num_duplicates += num_adjacent_faces; } @@ -1933,4 +1933,47 @@ void BKE_subdiv_ccg_grid_hidden_ensure(SubdivCCG *subdiv_ccg, int grid_index) subdiv_ccg->grid_hidden[grid_index] = BLI_BITMAP_NEW(key.grid_area, __func__); } +static void subdiv_ccg_coord_to_ptex_coord(const SubdivCCG *subdiv_ccg, + const SubdivCCGCoord *coord, + int *r_ptex_face_index, + float *r_u, + float *r_v) +{ + Subdiv *subdiv = subdiv_ccg->subdiv; + + const float grid_size = subdiv_ccg->grid_size; + const float grid_size_1_inv = 1.0f / (grid_size - 1); + + const float grid_u = coord->x * grid_size_1_inv; + const float grid_v = coord->y * grid_size_1_inv; + + const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, coord->grid_index); + const SubdivCCGFace *faces = subdiv_ccg->faces; + const SubdivCCGFace *face = &faces[face_index]; + const int *face_ptex_offset = BKE_subdiv_face_ptex_offset_get(subdiv); + *r_ptex_face_index = face_ptex_offset[face_index]; + + const float corner = coord->grid_index - face->start_grid_index; + + if (face->num_grids == 4) { + BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, r_u, r_v); + } + else { + *r_ptex_face_index += corner; + *r_u = 1.0f - grid_v; + *r_v = 1.0f - grid_u; + } +} + +void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg, + const SubdivCCGCoord *coord, + float r_point[3]) +{ + Subdiv *subdiv = subdiv_ccg->subdiv; + int ptex_face_index; + float u, v; + subdiv_ccg_coord_to_ptex_coord(subdiv_ccg, coord, &ptex_face_index, &u, &v); + BKE_subdiv_eval_limit_point(subdiv, ptex_face_index, u, v, r_point); +} + /** \} */ |