[Bf-blender-cvs] [b0a3f32] master: improvements and simplification to gravity code:

Antony Riakiotakis noreply at git.blender.org
Thu Dec 12 18:35:48 CET 2013


Commit: b0a3f32ed39dae9340efde10187b23cb0cbdf9e1
Author: Antony Riakiotakis
Date:   Thu Dec 12 19:35:33 2013 +0200
http://developer.blender.org/rBb0a3f32ed39dae9340efde10187b23cb0cbdf9e1

improvements and simplification to gravity code:

* world to object matrix is calculated for view vector as well, reuse
that.
* if no orientation exists use world negative axis instead of object
negative axis for gravity.

there's also the issue of mirroring, it may be wise to invert the
gravity effect there but it may be better to have artist feedback on
that.

===================================================================

M	source/blender/editors/sculpt_paint/sculpt.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 14b6ab8..a0b6bd5 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3873,25 +3873,6 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio
 	cache->scale[1] = max_scale / ob->size[1];
 	cache->scale[2] = max_scale / ob->size[2];
 
-	if (sd->gravity_object) {
-		Object *gravity_object = sd->gravity_object;
-		float rmat[3][3], loc[3], size[3];
-
-		/* get gravity vector in world space */
-		copy_v3_v3(cache->gravity_direction, gravity_object->obmat[2]);
-		normalize_v3(cache->gravity_direction);
-
-		/* transform to sculpted object space by inverting object rotation matrix */
-		mat4_to_loc_rot_size(loc, rmat, size, ob->obmat);
-		/* transposition of orthogonal matrix (rotation), inverts */
-		transpose_m3(rmat);
-		mul_m3_v3(rmat, cache->gravity_direction);
-	}
-	else {
-		cache->gravity_direction[0] = cache->gravity_direction[1] = 0.0;
-		cache->gravity_direction[2] = sd->gravity_factor;
-	}
-
 	cache->plane_trim_squared = brush->plane_trim * brush->plane_trim;
 
 	cache->flag = 0;
@@ -3957,6 +3938,21 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio
 	mul_m3_v3(mat, viewDir);
 	normalize_v3_v3(cache->true_view_normal, viewDir);
 
+	/* get gravity vector in world space */
+	if (sd->gravity_object) {
+		Object *gravity_object = sd->gravity_object;
+
+		copy_v3_v3(cache->gravity_direction, gravity_object->obmat[2]);
+	}
+	else {
+		cache->gravity_direction[0] = cache->gravity_direction[1] = 0.0;
+		cache->gravity_direction[2] = 1.0;
+	}
+
+	/* transform to sculpted object space by inverting object rotation matrix */
+	mul_m3_v3(mat, cache->gravity_direction);
+	normalize_v3(cache->gravity_direction);
+
 	/* Initialize layer brush displacements and persistent coords */
 	if (brush->sculpt_tool == SCULPT_TOOL_LAYER) {
 		/* not supported yet for multires or dynamic topology */




More information about the Bf-blender-cvs mailing list