Blender V5.0
mesh_remap.cc File Reference
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_array.hh"
#include "BLI_astar.h"
#include "BLI_bit_vector.hh"
#include "BLI_index_mask.hh"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_solvers.h"
#include "BLI_math_statistics.h"
#include "BLI_math_vector.h"
#include "BLI_memarena.h"
#include "BLI_polyfill_2d.h"
#include "BLI_rand.h"
#include "BLI_utildefines.h"
#include "DNA_modifier_enums.h"
#include "BKE_attribute.hh"
#include "BKE_bvhutils.hh"
#include "BKE_customdata.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_mapping.hh"
#include "BKE_mesh_remap.hh"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  IslandResult

Typedefs

using float3

Functions

Some Generic Helpers
static bool mesh_remap_bvhtree_query_nearest (blender::bke::BVHTreeFromMesh *treedata, BVHTreeNearest *nearest, const float co[3], const float max_dist_sq, float *r_hit_dist)
static bool mesh_remap_bvhtree_query_raycast (blender::bke::BVHTreeFromMesh *treedata, BVHTreeRayHit *rayhit, const float co[3], const float no[3], const float radius, const float max_dist, float *r_hit_dist)
Auto-match.

Find transform of a mesh to get best match with another.

float BKE_mesh_remap_calc_difference_from_mesh (const SpaceTransform *space_transform, const Span< float3 > vert_positions_dst, const Mesh *me_src)
static void mesh_calc_eigen_matrix (const Span< float3 > positions, float r_mat[4][4])
void BKE_mesh_remap_find_best_match_from_mesh (const Span< float3 > vert_positions_dst, const Mesh *me_src, SpaceTransform *r_space_transform)

Variables

static CLG_LogRef LOG = {"geom.mesh"}

Mesh to Mesh Mapping

#define MREMAP_RAYCAST_APPROXIMATE_NR   3
#define MREMAP_RAYCAST_APPROXIMATE_FAC   5.0f
#define MREMAP_RAYCAST_TRI_SAMPLES_MIN   4
#define MREMAP_RAYCAST_TRI_SAMPLES_MAX   20
#define MREMAP_DEFAULT_BUFSIZE   32
#define POLY_UNSET   0
#define POLY_CENTER_INIT   1
#define POLY_COMPLETE   2
#define ASTAR_STEPS_MAX   64
void BKE_mesh_remap_init (MeshPairRemap *map, const int items_num)
void BKE_mesh_remap_free (MeshPairRemap *map)
static void mesh_remap_item_define (MeshPairRemap *map, const int index, const float, const int island, const int sources_num, const int *indices_src, const float *weights_src)
void BKE_mesh_remap_item_define_invalid (MeshPairRemap *map, const int index)
static int mesh_remap_interp_face_data_get (const blender::IndexRange face, const blender::Span< int > corner_verts, const blender::Span< blender::float3 > positions_src, const float point[3], size_t *buff_size, float(**vcos)[3], const bool use_loops, int **indices, float **weights, const bool do_weights, int *r_closest_index)
void BKE_mesh_remap_calc_verts_from_mesh (const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius, const Span< float3 > vert_positions_dst, const Mesh *me_src, Mesh *me_dst, MeshPairRemap *r_map)
void BKE_mesh_remap_calc_edges_from_mesh (const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius, const Span< float3 > vert_positions_dst, const Span< blender::int2 > edges_dst, const Mesh *me_src, Mesh *me_dst, MeshPairRemap *r_map)
static void mesh_island_to_astar_graph_edge_process (MeshIslandStore *islands, const int island_index, BLI_AStarGraph *as_graph, const blender::Span< blender::float3 > positions, const blender::OffsetIndices< int > faces, const blender::Span< int > corner_verts, const int edge_idx, BLI_bitmap *done_edges, const blender::GroupedSpan< int > edge_to_face_map, const bool is_edge_innercut, const int *face_island_index_map, float(*face_centers)[3], uchar *face_status)
static void mesh_island_to_astar_graph (MeshIslandStore *islands, const int island_index, const blender::Span< blender::float3 > positions, const blender::GroupedSpan< int > edge_to_face_map, const int numedges, const blender::OffsetIndices< int > faces, const blender::Span< int > corner_verts, const blender::Span< int > corner_edges, BLI_AStarGraph *r_as_graph)
static float mesh_remap_calc_loops_astar_f_cost (BLI_AStarGraph *as_graph, BLI_AStarSolution *as_solution, BLI_AStarGNLink *link, const int node_idx_curr, const int node_idx_next, const int node_idx_dst)
void BKE_mesh_remap_calc_loops_from_mesh (const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius, const Mesh *mesh_dst, const Span< float3 > vert_positions_dst, const Span< int > corner_verts_dst, const blender::OffsetIndices< int > faces_dst, const Mesh *me_src, MeshRemapIslandsCalc gen_islands_src, const float islands_precision_src, MeshPairRemap *r_map)
void BKE_mesh_remap_calc_faces_from_mesh (const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius, const Mesh *mesh_dst, const Span< float3 > vert_positions_dst, const Span< int > corner_verts_dst, const blender::OffsetIndices< int > faces_dst, const Mesh *me_src, MeshPairRemap *r_map)

