Blender V4.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
10/* Shrinkwrap stuff */
11#include "BKE_bvhutils.hh"
12
13#include "BLI_array.hh"
14#include "BLI_bit_vector.hh"
16#include "BLI_offset_indices.hh"
17#include "BLI_span.hh"
18#include "BLI_virtual_array.hh"
19
20/*
21 * Shrinkwrap is composed by a set of functions and options that define the type of shrink.
22 *
23 * 3 modes are available:
24 * - Nearest vertex.
25 * - Nearest surface.
26 * - Normal projection.
27 *
28 * #ShrinkwrapCalcData encapsulates all needed data for shrink-wrap functions.
29 * (So that you don't have to pass an enormous amount of arguments to functions)
30 */
31
32struct BVHTree;
33struct MDeformVert;
34struct Mesh;
36struct Object;
39struct SpaceTransform;
40
41/* Information about boundary edges in the mesh. */
43 /* Average direction of edges that meet here. */
44 float direction[3];
45
46 /* Closest vector to direction that is orthogonal to vertex normal. */
47 float normal_plane[3];
48};
49
51 public:
52 /* Returns true if there is boundary information. If there is no boundary information, then the
53 * mesh from which this data is created from has no boundaries. */
54 inline bool has_boundary() const
55 {
56 return !edge_is_boundary.is_empty();
57 }
58
59 /* True if the edge belongs to exactly one face. */
61 /* True if the triangle has any boundary edges. */
63
64 /* Mapping from vertex index to boundary vertex index, or -1.
65 * Used for compact storage of data about boundary vertices. */
67
68 /* Direction data about boundary vertices. */
70};
71
73
75
76} // namespace blender::bke::shrinkwrap
77
78/* Information about a mesh and BVH tree. */
94
98bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode);
99
104 ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals);
105
110
115 const ModifierEvalContext *ctx,
116 Scene *scene,
117 Object *ob,
118 Mesh *mesh,
119 const MDeformVert *dvert,
120 int defgrp_index,
121 float (*vertexCos)[3],
122 int numVerts);
123/* Implementation of the Shrinkwrap Grease Pencil modifier. */
125 Object *ob,
126 MDeformVert *dvert,
127 int defgrp_index,
128 float (*vertexCos)[3],
129 int numVerts);
130
133 Object *target = nullptr;
135 Object *aux_target = nullptr;
136 /* Use inverse vertex group weights. */
139 float keep_distance = 0.05f;
141 short shrink_type = 0 /*MOD_SHRINKWRAP_NEAREST_SURFACE*/;
143 char shrink_options = 0 /*MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR*/;
145 char shrink_mode = 0 /*MOD_SHRINKWRAP_ON_SURFACE*/;
147 float projection_limit = 0.0f;
149 char projection_axis = 0 /*MOD_SHRINKWRAP_PROJECT_OVER_NORMAL*/;
155};
156
158 Object &object,
161 int defgrp_index,
163
168 Scene *scene,
169 Object *ob_source,
170 Object *ob_target);
171
175void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target);
176
195 const float vert[3],
196 const float dir[3],
197 float ray_radius,
198 const SpaceTransform *transf,
200 BVHTreeRayHit *hit);
201
206 BVHTreeNearest *nearest,
207 float co[3],
208 int type);
209
218 const SpaceTransform *transform,
219 int tri_idx,
220 const float hit_co[3],
221 const float hit_no[3],
222 float r_no[3]);
223
232 const SpaceTransform *transform,
233 int mode,
234 int hit_idx,
235 const float hit_co[3],
236 const float hit_no[3],
237 float goal_dist,
238 const float point_co[3],
239 float r_point_co[3]);
240
241/*
242 * NULL initializes to local data
243 */
244#define NULL_ShrinkwrapCalcData \
245 { \
246 NULL, \
247 }
248#define NULL_BVHTreeFromMesh \
249 { \
250 NULL, \
251 }
252#define NULL_BVHTreeRayHit \
253 { \
254 NULL, \
255 }
256#define NULL_BVHTreeNearest \
257 { \
258 0, \
259 }
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
void shrinkwrapGpencilModifier_deform(ShrinkwrapGpencilModifierData *mmd, Object *ob, 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:96
void BKE_shrinkwrap_find_nearest_surface(ShrinkwrapTreeData *tree, BVHTreeNearest *nearest, float co[3], int type)
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
const Depsgraph * depsgraph
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
const ShrinkwrapBoundaryData * boundary
blender::VArraySpan< bool > sharp_faces
blender::Span< blender::float3 > corner_normals
blender::Span< int > corner_edges
BVHTreeFromMesh treeData
blender::Span< blender::float3 > vert_normals