Blender V5.0
shrinkwrap.cc File Reference
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <memory.h>
#include "DNA_gpencil_modifier_types.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_solvers.h"
#include "BLI_math_vector.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BKE_attribute.hh"
#include "BKE_modifier.hh"
#include "BKE_shrinkwrap.hh"
#include "BKE_subdiv.hh"
#include "BKE_deform.hh"
#include "BKE_editmesh.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_wrapper.hh"
#include "BKE_subdiv_deform.hh"
#include "DEG_depsgraph_query.hh"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  ShrinkwrapCalcData
struct  ShrinkwrapCalcCBData
struct  TargetProjectTriData

Namespaces

namespace  blender
namespace  blender::bke
namespace  blender::bke::shrinkwrap

Macros

#define TIMEIT_BENCH(expr, id)
#define OUT_OF_MEMORY()

Functions

bool BKE_shrinkwrap_needs_normals (int shrinkType, int shrinkMode)
bool BKE_shrinkwrap_init_tree (ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
void BKE_shrinkwrap_free_tree (ShrinkwrapTreeData *)
static void blender::bke::shrinkwrap::merge_vert_dir (ShrinkwrapBoundaryVertData *vdata, MutableSpan< int8_t > status, int index, const float edge_dir[3], signed char side)
static ShrinkwrapBoundaryData blender::bke::shrinkwrap::shrinkwrap_build_boundary_data (const Mesh &mesh)
const ShrinkwrapBoundaryDatablender::bke::shrinkwrap::boundary_cache_ensure (const Mesh &mesh)
static void shrinkwrap_calc_nearest_vertex_cb_ex (void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
static void shrinkwrap_calc_nearest_vertex (ShrinkwrapCalcData *calc)
bool BKE_shrinkwrap_project_normal (char options, const float vert[3], const float dir[3], const float ray_radius, const SpaceTransform *transf, ShrinkwrapTreeData *tree, BVHTreeRayHit *hit)
static void shrinkwrap_calc_normal_projection_cb_ex (void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
static void shrinkwrap_calc_normal_projection (ShrinkwrapCalcData *calc)
static void target_project_tri_deviation (void *userdata, const float x[3], float r_delta[3])
static void target_project_tri_jacobian (void *userdata, const float x[3], float r_jacobian[3][3])
static void target_project_tri_clamp (float x[3])
static bool target_project_tri_correct (void *, const float x[3], float step[3], float x_next[3])
static bool target_project_solve_point_tri (const float *vtri_co[3], const float vtri_no[3][3], const float point_co[3], const float hit_co[3], float hit_dist_sq, float r_hit_co[3], float r_hit_no[3])
static bool update_hit (BVHTreeNearest *nearest, int index, const float co[3], const float hit_co[3], const float hit_no[3])
static void target_project_edge (const ShrinkwrapTreeData *tree, int index, const float co[3], BVHTreeNearest *nearest, int eidx)
static void mesh_corner_tris_target_project (void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
void BKE_shrinkwrap_find_nearest_surface (ShrinkwrapTreeData *tree, BVHTreeNearest *nearest, float co[3], int type)
static void shrinkwrap_calc_nearest_surface_point_cb_ex (void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
void BKE_shrinkwrap_compute_smooth_normal (const ShrinkwrapTreeData *tree, const SpaceTransform *transform, int corner_tri_idx, const float hit_co[3], const float hit_no[3], float r_no[3])
static void shrinkwrap_snap_with_side (float r_point_co[3], const float point_co[3], const float hit_co[3], const float hit_no[3], float goal_dist, float forcesign, bool forcesnap)
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])
static void shrinkwrap_calc_nearest_surface_point (ShrinkwrapCalcData *calc)
static blender::Array< blender::float3shrinkwrap_calc_subdivided_positions (Mesh *mesh, const int subdivision_level)
void shrinkwrapModifier_deform (ShrinkwrapModifierData *smd, const ModifierEvalContext *ctx, Scene *, Object *ob, Mesh *mesh, const MDeformVert *dvert, const int defgrp_index, float(*vertexCos)[3], int numVerts)
void shrinkwrapParams_deform (const ShrinkwrapParams &params, Object &object, ShrinkwrapTreeData &tree, const blender::Span< MDeformVert > dvert, const int defgrp_index, const 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)

Macro Definition Documentation

◆ OUT_OF_MEMORY

#define OUT_OF_MEMORY ( )
Value:
((void)printf("Shrinkwrap: Out of memory\n"))
#define printf(...)

Definition at line 53 of file shrinkwrap.cc.

◆ TIMEIT_BENCH

#define TIMEIT_BENCH ( expr,
id )
Value:
(expr)

Definition at line 49 of file shrinkwrap.cc.

Referenced by BKE_shrinkwrap_remesh_target_project(), and shrinkwrapModifier_deform().

Function Documentation

◆ BKE_shrinkwrap_compute_smooth_normal()

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] )

Compute a smooth normal of the target (if applicable) at the hit location.

Parameters
treeinformation about the mesh.
transformtransform from the hit coordinate space to the object space; may be null.
r_nooutput in hit coordinate space; may be shared with inputs.

Definition at line 1144 of file shrinkwrap.cc.

References BLI_space_transform_apply(), BLI_space_transform_invert_normal(), copy_v3_v3(), blender::bke::BVHTreeFromMesh::corner_tris, blender::bke::BVHTreeFromMesh::corner_verts, interp_v3_v3v3v3(), interp_weights_tri_v3(), normalize_v3(), transform(), tree, blender::bke::BVHTreeFromMesh::vert_positions, and w().

