Blender V4.3
shrinkwrap.cc File Reference
#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_mesh_legacy_derived_mesh.hh"
#include "BKE_modifier.hh"
#include "BKE_shrinkwrap.hh"
#include "BKE_deform.hh"
#include "BKE_editmesh.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_wrapper.hh"
#include "BKE_subsurf.hh"
#include "DEG_depsgraph_query.hh"
#include "MEM_guardedalloc.h"
#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)   (expr)
 
#define OUT_OF_MEMORY()   ((void)printf("Shrinkwrap: Out of memory\n"))
 

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 *data)
 
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)
 
void shrinkwrapModifier_deform (ShrinkwrapModifierData *smd, const ModifierEvalContext *ctx, Scene *scene, Object *ob, Mesh *mesh, const MDeformVert *dvert, const int defgrp_index, float(*vertexCos)[3], int numVerts)
 
void shrinkwrapGpencilModifier_deform (ShrinkwrapGpencilModifierData *mmd, Object *ob, 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 ( )    ((void)printf("Shrinkwrap: Out of memory\n"))

Definition at line 53 of file shrinkwrap.cc.

◆ TIMEIT_BENCH

#define TIMEIT_BENCH ( expr,
id )   (expr)

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 1153 of file shrinkwrap.cc.

References BLI_space_transform_apply(), BLI_space_transform_invert_normal(), copy_v3_v3(), BVHTreeFromMesh::corner_tris, BVHTreeFromMesh::corner_verts, interp_v3_v3v3v3(), interp_weights_tri_v3(), normalize_v3(), tree, 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 )

Maps the point to the nearest surface, either by simple nearest, or by target normal projection.

Definition at line 1049 of file shrinkwrap.cc.

References BLI_bvhtree_find_nearest(), BLI_bvhtree_find_nearest_ex(), BVH_NEAREST_OPTIMAL_ORDER, mesh_corner_tris_target_project(), MOD_SHRINKWRAP_TARGET_PROJECT, BVHTreeFromMesh::nearest_callback, printf, and tree.

Referenced by shrinkwrap_calc_nearest_surface_point_cb_ex(), and shrinkwrap_get_tarmat().

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

◆ 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 390 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_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 1275 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(), 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()

static void mesh_corner_tris_target_project ( void * userdata,
int index,
const float co[3],
BVHTreeNearest * nearest )
static

◆ shrinkwrap_calc_nearest_surface_point()

◆ shrinkwrap_calc_nearest_surface_point_cb_ex()

◆ shrinkwrap_calc_nearest_vertex()

◆ shrinkwrap_calc_nearest_vertex_cb_ex()

static void shrinkwrap_calc_nearest_vertex_cb_ex ( void *__restrict userdata,
const int i,
const TaskParallelTLS *__restrict tls )
static

◆ shrinkwrap_calc_normal_projection()

◆ shrinkwrap_calc_normal_projection_cb_ex()

◆ shrinkwrap_snap_with_side()

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

◆ shrinkwrapGpencilModifier_deform()

void shrinkwrapGpencilModifier_deform ( ShrinkwrapGpencilModifierData * mmd,
Object * ob,
MDeformVert * dvert,
const int defgrp_index,
float(*) vertexCos[3],
int numVerts )

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

Main shrink-wrap function (implementation of the shrink-wrap modifier).

Definition at line 1353 of file shrinkwrap.cc.

References ShrinkwrapCalcData::aux_target, ShrinkwrapModifierData::auxTarget, BKE_modifier_get_evaluated_mesh_from_evaluated_object(), BKE_shrinkwrap_free_tree(), BKE_shrinkwrap_init_tree(), BLI_assert, BLI_SPACE_TRANSFORM_SETUP, CDDM_from_mesh(), DEG_get_evaluated_object(), ModifierEvalContext::depsgraph, ShrinkwrapCalcData::dvert, SubsurfModifierData::emCache, DerivedMesh::getNumVerts, DerivedMesh::getVertArray, ShrinkwrapCalcData::invert_vgroup, ShrinkwrapCalcData::keepDist, ShrinkwrapModifierData::keepDist, SubsurfModifierData::levels, ShrinkwrapCalcData::local2target, SubsurfModifierData::mCache, ME_CC_SUBSURF, MOD_SHRINKWRAP_INVERT_VGROUP, MOD_SHRINKWRAP_NEAREST_SURFACE, MOD_SHRINKWRAP_NEAREST_VERTEX, MOD_SHRINKWRAP_PROJECT, MOD_SHRINKWRAP_TARGET_PROJECT, Object::mode, NULL_ShrinkwrapCalcData, ShrinkwrapCalcData::numVerts, ShrinkwrapCalcData::ob, OB_MODE_EDIT, DerivedMesh::release, ShrinkwrapModifierData::shrinkMode, ShrinkwrapModifierData::shrinkOpts, ShrinkwrapModifierData::shrinkType, shrinkwrap_calc_nearest_surface_point(), shrinkwrap_calc_nearest_vertex(), shrinkwrap_calc_normal_projection(), ShrinkwrapCalcData::smd, SubsurfModifierData::subdivType, SUBSURF_IN_EDIT_MODE, subsurf_make_derived_from_derived(), ShrinkwrapModifierData::subsurfLevels, ShrinkwrapCalcData::target, ShrinkwrapModifierData::target, TIMEIT_BENCH, ShrinkwrapCalcData::tree, tree, ShrinkwrapCalcData::vert_normals, ShrinkwrapCalcData::vert_positions, ShrinkwrapCalcData::vertexCos, and ShrinkwrapCalcData::vgroup.

Referenced by BKE_shrinkwrap_mesh_nearest_surface_deform(), and deform_verts().

◆ shrinkwrapParams_deform()

◆ target_project_edge()

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

◆ target_project_solve_point_tri()

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

◆ target_project_tri_clamp()

static void target_project_tri_clamp ( float x[3])
static

Definition at line 735 of file shrinkwrap.cc.

Referenced by target_project_solve_point_tri(), and target_project_tri_correct().

◆ target_project_tri_correct()

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

◆ target_project_tri_deviation()

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

Definition at line 709 of file shrinkwrap.cc.

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

Referenced by target_project_solve_point_tri().

◆ target_project_tri_jacobian()

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

Definition at line 722 of file shrinkwrap.cc.

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

Referenced by target_project_solve_point_tri().

◆ update_hit()

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