Detailed Description

Functions for mapping data between meshes.

Definition in file mesh_remap.cc.

Macro Definition Documentation

◆ ASTAR_STEPS_MAX

#define ASTAR_STEPS_MAX   64

Definition at line 1181 of file mesh_remap.cc.

Referenced by BKE_mesh_remap_calc_loops_from_mesh().

◆ MREMAP_DEFAULT_BUFSIZE

#define MREMAP_DEFAULT_BUFSIZE   32

◆ MREMAP_RAYCAST_APPROXIMATE_FAC

#define MREMAP_RAYCAST_APPROXIMATE_FAC   5.0f

Each approximated ray-casts will have n times bigger radius than previous one.

Definition at line 425 of file mesh_remap.cc.

Referenced by BKE_mesh_remap_calc_edges_from_mesh(), BKE_mesh_remap_calc_faces_from_mesh(), and BKE_mesh_remap_calc_loops_from_mesh().

◆ MREMAP_RAYCAST_APPROXIMATE_NR

#define MREMAP_RAYCAST_APPROXIMATE_NR   3
Note
About all BVH/ray-casting stuff below:
  • We must use our ray radius as BVH epsilon too, else rays not hitting anything but 'passing near' an item would be missed (since BVH handling would not detect them, 'refining' callbacks won't be executed, even though they would return a valid hit).
  • However, in 'islands' case where each hit gets a weight, 'precise' hits should have a better weight than 'approximate' hits. To address that, we simplify things with:

    • A first ray-cast with default, given ray-radius;
    • If first one fails, we do more ray-casting with bigger radius, but if hit is found it will get smaller weight.

    This only concerns loops, currently (because of islands), and 'sampled' edges/faces norproj. At most N ray-casts per 'real' ray.

Definition at line 423 of file mesh_remap.cc.

Referenced by BKE_mesh_remap_calc_edges_from_mesh(), BKE_mesh_remap_calc_faces_from_mesh(), and BKE_mesh_remap_calc_loops_from_mesh().

◆ MREMAP_RAYCAST_TRI_SAMPLES_MAX

#define MREMAP_RAYCAST_TRI_SAMPLES_MAX   20

Definition at line 429 of file mesh_remap.cc.

Referenced by BKE_mesh_remap_calc_faces_from_mesh().

◆ MREMAP_RAYCAST_TRI_SAMPLES_MIN

#define MREMAP_RAYCAST_TRI_SAMPLES_MIN   4

Definition at line 428 of file mesh_remap.cc.

Referenced by BKE_mesh_remap_calc_faces_from_mesh().

◆ POLY_CENTER_INIT

#define POLY_CENTER_INIT   1

Definition at line 996 of file mesh_remap.cc.

Referenced by mesh_island_to_astar_graph_edge_process().

◆ POLY_COMPLETE

#define POLY_COMPLETE   2

◆ POLY_UNSET

#define POLY_UNSET   0

Definition at line 995 of file mesh_remap.cc.

Referenced by mesh_island_to_astar_graph_edge_process().

Typedef Documentation

◆ float3

Definition at line 619 of file BLI_math_vector_types.hh.

Function Documentation

◆ BKE_mesh_remap_calc_difference_from_mesh()

float BKE_mesh_remap_calc_difference_from_mesh ( const SpaceTransform * space_transform,
const Span< float3 > vert_positions_dst,
const Mesh * me_src )

◆ BKE_mesh_remap_calc_edges_from_mesh()

◆ BKE_mesh_remap_calc_faces_from_mesh()

void BKE_mesh_remap_calc_faces_from_mesh ( const int mode,
const SpaceTransform * space_transform,
const float max_dist,
const float ray_radius,
const Mesh * mesh_dst,
const Span< float3 > vert_positions_dst,
const Span< int > corner_verts_dst,
const blender::OffsetIndices< int > faces_dst,
const Mesh * me_src,
MeshPairRemap * r_map )

◆ BKE_mesh_remap_calc_loops_from_mesh()

void BKE_mesh_remap_calc_loops_from_mesh ( const int mode,
const SpaceTransform * space_transform,
const float max_dist,
const float ray_radius,
const Mesh * mesh_dst,
const Span< float3 > vert_positions_dst,
const Span< int > corner_verts_dst,
const blender::OffsetIndices< int > faces_dst,
const Mesh * me_src,
MeshRemapIslandsCalc gen_islands_src,
const float islands_precision_src,
MeshPairRemap * r_map )

Definition at line 1183 of file mesh_remap.cc.

References ASTAR_STEPS_MAX, Geometry::attributes, BKE_mesh_loop_islands_free(), BKE_mesh_origindex_map_create_corner_tri(), BKE_mesh_remap_init(), BKE_mesh_remap_item_define_invalid(), BLI_assert, BLI_astar_graph_free(), BLI_astar_graph_solve(), BLI_astar_solution_clear(), BLI_astar_solution_free(), BLI_astar_solution_init(), BLI_space_transform_apply(), BLI_space_transform_apply_normal(), blender::bke::mesh::build_edge_to_face_map(), blender::bke::bvhtree_from_mesh_corner_tris_ex(), blender::bke::bvhtree_from_mesh_verts_ex(), closest_on_tri_to_point_v3(), BVHTreeNearest::co, BVHTreeRayHit::co, copy_v3_v3(), Mesh::corners_num, count, MeshElemMap::count, BLI_AStarGNLink::custom_data, BLI_AStarGraph::custom_data, BLI_AStarSolution::custom_data, blender::Span< T >::data(), dot(), dot_v3v3(), blender::bke::Edge, ELEM, blender::bke::mesh::face_center_calc(), IslandResult::factor, blender::bits::BitVector< InlineBufferCapacity, Allocator >::fill(), float, FLT_MAX, IndexMask::from_bits(), IslandResult::hit_dist, IslandResult::hit_point, i, BVHTreeNearest::index, BVHTreeRayHit::index, blender::offset_indices::OffsetIndices< T >::index_range(), IslandResult::index_src, MeshElemMap::indices, MeshIslandStore::innercut_type, MeshIslandStore::island_type, MeshIslandStore::islands, MeshIslandStore::islands_num, MeshIslandStore::item_type, MeshIslandStore::items_to_islands, len_squared_v3v3(), blender::bke::AttributeAccessor::lookup(), max_ii(), MEM_calloc_arrayN(), MEM_callocN(), MEM_freeN(), MEM_malloc_arrayN(), MEM_reallocN, mesh_island_to_astar_graph(), mesh_remap_bvhtree_query_nearest(), mesh_remap_bvhtree_query_raycast(), mesh_remap_calc_loops_astar_f_cost(), mesh_remap_interp_face_data_get(), mesh_remap_item_define(), MISLAND_TYPE_EDGE, MISLAND_TYPE_LOOP, MISLAND_TYPE_POLY, MREMAP_DEFAULT_BUFSIZE, MREMAP_MODE_LOOP, MREMAP_MODE_LOOP_NEAREST_LOOPNOR, MREMAP_MODE_LOOP_NEAREST_POLYNOR, MREMAP_MODE_LOOP_POLY_NEAREST, MREMAP_MODE_TOPOLOGY, MREMAP_RAYCAST_APPROXIMATE_FAC, MREMAP_RAYCAST_APPROXIMATE_NR, MREMAP_USE_LOOP, MREMAP_USE_NORMAL, MREMAP_USE_NORPROJ, MREMAP_USE_POLY, MREMAP_USE_VERT, POINTER_AS_INT, POINTER_FROM_INT, BLI_AStarSolution::prev_links, BLI_AStarSolution::prev_nodes, Array< T, InlineBufferCapacity, Allocator >::reinitialize(), blender::Array< T, InlineBufferCapacity, Allocator >::reinitialize(), blender::IndexRange::size(), blender::offset_indices::OffsetIndices< T >::size(), blender::Span< T >::size(), blender::Span< T >::slice(), blender::IndexRange::start(), BLI_AStarSolution::steps, Mesh::verts_num, and w().

◆ BKE_mesh_remap_calc_verts_from_mesh()

◆ BKE_mesh_remap_find_best_match_from_mesh()

void BKE_mesh_remap_find_best_match_from_mesh ( const Span< float3 > vert_positions_dst,
const Mesh * me_src,
SpaceTransform * r_space_transform )

◆ BKE_mesh_remap_free()

void BKE_mesh_remap_free ( MeshPairRemap * map)

◆ BKE_mesh_remap_init()

◆ BKE_mesh_remap_item_define_invalid()

void BKE_mesh_remap_item_define_invalid ( MeshPairRemap * map,
const int index )

◆ mesh_calc_eigen_matrix()

◆ mesh_island_to_astar_graph()

void mesh_island_to_astar_graph ( MeshIslandStore * islands,
const int island_index,
const blender::Span< blender::float3 > positions,
const blender::GroupedSpan< int > edge_to_face_map,
const int numedges,
const blender::OffsetIndices< int > faces,
const blender::Span< int > corner_verts,
const blender::Span< int > corner_edges,
BLI_AStarGraph * r_as_graph )
static

◆ mesh_island_to_astar_graph_edge_process()

void mesh_island_to_astar_graph_edge_process ( MeshIslandStore * islands,
const int island_index,
BLI_AStarGraph * as_graph,
const blender::Span< blender::float3 > positions,
const blender::OffsetIndices< int > faces,
const blender::Span< int > corner_verts,
const int edge_idx,
BLI_bitmap * done_edges,
const blender::GroupedSpan< int > edge_to_face_map,
const bool is_edge_innercut,
const int * face_island_index_map,
float(*) face_centers[3],
uchar * face_status )
static

◆ mesh_remap_bvhtree_query_nearest()

◆ mesh_remap_bvhtree_query_raycast()

◆ mesh_remap_calc_loops_astar_f_cost()

float mesh_remap_calc_loops_astar_f_cost ( BLI_AStarGraph * as_graph,
BLI_AStarSolution * as_solution,
BLI_AStarGNLink * link,
const int node_idx_curr,
const int node_idx_next,
const int node_idx_dst )
static

◆ mesh_remap_interp_face_data_get()

int mesh_remap_interp_face_data_get ( const blender::IndexRange face,
const blender::Span< int > corner_verts,
const blender::Span< blender::float3 > positions_src,
const float point[3],
size_t * buff_size,
float(**) vcos[3],
const bool use_loops,
int ** indices,
float ** weights,
const bool do_weights,
int * r_closest_index )
static

◆ mesh_remap_item_define()

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"geom.mesh"}
static

Definition at line 40 of file mesh_remap.cc.