Blender V5.0
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_bvhutils.hh"
12
13#include "BKE_context.hh"
14#include "BLI_array.hh"
15#include "BLI_bit_vector.hh"
17#include "BLI_offset_indices.hh"
18#include "BLI_span.hh"
19#include "BLI_virtual_array.hh"
20
21/*
22 * Shrinkwrap is composed by a set of functions and options that define the type of shrink.
23 *
24 * 3 modes are available:
25 * - Nearest vertex.
26 * - Nearest surface.
27 * - Normal projection.
28 *
29 * #ShrinkwrapCalcData encapsulates all needed data for shrink-wrap functions.
30 * (So that you don't have to pass an enormous amount of arguments to functions)
31 */
32
33struct Depsgraph;
34struct BVHTree;
35struct MDeformVert;
36struct Mesh;
38struct Object;
41struct SpaceTransform;
42
43/* Information about boundary edges in the mesh. */
45 /* Average direction of edges that meet here. */
46 float direction[3];
47
48 /* Closest vector to direction that is orthogonal to vertex normal. */
49 float normal_plane[3];
50};
51
53 public:
54 /* Returns true if there is boundary information. If there is no boundary information, then the
55 * mesh from which this data is created from has no boundaries. */
56 bool has_boundary() const
57 {
58 return !edge_is_boundary.is_empty();
59 }
60
61 /* True if the edge belongs to exactly one face. */
63 /* True if the triangle has any boundary edges. */
65
66 /* Mapping from vertex index to boundary vertex index, or -1.
67 * Used for compact storage of data about boundary vertices. */
69
70 /* Direction data about boundary vertices. */
72};
73
75
77
78} // namespace blender::bke::shrinkwrap
79
80/* Information about a mesh and BVH tree. */
97
101bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode);
102
107 ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals);
108
113
118 const ModifierEvalContext *ctx,
119 Scene *scene,
120 Object *ob,
121 Mesh *mesh,
122 const MDeformVert *dvert,
123 int defgrp_index,
124 float (*vertexCos)[3],
125 int numVerts);
126
129 Object *target = nullptr;
131 Object *aux_target = nullptr;
132 /* Use inverse vertex group weights. */
135 float keep_distance = 0.05f;
137 short shrink_type = 0 /*MOD_SHRINKWRAP_NEAREST_SURFACE*/;
139 char shrink_options = 0 /*MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR*/;
141 char shrink_mode = 0 /*MOD_SHRINKWRAP_ON_SURFACE*/;
143 float projection_limit = 0.0f;
145 char projection_axis = 0 /*MOD_SHRINKWRAP_PROJECT_OVER_NORMAL*/;
151};
152
154 Object &object,
157 int defgrp_index,
159
164 Scene *scene,
165 Object *ob_source,
166 Object *ob_target);
167
171void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target);
172
191 const float vert[3],
192 const float dir[3],
193 float ray_radius,
194 const SpaceTransform *transf,
196 BVHTreeRayHit *hit);
197
202 BVHTreeNearest *nearest,
203 float co[3],
204 int type);
205
215 int tri_idx,
216 const float hit_co[3],
217 const float hit_no[3],
218 float r_no[3]);
219
229 int mode,
230 int hit_idx,
231 const float hit_co[3],
232 const float hit_no[3],
233 float goal_dist,
234 const float point_co[3],
235 float r_point_co[3]);
236
237/*
238 * NULL initializes to local data
239 */
240#define NULL_ShrinkwrapCalcData \
241 { \
242 NULL, \
243 }
244#define NULL_BVHTreeFromMesh \
245 { \
246 NULL, \
247 }
248#define NULL_BVHTreeRayHit \
249 { \
250 NULL, \
251 }
252#define NULL_BVHTreeNearest \
253 { \
254 0, \
255 }
bool BKE_shrinkwrap_project_normal(char options, const float vert[3], const float dir[3], float ray_radius, const SpaceTransform *transf, ShrinkwrapTreeData *tree, BVHTreeRayHit *hit)
void BKE_shrinkwrap_free_tree(ShrinkwrapTreeData *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)
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])
void shrinkwrapParams_deform(const ShrinkwrapParams &params, Object &object, ShrinkwrapTreeData &tree, blender::Span< MDeformVert > dvert, int defgrp_index, blender::MutableSpan< blender::float3 > positions)
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)
bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode)
Definition shrinkwrap.cc:89
bool BKE_shrinkwrap_init_tree(ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
Definition shrinkwrap.cc:96
void BKE_shrinkwrap_find_nearest_surface(ShrinkwrapTreeData *tree, BVHTreeNearest *nearest, float co[3], int type)
BMesh const char void * data
BPy_StructRNA * depsgraph
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
blender::BitVector tri_has_boundary
blender::Array< int > vert_boundary_id
blender::Array< ShrinkwrapBoundaryVertData > boundary_verts
blender::BitVector edge_is_boundary
CCL_NAMESPACE_BEGIN struct Options options
KDTree_3d * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
const ShrinkwrapBoundaryData & boundary_cache_ensure(const Mesh &mesh)
blender::OffsetIndices< int > faces
blender::Span< blender::float3 > face_normals
blender::Span< blender::int2 > edges
const ShrinkwrapBoundaryData * boundary
blender::VArraySpan< bool > sharp_faces
blender::Span< blender::float3 > corner_normals
blender::bke::BVHTreeFromMesh treeData
blender::Span< int > corner_edges
const BVHTree * bvh
blender::Span< blender::float3 > vert_normals