[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59833] branches/soc-2013-depsgraph_mt/ source/blender: Initial support of render mode for constraints

Sergey Sharybin sergey.vfx at gmail.com
Thu Sep 5 14:23:29 CEST 2013


Revision: 59833
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59833
Author:   nazgul
Date:     2013-09-05 12:23:29 +0000 (Thu, 05 Sep 2013)
Log Message:
-----------
Initial support of render mode for constraints

Rendering now works rather fine, but because of object matrix
is shared between viewport and render, objects might be placed
on the wrong locations in viewport after rendering.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_constraint.h
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_object.h
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/object.c
    branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/view3d_snap.c

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_constraint.h	2013-09-05 12:23:23 UTC (rev 59832)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_constraint.h	2013-09-05 12:23:29 UTC (rev 59833)
@@ -57,6 +57,7 @@
 	
 	short type;                 /* type of owner  */
 	short rotOrder;             /* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_math.h) */
+	bool for_render;            /* constraints need to be evaluated for render purposes */
 } bConstraintOb;
 
 /* ---------------------------------------------------------------------------- */
@@ -144,7 +145,7 @@
 short BKE_proxylocked_constraints_owner(struct Object *ob, struct bPoseChannel *pchan);
 
 /* Constraint Evaluation function prototypes */
-struct bConstraintOb *BKE_constraints_make_evalob(struct Scene *scene, struct Object *ob, void *subdata, short datatype);
+struct bConstraintOb *BKE_constraints_make_evalob(struct Scene *scene, struct Object *ob, void *subdata, short datatype, bool for_render);
 void BKE_constraints_clear_evalob(struct bConstraintOb *cob);
 
 void BKE_constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, float mat[4][4], short from, short to);

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_object.h
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_object.h	2013-09-05 12:23:23 UTC (rev 59832)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_object.h	2013-09-05 12:23:29 UTC (rev 59833)
@@ -104,10 +104,10 @@
 struct Object *BKE_object_pose_armature_get(struct Object *ob);
 
 void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
-void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float r_originmat[3][3]);
+void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, bool for_render, float r_originmat[3][3]);
 void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime);
 void BKE_object_where_is_calc_time_ex(struct Scene *scene, struct Object *ob, float ctime,
-                                      struct RigidBodyWorld *rbw, float r_originmat[3][3]);
+                                      struct RigidBodyWorld *rbw, bool for_render, float r_originmat[3][3]);
 void BKE_object_where_is_calc_simul(struct Scene *scene, struct Object *ob);
 void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]);
 

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c	2013-09-05 12:23:23 UTC (rev 59832)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c	2013-09-05 12:23:29 UTC (rev 59833)
@@ -2430,7 +2430,8 @@
 			/* prepare PoseChannel for Constraint solving
 			 * - makes a copy of matrix, and creates temporary struct to use
 			 */
-			cob = BKE_constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE);
+			/* TODO(sergey): We need to use proper for_render flag here */
+			cob = BKE_constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE, false);
 
 			/* Solve PoseChannel's Constraints */
 			BKE_solve_constraints(&pchan->constraints, cob, ctime); /* ctime doesnt alter objects */

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c	2013-09-05 12:23:23 UTC (rev 59832)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c	2013-09-05 12:23:29 UTC (rev 59833)
@@ -108,7 +108,7 @@
 
 /* package an object/bone for use in constraint evaluation */
 /* This function MEM_calloc's a bConstraintOb struct, that will need to be freed after evaluation */
-bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subdata, short datatype)
+bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subdata, short datatype, bool for_render)
 {
 	bConstraintOb *cob;
 	
@@ -166,7 +166,9 @@
 			unit_m4(cob->startmat);
 			break;
 	}
-	
+
+	cob->for_render = for_render;
+
 	return cob;
 }
 
@@ -347,7 +349,7 @@
 /* ------------ General Target Matrix Tools ---------- */
 
 /* function that sets the given matrix based on given vertex group in mesh */
