Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BKE_shrinkwrap.h « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70aeb37d99540afe96529a05385b24a51d975544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) Blender Foundation.
 * All rights reserved.
 */
#pragma once

/** \file
 * \ingroup bke
 */

/* Shrinkwrap stuff */
#include "BKE_bvhutils.h"
#include "BLI_bitmap.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Shrinkwrap is composed by a set of functions and options that define the type of shrink.
 *
 * 3 modes are available:
 * - Nearest vertex
 * - Nearest surface
 * - Normal projection
 *
 * ShrinkwrapCalcData encapsulates all needed data for shrinkwrap functions.
 * (So that you don't have to pass an enormous amount of arguments to functions)
 */

struct BVHTree;
struct MDeformVert;
struct Mesh;
struct ModifierEvalContext;
struct Object;
struct ShrinkwrapModifierData;
struct SpaceTransform;

/* Information about boundary edges in the mesh. */
typedef struct ShrinkwrapBoundaryVertData {
  /* Average direction of edges that meet here. */
  float direction[3];

  /* Closest vector to direction that is orthogonal to vertex normal. */
  float normal_plane[3];
} ShrinkwrapBoundaryVertData;

typedef struct ShrinkwrapBoundaryData {
  /* True if the edge belongs to exactly one face. */
  const BLI_bitmap *edge_is_boundary;
  /* True if the looptri has any boundary edges. */
  const BLI_bitmap *looptri_has_boundary;

  /* Mapping from vertex index to boundary vertex index, or -1.
   * Used for compact storage of data about boundary vertices. */
  const int *vert_boundary_id;
  unsigned int num_boundary_verts;

  /* Direction data about boundary vertices. */
  const ShrinkwrapBoundaryVertData *boundary_verts;
} ShrinkwrapBoundaryData;

void BKE_shrinkwrap_discard_boundary_data(struct Mesh *mesh);
void BKE_shrinkwrap_compute_boundary_data(struct Mesh *mesh);

/* Information about a mesh and BVH tree. */
typedef struct ShrinkwrapTreeData {
  Mesh *mesh;

  BVHTree *bvh;
  BVHTreeFromMesh treeData;

  float (*pnors)[3];
  float (*clnors)[3];
  ShrinkwrapBoundaryData *boundary;
} ShrinkwrapTreeData;

/* Checks if the modifier needs target normals with these settings. */
bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode);

/* Initializes the mesh data structure from the given mesh and settings. */
bool BKE_shrinkwrap_init_tree(struct ShrinkwrapTreeData *data,
                              Mesh *mesh,
                              int shrinkType,
                              int shrinkMode,
                              bool force_normals);

/* Frees the tree data if necessary. */
void BKE_shrinkwrap_free_tree(struct ShrinkwrapTreeData *data);

/* Implementation of the Shrinkwrap modifier */
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);

/* Used in editmesh_mask_extract.c to shrinkwrap the extracted mesh to the sculpt */
void BKE_shrinkwrap_mesh_nearest_surface_deform(struct bContext *C,
                                                struct Object *ob_source,
                                                struct Object *ob_target);

/* Used in object_remesh.cc to preserve the details and volume in the voxel remesher */
void BKE_shrinkwrap_remesh_target_project(struct Mesh *src_me,
                                          struct Mesh *target_me,
                                          struct Object *ob_target);

/*
 * This function casts a ray in the given BVHTree.
 * but it takes into consideration the space_transform, that is:
 *
 * if transf was configured with "SPACE_TRANSFORM_SETUP( &transf,  ob1, ob2 )"
 * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space
 * and the BVHTree must be built in ob2 coordinate space.
 *
 * Thus it provides an easy way to cast the same ray across several trees
 * (where each tree was built on its own coords space)
 */
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);

/* Maps the point to the nearest surface, either by simple nearest,
 * or by target normal projection. */
void BKE_shrinkwrap_find_nearest_surface(struct ShrinkwrapTreeData *tree,
                                         struct BVHTreeNearest *nearest,
                                         float co[3],
                                         int type);

/* Computes a smooth normal of the target (if applicable) at the hit location. */
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]);

/* Apply the shrink to surface modes to the given original coordinates and nearest point. */
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]);

/*
 * NULL initializes to local data
 */
#define NULL_ShrinkwrapCalcData \
  { \
    NULL, \
  }
#define NULL_BVHTreeFromMesh \
  { \
    NULL, \
  }
#define NULL_BVHTreeRayHit \
  { \
    NULL, \
  }
#define NULL_BVHTreeNearest \
  { \
    0, \
  }

#ifdef __cplusplus
}
#endif