Referenced by BKE_shrinkwrap_snap_point_to_surface(), and shrinkwrap_get_tarmat().

◆ BKE_shrinkwrap_find_nearest_surface()

void BKE_shrinkwrap_find_nearest_surface ( ShrinkwrapTreeData * tree,
BVHTreeNearest * nearest,
float co[3],
int type )

◆ BKE_shrinkwrap_free_tree()

◆ BKE_shrinkwrap_init_tree()

◆ BKE_shrinkwrap_mesh_nearest_surface_deform()

void BKE_shrinkwrap_mesh_nearest_surface_deform ( Depsgraph * depsgraph,
Scene * scene,
Object * ob_source,
Object * ob_target )

◆ BKE_shrinkwrap_needs_normals()

bool BKE_shrinkwrap_needs_normals ( int shrinkType,
int shrinkMode )

Checks if the modifier needs target normals with these settings.

Definition at line 89 of file shrinkwrap.cc.

References MOD_SHRINKWRAP_ABOVE_SURFACE, MOD_SHRINKWRAP_NEAREST_VERTEX, and MOD_SHRINKWRAP_TARGET_PROJECT.

Referenced by BKE_shrinkwrap_init_tree().

◆ BKE_shrinkwrap_project_normal()

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 )

This function ray-cast a single vertex and updates the hit if the "hit" is considered valid.

Parameters
optionsOpts control whether an hit is valid or not. Supported options are:
transfTake 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).
Returns
true if "hit" was updated.

Definition at line 386 of file shrinkwrap.cc.

References BLI_assert, BLI_bvhtree_ray_cast(), BLI_space_transform_apply(), BLI_space_transform_apply_normal(), BLI_space_transform_invert(), BLI_space_transform_invert_normal(), BVHTreeRayHit::co, copy_v3_v3(), BVHTreeRayHit::dist, dot(), dot_v3v3(), BVHTreeRayHit::index, len_v3v3(), mat4_to_scale(), MOD_SHRINKWRAP_CULL_TARGET_BACKFACE, MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE, MOD_SHRINKWRAP_CULL_TARGET_MASK, BVHTreeRayHit::no, options, and tree.

Referenced by shrinkwrap_calc_normal_projection_cb_ex(), and shrinkwrap_get_tarmat().

◆ BKE_shrinkwrap_remesh_target_project()

◆ BKE_shrinkwrap_snap_point_to_surface()

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] )

Apply the shrink to surface modes to the given original coordinates and nearest point.

Parameters
treemesh data for smooth normals.
transformtransform from the hit coordinate space to the object space; may be null.
r_point_comay be the same memory location as point_co, hit_co, or hit_no.

Definition at line 1266 of file shrinkwrap.cc.

References BKE_shrinkwrap_compute_smooth_normal(), copy_v3_v3(), madd_v3_v3v3fl(), MOD_SHRINKWRAP_ABOVE_SURFACE, MOD_SHRINKWRAP_INSIDE, MOD_SHRINKWRAP_ON_SURFACE, MOD_SHRINKWRAP_OUTSIDE, MOD_SHRINKWRAP_OUTSIDE_SURFACE, printf, shrinkwrap_snap_with_side(), transform(), and tree.

Referenced by shrinkwrap_calc_nearest_surface_point_cb_ex(), shrinkwrap_calc_normal_projection_cb_ex(), and shrinkwrap_get_tarmat().

◆ mesh_corner_tris_target_project()

◆ shrinkwrap_calc_nearest_surface_point()

◆ shrinkwrap_calc_nearest_surface_point_cb_ex()

◆ shrinkwrap_calc_nearest_vertex()

◆ shrinkwrap_calc_nearest_vertex_cb_ex()

◆ shrinkwrap_calc_normal_projection()

◆ shrinkwrap_calc_normal_projection_cb_ex()

◆ shrinkwrap_calc_subdivided_positions()

◆ shrinkwrap_snap_with_side()

void shrinkwrap_snap_with_side ( float r_point_co[3],
const float point_co[3],
const float hit_co[3],
const float hit_no[3],
float goal_dist,
float forcesign,
bool forcesnap )
static

◆ shrinkwrapModifier_deform()

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 )

◆ shrinkwrapParams_deform()

◆ target_project_edge()

void target_project_edge ( const ShrinkwrapTreeData * tree,
int index,
const float co[3],
BVHTreeNearest * nearest,
int eidx )
static

◆ target_project_solve_point_tri()

◆ target_project_tri_clamp()

void target_project_tri_clamp ( float x[3])
static

Definition at line 728 of file shrinkwrap.cc.

References x.

Referenced by target_project_solve_point_tri(), and target_project_tri_correct().

◆ target_project_tri_correct()

bool target_project_tri_correct ( void * ,
const float x[3],
float step[3],
float x_next[3] )
static

◆ target_project_tri_deviation()

void target_project_tri_deviation ( void * userdata,
const float x[3],
float r_delta[3] )
static

Definition at line 702 of file shrinkwrap.cc.

References data, interp_v3_v3v3v3(), madd_v3_v3v3fl(), sub_v3_v3(), w(), and x.

Referenced by target_project_solve_point_tri().

◆ target_project_tri_jacobian()

void target_project_tri_jacobian ( void * userdata,
const float x[3],
float r_jacobian[3][3] )
static

Definition at line 715 of file shrinkwrap.cc.

References copy_v3_v3(), data, madd_v3_v3fl(), madd_v3_v3v3fl(), and x.

Referenced by target_project_solve_point_tri().

◆ update_hit()

bool update_hit ( BVHTreeNearest * nearest,
int index,
const float co[3],
const float hit_co[3],
const float hit_no[3] )
static