[Bf-blender-cvs] [6940bf0] master: Code cleanup and structural improvements for dupli generation.

Lukas Tönne noreply at git.blender.org
Tue Jan 21 12:16:00 CET 2014


Commit: 6940bf0c96f46db78dd139a1b0246e6bcb0fe8c2
Author: Lukas Tönne
Date:   Tue Jan 21 12:11:34 2014 +0100
https://developer.blender.org/rB6940bf0c96f46db78dd139a1b0246e6bcb0fe8c2

Code cleanup and structural improvements for dupli generation.

This is a first step toward improving our dupli system. It implements a more
generic way of treating the various methods of dupli generation by adding a few
structs:
  * DupliContext holds a number of arguments commonly used in the recursive dupli functions and defines a recursion state for generating sub-duplis (nested groups). It also helps to prevent bloated argument lists.
  * DupliGenerator is a type struct that unifies the different dupli creation methods (groups, frames, verts, text chars, faces, particles). (As with context there should be no overhead from pointer indirection because everything can still be inlined inside anim.c)

Beside making the code more easily understandable this implementation should
also help to avoid weird side effects from custom matrix hacks by defining
clearly what a generator does. The DupliContext is deliberately made const, so a
generator can not simply add hidden matrix or flag modifications that are hard
to track down.

The result container for the generated duplis is stored in the context instead
of being passed explicitly. This means the generators are oblivious to the
storage of duplis, all they need to do is call the make_dupli function. This
will allow us to implement more efficient ways of storing DupliObject instances,
such as MemPools or batches. These can be implemented alongside the current
ListBase so we can improve dupli bottlenecks without having to replace each and
every dupli use case at once.

Differential Revision: https://developer.blender.org/D189

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

M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/anim.c
A	source/blender/blenkernel/intern/object_dupli.c

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 815ba23..c28c857 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -125,6 +125,7 @@ set(SRC
 	intern/node.c
 	intern/object.c
 	intern/object_deform.c
+	intern/object_dupli.c
 	intern/ocean.c
 	intern/packedFile.c
 	intern/paint.c
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 4278adc..761c923 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -29,57 +29,36 @@
  *  \ingroup bke
  */
 
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
 #include "MEM_guardedalloc.h"
 
-#include "BLI_blenlib.h"
+#include <stdlib.h>
+
+#include "BLI_listbase.h"
 #include "BLI_math.h"
-#include "BLI_rand.h"
-#include "BLI_utildefines.h"
 
 #include "BLF_translation.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
-#include "DNA_group_types.h"
 #include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_vfont_types.h"
 
-#include "BKE_animsys.h"
 #include "BKE_curve.h"
-#include "BKE_DerivedMesh.h"
 #include "BKE_depsgraph.h"
-#include "BKE_font.h"
-#include "BKE_group.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
-#include "BKE_lattice.h"
 #include "BKE_main.h"
-#include "BKE_mesh.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_scene.h"
-#include "BKE_editmesh.h"
-#include "BKE_depsgraph.h"
 #include "BKE_anim.h"
 #include "BKE_report.h"
 
-
 // XXX bad level call...
 
 /* --------------------- */
 /* forward declarations */
 
-static void object_duplilist_recursive(EvaluationContext *eval_ctx,
-                                       ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[4][4],
-                                       int persistent_id[MAX_DUPLI_RECUR], int level, int index, short flag);
-
 /* ******************************************************************** */
 /* Animation Visualization */
 
@@ -710,1135 +689,3 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua
 
 	return 1;
 }
