79 memset(reshape_context, 0,
sizeof(*reshape_context));
86 const int num_faces = base_mesh->
totpoly;
89 sizeof(
int), num_faces,
"face_start_grid_index");
91 int num_ptex_faces = 0;
92 for (
int face_index = 0; face_index < num_faces; ++face_index) {
93 const int num_corners = mpoly[face_index].
totloop;
95 num_grids += num_corners;
96 num_ptex_faces += (num_corners == 4) ? 1 : num_corners;
100 sizeof(
int), num_grids,
"grid_to_face_index");
102 sizeof(
int), num_ptex_faces,
"ptex_start_grid_index");
103 for (
int face_index = 0, grid_index = 0, ptex_index = 0; face_index < num_faces; ++face_index) {
104 const int num_corners = mpoly[face_index].
totloop;
105 const int num_face_ptex_faces = (num_corners == 4) ? 1 : num_corners;
106 for (
int i = 0; i < num_face_ptex_faces; ++i) {
112 ptex_index += num_face_ptex_faces;
162 const bool use_render_params =
false;
167 reshape_context->
object =
object;
168 reshape_context->
mmd = mmd;
176 scene_eval,
object, mmd, use_render_params,
true);
195 const bool use_render_params =
false;
200 reshape_context->
object =
object;
201 reshape_context->
mmd = mmd;
209 scene_eval,
object, mmd, use_render_params,
true);
237 reshape_context->
top.
level = top_level;
253 reshape_context,
object, mmd, subdiv, top_level);
270 reshape_context->
mmd = mmd;
273 reshape_context->
subdiv = subdiv;
280 reshape_context->
top.
level = top_level;
293 if (orig_mdisps ==
NULL && orig_grid_paint_masks ==
NULL) {
297 const int num_grids = reshape_context->
num_grids;
298 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
299 if (orig_mdisps !=
NULL) {
300 MDisps *orig_grid = &orig_mdisps[grid_index];
303 if (orig_grid_paint_masks !=
NULL) {
304 GridPaintMask *orig_paint_mask_grid = &orig_grid_paint_masks[grid_index];
340 BLI_assert(grid_index < reshape_context->num_grids);
352 BLI_assert(grid_index < reshape_context->num_grids);
364 return (base_poly->
totloop == 4);
386 float corner_u, corner_v;
393 float grid_u, grid_v;
398 ptex_coord.
u = corner_u;
399 ptex_coord.
v = corner_v;
417 ptex_coord->
u, ptex_coord->
v, &grid_coord.
u, &grid_coord.
v);
421 grid_coord.
u = ptex_coord->
u;
422 grid_coord.
v = ptex_coord->
v;
424 grid_coord.
grid_index = start_grid_index + corner_delta;
432 const int face_index,
436 float r_tangent_matrix[3][3])
441 const int tangent_corner = is_quad ?
corner : 0;
451 const int grid_x = lround(grid_coord->
u * (grid_size - 1));
452 const int grid_y = lround(grid_coord->
v * (grid_size - 1));
453 const int grid_element_index = grid_y * grid_size + grid_x;
462 grid_element.
mask = &grid_paint_mask->
data[grid_element_index];
481 if (mdisps !=
NULL) {
485 const int grid_x = lround(grid_coord->
u * (grid_size - 1));
486 const int grid_y = lround(grid_coord->
v * (grid_size - 1));
487 const int grid_element_index = grid_y * grid_size + grid_x;
493 if (grid_paint_masks !=
NULL) {
495 if (paint_mask_grid->
data !=
NULL) {
497 const int grid_x = lround(grid_coord->
u * (grid_size - 1));
498 const int grid_y = lround(grid_coord->
v * (grid_size - 1));
499 const int grid_element_index = grid_y * grid_size + grid_x;
500 grid_element.
mask = paint_mask_grid->
data[grid_element_index];
516 float r_tangent_matrix[3][3])
518 float dPdu[3], dPdv[3];
522 subdiv, ptex_coord.
ptex_face_index, ptex_coord.
u, ptex_coord.
v, r_P, dPdu, dPdv);
528 reshape_context, face_index,
corner, dPdu, dPdv, r_tangent_matrix);
540 const int grid_area = grid_size * grid_size;
546 displacement_grid->
disps = disps;
547 displacement_grid->
totdisp = grid_area;
548 displacement_grid->
level = level;
553 if (displacement_grid->
disps !=
NULL && displacement_grid->
level >= level) {
563 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
571 if (grid_paint_masks ==
NULL) {
576 const int grid_area = grid_size * grid_size;
577 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
578 GridPaintMask *grid_paint_mask = &grid_paint_masks[grid_index];
579 if (grid_paint_mask->
level >= level) {
582 grid_paint_mask->
level = level;
583 if (grid_paint_mask->
data) {
610 if (grid_paint_masks !=
NULL) {
614 const int num_grids = reshape_context->
num_grids;
615 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
616 MDisps *orig_grid = &orig_mdisps[grid_index];
624 if (orig_grid_paint_masks !=
NULL) {
625 GridPaintMask *orig_paint_mask_grid = &orig_grid_paint_masks[grid_index];
626 if (orig_paint_mask_grid->
data !=
NULL) {
651 const int face_index,
658 const Mesh *base_mesh =
data->reshape_context->base_mesh;
660 const int grid_size =
data->grid_size;
661 const float grid_size_1_inv = 1.0f / (((
float)grid_size) - 1.0f);
663 const int num_corners = mpoly[face_index].
totloop;
666 for (
int y = 0;
y < grid_size; ++
y) {
667 const float v = (
float)
y * grid_size_1_inv;
668 for (
int x = 0;
x < grid_size; ++
x) {
669 const float u = (
float)
x * grid_size_1_inv;
676 data->callback(
data->reshape_context, &grid_coord,
data->callback_userdata_v);
689 data.reshape_context = reshape_context;
691 data.grid_size_1_inv = 1.0f / (((
float)
data.grid_size) - 1.0f);
693 data.callback_userdata_v = userdata_v;
700 const int num_faces = base_mesh->
totpoly;
711 float tangent_matrix[3][3];
714 float inv_tangent_matrix[3][3];
752 float tangent_matrix[3][3];
775 float tangent_matrix[3][3];
789 *grid_element.
mask = orig_grid_element.
mask;
typedef float(TangentPoint)[2]
const CustomData_MeshMasks CD_MASK_BAREMESH
void * CustomData_get_layer(const struct CustomData *data, int type)
struct Mesh * mesh_get_eval_deform(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, const struct CustomData_MeshMasks *dataMask)
void BKE_multires_subdiv_settings_init(struct SubdivSettings *settings, const struct MultiresModifierData *mmd)
int multires_get_level(const struct Scene *scene, const struct Object *ob, const struct MultiresModifierData *mmd, bool render, bool ignore_simplify)
BLI_INLINE void BKE_multires_construct_tangent_matrix(float tangent_matrix[3][3], const float dPdu[3], const float dPdv[3], const int corner)
BLI_INLINE void BKE_subdiv_rotate_grid_to_quad(const int corner, const float grid_u, const float grid_v, float *r_quad_u, float *r_quad_v)
BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level)
void BKE_subdiv_free(Subdiv *subdiv)
BLI_INLINE int BKE_subdiv_rotate_quad_to_corner(const float quad_u, const float quad_v, float *r_corner_u, float *r_corner_v)
Subdiv * BKE_subdiv_new_from_mesh(const SubdivSettings *settings, const struct Mesh *mesh)
int * BKE_subdiv_face_ptex_offset_get(Subdiv *subdiv)
BLI_INLINE void BKE_subdiv_grid_uv_to_ptex_face_uv(const float grid_u, const float grid_v, float *r_ptex_u, float *r_ptex_v)
BLI_INLINE void BKE_subdiv_ptex_face_uv_to_grid_uv(const float ptex_u, const float ptex_v, float *r_grid_u, float *r_grid_v)
bool BKE_subdiv_eval_begin_from_mesh(struct Subdiv *subdiv, const struct Mesh *mesh, const float(*coarse_vertex_cos)[3])
void BKE_subdiv_eval_limit_point_and_derivatives(struct Subdiv *subdiv, const int ptex_face_index, const float u, const float v, float r_P[3], float r_dPdu[3], float r_dPdv[3])
bool invert_m3_m3(float R[3][3], const float A[3][3])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
struct Depsgraph Depsgraph
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
const Depsgraph * depsgraph
DEGForeachIDComponentCallback callback
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
int multires_reshape_grid_to_face_index(const MultiresReshapeContext *reshape_context, int grid_index)
void multires_reshape_assign_final_elements_from_orig_mdisps(const MultiresReshapeContext *reshape_context)
static void ensure_displacement_grids(Mesh *mesh, const int grid_level)
bool multires_reshape_is_quad_face(const MultiresReshapeContext *reshape_context, int face_index)
static void foreach_grid_face_coordinate_task(void *__restrict userdata_v, const int face_index, const TaskParallelTLS *__restrict UNUSED(tls))
void multires_reshape_assign_final_coords_from_mdisps(const MultiresReshapeContext *reshape_context)
static void context_init_grid_pointers(MultiresReshapeContext *reshape_context)
bool multires_reshape_context_create_from_object(MultiresReshapeContext *reshape_context, Depsgraph *depsgraph, Object *object, MultiresModifierData *mmd)
static bool context_verify_or_free(MultiresReshapeContext *reshape_context)
static void object_grid_element_to_tangent_displacement(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord, void *UNUSED(userdata_v))
struct ForeachGridCoordinateTaskData ForeachGridCoordinateTaskData
ReshapeGridElement multires_reshape_grid_element_for_grid_coord(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord)
int multires_reshape_grid_to_ptex_index(const MultiresReshapeContext *reshape_context, int grid_index)
static void context_init_lookup(MultiresReshapeContext *reshape_context)
PTexCoord multires_reshape_grid_coord_to_ptex(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord)
void multires_reshape_context_free(MultiresReshapeContext *reshape_context)
void multires_reshape_store_original_grids(MultiresReshapeContext *reshape_context)
static void allocate_displacement_grid(MDisps *displacement_grid, const int level)
int multires_reshape_grid_to_corner(const MultiresReshapeContext *reshape_context, int grid_index)
void multires_reshape_tangent_matrix_for_corner(const MultiresReshapeContext *reshape_context, const int face_index, const int corner, const float dPdu[3], const float dPdv[3], float r_tangent_matrix[3][3])
bool multires_reshape_context_create_from_modifier(MultiresReshapeContext *reshape_context, struct Object *object, struct MultiresModifierData *mmd, int top_level)
void multires_reshape_ensure_grids(Mesh *mesh, const int level)
void multires_reshape_free_original_grids(MultiresReshapeContext *reshape_context)
void(* ForeachGridCoordinateCallback)(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord, void *userdata_v)
static void foreach_grid_coordinate(const MultiresReshapeContext *reshape_context, const int level, ForeachGridCoordinateCallback callback, void *userdata_v)
bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape_context, struct Object *object, struct MultiresModifierData *mmd, struct Subdiv *subdiv, int top_level)
static void context_zero(MultiresReshapeContext *reshape_context)
Subdiv * multires_reshape_create_subdiv(Depsgraph *depsgraph, Object *object, const MultiresModifierData *mmd)
void multires_reshape_object_grids_to_tangent_displacement(const MultiresReshapeContext *reshape_context)
bool multires_reshape_context_create_from_base_mesh(MultiresReshapeContext *reshape_context, Depsgraph *depsgraph, Object *object, MultiresModifierData *mmd)
ReshapeConstGridElement multires_reshape_orig_grid_element_for_grid_coord(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord)
ReshapeGridElement multires_reshape_grid_element_for_ptex_coord(const MultiresReshapeContext *reshape_context, const PTexCoord *ptex_coord)
static void ensure_displacement_grid(MDisps *displacement_grid, const int level)
static bool context_is_valid(MultiresReshapeContext *reshape_context)
GridCoord multires_reshape_ptex_coord_to_grid(const MultiresReshapeContext *reshape_context, const PTexCoord *ptex_coord)
static void assign_final_elements_from_orig_mdisps(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord, void *UNUSED(userdata_v))
static void context_init_commoon(MultiresReshapeContext *reshape_context)
static void ensure_mask_grids(Mesh *mesh, const int level)
void multires_reshape_evaluate_limit_at_grid(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord, float r_P[3], float r_tangent_matrix[3][3])
bool multires_reshape_context_create_from_ccg(MultiresReshapeContext *reshape_context, SubdivCCG *subdiv_ccg, Mesh *base_mesh, int top_level)
static void assign_final_coords_from_mdisps(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord, void *UNUSED(userdata_v))
void * callback_userdata_v
ForeachGridCoordinateCallback callback
const MultiresReshapeContext * reshape_context
struct CustomData pdata ldata
struct MultiresReshapeContext::@101 orig
struct GridPaintMask * grid_paint_masks
struct MultiresModifierData * mmd
struct MultiresReshapeContext::@99 reshape
int * face_start_grid_index
int * ptex_start_grid_index
struct Depsgraph * depsgraph
struct MultiresReshapeContext::@100 top
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)