Blender  V2.93
BKE_shrinkwrap.h
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) Blender Foundation.
17  * All rights reserved.
18  */
19 #pragma once
20 
25 /* Shrinkwrap stuff */
26 #include "BKE_bvhutils.h"
27 #include "BLI_bitmap.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Shrinkwrap is composed by a set of functions and options that define the type of shrink.
35  *
36  * 3 modes are available:
37  * - Nearest vertex
38  * - Nearest surface
39  * - Normal projection
40  *
41  * ShrinkwrapCalcData encapsulates all needed data for shrinkwrap functions.
42  * (So that you don't have to pass an enormous amount of arguments to functions)
43  */
44 
45 struct BVHTree;
46 struct MDeformVert;
47 struct Mesh;
48 struct ModifierEvalContext;
49 struct Object;
51 struct SpaceTransform;
52 
53 /* Information about boundary edges in the mesh. */
55  /* Average direction of edges that meet here. */
56  float direction[3];
57 
58  /* Closest vector to direction that is orthogonal to vertex normal. */
59  float normal_plane[3];
61 
62 typedef struct ShrinkwrapBoundaryData {
63  /* True if the edge belongs to exactly one face. */
65  /* True if the looptri has any boundary edges. */
67 
68  /* Mapping from vertex index to boundary vertex index, or -1.
69  * Used for compact storage of data about boundary vertices. */
70  const int *vert_boundary_id;
71  unsigned int num_boundary_verts;
72 
73  /* Direction data about boundary vertices. */
76 
79 
80 /* Information about a mesh and BVH tree. */
81 typedef struct ShrinkwrapTreeData {
83 
86 
87  float (*pnors)[3];
88  float (*clnors)[3];
91 
92 /* Checks if the modifier needs target normals with these settings. */
93 bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode);
94 
95 /* Initializes the mesh data structure from the given mesh and settings. */
97  Mesh *mesh,
98  int shrinkType,
99  int shrinkMode,
100  bool force_normals);
101 
102 /* Frees the tree data if necessary. */
104 
105 /* Implementation of the Shrinkwrap modifier */
107  const struct ModifierEvalContext *ctx,
108  struct Scene *scene,
109  struct Object *ob,
110  struct Mesh *mesh,
111  struct MDeformVert *dvert,
112  const int defgrp_index,
113  float (*vertexCos)[3],
114  int numVerts);
115 
116 /* Used in editmesh_mask_extract.c to shrinkwrap the extracted mesh to the sculpt */
118  struct Object *ob_source,
119  struct Object *ob_target);
120 
121 /* Used in object_remesh.c to preserve the details and volume in the voxel remesher */
122 void BKE_shrinkwrap_remesh_target_project(struct Mesh *src_me,
123  struct Mesh *target_me,
124  struct Object *ob_target);
125 
126 /*
127  * This function casts a ray in the given BVHTree.
128  * but it takes into consideration the space_transform, that is:
129  *
130  * if transf was configured with "SPACE_TRANSFORM_SETUP( &transf, ob1, ob2 )"
131  * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space
132  * and the BVHTree must be built in ob2 coordinate space.
133  *
134  * Thus it provides an easy way to cast the same ray across several trees
135  * (where each tree was built on its own coords space)
136  */
138  const float vert[3],
139  const float dir[3],
140  const float ray_radius,
141  const struct SpaceTransform *transf,
142  struct ShrinkwrapTreeData *tree,
143  BVHTreeRayHit *hit);
144 
145 /* Maps the point to the nearest surface, either by simple nearest,
146  * or by target normal projection. */
148  struct BVHTreeNearest *nearest,
149  float co[3],
150  int type);
151 
152 /* Computes a smooth normal of the target (if applicable) at the hit location. */
154  const struct SpaceTransform *transform,
155  int looptri_idx,
156  const float hit_co[3],
157  const float hit_no[3],
158  float r_no[3]);
159 
160 /* Apply the shrink to surface modes to the given original coordinates and nearest point. */
162  const struct SpaceTransform *transform,
163  int mode,
164  int hit_idx,
165  const float hit_co[3],
166  const float hit_no[3],
167  float goal_dist,
168  const float point_co[3],
169  float r_point_co[3]);
170 
171 /*
172  * NULL initializes to local data
173  */
174 #define NULL_ShrinkwrapCalcData \
175  { \
176  NULL, \
177  }
178 #define NULL_BVHTreeFromMesh \
179  { \
180  NULL, \
181  }
182 #define NULL_BVHTreeRayHit \
183  { \
184  NULL, \
185  }
186 #define NULL_BVHTreeNearest \
187  { \
188  0, \
189  }
190 
191 #ifdef __cplusplus
192 }
193 #endif
typedef float(TangentPoint)[2]
bool BKE_shrinkwrap_project_normal(char options, const float vert[3], const float dir[3], const float ray_radius, const struct SpaceTransform *transf, struct ShrinkwrapTreeData *tree, BVHTreeRayHit *hit)
void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, const struct ModifierEvalContext *ctx, struct Scene *scene, struct Object *ob, struct Mesh *mesh, struct MDeformVert *dvert, const int defgrp_index, float(*vertexCos)[3], int numVerts)
struct ShrinkwrapBoundaryData ShrinkwrapBoundaryData
void BKE_shrinkwrap_find_nearest_surface(struct ShrinkwrapTreeData *tree, struct BVHTreeNearest *nearest, float co[3], int type)
Definition: shrinkwrap.c:1095
void BKE_shrinkwrap_remesh_target_project(struct Mesh *src_me, struct Mesh *target_me, struct Object *ob_target)
Definition: shrinkwrap.c:1541
struct ShrinkwrapBoundaryVertData ShrinkwrapBoundaryVertData
void BKE_shrinkwrap_mesh_nearest_surface_deform(struct bContext *C, struct Object *ob_source, struct Object *ob_target)
Definition: shrinkwrap.c:1516
void BKE_shrinkwrap_compute_smooth_normal(const struct ShrinkwrapTreeData *tree, const struct SpaceTransform *transform, int looptri_idx, const float hit_co[3], const float hit_no[3], float r_no[3])
Definition: shrinkwrap.c:1206
bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode)
Definition: shrinkwrap.c:105
void BKE_shrinkwrap_compute_boundary_data(struct Mesh *mesh)
Definition: shrinkwrap.c:341
void BKE_shrinkwrap_discard_boundary_data(struct Mesh *mesh)
Definition: shrinkwrap.c:170
bool BKE_shrinkwrap_init_tree(struct ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
Definition: shrinkwrap.c:113
void BKE_shrinkwrap_free_tree(struct ShrinkwrapTreeData *data)
Definition: shrinkwrap.c:164
struct ShrinkwrapTreeData ShrinkwrapTreeData
void BKE_shrinkwrap_snap_point_to_surface(const struct ShrinkwrapTreeData *tree, const struct SpaceTransform *transform, int mode, int hit_idx, const float hit_co[3], const float hit_no[3], float goal_dist, const float point_co[3], float r_point_co[3])
Definition: shrinkwrap.c:1328
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
_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 type
#define C
Definition: RandGen.cpp:39
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
CCL_NAMESPACE_BEGIN struct Options options
Scene scene
void * tree
const int * vert_boundary_id
const ShrinkwrapBoundaryVertData * boundary_verts
const BLI_bitmap * looptri_has_boundary
const BLI_bitmap * edge_is_boundary
unsigned int num_boundary_verts
float(* clnors)[3]
BVHTreeFromMesh treeData
ShrinkwrapBoundaryData * boundary