Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/object/object_vgroup.c')
-rw-r--r--source/blender/editors/object/object_vgroup.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index 797cf428969..7b4db347315 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -756,7 +756,8 @@ static void vgroup_normalize(Object *ob)
It returns the number that it added (0-2)
It relies on verts having -1 for unassigned indices
*/
-static int tryToAddVerts(int *verts, int length, int a, int b) {
+static int tryToAddVerts(int *verts, int length, int a, int b)
+{
char containsA = FALSE;
char containsB = FALSE;
int added = 0;
@@ -786,7 +787,8 @@ and returns an array of indices of size count
count is an int passed by reference so it can be assigned the value of the length here.
*/
-static int* getSurroundingVerts(Mesh *me, int vert, int *count) {
+static int* getSurroundingVerts(Mesh *me, int vert, int *count)
+{
int length = 0;
int *tverts;
int *verts = NULL;
@@ -848,7 +850,8 @@ static int* getSurroundingVerts(Mesh *me, int vert, int *count) {
/* get a single point in space by averaging a point cloud (vectors of size 3)
coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud
*/
-static void getSingleCoordinate(MVert *points, int count, float coord[3]) {
+static void getSingleCoordinate(MVert *points, int count, float coord[3])
+{
int i;
zero_v3(coord);
for(i = 0; i < count; i++) {
@@ -875,7 +878,8 @@ static void getNearestPointOnPlane(const float norm[3], const float coord[3], co
}
/* distance of two vectors a and b of size length */
-static float distance(float* a, float *b, int length) {
+static float distance(float* a, float *b, int length)
+{
int i;
float sum = 0;
for(i = 0; i < length; i++) {
@@ -888,7 +892,9 @@ static float distance(float* a, float *b, int length) {
compute the amount of vertical distance relative to the plane and store it in dists,
then get the horizontal and vertical change and store them in changes
*/
-static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float (*changes)[2], float *dists, int index) {
+static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart,
+ float *end, float (*changes)[2], float *dists, int index)
+{
// A=Q-((Q-P).N)N
// D = (a*x0 + b*y0 +c*z0 +d)
float projA[3] = {0}, projB[3] = {0};
@@ -906,7 +912,8 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f
}
// I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc)
-static void dm_deform_clear(DerivedMesh *dm, Object *ob) {
+static void dm_deform_clear(DerivedMesh *dm, Object *ob)
+{
if(ob->derivedDeform && (ob->derivedDeform)==dm) {
ob->derivedDeform->needsFree = 1;
ob->derivedDeform->release(ob->derivedDeform);
@@ -919,19 +926,23 @@ static void dm_deform_clear(DerivedMesh *dm, Object *ob) {
}
// recalculate the deformation
-static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) {
+static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob)
+{
return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
}
-/* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to distToBe distance away from the provided plane
-strength can change distToBe so that it moves towards distToBe by that percentage
-cp changes how much the weights are adjusted to check the distance
+/* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to
+distToBe distance away from the provided plane strength can change distToBe so that it moves
+towards distToBe by that percentage cp changes how much the weights are adjusted
+to check the distance
index is the index of the vertex being moved
norm and d are the plane's properties for the equation: ax + by + cz + d = 0
coord is a point on the plane
*/
-static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float norm[3], float coord[3], float d, float distToBe, float strength, float cp) {
+static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float norm[3],
+ float coord[3], float d, float distToBe, float strength, float cp)
+{
DerivedMesh *dm;
MDeformWeight *dw;
MVert m;
@@ -939,7 +950,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in
int totweight = dvert->totweight;
float oldw = 0;
float oldPos[3] = {0};
- float vc, hc, dist;
+ float vc, hc, dist = 0.0f /* Not necessary, but quites down gcc warnings! */;
int i, k;
float (*changes)[2] = MEM_mallocN(sizeof(float *)*totweight*2, "vertHorzChange");
float *dists = MEM_mallocN(sizeof(float)*totweight, "distance");
@@ -955,10 +966,8 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in
wasChange = FALSE;
dm = dm_deform_recalc(scene, ob);
dm->getVert(dm, index, &m);
- oldPos[0] = m.co[0];
- oldPos[1] = m.co[1];
- oldPos[2] = m.co[2];
- distToStart = norm[0]*oldPos[0] + norm[1]*oldPos[1] + norm[2]*oldPos[2] + d;
+ copy_v3_v3(oldPos, m.co);
+ distToStart = dot_v3v3(norm, oldPos) + d;
if(distToBe == originalDistToBe) {
distToBe += distToStart - distToStart*strength;
@@ -1088,7 +1097,8 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in
dm_deform_clear(dm, ob); dm = NULL;
}
}
- }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe));
+ } while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) ==
+ (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe));
MEM_freeN(upDown);
MEM_freeN(changes);
MEM_freeN(dists);
@@ -1123,18 +1133,14 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength,
if(count >= 3) {
float d /*, dist */ /* UNUSED */, mag;
- float coord[3] = {0};
- float norm[3] = {0};
+ float coord[3];
+ float norm[3];
getSingleCoordinate(p, count, coord);
dm->getVert(dm, i, &m);
- norm[0] = m.co[0]-coord[0];
- norm[1] = m.co[1]-coord[1];
- norm[2] = m.co[2]-coord[2];
- mag = sqrt(norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2]);
- if(mag) {// zeros fix
- mul_v3_fl(norm, 1.0f/mag);
-
- d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2];
+ sub_v3_v3v3(norm, m.co, coord);
+ mag= normalize_v3(norm);
+ if(mag) { /* zeros fix */
+ d = -dot_v3v3(norm, coord);
/* dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); */ /* UNUSED */
moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp);
}
@@ -2317,7 +2323,8 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot)
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
- RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others");
+ RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active",
+ "Keep the values of the active group while normalizing others");
}
static int vertex_group_fix_exec(bContext *C, wmOperator *op)
@@ -2355,7 +2362,8 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot)
/* identifiers */
ot->name= "Fix Vertex Group Deform";
ot->idname= "OBJECT_OT_vertex_group_fix";
- ot->description= "Modify the position of selected vertices by changing only their respective groups' weights (this tool may be slow for many vertices).";
+ ot->description= "Modify the position of selected vertices by changing only their respective "
+ "groups' weights (this tool may be slow for many vertices)";
/* api callbacks */
ot->poll= vertex_group_poll;
@@ -2363,9 +2371,11 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot)
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
- RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to.", -10.0f, 10.0f);
- RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance moved can be changed by this multiplier.", -2.0f, 2.0f);
- RNA_def_float(ot->srna, "accuracy", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f);
+ RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to", -10.0f, 10.0f);
+ RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength",
+ "The distance moved can be changed by this multiplier", -2.0f, 2.0f);
+ RNA_def_float(ot->srna, "accuracy", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity",
+ "Change the amount weights are altered with each iteration: lower values are slower", 0.05f, 1.f);
}
@@ -2423,8 +2433,10 @@ void OBJECT_OT_vertex_group_invert(wmOperatorType *ot)
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
- RNA_def_boolean(ot->srna, "auto_assign", TRUE, "Add Weights", "Add verts from groups that have zero weight before inverting");
- RNA_def_boolean(ot->srna, "auto_remove", TRUE, "Remove Weights", "Remove verts from groups that have zero weight after inverting");
+ RNA_def_boolean(ot->srna, "auto_assign", TRUE, "Add Weights",
+ "Add verts from groups that have zero weight before inverting");
+ RNA_def_boolean(ot->srna, "auto_remove", TRUE, "Remove Weights",
+ "Remove verts from groups that have zero weight after inverting");
}
@@ -2513,7 +2525,8 @@ void OBJECT_OT_vertex_group_mirror(wmOperatorType *ot)
/* identifiers */
ot->name= "Mirror Vertex Group";
ot->idname= "OBJECT_OT_vertex_group_mirror";
- ot->description= "Mirror all vertex groups, flip weights and/or names, editing only selected vertices, flipping when both sides are selected otherwise copy from unselected";
+ ot->description= "Mirror all vertex groups, flip weights and/or names, editing only selected vertices, "
+ "flipping when both sides are selected otherwise copy from unselected";
/* api callbacks */
ot->poll= vertex_group_poll_edit;
@@ -2585,7 +2598,9 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op)
CTX_DATA_END;
if((change == 0 && fail == 0) || fail) {
- BKE_reportf(op->reports, RPT_ERROR, "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies", change, fail);
+ BKE_reportf(op->reports, RPT_ERROR,
+ "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies",
+ change, fail);
}
return OPERATOR_FINISHED;