40 #include "RNA_prototypes.h"
285 const MLoop *
const mloop,
286 const uint polys_num,
287 const uint edges_num,
295 for (
int i = 0; i < polys_num; i++, poly++) {
298 for (
int j = 0; j < poly->
totloop; j++, loop++) {
299 if (edge_polys[loop->
e].
num == 0) {
300 edge_polys[loop->
e].
polys[0] = i;
301 edge_polys[loop->
e].
polys[1] = -1;
302 edge_polys[loop->
e].
num++;
304 else if (edge_polys[loop->
e].
num == 1) {
305 edge_polys[loop->
e].
polys[1] = i;
306 edge_polys[loop->
e].
num++;
315 for (
int i = 0; i < edges_num; i++, edge++) {
318 vert_edges[edge->v1].
first = adj;
319 vert_edges[edge->v1].
num += edge_polys[i].
num;
324 vert_edges[edge->v2].
first = adj;
325 vert_edges[edge->v2].
num += edge_polys[i].
num;
333 const MLoop *
const mloop,
339 for (
int i = 0; i < num; i++) {
340 if (mloop[i].
e == edge) {
350 for (
int i = 0; mloop[i].
e != edge; i++) {
357 const MLoop *
const mloop,
358 const uint loopstart,
361 for (
int i = loopstart; i < num; i++) {
366 for (
int i = 0; i < loopstart; i++) {
382 float max_dist = FLT_MAX;
389 data->treeData->tree, t_point, &nearest,
data->treeData->nearest_callback,
data->treeData);
394 for (
int i = 0; i < poly->
totloop; i++, loop++) {
395 edge = &
data->medge[loop->
e];
397 point_co,
data->targetCos[edge->v1],
data->targetCos[edge->v2]);
399 if (dist < max_dist) {
405 edge = &
data->medge[index];
416 float prev_co[2], prev_prev_co[2];
417 float curr_vec[2], prev_vec[2];
428 for (
int i = 0; i < nr; i++) {
433 if (curr_len < FLT_EPSILON) {
438 if (
len_squared_v2v2(prev_prev_co, coords[i]) < FLT_EPSILON * FLT_EPSILON) {
443 if (1.0f -
dot_v2v2(prev_vec, curr_vec) < FLT_EPSILON) {
460 for (
int i = 0; i < bwdata->
polys_num; bpoly++, i++) {
477 const float point_co[3])
490 const float world[3] = {0.0f, 0.0f, 1.0f};
491 float avg_point_dist = 0.0f;
492 float tot_weight = 0.0f;
493 int inf_weight_flags = 0;
495 bwdata =
MEM_callocN(
sizeof(*bwdata),
"SDefBindWeightData");
496 if (bwdata ==
NULL) {
514 for (vedge = vert_edges; vedge; vedge = vedge->
next) {
517 for (
int i = 0; i < edge_polys[edge_ind].
num; i++) {
521 for (
int j = 0; j < bwdata->
polys_num; bpoly++, j++) {
548 poly->
totloop,
sizeof(*bpoly->
coords),
"SDefBindPolyCoords");
563 for (
int j = 0; j < poly->
totloop; j++, loop++) {
567 if (loop->
v == nearest) {
591 for (
int j = 0; j < poly->
totloop; j++) {
600 data->success = is_poly_valid;
639 float corner_angles[2];
652 if (bpoly->
scales[0] < FLT_EPSILON || bpoly->
scales[1] < FLT_EPSILON ||
670 float cent_point_vec[2], point_angles[2];
676 signf(corner_angles[0]);
678 signf(corner_angles[1]);
680 if (point_angles[0] <= 0 && point_angles[1] <= 0) {
683 if (point_angles[0] < point_angles[1]) {
726 if (!inf_weight_flags) {
727 for (vedge = vert_edges; vedge; vedge = vedge->
next) {
730 float ang_weights[2];
732 uint edge_on_poly[2];
734 epolys = &edge_polys[edge_ind];
739 for (
int i = 0, j = 0; (i < bwdata->
polys_num) && (j < epolys->num); bpoly++, i++) {
755 if (epolys->
num == 1) {
757 bpolys[0]->edgemid_angle);
760 else if (epolys->
num == 2) {
762 bpolys[0]->edgemid_angle);
764 bpolys[1]->edgemid_angle);
776 if (!inf_weight_flags) {
779 for (
int i = 0; i < bwdata->
polys_num; bpoly++, i++) {
780 float corner_angle_weights[2];
781 float scale_weight,
sqr, inv_sqr;
786 if (
isnan(corner_angle_weights[0]) ||
isnan(corner_angle_weights[1])) {
793 if (corner_angle_weights[0] < corner_angle_weights[1]) {
818 scale_weight /= scale_weight + (edge_angle_b /
max_ff(edge_angle_b, bpoly->
edgemid_angle));
821 sqr = scale_weight * scale_weight;
822 inv_sqr = 1.0f - scale_weight;
824 scale_weight =
sqr / (
sqr + inv_sqr);
826 BLI_assert(scale_weight >= 0 && scale_weight <= 1);
859 for (
int i = 0; i < bwdata->
polys_num; bpoly++, i++) {
874 for (
int i = 0; i < bwdata->
polys_num; bpoly++, i++) {
896 tot_weight += bpoly->
weight;
901 for (
int i = 0; i < bwdata->
polys_num; bpoly++, i++) {
902 bpoly->
weight /= tot_weight;
908 if (bpoly->
weight >= FLT_EPSILON) {
928 const float point_co_proj[3],
935 normal_dist =
len_v3(disp_vec);
950 float point_co_proj[3];
965 if (
data->sparse_bind) {
968 if (
data->dvert &&
data->defgrp_index != -1) {
972 if (
data->invert_vgroup) {
973 weight = 1.0f - weight;
986 if (bwdata ==
NULL) {
1001 sdbind = sdvert->
binds;
1005 for (
int i = 0; i < bwdata->
binds_num; bpoly++) {
1006 if (bpoly->
weight >= FLT_EPSILON) {
1034 for (
int j = 0; j < bpoly->
verts_num; j++, loop++) {
1046 float cent[3],
norm[3];
1047 float v1[3],
v2[3], v3[3];
1055 3,
sizeof(*sdbind->
vert_weights),
"SDefCentVertWeights");
1102 3,
sizeof(*sdbind->
vert_weights),
"SDefTriVertWeights");
1167 float (*vertexCos)[3],
1169 uint target_polys_num,
1170 uint target_verts_num,
1185 vert_edges =
MEM_calloc_arrayN(target_verts_num,
sizeof(*vert_edges),
"SDefVertEdgeMap");
1186 if (vert_edges ==
NULL) {
1191 adj_array =
MEM_malloc_arrayN(tedges_num, 2 *
sizeof(*adj_array),
"SDefVertEdge");
1192 if (adj_array ==
NULL) {
1198 edge_polys =
MEM_calloc_arrayN(tedges_num,
sizeof(*edge_polys),
"SDefEdgeFaceMap");
1199 if (edge_polys ==
NULL) {
1223 mpoly, medge, mloop, target_polys_num, tedges_num, vert_edges, adj_array, edge_polys);
1227 ob, (
ModifierData *)smd_eval,
"Target has edges with more than two polygons");
1246 .treeData = &treeData,
1247 .vert_edges = vert_edges,
1248 .edge_polys = edge_polys,
1254 target_verts_num,
sizeof(
float[3]),
"SDefTargetBindVertArray"),
1255 .bind_verts = smd_orig->
verts,
1256 .vertexCos = vertexCos,
1260 .defgrp_index = defgrp_index,
1261 .invert_vgroup = invert_vgroup,
1262 .sparse_bind = sparse_bind,
1273 for (
int i = 0; i < target_verts_num; i++) {
1297 ob, (
ModifierData *)smd_eval,
"Target has edges with more than two polygons");
1325 return data.success == 1;
1333 const SDefBind *sdbind =
data->bind_verts[index].binds;
1334 const int sdbind_num =
data->bind_verts[index].binds_num;
1335 const unsigned int vertex_idx =
data->bind_verts[index].vertex_idx;
1336 float *
const vertexCos =
data->vertexCos[vertex_idx];
1340 float weight = 1.0f;
1342 if (
data->dvert &&
data->defgrp_index != -1) {
1345 if (
data->invert_vgroup) {
1346 weight = 1.0f - weight;
1352 if (weight == 0.0f) {
1360 for (
int j = 0; j < sdbind_num; j++) {
1361 max_verts =
MAX2(max_verts, sdbind[j].verts_num);
1364 const bool big_buffer = max_verts > 256;
1365 float(*coords_buffer)[3];
1374 for (
int j = 0; j < sdbind_num; j++, sdbind++) {
1375 for (
int k = 0; k < sdbind->
verts_num; k++) {
1382 switch (sdbind->
mode) {
1393 for (
int k = 0; k < sdbind->
verts_num; k++) {
1429 float (*vertexCos)[3],
1436 uint target_verts_num, target_polys_num;
1470 float tmp_mat[4][4];
1496 ob, md,
"Vertices changed from %u to %u", smd->
mesh_verts_num, verts_num);
1506 ob, md,
"Target polygons changed from %u to %u", smd->
target_polys_num, target_polys_num);
1514 "Target vertices changed from %u to %u",
1526 "Target vertices changed from %u to %u, continuing anyway",
1548 .bind_verts = smd->
verts,
1549 .targetCos =
MEM_malloc_arrayN(target_verts_num,
sizeof(
float[3]),
"SDefTargetVertArray"),
1550 .vertexCos = vertexCos,
1552 .defgrp_index = defgrp_index,
1553 .invert_vgroup = invert_vgroup,
1559 target,
data.targetCos, target_verts_num, smd->
mat);
1573 float (*vertexCos)[3],
1595 float (*vertexCos)[3],
1607 if (mesh_src !=
NULL) {
1702 if (bind_verts[i].binds) {
1703 for (
int j = 0; j < bind_verts[i].
binds_num; j++) {
1705 writer, bind_verts[i].binds[j].verts_num, bind_verts[i].binds[j].vert_inds);
1712 writer, bind_verts[i].binds[j].verts_num, bind_verts[i].binds[j].vert_weights);
1749 N_(
"SurfaceDeform"),
1750 "SurfaceDeformModifierData",
1752 &RNA_SurfaceDeformModifier,
1755 ICON_MOD_MESHDEFORM,
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)
void BKE_id_free(struct Main *bmain, void *idv)
const struct MLoopTri * BKE_mesh_runtime_looptri_ensure(const struct Mesh *mesh)
void BKE_mesh_wrapper_ensure_mdata(struct Mesh *me)
int BKE_mesh_wrapper_vert_len(const struct Mesh *me)
int BKE_mesh_wrapper_poly_len(const struct Mesh *me)
void BKE_mesh_wrapper_vert_coords_copy_with_mat4(const struct Mesh *me, float(*vert_coords)[3], int vert_coords_len, const float mat[4][4])
struct ModifierData * BKE_modifier_get_original(const struct Object *object, struct ModifierData *md)
void void BKE_modifier_set_warning(const struct Object *ob, struct ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
void(* IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsMesh
void BKE_modifier_copydata_generic(const struct ModifierData *md, struct ModifierData *md_dst, int flag)
struct Mesh * BKE_modifier_get_evaluated_mesh_from_evaluated_object(struct Object *ob_eval)
@ eModifierTypeType_OnlyDeform
void BKE_modifier_set_error(const struct Object *ob, struct ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_array_alloca(arr, realsize)
int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
MINLINE float interpf(float a, float b, float t)
MINLINE float signf(float f)
float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3])
MINLINE float area_tri_v2(const float v1[2], const float v2[2], const float v3[2])
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 map_to_plane_axis_angle_v2_v3v3fl(float r_co[2], const float co[3], const float axis[3], float angle)
void interp_weights_poly_v2(float w[], float v[][2], int n, const float co[2])
bool isect_line_plane_v3(float r_isect_co[3], const float l1[3], const float l2[3], const float plane_co[3], const float plane_no[3]) ATTR_WARN_UNUSED_RESULT
float normal_poly_v3(float n[3], const float verts[][3], unsigned int nr)
bool is_poly_convex_v2(const float verts[][2], unsigned int nr)
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
bool isect_point_poly_v2(const float pt[2], const float verts[][2], unsigned int nr, bool use_holes)
float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
bool invert_m4_m4(float R[4][4], const float A[4][4])
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
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 len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
float angle_normalized_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
void mid_v3_v3_array(float r[3], const float(*vec_arr)[3], unsigned int vec_arr_num)
MINLINE void sub_v2_v2(float r[2], const float a[2])
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3(float r[3], const float a[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 copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_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
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
float angle_signed_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v2(float r[2])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE float normalize_v2(float r[2])
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
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)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
void BLO_read_float3_array(BlendDataReader *reader, int array_size, float **ptr_p)
void BLO_write_uint32_array(BlendWriter *writer, uint num, const uint32_t *data_ptr)
#define BLO_read_data_address(reader, ptr_p)
void BLO_write_float3_array(BlendWriter *writer, uint num, const float *data_ptr)
void BLO_read_float_array(BlendDataReader *reader, int array_size, float **ptr_p)
void BLO_read_uint32_array(BlendDataReader *reader, int array_size, uint32_t **ptr_p)
void BLO_write_float_array(BlendWriter *writer, uint num, const float *data_ptr)
#define BLO_write_struct_array(writer, struct_name, array_size, data_ptr)
bool BLO_write_is_undo(BlendWriter *writer)
#define BLO_write_struct_at_address(writer, struct_name, address, data_ptr)
bool DEG_is_active(const struct Depsgraph *depsgraph)
void DEG_add_object_relation(struct DepsNodeHandle *node_handle, struct Object *object, eDepsObjectComponentType component, const char *description)
#define ID_IS_LINKED(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
#define CD_MASK_MDEFORMVERT
#define DNA_struct_default_get(struct_name)
@ eModifierFlag_OverrideLibrary_Local
struct SurfaceDeformModifierData SurfaceDeformModifierData
@ eModifierType_SurfaceDeform
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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
Read Guarded memory(de)allocation.
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
void modifier_vgroup_ui(uiLayout *layout, PointerRNA *ptr, PointerRNA *ob_ptr, const char *vgroup_prop, const char *invert_vgroup_prop, const char *text)
Mesh * MOD_deform_mesh_eval_get(Object *ob, struct BMEditMesh *em, Mesh *mesh, const float(*vertexCos)[3], const int verts_num, const bool use_normals, const bool use_orco)
void MOD_get_vgroup(Object *ob, struct Mesh *mesh, const char *name, MDeformVert **dvert, int *defgrp_index)
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemS(uiLayout *layout)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
IconTextureDrawCall normal
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_gpu_kernel_postfix int ccl_global int * indices
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
void *(* MEM_reallocN_id)(void *vmemh, size_t len, const char *str)
void *(* MEM_callocN)(size_t len, const char *str)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
int RNA_string_length(PointerRNA *ptr, const char *name)
bool RNA_pointer_is_null(const PointerRNA *ptr)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
struct Depsgraph * depsgraph
struct DepsNodeHandle * node
struct SDefAdjacency * next
BVHTreeFromMesh *const treeData
SDefVert *const bind_verts
float(*const targetCos)[3]
const MLoopTri *const looptri
float(*const vertexCos)[3]
const MDeformVert *const dvert
const SDefEdgePolys *const edge_polys
const SDefAdjacencyArray *const vert_edges
float corner_edgemid_angles[2]
float dominant_angle_weight
float cent_edgemid_vecs_v2[2][2]
float point_edgemid_angles[2]
SDefBindPoly * bind_polys
ccl_device_inline float sqr(float a)