Blender V5.3
BKE_shrinkwrap.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
10/* Shrinkwrap stuff */
11#include "BKE_bvh.hh"
12#include "BKE_bvhutils.hh"
13
14#include "BKE_context.hh"
15#include "BLI_array.hh"
16#include "BLI_bit_vector.hh"
18#include "BLI_offset_indices.hh"
19#include "BLI_span.hh"
20#include "BLI_virtual_array.hh"
21
22/*
23 * Shrinkwrap is composed by a set of functions and options that define the type of shrink.
24 *
25 * 3 modes are available:
26 * - Nearest vertex.
27 * - Nearest surface.
28 * - Normal projection.
29 *
30 * #ShrinkwrapCalcData encapsulates all needed data for shrink-wrap functions.
31 * (So that you don't have to pass an enormous amount of arguments to functions)
32 */
33
34namespace blender {
35
36struct BVHTree;
37struct Depsgraph;
38struct MDeformVert;
39struct Mesh;
41struct Object;
44struct SpaceTransform;
45
46/* Information about boundary edges in the mesh. */
48 /* Average direction of edges that meet here. */
49 float direction[3];
50
51 /* Closest vector to direction that is orthogonal to vertex normal. */
52 float normal_plane[3];
53};
54
56 public:
57 /* Returns true if there is boundary information. If there is no boundary information, then the
58 * mesh from which this data is created from has no boundaries. */
59 bool has_boundary() const
60 {
61 return !edge_is_boundary.is_empty();
62 }
63
64 /* True if the edge belongs to exactly one face. */
66 /* True if the triangle has any boundary edges. */
68
69 /* Mapping from vertex index to boundary vertex index, or -1.
70 * Used for compact storage of data about boundary vertices. */
72
73 /* Direction data about boundary vertices. */
75};
76
77namespace bke::shrinkwrap {
78
80
81} // namespace bke::shrinkwrap
82
83/* Information about a mesh and BVH tree. */
103
107bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode);
108
113 ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals);
114
119
124 const ModifierEvalContext *ctx,
125 Scene *scene,
126 Object *ob,
127 Mesh *mesh,
128 const MDeformVert *dvert,
129 int defgrp_index,
130 float (*vertexCos)[3],
131 int numVerts);
132
135 Object *target = nullptr;
137 Object *aux_target = nullptr;
138 /* Use inverse vertex group weights. */
141 float keep_distance = 0.05f;
143 short shrink_type = 0 /*MOD_SHRINKWRAP_NEAREST_SURFACE*/;
145 char shrink_options = 0 /*MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR*/;
147 char shrink_mode = 0 /*MOD_SHRINKWRAP_ON_SURFACE*/;
149 float projection_limit = 0.0f;
151 char projection_axis = 0 /*MOD_SHRINKWRAP_PROJECT_OVER_NORMAL*/;
157};
158
160 Object &object,
161 ShrinkwrapTreeData &tree,
162 Span<MDeformVert> dvert,
163 int defgrp_index,
164 MutableSpan<float3> positions);
165
169void BKE_shrinkwrap_mesh_nearest_surface_deform(Depsgraph *depsgraph,
170 Scene *scene,
171 Object *ob_source,
172 Object *ob_target);
173
177void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target);
178
197 const float vert[3],
198 const float dir[3],
199 const SpaceTransform *transf,
200 ShrinkwrapTreeData *tree,
201 BVHTreeRayHit *hit);
202
207 BVHTreeNearest *nearest,
208 float co[3],
209 int type);
210
220 int tri_idx,
221 const float hit_co[3],
222 const float hit_no[3],
223 float r_no[3]);
224
234 int mode,
235 int hit_idx,
236 const float hit_co[3],
237 const float hit_no[3],
238 float goal_dist,
239 const float point_co[3],
240 float r_point_co[3]);
241
242/*
243 * NULL initializes to local data
244 */
245#define NULL_ShrinkwrapCalcData \
246 { \
247 NULL, \
248 }
249#define NULL_BVHTreeFromMesh \
250 { \
251 NULL, \
252 }
253#define NULL_BVHTreeRayHit \
254 { \
255 NULL, \
256 }
257#define NULL_BVHTreeNearest \
258 { \
259 0, \
260 }
261
262} // namespace blender
Array< ShrinkwrapBoundaryVertData > boundary_verts
CCL_NAMESPACE_BEGIN struct Options options
const ShrinkwrapBoundaryData & boundary_cache_ensure(const Mesh &mesh)
BMesh Iterators.
void shrinkwrapParams_deform(const ShrinkwrapParams &params, Object &object, ShrinkwrapTreeData &tree, Span< MDeformVert > dvert, int defgrp_index, MutableSpan< float3 > positions)
bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode)
Definition shrinkwrap.cc:80
bool BKE_shrinkwrap_project_normal(char options, const float vert[3], const float dir[3], const SpaceTransform *transf, ShrinkwrapTreeData *tree, BVHTreeRayHit *hit)
void BKE_shrinkwrap_free_tree(ShrinkwrapTreeData *data)
void BKE_shrinkwrap_mesh_nearest_surface_deform(Depsgraph *depsgraph, Scene *scene, Object *ob_source, Object *ob_target)
void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target)
void BKE_shrinkwrap_find_nearest_surface(ShrinkwrapTreeData *tree, BVHTreeNearest *nearest, float co[3], int type)
void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree, const SpaceTransform *transform, int tri_idx, const float hit_co[3], const float hit_no[3], float r_no[3])
BMesh const char void * data
void BKE_shrinkwrap_snap_point_to_surface(const ShrinkwrapTreeData *tree, const 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])
void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, const ModifierEvalContext *ctx, Scene *scene, Object *ob, Mesh *mesh, const MDeformVert *dvert, int defgrp_index, float(*vertexCos)[3], int numVerts)
bool BKE_shrinkwrap_init_tree(ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
Definition shrinkwrap.cc:87
OffsetIndices< int > faces
bke::BVHTreeFromMesh treeData
VArraySpan< bool > sharp_faces
const ShrinkwrapBoundaryData * boundary
const bke::bvh::Tree * vert_tree