-
-/* ******************************************************************** */
-/* Dupli-Geometry */
-
-#define DUPLILIST_DO_UPDATE		1
-#define DUPLILIST_FOR_RENDER	2
-#define DUPLILIST_ANIMATED		4
-
-static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[4][4], int lay,
-                                     int persistent_id[MAX_DUPLI_RECUR], int level, int index, int type, short flag)
-{
-	DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject");
-	int i;
-
-	BLI_addtail(lb, dob);
-	dob->ob = ob;
-	copy_m4_m4(dob->mat, mat);
-	copy_m4_m4(dob->omat, ob->obmat);
-	dob->origlay = ob->lay;
-	dob->type = type;
-	dob->animated = (type == OB_DUPLIGROUP) && (flag & DUPLILIST_ANIMATED);
-	ob->lay = lay;
-
-	/* set persistent id, which is an array with a persistent index for each level
-	 * (particle number, vertex number, ..). by comparing this we can find the same
-	 * dupli object between frames, which is needed for motion blur. last level
-	 * goes first in the array. */
-	dob->persistent_id[0] = index;
-	for (i = 1; i < level; i++)
-		dob->persistent_id[i] = persistent_id[level - 1 - i];
-	
-	/* metaballs never draw in duplis, they are instead merged into one by the basis
-	 * mball outside of the group. this does mean that if that mball is not in the
-	 * scene, they will not show up at all, limitation that should be solved once. */
-	if (ob->type == OB_MBALL)
-		dob->no_draw = TRUE;
-	
-	return dob;
-}
-
-static void group_duplilist(EvaluationContext *eval_ctx,
-                            ListBase *lb, Scene *scene, Object *ob, int persistent_id[MAX_DUPLI_RECUR],
-                            int level, short flag)
-{
-	DupliObject *dob;
-	Group *group;
-	GroupObject *go;
-	float mat[4][4], ob_obmat_ofs[4][4], id;
-
-	if (ob->dup_group == NULL) return;
-	group = ob->dup_group;
-	
-	/* simple preventing of too deep nested groups */
-	if (level > MAX_DUPLI_RECUR) return;
-	
-	/* don't access 'ob->obmat' from now on. */
-	copy_m4_m4(ob_obmat_ofs, ob->obmat);
-
-	if (!is_zero_v3(group->dupli_ofs)) {
-		float tvec[3];
-		copy_v3_v3(tvec, group->dupli_ofs);
-		mul_mat3_m4_v3(ob_obmat_ofs, tvec);
-		sub_v3_v3(ob_obmat_ofs[3], tvec);
-	}
-
-	/* handles animated groups, and */
-
-	/* we need to check update for objects that are not in scene... */
-	if (flag & DUPLILIST_DO_UPDATE) {
-		/* note: update is optional because we don't always need object
-		 * transformations to be correct. Also fixes bug [#29616]. */
-		BKE_group_handle_recalc_and_update(eval_ctx, scene, ob, group);
-	}
-
-	if (BKE_group_is_animated(group, ob))
-		flag |= DUPLILIST_ANIMATED;
-	
-	for (go = group->gobject.first, id = 0; go; go = go->next, id++) {
-		/* note, if you check on layer here, render goes wrong... it still deforms verts and uses parent imat */
-		if (go->ob != ob) {
-			
-			/* group dupli offset, should apply after everything else */
-			mul_m4_m4m4(mat, ob_obmat_ofs, go->ob->obmat);
-			
-			dob = new_dupli_object(lb, go->ob, mat, ob->lay, persistent_id, level, id, OB_DUPLIGROUP, flag);
-
-			/* check the group instance and object layers match, also that the object visible flags are ok. */
-			if ((dob->origlay & group->layer) == 0 ||
-			    ((eval_ctx->for_render == false) && dob->ob->restrictflag & OB_RESTRICT_VIEW) ||
-			    ((eval_ctx->for_render == true)  && dob->ob->restrictflag & OB_RESTRICT_RENDER))
-			{
-				dob->no_draw = TRUE;
-			}
-
-			if (go->ob->transflag & OB_DUPLI) {
-				copy_m4_m4(dob->ob->obmat, dob->mat);
-				object_duplilist_recursive(eval_ctx, &group->id, scene, go->ob, lb, ob_obmat_ofs, persistent_id, level + 1, id, flag);
-				copy_m4_m4(dob->ob->obmat, dob->omat);
-			}
-		}
-	}
-}
-
-static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int persistent_id[MAX_DUPLI_RECUR], int level, short flag)
-{
-	extern int enable_cu_speed; /* object.c */
-	Object copyob;
-	int cfrao = scene->r.cfra;
-	int dupend = ob->dupend;
-	
-	/* simple prevention of too deep nested groups */
-	if (level > MAX_DUPLI_RECUR) return;
-	
-	/* if we don't have any data/settings which will lead to object movement,
-	 * don't waste time trying, as it will all look the same...
-	 */
-	if (ob->parent == NULL && ob->constraints.first == NULL && ob->adt == NULL)
-		return;
-	
-	/* make a copy of the object's original data (before any dupli-data overwrites it) 
-	 * as we'll need this to keep track of unkeyed data
-	 *	- this doesn't take into account other data that can be reached from the object,
-	 *	  for example it's shapekeys or bones, hence the need for an update flush at the end
-	 */
-	copyob = *ob;
-	
-	/* duplicate over the required range */
-	if (ob->transflag & OB_DUPLINOSPEED) enable_cu_speed = 0;
-	
-	for (scene->r.cfra = ob->dupsta; scene->r.cfra <= dupend; scene->r.cfra++) {
-		short ok = 1;
-		
-		/* - dupoff = how often a frames within the range shouldn't be made into duplis
-		 * - dupon = the length of each "skipping" block in frames
-		 */
-		if (ob->dupoff) {
-			ok = scene->r.cfra - ob->dupsta;
-			ok = ok % (ob->dupon + ob->dupoff);
-			ok = (ok < ob->dupon);
-		}
-		
-		if (ok) {
-			DupliObject *dob;
-			
-			/* WARNING: doing animation updates in this way is not terribly accurate, as the dependencies
-			 * and/or other objects which may affect this object's transforms are not updated either.
-			 * However, this has always been the way that this worked (i.e. pre 2.5), so I guess that it'll be fine!
-			 */
-			BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
-			BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
-			
-			dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, persistent_id, level, scene->r.cfra, OB_DUPLIFRAMES, flag);
-			copy_m4_m4(dob->omat, copyob.obmat);
-		}
-	}
-
-	enable_cu_speed = 1;
-	
-	/* reset frame to original frame, then re-evaluate animation as above 
-	 * as 2.5 animation data may have far-reaching consequences
-	 */
-	scene->r.cfra = cfrao;
-	
-	BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
-	BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
-	
-	/* but, to make sure unkeyed object transforms are still sane, 
-	 * let's copy object's original data back over
-	 */
-	*ob = copyob;
-}
-
-typedef struct VertexDupliData {
-	EvaluationContext *eval_ctx;
-	ID *id; /* scene or group, for recursive loops */
-	int level;
-	short flag;
-	ListBase *lb;
-	float pmat[4][4];
-	float obmat[4][4]; /* Only used for dupliverts inside dupligroups, where the ob->obmat is modified */
-	Scene *scene;
-	Object *ob, *par;
-	float (*orco)[3];
-	int *persistent_id;
-} VertexDupliData;
-
-/* ------------- */
-
-static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
-                                  const float no_f[3], const short no_s[3])
-{
-	DupliObject *dob;
-	VertexDupliData *vdd = userData;
-	float vec[3], q2[4], mat[3][3], tmat[4][4], obmat[4][4];
-	int origlay;
-	
-	mul_v3_m4v3(vec, vdd->pmat, co);
-	sub_v3_v3(vec, vdd->pmat[3]);
-	add_v3_v3(vec, vdd->obmat[3]);
-	
-	copy_m4_m4(obmat, vdd->obmat);
-	copy_v3_v3(obmat[3], vec);
-	
-	if (vdd->par->transflag & OB_DUPLIROT) {
-		if (no_f) {
-			vec[0] = -no_f[0]; vec[1] = -no_f[1]; vec[2] = -no_f[2];
-		}
-		else if (no_s) {
-			vec[0] = -no_s[0]; vec[1] = -no_s[1]; vec[2] = -no_s[2];
-		}
-		
-		vec_to_quat(q2, vec, vdd->ob->trackflag, vdd->ob->upflag);
-		
-		quat_to_mat3(mat, q2);
-		copy_m4_m4(tmat, obmat);
-		mul_m4_m4m3(obmat, tmat, mat);
-	}
-
-	origlay = vdd->ob->lay;
-	
-	dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, vdd->persistent_id, vdd->level, index, OB_DUPLIVERTS, vdd->flag);
-
-	/* restore the original layer so that each dupli will have proper dob->origlay */
-	vdd->ob->lay = origlay;
-
-	if (vdd->orco)
-		copy_v3_v3(dob->orco, vdd->orco[index]);


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list