From 969cbed49b027b8eb05f2f1606f684a6acf4b7af Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 23 Sep 2018 13:10:31 +0300 Subject: Add support for a one-dimensional Force Field source shape. The fields currently support a Point source and a two-dimensional Plane source, but there is no way to create a field that pulls toward or from a line in space other than using the Texture field type. This adds a new simple shape option to do that. The line is aligned along the Z axis so that it works meaningfully with the Tube and Cone falloff modes. Reviewers: brecht, mont29, LucaRood Differential Revision: https://developer.blender.org/D3721 --- source/blender/blenkernel/intern/effect.c | 8 ++++---- source/blender/makesdna/DNA_object_force_types.h | 1 + source/blender/makesrna/intern/rna_object_force.c | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index a123b12d385..e6e138f8a43 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -544,7 +544,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU if (falloff == 0.0f) break; - r_fac= RAD2DEGF(saacos(fac/len_v3(efd->vec_to_point))); + r_fac= RAD2DEGF(saacos(fac/len_v3(efd->vec_to_point2))); falloff*= falloff_func_rad(eff->pd, r_fac); break; @@ -667,13 +667,13 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin /* use z-axis as normal*/ normalize_v3_v3(efd->nor, ob->obmat[2]); - if (eff->pd && eff->pd->shape == PFIELD_SHAPE_PLANE) { + if (eff->pd && ELEM(eff->pd->shape, PFIELD_SHAPE_PLANE, PFIELD_SHAPE_LINE)) { float temp[3], translate[3]; sub_v3_v3v3(temp, point->loc, ob->obmat[3]); project_v3_v3v3(translate, temp, efd->nor); /* for vortex the shape chooses between old / new force */ - if (eff->pd->forcefield == PFIELD_VORTEX) + if (eff->pd->forcefield == PFIELD_VORTEX || eff->pd->shape == PFIELD_SHAPE_LINE) add_v3_v3v3(efd->loc, ob->obmat[3], translate); else /* normally efd->loc is closest point on effector xy-plane */ sub_v3_v3v3(efd->loc, point->loc, translate); @@ -900,7 +900,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected } break; case PFIELD_MAGNET: - if (eff->pd->shape == PFIELD_SHAPE_POINT) + if (ELEM(eff->pd->shape, PFIELD_SHAPE_POINT, PFIELD_SHAPE_LINE)) /* magnetic field of a moving charge */ cross_v3_v3v3(temp, efd->nor, efd->vec_to_point); else diff --git a/source/blender/makesdna/DNA_object_force_types.h b/source/blender/makesdna/DNA_object_force_types.h index 721154a62eb..a0f22f28aed 100644 --- a/source/blender/makesdna/DNA_object_force_types.h +++ b/source/blender/makesdna/DNA_object_force_types.h @@ -348,6 +348,7 @@ typedef struct SoftBody { #define PFIELD_SHAPE_PLANE 1 #define PFIELD_SHAPE_SURFACE 2 #define PFIELD_SHAPE_POINTS 3 +#define PFIELD_SHAPE_LINE 4 /* pd->tex_mode */ #define PFIELD_TEX_RGB 0 diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c index 97f1985b48b..2f1527651e6 100644 --- a/source/blender/makesrna/intern/rna_object_force.c +++ b/source/blender/makesrna/intern/rna_object_force.c @@ -42,10 +42,11 @@ #include "WM_types.h" static const EnumPropertyItem effector_shape_items[] = { - {PFIELD_SHAPE_POINT, "POINT", 0, "Point", ""}, - {PFIELD_SHAPE_PLANE, "PLANE", 0, "Plane", ""}, - {PFIELD_SHAPE_SURFACE, "SURFACE", 0, "Surface", ""}, - {PFIELD_SHAPE_POINTS, "POINTS", 0, "Every Point", ""}, + {PFIELD_SHAPE_POINT, "POINT", 0, "Point", "Field originates from the object center"}, + {PFIELD_SHAPE_LINE, "LINE", 0, "Line", "Field originates from the local Z axis of the object"}, + {PFIELD_SHAPE_PLANE, "PLANE", 0, "Plane", "Field originates from the local XY plane of the object"}, + {PFIELD_SHAPE_SURFACE, "SURFACE", 0, "Surface", "Field originates from the surface of the object"}, + {PFIELD_SHAPE_POINTS, "POINTS", 0, "Every Point", "Field originates from all of the vertices of the object"}, {0, NULL, 0, NULL, NULL} }; @@ -56,15 +57,17 @@ static const EnumPropertyItem effector_shape_items[] = { /* type specific return values only used from functions */ static const EnumPropertyItem curve_shape_items[] = { - {PFIELD_SHAPE_POINT, "POINT", 0, "Point", ""}, - {PFIELD_SHAPE_PLANE, "PLANE", 0, "Plane", ""}, - {PFIELD_SHAPE_SURFACE, "SURFACE", 0, "Curve", ""}, + {PFIELD_SHAPE_POINT, "POINT", 0, "Point", "Field originates from the object center"}, + {PFIELD_SHAPE_LINE, "LINE", 0, "Line", "Field originates from the local Z axis of the object"}, + {PFIELD_SHAPE_PLANE, "PLANE", 0, "Plane", "Field originates from the local XY plane of the object"}, + {PFIELD_SHAPE_SURFACE, "SURFACE", 0, "Curve", "Field originates from the curve itself"}, {0, NULL, 0, NULL, NULL} }; static const EnumPropertyItem empty_shape_items[] = { - {PFIELD_SHAPE_POINT, "POINT", 0, "Point", ""}, - {PFIELD_SHAPE_PLANE, "PLANE", 0, "Plane", ""}, + {PFIELD_SHAPE_POINT, "POINT", 0, "Point", "Field originates from the object center"}, + {PFIELD_SHAPE_LINE, "LINE", 0, "Line", "Field originates from the local Z axis of the object"}, + {PFIELD_SHAPE_PLANE, "PLANE", 0, "Plane", "Field originates from the local XY plane of the object"}, {0, NULL, 0, NULL, NULL} }; -- cgit v1.2.3