51 # define TIMEIT_BENCH(expr, id) (expr)
55 #define OUT_OF_MEMORY() ((void)printf("Shrinkwrap: Out of memory\n"))
172 const float edge_dir[3],
176 float *direction = vdata[index].
direction;
182 if (status[index] >= 0 ? status[index] == side :
dot_v3v3(direction, edge_dir) < 0) {
189 status[index] = (status[index] == 0) ? side : -1;
202 unsigned int eidx = mloop[i].
e;
204 if (edge_mode[eidx] < 2) {
211 "ShrinkwrapBoundaryData::edge_is_boundary");
212 unsigned int num_boundary_edges = 0;
215 edge_mode[i] = (edge_mode[i] == 1);
219 num_boundary_edges++;
224 if (num_boundary_edges == 0) {
232 "ShrinkwrapBoundaryData");
241 "ShrinkwrapBoundaryData::looptri_is_boundary");
243 for (
int i = 0; i < totlooptri; i++) {
247 for (
int j = 0; j < 3; j++) {
248 if (edges[j] >= 0 && edge_mode[edges[j]]) {
259 (
size_t)
mesh->
totvert,
sizeof(
int),
"ShrinkwrapBoundaryData::vert_boundary_id");
263 const MEdge *edge = &medge[i];
287 const MEdge *edge = &medge[i];
351 weight = 1.0f - weight;
354 if (weight == 0.0f) {
372 if (nearest->
index != -1) {
382 if (nearest->
index != -1) {
385 if (nearest->
dist_sq > FLT_EPSILON) {
387 weight *= (dist - calc->
keepDist) / dist;
422 const float ray_radius,
432 float tmp_co[3], tmp_no[3];
433 const float *co, *no;
437 memcpy(&hit_tmp, hit,
sizeof(hit_tmp));
449 #ifdef USE_DIST_CORRECT
461 tree->bvh, co, no, ray_radius, &hit_tmp,
tree->treeData.raycast_callback, &
tree->treeData);
463 if (hit_tmp.
index != -1) {
481 #ifdef USE_DIST_CORRECT
488 memcpy(hit, &hit_tmp,
sizeof(hit_tmp));
504 float *proj_axis =
data->proj_axis;
511 float tmp_co[3], tmp_no[3];
515 weight = 1.0f - weight;
518 if (weight == 0.0f) {
582 if (proj_limit_squared != 0.0f) {
588 if (hit->
index != -1) {
619 float proj_axis[3] = {0.0f, 0.0f, 0.0f};
678 aux_tree = &aux_tree_stack;
685 .aux_tree = aux_tree,
686 .proj_axis = proj_axis,
687 .local2aux = &local2aux,
736 const float w[3] = {
x[0],
x[1], 1.0f -
x[0] -
x[1]};
766 if (
x[0] +
x[1] > 1.0f) {
767 x[0] =
x[0] / (
x[0] +
x[1]);
781 const float dir_epsilon = 0.5f;
782 bool fixed =
false, locked =
false;
787 float sum =
x[0] +
x[1];
788 float sstep = -(step[0] + step[1]);
790 if (
sum + sstep > 1.0f) {
791 float ldist = 1.0f -
sum;
795 float step_len =
len_v2(step);
798 if (step_len >
epsilon && sstep > step_len * dir_epsilon * (
float)
M_SQRT2) {
804 fixed = locked =
true;
814 for (
int i = 0; i < 2; i++) {
815 if (step[i] >
x[i]) {
818 float step_len =
len_v2(step);
821 if (step_len >
epsilon && (locked || step[i] > step_len * dir_epsilon)) {
847 const float vtri_no[3][3],
848 const float point_co[3],
849 const float hit_co[3],
855 float dist =
sqrtf(hit_dist_sq);
858 float epsilon = magnitude_estimate * 1.0e-6f;
866 x[2] = (
dot_v3v3(tmp, r_hit_no) < 0) ? -dist : dist;
872 .point_co = point_co,
882 #ifdef TRACE_TARGET_PROJECT
883 const bool trace =
true;
885 const bool trace =
false;
911 const float hit_co[3],
912 const float hit_no[3])
916 if (dist_sq < nearest->dist_sq) {
917 #ifdef TRACE_TARGET_PROJECT
919 "#=#=#> %d (%.3f,%.3f,%.3f) %g < %g\n", index,
UNPACK3(hit_co), dist_sq, nearest->
dist_sq);
921 nearest->
index = index;
940 const MEdge *edge = &
tree->mesh->medge[eidx];
941 const float *vedge_co[2] = {
data->vert[edge->v1].co,
data->vert[edge->v2].co};
943 #ifdef TRACE_TARGET_PROJECT
944 printf(
"EDGE %d (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n",
951 const int *vert_boundary_id =
tree->boundary->vert_boundary_id;
952 int bid1 = vert_boundary_id[edge->v1], bid2 = vert_boundary_id[edge->v2];
954 if (bid1 < 0 || bid2 < 0) {
960 float vedge_dir[2][3], dir[3];
962 copy_v3_v3(vedge_dir[0], boundary_verts[bid1].normal_plane);
963 copy_v3_v3(vedge_dir[1], boundary_verts[bid2].normal_plane);
967 if (
dot_v3v3(boundary_verts[bid1].direction, dir) < 0) {
970 if (
dot_v3v3(boundary_verts[bid2].direction, dir) < 0) {
975 float d0v0 =
dot_v3v3(vedge_dir[0], vedge_co[0]), d0v1 =
dot_v3v3(vedge_dir[0], vedge_co[1]);
976 float d1v0 =
dot_v3v3(vedge_dir[1], vedge_co[0]), d1v1 =
dot_v3v3(vedge_dir[1], vedge_co[1]);
977 float d0co =
dot_v3v3(vedge_dir[0], co);
979 float a = d0v1 - d0v0 + d1v0 - d1v1;
980 float b = 2 * d0v0 - d0v1 - d0co - d1v0 +
dot_v3v3(vedge_dir[1], co);
981 float c = d0co - d0v0;
982 float det =
b *
b - 4 *
a *
c;
986 float sdet =
sqrtf(det);
987 float hit_co[3], hit_no[3];
989 for (
int i = (det > 0 ? 2 : 0); i >= 0; i -= 2) {
990 float x = (-
b + ((
float)i - 1) * sdet) / (2 *
a);
995 float vedge_no[2][3];
1002 update_hit(nearest, index, co, hit_co, hit_no);
1017 const MLoop *loop[3] = {
1019 const MVert *vtri[3] = {
1020 &
data->vert[loop[0]->
v], &
data->vert[loop[1]->
v], &
data->vert[loop[2]->
v]};
1021 const float *vtri_co[3] = {vtri[0]->
co, vtri[1]->
co, vtri[2]->
co};
1022 float raw_hit_co[3], hit_co[3], hit_no[3], dist_sq, vtri_no[3][3];
1028 #ifdef TRACE_TARGET_PROJECT
1029 printf(
"TRIANGLE %d (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f) %g %g\n",
1038 if (dist_sq >= nearest->
dist_sq) {
1049 update_hit(nearest, index, co, hit_co, hit_no);
1053 const BLI_bitmap *is_boundary =
tree->boundary->edge_is_boundary;
1058 for (
int i = 0; i < 3; i++) {
1074 #ifdef TRACE_TARGET_PROJECT
1075 printf(
"\n====== TARGET PROJECT START ======\n");
1081 #ifdef TRACE_TARGET_PROJECT
1082 printf(
"====== TARGET PROJECT END: %d %g ======\n\n", nearest->
index, nearest->
dist_sq);
1085 if (nearest->
index < 0) {
1115 weight = 1.0f - weight;
1118 if (weight == 0.0f) {
1136 if (nearest->
index != -1) {
1139 nearest->
index = -1;
1153 if (nearest->
index != -1) {
1173 const float hit_co[3],
1174 const float hit_no[3],
1179 const float(*vert_normals)[3] =
tree->treeData.vert_normals;
1186 float w[3], no[3][3], tmp_co[3];
1196 copy_v3_v3(no[0], vert_normals[vert_indices[0]]);
1197 copy_v3_v3(no[1], vert_normals[vert_indices[1]]);
1198 copy_v3_v3(no[2], vert_normals[vert_indices[2]]);
1209 treeData->
vert[vert_indices[0]].
co,
1210 treeData->
vert[vert_indices[1]].
co,
1211 treeData->
vert[vert_indices[2]].
co,
1236 const float point_co[3],
1237 const float hit_co[3],
1238 const float hit_no[3],
1246 float dist =
len_v3(delta);
1249 if (dist < FLT_EPSILON) {
1250 if (forcesnap || goal_dist > 0) {
1251 madd_v3_v3v3fl(r_point_co, hit_co, hit_no, goal_dist * forcesign);
1261 if (forcesign == 0.0f) {
1266 if (forcesnap || dsign * dist * forcesign < goal_dist) {
1272 if (dist < dist_epsilon) {
1273 #ifdef TRACE_TARGET_PROJECT
1274 printf(
"zero_factor %g = %g / %g\n", dist / dist_epsilon, dist, dist_epsilon);
1280 madd_v3_v3v3fl(r_point_co, hit_co, delta, goal_dist * forcesign);
1292 const float hit_co[3],
1293 const float hit_no[3],
1295 const float point_co[3],
1296 float r_point_co[3])
1303 if (goal_dist != 0) {
1320 if (goal_dist != 0) {
1330 if (goal_dist != 0) {
1340 printf(
"Unknown Shrinkwrap surface snap mode: %d\n", mode);
1373 const int defgrp_index,
1374 float (*vertexCos)[3],
1395 calc.
vgroup = defgrp_index;
1479 const int defgrp_index,
1480 float (*vertexCos)[3],
1502 calc.
vgroup = defgrp_index;
1563 const float projLimitTolerance = 5.0f;
typedef float(TangentPoint)[2]
void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
BVHTree * BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, const struct Mesh *mesh, BVHCacheType bvh_cache_type, int tree_type)
struct DerivedMesh * CDDM_from_mesh(struct Mesh *mesh)
struct Scene * CTX_data_scene(const bContext *C)
struct Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void * CustomData_get_layer(const struct CustomData *data, int type)
const float(* BKE_mesh_poly_normals_ensure(const struct Mesh *mesh))[3]
#define BKE_MESH_OMP_LIMIT
void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float(*vert_coords)[3])
const float(* BKE_mesh_vertex_normals_ensure(const struct Mesh *mesh))[3]
void BKE_mesh_looptri_get_real_edges(const struct Mesh *mesh, const struct MLoopTri *looptri, int r_edges[3])
float(* BKE_mesh_vert_coords_alloc(const struct Mesh *mesh, int *r_vert_len))[3]
const struct MLoopTri * BKE_mesh_runtime_looptri_ensure(const struct Mesh *mesh)
int BKE_mesh_runtime_looptri_len(const struct Mesh *mesh)
void BKE_mesh_wrapper_ensure_mdata(struct Mesh *me)
struct Mesh * BKE_modifier_get_evaluated_mesh_from_evaluated_object(struct Object *ob_eval)
#define NULL_BVHTreeNearest
#define NULL_ShrinkwrapCalcData
struct DerivedMesh * subsurf_make_derived_from_derived(struct DerivedMesh *dm, struct SubsurfModifierData *smd, const struct Scene *scene, float(*vertCos)[3], SubsurfFlags flags)
#define BLI_BITMAP_NEW(_num, _alloc_string)
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
#define BVH_RAYCAST_DIST_MAX
int BLI_bvhtree_find_nearest_ex(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata, int flag)
@ BVH_NEAREST_OPTIMAL_ORDER
int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
MINLINE float signf(float f)
void interp_weights_tri_v3(float w[3], const float v1[3], const float v2[3], const float v3[3], const float co[3])
void closest_on_tri_to_point_v3(float r[3], const float p[3], const float v1[3], const float v2[3], const float v3[3])
void BLI_space_transform_apply_normal(const struct SpaceTransform *data, float no[3])
void BLI_space_transform_apply(const struct SpaceTransform *data, float co[3])
float mat4_to_scale(const float M[4][4])
void BLI_space_transform_invert_normal(const struct SpaceTransform *data, float no[3])
void BLI_space_transform_invert(const struct SpaceTransform *data, float co[3])
#define BLI_SPACE_TRANSFORM_SETUP(data, local, target)
bool BLI_newton3d_solve(Newton3D_DeltaFunc func_delta, Newton3D_JacobianFunc func_jacobian, Newton3D_CorrectionFunc func_correction, void *userdata, float epsilon, int max_iterations, bool trace, const float x_init[3], float result[3])
Solve a generic f(x) = 0 equation using Newton's method.
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void add_v2_fl(float r[2], float f)
MINLINE void negate_v3(float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE float len_manhattan_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
struct Depsgraph Depsgraph
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ GP_SHRINKWRAP_INVERT_VGROUP
#define MOD_SHRINKWRAP_CULL_TARGET_MASK
@ MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR
@ MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE
@ MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR
@ MOD_SHRINKWRAP_CULL_TARGET_BACKFACE
@ MOD_SHRINKWRAP_INVERT_VGROUP
@ MOD_SHRINKWRAP_INVERT_CULL_TARGET
@ MOD_SHRINKWRAP_TARGET_PROJECT
@ MOD_SHRINKWRAP_NEAREST_VERTEX
@ MOD_SHRINKWRAP_NEAREST_SURFACE
@ MOD_SHRINKWRAP_ON_SURFACE
@ MOD_SHRINKWRAP_ABOVE_SURFACE
@ MOD_SHRINKWRAP_OUTSIDE_SURFACE
@ MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS
@ MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS
@ MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS
@ MOD_SHRINKWRAP_PROJECT_OVER_NORMAL
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
Utility defines for timing/benchmarks.
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static T sum(const btAlignedObjectArray< T > &items)
CCL_NAMESPACE_BEGIN struct Options options
const Depsgraph * depsgraph
void(* MEM_freeN)(void *vmemh)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
void *(* MEM_callocN)(size_t len, const char *str)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
struct ShrinkwrapCalcData ShrinkwrapCalcData
static void target_project_edge(const ShrinkwrapTreeData *tree, int index, const float co[3], BVHTreeNearest *nearest, int eidx)
static void target_project_tri_clamp(float x[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])
void BKE_shrinkwrap_free_tree(ShrinkwrapTreeData *data)
static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc)
static ShrinkwrapBoundaryData * shrinkwrap_build_boundary_data(struct Mesh *mesh)
struct ShrinkwrapCalcCBData ShrinkwrapCalcCBData
static void mesh_looptri_target_project(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
void BKE_shrinkwrap_find_nearest_surface(struct ShrinkwrapTreeData *tree, BVHTreeNearest *nearest, float co[3], int type)
void shrinkwrapGpencilModifier_deform(ShrinkwrapGpencilModifierData *mmd, Object *ob, MDeformVert *dvert, const int defgrp_index, float(*vertexCos)[3], int numVerts)
static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
static bool update_hit(BVHTreeNearest *nearest, int index, const float co[3], const float hit_co[3], const float hit_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)
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 target_project_tri_deviation(void *userdata, const float x[3], float r_delta[3])
static void merge_vert_dir(ShrinkwrapBoundaryVertData *vdata, signed char *status, int index, const float edge_dir[3], signed char side)
static void shrinkwrap_calc_nearest_vertex_cb_ex(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
struct TargetProjectTriData TargetProjectTriData
void BKE_shrinkwrap_mesh_nearest_surface_deform(struct bContext *C, Object *ob_source, Object *ob_target)
static void shrinkwrap_calc_normal_projection_cb_ex(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target)
void BKE_shrinkwrap_compute_smooth_normal(const struct ShrinkwrapTreeData *tree, const struct SpaceTransform *transform, int looptri_idx, const float hit_co[3], const float hit_no[3], float r_no[3])
#define TIMEIT_BENCH(expr, id)
bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode)
void BKE_shrinkwrap_compute_boundary_data(struct Mesh *mesh)
static void target_project_tri_jacobian(void *userdata, const float x[3], float r_jacobian[3][3])
bool BKE_shrinkwrap_init_tree(ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
void BKE_shrinkwrap_discard_boundary_data(struct Mesh *mesh)
void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, const ModifierEvalContext *ctx, struct Scene *scene, Object *ob, Mesh *mesh, MDeformVert *dvert, const int defgrp_index, float(*vertexCos)[3], int numVerts)
static bool target_project_tri_correct(void *UNUSED(userdata), const float x[3], float step[3], float x_next[3])
static void shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc)
void BKE_shrinkwrap_snap_point_to_surface(const struct ShrinkwrapTreeData *tree, const struct 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])
const struct MLoop * loop
const struct MVert * vert
BVHTree_NearestPointCallback nearest_callback
const struct MLoopTri * looptri
void *(* getVertDataArray)(DerivedMesh *dm, int type)
int(* getNumVerts)(DerivedMesh *dm)
void(* release)(DerivedMesh *dm)
struct ShrinkwrapBoundaryData * shrinkwrap_data
struct Depsgraph * depsgraph
const int * vert_boundary_id
const ShrinkwrapBoundaryVertData * boundary_verts
const BLI_bitmap * looptri_has_boundary
const BLI_bitmap * edge_is_boundary
unsigned int num_boundary_verts
SpaceTransform * local2aux
ShrinkwrapTreeData * tree
ShrinkwrapCalcData * calc
ShrinkwrapTreeData * aux_tree
struct SpaceTransform local2target
struct ShrinkwrapTreeData * tree
struct Object * aux_target
ShrinkwrapModifierData * smd
struct MDeformVert * dvert
const float(* vert_normals)[3]
struct Object * aux_target
struct ShrinkwrapTreeData * cache_data
struct Object * auxTarget
const float(* vtri_no)[3]
size_t userdata_chunk_size