Blender  V3.3
multires_reshape.h
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 #pragma once
9 
10 #include "BLI_sys_types.h"
11 
12 #include "BKE_multires.h"
13 
14 struct Depsgraph;
15 struct GridPaintMask;
16 struct MDisps;
17 struct Mesh;
19 struct Object;
20 struct Subdiv;
21 struct SubdivCCG;
22 
23 typedef struct MultiresReshapeContext {
24  /* NOTE: Only available when context is initialized from object. */
26  struct Object *object;
27 
29 
30  /* Base mesh from original object.
31  * NOTE: Does NOT include any leading modifiers in it. */
32  struct Mesh *base_mesh;
33 
34  /* Subdivision surface created for multires modifier.
35  *
36  * The coarse mesh of this subdivision surface is a base mesh with all deformation modifiers
37  * leading multires applied on it. */
38  struct Subdiv *subdiv;
40 
41  struct {
42  /* Level at which displacement is being assigned to.
43  * It will be propagated up from this level to top.level. */
44  int level;
45 
46  /* Grid size for reshape.level. */
47  int grid_size;
49 
50  struct {
51  /* Top level of the displacement grids.
52  * The displacement will be propagated up to this level. */
53  int level;
54 
55  /* Grid size for top.level. */
56  int grid_size;
57  } top;
58 
59  struct {
60  /* Copy of original displacement and painting masks. */
61  struct MDisps *mdisps;
63  } orig;
64 
65  /* Number of grids which are required for base_mesh. */
66  int num_grids;
67 
68  /* Destination displacement and mask.
69  * Points to a custom data on a destination mesh. */
70  struct MDisps *mdisps;
72 
73  /* Indexed by face index, gives first grid index of the face. */
75 
76  /* Indexed by grid index, contains face (poly) index in the base mesh from which the grid has
77  * been created (in other words, index of a poly which contains loop corresponding to the grid
78  * index). */
80 
81  /* Indexed by ptex face index, gives first grid index of the ptex face.
82  *
83  * For non-quad base faces ptex face is created for every face corner, so it's similar to a
84  * grid in this case. In this case start grid index will be the only one for this ptex face.
85  *
86  * For quad base faces there is a single ptex face but 4 grids. So in this case there will be
87  * 4 grids for the ptex, starting at a value stored in this mapping. */
89 
90  /* Indexed by base face index, returns first ptex face index corresponding
91  * to that base face. */
93 
94  /* Vertex crease custom data layer, null if none is present. */
95  const float *cd_vertex_crease;
97 
102 typedef struct GridCoord {
104  float u, v;
106 
110 typedef struct PTexCoord {
112  float u, v;
114 
119 typedef struct ReshapeGridElement {
120  float *displacement;
121  float *mask;
123 
124 typedef struct ReshapeConstGridElement {
125  float displacement[3];
126  float mask;
128 
129 /* --------------------------------------------------------------------
130  * Construct/destruct reshape context.
131  */
132 
138  struct Object *object,
139  const struct MultiresModifierData *mmd);
140 
147  struct Depsgraph *depsgraph,
148  struct Object *object,
149  struct MultiresModifierData *mmd);
150 
152  struct Depsgraph *depsgraph,
153  struct Object *object,
154  struct MultiresModifierData *mmd);
155 
157  struct SubdivCCG *subdiv_ccg,
158  struct Mesh *base_mesh,
159  int top_level);
160 
162  struct Object *object,
163  struct MultiresModifierData *mmd,
164  int top_level);
165 
167  struct Object *object,
168  struct MultiresModifierData *mmd,
169  struct Subdiv *subdiv,
170  int top_level);
171 
174 
175 /* --------------------------------------------------------------------
176  * Helper accessors.
177  */
178 
183  int grid_index);
184 
188 int multires_reshape_grid_to_corner(const MultiresReshapeContext *reshape_context, int grid_index);
189 
190 bool multires_reshape_is_quad_face(const MultiresReshapeContext *reshape_context, int face_index);
191 
196  int grid_index);
197 
202  const GridCoord *grid_coord);
203 
208  const PTexCoord *ptex_coord);
209 
215  int face_index,
216  int corner,
217  const float dPdu[3],
218  const float dPdv[3],
219  float r_tangent_matrix[3][3]);
220 
226  const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord);
228  const MultiresReshapeContext *reshape_context, const PTexCoord *ptex_coord);
229 
234  const MultiresReshapeContext *reshape_context, const GridCoord *grid_coord);
235 
236 /* --------------------------------------------------------------------
237  * Sample limit surface of the base mesh.
238  */
239 
245  const GridCoord *grid_coord,
246  float r_P[3],
247  float r_tangent_matrix[3][3]);
248 
249 /* --------------------------------------------------------------------
250  * Custom data preparation.
251  */
252 
256 void multires_reshape_ensure_grids(struct Mesh *mesh, int level);
257 
258 /* --------------------------------------------------------------------
259  * Functions specific to reshaping from a set of vertices in a object position.
260  */
261 
271  const MultiresReshapeContext *reshape_context,
272  const float (*vert_coords)[3],
273  int num_vert_coords);
274 
275 /* --------------------------------------------------------------------
276  * Functions specific to reshaping from CCG.
277  */
278 
289  struct SubdivCCG *subdiv_ccg);
290 
291 /* --------------------------------------------------------------------
292  * Functions specific to reshaping from MDISPS.
293  */
294 
299  const MultiresReshapeContext *reshape_context);
300 
305  const MultiresReshapeContext *reshape_context);
306 
307 /* --------------------------------------------------------------------
308  * Displacement smooth.
309  */
310 
319  const MultiresReshapeContext *reshape_context);
320 
328  enum eMultiresSubdivideModeType mode);
329 
330 /* --------------------------------------------------------------------
331  * Displacement, space conversion.
332  */
333 
339 
341  const MultiresReshapeContext *reshape_context);
342 
343 /* --------------------------------------------------------------------
344  * Apply base.
345  */
346 
354 
360 
365 
eMultiresSubdivideModeType
Definition: BKE_multires.h:195
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
const Depsgraph * depsgraph
int multires_reshape_grid_to_face_index(const MultiresReshapeContext *reshape_context, int grid_index)
struct MultiresReshapeContext MultiresReshapeContext
void multires_reshape_assign_final_elements_from_orig_mdisps(const MultiresReshapeContext *reshape_context)
struct ReshapeConstGridElement ReshapeConstGridElement
bool multires_reshape_is_quad_face(const MultiresReshapeContext *reshape_context, int face_index)
void multires_reshape_smooth_object_grids_with_details(const MultiresReshapeContext *reshape_context)
void multires_reshape_assign_final_coords_from_mdisps(const MultiresReshapeContext *reshape_context)
void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape_context)
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)
bool multires_reshape_assign_final_coords_from_vertcos(const MultiresReshapeContext *reshape_context, const float(*vert_coords)[3], int num_vert_coords)
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)
void multires_reshape_ensure_grids(struct Mesh *mesh, int level)
bool multires_reshape_context_create_from_base_mesh(MultiresReshapeContext *reshape_context, struct Depsgraph *depsgraph, struct Object *object, struct MultiresModifierData *mmd)
void multires_reshape_apply_base_refine_from_base(MultiresReshapeContext *reshape_context)
void multires_reshape_tangent_matrix_for_corner(const MultiresReshapeContext *reshape_context, int face_index, int corner, const float dPdu[3], const float dPdv[3], float r_tangent_matrix[3][3])
int multires_reshape_grid_to_corner(const MultiresReshapeContext *reshape_context, int grid_index)
bool multires_reshape_context_create_from_modifier(MultiresReshapeContext *reshape_context, struct Object *object, struct MultiresModifierData *mmd, int top_level)
bool multires_reshape_context_create_from_ccg(MultiresReshapeContext *reshape_context, struct SubdivCCG *subdiv_ccg, struct Mesh *base_mesh, int top_level)
void multires_reshape_free_original_grids(MultiresReshapeContext *reshape_context)
bool multires_reshape_context_create_from_object(MultiresReshapeContext *reshape_context, struct Depsgraph *depsgraph, struct Object *object, struct MultiresModifierData *mmd)
bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape_context, struct Object *object, struct MultiresModifierData *mmd, struct Subdiv *subdiv, int top_level)
void multires_reshape_apply_base_update_mesh_coords(MultiresReshapeContext *reshape_context)
void multires_reshape_smooth_object_grids(const MultiresReshapeContext *reshape_context, enum eMultiresSubdivideModeType mode)
void multires_reshape_object_grids_to_tangent_displacement(const MultiresReshapeContext *reshape_context)
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)
struct ReshapeGridElement ReshapeGridElement
GridCoord multires_reshape_ptex_coord_to_grid(const MultiresReshapeContext *reshape_context, const PTexCoord *ptex_coord)
struct PTexCoord PTexCoord
struct Subdiv * multires_reshape_create_subdiv(struct Depsgraph *depsgraph, struct Object *object, const struct MultiresModifierData *mmd)
void multires_reshape_apply_base_refine_from_deform(MultiresReshapeContext *reshape_context)
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])
struct GridCoord GridCoord
bool multires_reshape_assign_final_coords_from_ccg(const MultiresReshapeContext *reshape_context, struct SubdivCCG *subdiv_ccg)
struct MultiresReshapeContext::@101 orig
struct GridPaintMask * grid_paint_masks
struct MultiresModifierData * mmd
struct MultiresReshapeContext::@99 reshape
struct MDisps * mdisps
struct Object * object
const float * cd_vertex_crease
struct Depsgraph * depsgraph
struct MultiresReshapeContext::@100 top
struct Subdiv * subdiv