Blender  V3.3
multires_reshape_ccg.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
8 #include "multires_reshape.h"
9 
10 #include <string.h>
11 
12 #include "BLI_utildefines.h"
13 
14 #include "BKE_ccg.h"
15 #include "BKE_subdiv_ccg.h"
16 
18  struct SubdivCCG *subdiv_ccg)
19 {
20  CCGKey reshape_level_key;
21  BKE_subdiv_ccg_key(&reshape_level_key, subdiv_ccg, reshape_context->reshape.level);
22 
23  const int reshape_grid_size = reshape_context->reshape.grid_size;
24  const float reshape_grid_size_1_inv = 1.0f / (((float)reshape_grid_size) - 1.0f);
25 
26  int num_grids = subdiv_ccg->num_grids;
27  for (int grid_index = 0; grid_index < num_grids; ++grid_index) {
28  CCGElem *ccg_grid = subdiv_ccg->grids[grid_index];
29  for (int y = 0; y < reshape_grid_size; ++y) {
30  const float v = (float)y * reshape_grid_size_1_inv;
31  for (int x = 0; x < reshape_grid_size; ++x) {
32  const float u = (float)x * reshape_grid_size_1_inv;
33 
34  GridCoord grid_coord;
35  grid_coord.grid_index = grid_index;
36  grid_coord.u = u;
37  grid_coord.v = v;
38 
40  reshape_context, &grid_coord);
41 
42  BLI_assert(grid_element.displacement != NULL);
43  memcpy(grid_element.displacement,
44  CCG_grid_elem_co(&reshape_level_key, ccg_grid, x, y),
45  sizeof(float[3]));
46 
47  /* NOTE: The sculpt mode might have SubdivCCG's data out of sync from what is stored in
48  * the original object. This happens upon the following scenario:
49  *
50  * - User enters sculpt mode of the default cube object.
51  * - Sculpt mode creates new `layer`
52  * - User does some strokes.
53  * - User used undo until sculpt mode is exited.
54  *
55  * In an ideal world the sculpt mode will take care of keeping CustomData and CCG layers in
56  * sync by doing proper pushes to a local sculpt undo stack.
57  *
58  * Since the proper solution needs time to be implemented, consider the target object
59  * the source of truth of which data layers are to be updated during reshape. This means,
60  * for example, that if the undo system says object does not have paint mask layer, it is
61  * not to be updated.
62  *
63  * This is a fragile logic, and is only working correctly because the code path is only
64  * used by sculpt changes. In other use cases the code might not catch inconsistency and
65  * silently do wrong decision. */
66  /* NOTE: There is a known bug in Undo code that results in first Sculpt step
67  * after a Memfile one to never be undone (see T83806). This might be the root cause of
68  * this inconsistency. */
69  if (reshape_level_key.has_mask && grid_element.mask != NULL) {
70  *grid_element.mask = *CCG_grid_elem_mask(&reshape_level_key, ccg_grid, x, y);
71  }
72  }
73  }
74  }
75 
76  return true;
77 }
typedef float(TangentPoint)[2]
BLI_INLINE float * CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:114
struct CCGElem CCGElem
Definition: BKE_ccg.h:30
BLI_INLINE float * CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:124
void BKE_subdiv_ccg_key(struct CCGKey *key, const SubdivCCG *subdiv_ccg, int level)
Definition: subdiv_ccg.c:653
#define BLI_assert(a)
Definition: BLI_assert.h:46
_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
ATTR_WARN_UNUSED_RESULT const BMVert * v
ReshapeGridElement multires_reshape_grid_element_for_grid_coord(const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord)
bool multires_reshape_assign_final_coords_from_ccg(const MultiresReshapeContext *reshape_context, struct SubdivCCG *subdiv_ccg)
Definition: BKE_ccg.h:32
int has_mask
Definition: BKE_ccg.h:55
struct MultiresReshapeContext::@99 reshape
struct CCGElem ** grids