-static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[4][4])
+static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[4][4], bool for_render)
 {
 	DerivedMesh *dm = NULL;
 	BMEditMesh *em = BKE_editmesh_from_object(ob);
@@ -364,7 +366,10 @@
 	if (defgroup == -1) return;
 
 	/* get DerivedMesh */
-	if (em) {
+	if (for_render) {
+		dm = ob->derivedRender;
+	}
+	else if (em) {
 		/* target is in editmode, so get a special derived mesh */
 		dm = CDDM_from_editbmesh(em, FALSE, FALSE);
 		freeDM = 1;
@@ -498,7 +503,7 @@
 
 /* generic function to get the appropriate matrix for most target cases */
 /* The cases where the target can be object data have not been implemented */
-static void constraint_target_to_mat4(Object *ob, const char *substring, float mat[4][4], short from, short to, float headtail)
+static void constraint_target_to_mat4(Object *ob, const char *substring, float mat[4][4], short from, short to, float headtail, bool for_render)
 {
 	/*	Case OBJECT */
 	if (!strlen(substring)) {
@@ -515,7 +520,7 @@
 	 *		way as constraints can only really affect things on object/bone level.
 	 */
 	else if (ob->type == OB_MESH) {
-		contarget_get_mesh_mat(ob, substring, mat);
+		contarget_get_mesh_mat(ob, substring, mat, for_render);
 		BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
 	}
 	else if (ob->type == OB_LATTICE) {
@@ -594,10 +599,10 @@
 /* This function should be used for the get_target_matrix member of all 
  * constraints that are not picky about what happens to their target matrix.
  */
-static void default_get_tarmat(bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime))
+static void default_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 {
 	if (VALID_CONS_TARGET(ct))
-		constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail);
+		constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail, cob->for_render);
 	else if (ct)
 		unit_m4(ct->matrix);
 }
@@ -1065,7 +1070,7 @@
 	bKinematicConstraint *data = con->data;
 	
 	if (VALID_CONS_TARGET(ct)) 
-		constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail);
+		constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail, cob->for_render);
 	else if (ct) {
 		if (data->flag & CONSTRAINT_IK_AUTO) {
 			Object *ob = cob->ob;
@@ -1942,7 +1947,7 @@
 		/* firstly calculate the matrix the normal way, then let the py-function override
 		 * this matrix if it needs to do so
 		 */
-		constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail);
+		constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail, cob->for_render);
 		
 		/* only execute target calculation if allowed */
 #ifdef WITH_PYTHON
@@ -2054,7 +2059,7 @@
 		unit_m4(ct->matrix);
 		
 		/* get the transform matrix of the target */
-		constraint_target_to_mat4(ct->tar, ct->subtarget, tempmat, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail);
+		constraint_target_to_mat4(ct->tar, ct->subtarget, tempmat, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail, cob->for_render);
 		
 		/* determine where in transform range target is */
 		/* data->type is mapped as follows for backwards compatibility:
@@ -3345,8 +3350,7 @@
 		float dist;
 		
 		SpaceTransform transform;
-		/* TODO(sergey): use real forRender flag */
-		DerivedMesh *target = object_get_derived_final(ct->tar, false);
+		DerivedMesh *target = object_get_derived_final(ct->tar, cob->for_render);
 		BVHTreeRayHit hit;
 		BVHTreeNearest nearest;
 		
@@ -3987,8 +3991,7 @@
 
 			if (data->depth_ob) {
 				Object *depth_ob = data->depth_ob;
-				/* TODO(sergey): use real forRender flag */
-				DerivedMesh *target = object_get_derived_final(depth_ob, false);
+				DerivedMesh *target = object_get_derived_final(depth_ob, cob->for_render);
 				if (target) {
 					BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;
 					BVHTreeRayHit hit;

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/object.c	2013-09-05 12:23:23 UTC (rev 59832)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/object.c	2013-09-05 12:23:29 UTC (rev 59833)
@@ -2150,7 +2150,8 @@
 
 /* note, scene is the active scene while actual_scene is the scene the object resides in */
 void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
-                                      RigidBodyWorld *rbw, float r_originmat[3][3])
+                                      RigidBodyWorld *rbw, bool for_render,
+                                      float r_originmat[3][3])
 {
 	if (ob == NULL) return;
 	
@@ -2185,7 +2186,7 @@
 	if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
 		bConstraintOb *cob;
 		
-		cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
+		cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT, for_render);
 		BKE_solve_constraints(&ob->constraints, cob, ctime);
 		BKE_constraints_clear_evalob(cob);
 	}
@@ -2197,7 +2198,8 @@
 
 void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
 {
-	BKE_object_where_is_calc_time_ex(scene, ob, ctime, NULL, NULL);
+	/* TODO(sergey): We might need real for_render flag here */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list