63 memset(reshape_context, 0,
sizeof(*reshape_context));
70 const int num_faces = base_mesh->
totpoly;
73 num_faces,
sizeof(
int),
"face_start_grid_index");
75 int num_ptex_faces = 0;
76 for (
int face_index = 0; face_index < num_faces; ++face_index) {
77 const int num_corners = mpoly[face_index].
totloop;
79 num_grids += num_corners;
80 num_ptex_faces += (num_corners == 4) ? 1 : num_corners;
84 num_grids,
sizeof(
int),
"grid_to_face_index");
86 num_ptex_faces,
sizeof(
int),
"ptex_start_grid_index");
87 for (
int face_index = 0, grid_index = 0, ptex_index = 0; face_index < num_faces; ++face_index) {
88 const int num_corners = mpoly[face_index].
totloop;
89 const int num_face_ptex_faces = (num_corners == 4) ? 1 : num_corners;
90 for (
int i = 0; i < num_face_ptex_faces; ++i) {
96 ptex_index += num_face_ptex_faces;
146 const bool use_render_params =
false;
151 reshape_context->
object =
object;
152 reshape_context->
mmd = mmd;
160 scene_eval,
object, mmd, use_render_params,
true);
179 const bool use_render_params =
false;
184 reshape_context->
object =
object;
185 reshape_context->
mmd = mmd;
193 scene_eval,
object, mmd, use_render_params,
true);
223 reshape_context->
top.
level = top_level;
239 reshape_context,
object, mmd, subdiv, top_level);
256 reshape_context->
mmd = mmd;
259 reshape_context->
subdiv = subdiv;
266 reshape_context->
top.
level = top_level;
279 if (orig_mdisps ==
NULL && orig_grid_paint_masks ==
NULL) {
283 const int num_grids = reshape_context->
num_grids;
284 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
285 if (orig_mdisps !=
NULL) {
286 MDisps *orig_grid = &orig_mdisps[grid_index];
289 if (orig_grid_paint_masks !=
NULL) {
290 GridPaintMask *orig_paint_mask_grid = &orig_grid_paint_masks[grid_index];
325 BLI_assert(grid_index < reshape_context->num_grids);
336 BLI_assert(grid_index < reshape_context->num_grids);
348 return (base_poly->
totloop == 4);
368 float corner_u, corner_v;
375 float grid_u, grid_v;
380 ptex_coord.
u = corner_u;
381 ptex_coord.
v = corner_v;
398 ptex_coord->
u, ptex_coord->
v, &grid_coord.
u, &grid_coord.
v);
402 grid_coord.
u = ptex_coord->
u;
403 grid_coord.
v = ptex_coord->
v;
405 grid_coord.
grid_index = start_grid_index + corner_delta;
413 const int face_index,
417 float r_tangent_matrix[3][3])
422 const int tangent_corner = is_quad ?
corner : 0;
432 const int grid_x = lround(grid_coord->
u * (grid_size - 1));
433 const int grid_y = lround(grid_coord->
v * (grid_size - 1));
434 const int grid_element_index = grid_y * grid_size + grid_x;
443 grid_element.
mask = &grid_paint_mask->
data[grid_element_index];
462 if (mdisps !=
NULL) {
466 const int grid_x = lround(grid_coord->
u * (grid_size - 1));
467 const int grid_y = lround(grid_coord->
v * (grid_size - 1));
468 const int grid_element_index = grid_y * grid_size + grid_x;
474 if (grid_paint_masks !=
NULL) {
476 if (paint_mask_grid->
data !=
NULL) {
478 const int grid_x = lround(grid_coord->
u * (grid_size - 1));
479 const int grid_y = lround(grid_coord->
v * (grid_size - 1));
480 const int grid_element_index = grid_y * grid_size + grid_x;
481 grid_element.
mask = paint_mask_grid->
data[grid_element_index];
497 float r_tangent_matrix[3][3])
499 float dPdu[3], dPdv[3];
503 subdiv, ptex_coord.
ptex_face_index, ptex_coord.
u, ptex_coord.
v, r_P, dPdu, dPdv);
509 reshape_context, face_index,
corner, dPdu, dPdv, r_tangent_matrix);
521 const int grid_area = grid_size * grid_size;
527 displacement_grid->
disps = disps;
528 displacement_grid->
totdisp = grid_area;
529 displacement_grid->
level = level;
534 if (displacement_grid->
disps !=
NULL && displacement_grid->
level >= level) {
544 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
552 if (grid_paint_masks ==
NULL) {
557 const int grid_area = grid_size * grid_size;
558 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
559 GridPaintMask *grid_paint_mask = &grid_paint_masks[grid_index];
560 if (grid_paint_mask->
level >= level) {
563 grid_paint_mask->
level = level;
564 if (grid_paint_mask->
data) {
591 if (grid_paint_masks !=
NULL) {
595 const int num_grids = reshape_context->
num_grids;
596 for (
int grid_index = 0; grid_index < num_grids; grid_index++) {
597 MDisps *orig_grid = &orig_mdisps[grid_index];
605 if (orig_grid_paint_masks !=
NULL) {
606 GridPaintMask *orig_paint_mask_grid = &orig_grid_paint_masks[grid_index];
607 if (orig_paint_mask_grid->
data !=
NULL) {
632 const int face_index,
639 const Mesh *base_mesh =
data->reshape_context->base_mesh;
641 const int grid_size =
data->grid_size;
642 const float grid_size_1_inv = 1.0f / (((
float)grid_size) - 1.0f);
644 const int num_corners = mpoly[face_index].
totloop;
647 for (
int y = 0;
y < grid_size; ++
y) {
648 const float v = (
float)
y * grid_size_1_inv;
649 for (
int x = 0;
x < grid_size; ++
x) {
650 const float u = (
float)
x * grid_size_1_inv;
657 data->callback(
data->reshape_context, &grid_coord,
data->callback_userdata_v);
670 data.reshape_context = reshape_context;
672 data.grid_size_1_inv = 1.0f / (((
float)
data.grid_size) - 1.0f);
674 data.callback_userdata_v = userdata_v;
681 const int num_faces = base_mesh->
totpoly;
692 float tangent_matrix[3][3];
695 float inv_tangent_matrix[3][3];
733 float tangent_matrix[3][3];
756 float tangent_matrix[3][3];
770 *grid_element.
mask = orig_grid_element.
mask;
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
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, const struct Scene *scene, struct Object *ob, const struct CustomData_MeshMasks *dataMask)
BLI_INLINE void BKE_multires_construct_tangent_matrix(float tangent_matrix[3][3], const float dPdu[3], const float dPdv[3], int corner)
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_subdiv_ptex_face_uv_to_grid_uv(float ptex_u, float ptex_v, float *r_grid_u, float *r_grid_v)
BLI_INLINE int BKE_subdiv_grid_size_from_level(int level)
BLI_INLINE void BKE_subdiv_rotate_grid_to_quad(int corner, float grid_u, float grid_v, float *r_quad_u, float *r_quad_v)
void BKE_subdiv_free(Subdiv *subdiv)
BLI_INLINE void BKE_subdiv_grid_uv_to_ptex_face_uv(float grid_u, float grid_v, float *r_ptex_u, float *r_ptex_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 int BKE_subdiv_rotate_quad_to_corner(float quad_u, float quad_v, float *r_corner_u, float *r_corner_v)
@ SUBDIV_EVALUATOR_TYPE_CPU
bool BKE_subdiv_eval_begin_from_mesh(struct Subdiv *subdiv, const struct Mesh *mesh, const float(*coarse_vertex_cos)[3], eSubdivEvaluatorType evaluator_type, struct OpenSubdiv_EvaluatorCache *evaluator_cache)
void BKE_subdiv_eval_limit_point_and_derivatives(struct Subdiv *subdiv, int ptex_face_index, float u, 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(int start, 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
SyclQueue void void size_t num_bytes void
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 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
const float * cd_vertex_crease
struct Depsgraph * depsgraph
struct MultiresReshapeContext::@100 top
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)