Blender  V2.93
multires_reshape_ccg.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "multires_reshape.h"
25 
26 #include <string.h>
27 
28 #include "BLI_utildefines.h"
29 
30 #include "BKE_ccg.h"
31 #include "BKE_subdiv_ccg.h"
32 
34  struct SubdivCCG *subdiv_ccg)
35 {
36  CCGKey reshape_level_key;
37  BKE_subdiv_ccg_key(&reshape_level_key, subdiv_ccg, reshape_context->reshape.level);
38 
39  const int reshape_grid_size = reshape_context->reshape.grid_size;
40  const float reshape_grid_size_1_inv = 1.0f / (((float)reshape_grid_size) - 1.0f);
41 
42  int num_grids = subdiv_ccg->num_grids;
43  for (int grid_index = 0; grid_index < num_grids; ++grid_index) {
44  CCGElem *ccg_grid = subdiv_ccg->grids[grid_index];
45  for (int y = 0; y < reshape_grid_size; ++y) {
46  const float v = (float)y * reshape_grid_size_1_inv;
47  for (int x = 0; x < reshape_grid_size; ++x) {
48  const float u = (float)x * reshape_grid_size_1_inv;
49 
50  GridCoord grid_coord;
51  grid_coord.grid_index = grid_index;
52  grid_coord.u = u;
53  grid_coord.v = v;
54 
56  reshape_context, &grid_coord);
57 
58  BLI_assert(grid_element.displacement != NULL);
59  memcpy(grid_element.displacement,
60  CCG_grid_elem_co(&reshape_level_key, ccg_grid, x, y),
61  sizeof(float[3]));
62 
63  /* NOTE: The sculpt mode might have SubdivCCG's data out of sync from what is stored in
64  * the original object. This happens upon the following scenario:
65  *
66  * - User enters sculpt mode of the default cube object.
67  * - Sculpt mode creates new `layer`
68  * - User does some strokes.
69  * - User used undo until sculpt mode is exited.
70  *
71  * In an ideal world the sculpt mode will take care of keeping CustomData and CCG layers in
72  * sync by doing proper pushes to a local sculpt undo stack.
73  *
74  * Since the proper solution needs time to be implemented, consider the target object
75  * the source of truth of which data layers are to be updated during reshape. This means,
76  * for example, that if the undo system says object does not have paint mask layer, it is
77  * not to be updated.
78  *
79  * This is a fragile logic, and is only working correctly because the code path is only
80  * used by sculpt changes. In other use cases the code might not catch inconsistency and
81  * silently do wrong decision. */
82  /* NOTE: There is a known bug in Undo code that results in first Sculpt step
83  * after a Memfile one to never be undone (see T83806). This might be the root cause of
84  * this inconsistency. */
85  if (reshape_level_key.has_mask && grid_element.mask != NULL) {
86  *grid_element.mask = *CCG_grid_elem_mask(&reshape_level_key, ccg_grid, x, y);
87  }
88  }
89  }
90  }
91 
92  return true;
93 }
typedef float(TangentPoint)[2]
BLI_INLINE float * CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:130
struct CCGElem CCGElem
Definition: BKE_ccg.h:46
BLI_INLINE float * CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:140
void BKE_subdiv_ccg_key(struct CCGKey *key, const SubdivCCG *subdiv_ccg, int level)
Definition: subdiv_ccg.c:662
#define BLI_assert(a)
Definition: BLI_assert.h:58
_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:48
int has_mask
Definition: BKE_ccg.h:71
struct MultiresReshapeContext::@99 reshape
struct CCGElem ** grids