53 #define CLNORS_VALID_VEC_LEN (1e-6f)
66 return (r1->
val < r2->
val) ? 1 : ((r1->
val > r2->
val) ? -1 : 0);
79 #define NUM_CACHED_INVERSE_POWERS_OF_WEIGHT 128
143 const float curr_val,
144 const bool use_face_influence)
152 const float weight = wn_data->
weight;
156 const bool has_vgroup = dvert !=
NULL;
157 const bool vert_of_group = has_vgroup &&
161 ((vert_of_group && use_invert_vgroup) || (!vert_of_group && !use_invert_vgroup))) {
181 const int num_loops = item_data->
num_loops;
183 cached_inverse_powers_of_weight[num_loops] == 0.0f) {
184 cached_inverse_powers_of_weight[num_loops] = 1.0f /
powf(weight, num_loops);
187 cached_inverse_powers_of_weight[num_loops] :
188 1.0f /
powf(weight, num_loops);
196 const int numVerts = wn_data->
numVerts;
197 const int numEdges = wn_data->
numEdges;
198 const int numLoops = wn_data->
numLoops;
199 const int numPolys = wn_data->
numPolys;
205 short(*clnors)[2] = wn_data->
clnors;
214 const short mode = wn_data->
mode;
223 poly_strength !=
NULL;
224 const bool has_vgroup = dvert !=
NULL;
235 loop_normals =
MEM_calloc_arrayN((
size_t)numLoops,
sizeof(*loop_normals), __func__);
249 has_clnors ? clnors :
NULL,
253 items_data =
MEM_calloc_arrayN((
size_t)num_items,
sizeof(*items_data), __func__);
260 for (mp = mpoly, mp_index = 0, item_index = 0; mp_index < numPolys; mp++, mp_index++) {
262 const int ml_end_index = ml_index + mp->
totloop;
264 for (; ml_index < ml_end_index; ml_index++) {
294 num_items = numVerts;
295 items_data =
MEM_calloc_arrayN((
size_t)num_items,
sizeof(*items_data), __func__);
296 if (use_face_influence) {
297 for (
int item_index = 0; item_index < num_items; item_index++) {
306 for (
int i = 0; i < numPolys; i++) {
307 const int mp_index = mode_pair[i].
index;
308 const float mp_val = mode_pair[i].
val;
310 int ml_index = mpoly[mp_index].
loopstart;
311 const int ml_index_end = ml_index + mpoly[mp_index].
totloop;
312 for (; ml_index < ml_index_end; ml_index++) {
313 const int mv_index = mloop[ml_index].
v;
318 wnmd, wn_data, item_data, mv_index, mp_index, mp_val, use_face_influence);
326 for (
int i = 0; i < numLoops; i++) {
327 const int ml_index = mode_pair[i].
index;
328 const float ml_val = mode_pair[i].
val;
330 const int mp_index = loop_to_poly[ml_index];
331 const int mv_index = mloop[ml_index].
v;
336 wnmd, wn_data, item_data, mv_index, mp_index, ml_val, use_face_influence);
344 for (
int item_index = 0; item_index < num_items; item_index++) {
355 for (
int ml_index = 0; ml_index < numLoops; ml_index++) {
385 (
size_t)numVerts,
sizeof(*loop_normals), __func__);
387 for (
int ml_index = 0; ml_index < numLoops; ml_index++) {
388 const int mv_index = mloop[ml_index].
v;
407 loop_normals =
MEM_calloc_arrayN((
size_t)numLoops,
sizeof(*loop_normals), __func__);
422 has_clnors ? clnors :
NULL,
425 for (
int ml_index = 0; ml_index < numLoops; ml_index++) {
426 const int item_index = mloop[ml_index].
v;
454 const int numPolys = wn_data->
numPolys;
466 for (mp_index = 0, mp = mpoly; mp_index < numPolys; mp_index++, mp++, f_area++) {
468 f_area->
index = mp_index;
479 const int numLoops = wn_data->
numLoops;
480 const int numPolys = wn_data->
numPolys;
489 int *loop_to_poly =
MEM_malloc_arrayN((
size_t)numLoops,
sizeof(*loop_to_poly), __func__);
493 for (mp_index = 0, mp = mpoly; mp_index < numPolys; mp_index++, mp++) {
500 float *angl = index_angle;
502 ml_index++, c_angl++, angl++) {
504 c_angl->
index = ml_index;
506 loop_to_poly[ml_index] = mp_index;
520 const int numLoops = wn_data->
numLoops;
521 const int numPolys = wn_data->
numPolys;
530 int *loop_to_poly =
MEM_malloc_arrayN((
size_t)numLoops,
sizeof(*loop_to_poly), __func__);
534 for (mp_index = 0, mp = mpoly; mp_index < numPolys; mp_index++, mp++) {
542 float *angl = index_angle;
544 ml_index++, cmbnd++, angl++) {
547 cmbnd->
index = ml_index;
549 loop_to_poly[ml_index] = mp_index;
585 const int numVerts =
result->totvert;
586 const int numEdges =
result->totedge;
587 const int numLoops =
result->totloop;
588 const int numPolys =
result->totpoly;
602 if (wnmd->
weight == 100) {
603 weight = (
float)SHRT_MAX;
605 else if (wnmd->
weight == 1) {
606 weight = 1 / (
float)SHRT_MAX;
608 else if ((weight - 1) * 25 > 1) {
609 weight = (weight - 1) * 25;
619 mvert,
NULL, numVerts, mloop, mpoly, numLoops, numPolys, polynors,
false);
628 const bool has_clnors = clnors !=
NULL;
639 .numEdges = numEdges,
640 .numLoops = numLoops,
641 .numPolys = numPolys,
648 .has_clnors = has_clnors,
649 .split_angle = split_angle,
652 .polynors = polynors,
657 .defgrp_index = defgrp_index,
664 switch (wnmd->
mode) {
683 result->runtime.is_original =
false;
750 "WeightedNormalModifierData",
typedef float(TangentPoint)[2]
void CustomData_free_layers(struct CustomData *data, int type, int totelem)
void * CustomData_get_layer_named(const struct CustomData *data, int type, const char *name)
void * CustomData_get_layer(const struct CustomData *data, int type)
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
void CustomData_set_layer_flag(struct CustomData *data, int type, int flag)
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_mesh_normals_loop_custom_set(const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges, struct MLoop *mloops, float(*r_custom_loopnors)[3], const int numLoops, struct MPoly *mpolys, const float(*polynors)[3], const int numPolys, short(*r_clnors_data)[2])
void BKE_mesh_calc_poly_angles(const struct MPoly *mpoly, const struct MLoop *loopstart, const struct MVert *mvarray, float angles[])
void BKE_mesh_normals_loop_custom_from_vertices_set(const struct MVert *mverts, float(*r_custom_vertnors)[3], const int numVerts, struct MEdge *medges, const int numEdges, struct MLoop *mloops, const int numLoops, struct MPoly *mpolys, const float(*polynors)[3], const int numPolys, short(*r_clnors_data)[2])
void BKE_mesh_normals_loop_split(const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges, struct MLoop *mloops, float(*r_loopnors)[3], const int numLoops, struct MPoly *mpolys, const float(*polynors)[3], const int numPolys, const bool use_split_normals, const float split_angle, MLoopNorSpaceArray *r_lnors_spacearr, short(*clnors_data)[2], int *r_loop_to_poly)
void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr)
float BKE_mesh_calc_poly_area(const struct MPoly *mpoly, const struct MLoop *loopstart, const struct MVert *mvarray)
void BKE_mesh_calc_normals_poly(struct MVert *mverts, float(*r_vertnors)[3], int numVerts, const struct MLoop *mloop, const struct MPoly *mpolys, int numLoops, int numPolys, float(*r_polyNors)[3], const bool only_face_normals)
@ eModifierTypeFlag_SupportsMapping
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsMesh
void BKE_modifier_copydata_generic(const struct ModifierData *md, struct ModifierData *md_dst, const int flag)
@ eModifierTypeType_Constructive
void BKE_modifier_set_error(const struct Object *ob, struct ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
#define BLI_BITMAP_NEW(_tot, _alloc_string)
MINLINE int compare_ff(float a, float b, const float max_diff)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float r[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
#define POINTER_AS_INT(i)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define CD_MASK_MDEFORMVERT
#define CD_MASK_PROP_INT32
#define CD_MASK_CUSTOMLOOPNORMAL
#define DNA_struct_default_get(struct_name)
@ MOD_WEIGHTEDNORMAL_KEEP_SHARP
@ MOD_WEIGHTEDNORMAL_FACE_INFLUENCE
@ MOD_WEIGHTEDNORMAL_INVERT_VGROUP
@ MOD_WEIGHTEDNORMAL_MODE_FACE
@ MOD_WEIGHTEDNORMAL_MODE_FACE_ANGLE
@ MOD_WEIGHTEDNORMAL_MODE_ANGLE
struct WeightedNormalModifierData WeightedNormalModifierData
@ eModifierType_WeightedNormal
#define MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID
Object is a sort of wrapper for general info.
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)
void MOD_get_vgroup(Object *ob, struct Mesh *mesh, const char *name, MDeformVert **dvert, int *defgrp_index)
static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data)
static Mesh * modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
static bool check_item_poly_strength(WeightedNormalData *wn_data, WeightedNormalDataAggregateItem *item_data, const int mp_index)
static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data)
static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data)
#define NUM_CACHED_INVERSE_POWERS_OF_WEIGHT
static bool dependsOnNormals(ModifierData *UNUSED(md))
ModifierTypeInfo modifierType_WeightedNormal
struct WeightedNormalData WeightedNormalData
static int modepair_cmp_by_val_inverse(const void *p1, const void *p2)
struct WeightedNormalDataAggregateItem WeightedNormalDataAggregateItem
#define CLNORS_VALID_VEC_LEN
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
static void initData(ModifierData *md)
static void panelRegister(ARegionType *region_type)
static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data)
static void aggregate_item_normal(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data, WeightedNormalDataAggregateItem *item_data, const int mv_index, const int mp_index, const float curr_val, const bool use_face_influence)
static void requiredDataMask(Object *UNUSED(ob), ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
StructRNA RNA_WeightedNormalModifier
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
IconTextureDrawCall normal
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
MLoopNorSpace ** lspacearr
WeightedNormalDataAggregateItem * items_data
const bool use_invert_vgroup
float cached_inverse_powers_of_weight[NUM_CACHED_INVERSE_POWERS_OF_WEIGHT]