From fedabce47c193926eb0c845a305a62bc73d8d6ce Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 26 Mar 2010 01:11:03 +0000 Subject: Bugfix #21757: Crash when setting up cyclic tracking dependencies (with old tracking) Note that users should not be doing this anyway (and to some degree, I wish that they have to learn this the hard way - i.e. a crash as was before) since it is always bound to cause troubles of various sorts. Having said this, the old tracking code was previously crashing if this sort of setup was created since a stack overflow would happen while bouncing between each object being recursively recalculated. I've fixed this by commenting out that recursive recalculation (solving the cyclic problems for n >= 2, while n=1 should still be fine without this pre-depsgraph hack), and also removing such cyclic dependencies in the n=2 case. (PS: Perhaps this is just a good opportunity to just remove this old feature instead ;) --- source/blender/blenkernel/intern/object.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index e4350cfde7f..2026bb3da6e 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2039,8 +2039,27 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) /* Handle tracking */ if(ob->track) { - if( ctime != ob->track->ctime) where_is_object_time(scene, ob->track, ctime); - solve_tracking (ob, ob->track->obmat); + /* Try to remove this tracking relationship if we can easily detect that + * it is cyclic (i.e. direct tracking), and bound to cause us troubles. + * For the other cases (i.e. a cyclic triangle, and higher orders), we can't + * easily detect or know how to remove those relationships, safely, so just + * let them be (with warnings). + * Of course, this could also be a simple track that doesn't do anything bad either :) + */ + if (ob->track->track == ob) { + printf("Removed direct cyclic tracking between %s and %s\n", ob->id.name+2, ob->track->id.name+2); + ob->track->track = NULL; + ob->track = NULL; + } + else { + /* NOTE: disabled recursive recalc for tracking for now, since this causes crashes + * when users create cyclic dependencies (stack overflow). Really, this step ought + * not to be needed anymore with the depsgraph, though this may not be the case. + * -- Aligorith, 2010 Mar 26 + */ + //if( ctime != ob->track->ctime) where_is_object_time(scene, ob->track, ctime); + solve_tracking(ob, ob->track->obmat); + } } /* solve constraints */ -- cgit v1.2.3 From 3c872daa59774abaf3f53acaa2baf876e54308a5 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 26 Mar 2010 02:57:49 +0000 Subject: 4 Devs in Agreement - End of the Road for Old Track This commit removes the Old Track method (used to be found under Object -> Animation -> Track), with all existing instances of this being converted to Track To Constraints. In fact, while performing this removal, I found that this was supposed to have happened in version 2.27 already, but for some reason the options were left in, and this function managed to survive for a further decade. I've left the tracking axes around still, since it seems some curve tools still use that. However, that usage should probably get faded out in future too? Misc notes: * Fixed compiling error with constaints from harkyman's Maintain Volume patch. * Subversion of 2.52 now bumped up to .2 --- source/blender/blenkernel/BKE_blender.h | 2 +- source/blender/blenkernel/intern/action.c | 1 - source/blender/blenkernel/intern/anim.c | 2 +- source/blender/blenkernel/intern/constraint.c | 3 +- source/blender/blenkernel/intern/depsgraph.c | 5 -- source/blender/blenkernel/intern/object.c | 71 --------------------------- 6 files changed, 3 insertions(+), 81 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 6b656f1d12e..8865757b85a 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -45,7 +45,7 @@ struct Scene; struct Main; #define BLENDER_VERSION 252 -#define BLENDER_SUBVERSION 1 +#define BLENDER_SUBVERSION 2 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index afd0b3a0f57..52f59c1681a 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -1063,7 +1063,6 @@ void what_does_obaction (Scene *scene, Object *ob, Object *workob, bPose *pose, copy_m4_m4(workob->parentinv, ob->parentinv); copy_m4_m4(workob->constinv, ob->constinv); workob->parent= ob->parent; - workob->track= ob->track; workob->rotmode= ob->rotmode; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index b2ac32da138..1465f4550f5 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -668,7 +668,7 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, if(level>MAX_DUPLI_RECUR) return; cfrao= scene->r.cfra; - if(ob->parent==NULL && ob->track==NULL && ob->ipo==NULL && ob->constraints.first==NULL) return; + if(ob->parent==NULL && ob->constraints.first==NULL) return; if(ob->transflag & OB_DUPLINOSPEED) enable_cu_speed= 0; copyob= *ob; /* store transform info */ diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 3ab5e9442b4..7994849a469 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -1867,7 +1867,7 @@ static void samevolume_new_data (void *cdata) data->volume = 1.0f; } -static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob) +static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) { bSameVolumeConstraint *data= con->data; @@ -1896,7 +1896,6 @@ static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob) } break; } - } static bConstraintTypeInfo CTI_SAMEVOL = { diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 4e0270315ad..86cafa733ff 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -468,11 +468,6 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O addtoroot = 0; } - if (ob->track) { - node2 = dag_get_node(dag,ob->track); - dag_add_relation(dag,node2,node,DAG_RL_OB_OB, "Track To"); - addtoroot = 0; - } if (ob->proxy) { node2 = dag_get_node(dag, ob->proxy); dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Proxy"); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 2026bb3da6e..b9e4894a868 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -361,11 +361,6 @@ void unlink_object(Scene *scene, Object *ob) obt->recalc |= OB_RECALC; } - if(obt->track==ob) { - obt->track= NULL; - obt->recalc |= OB_RECALC_OB; - } - modifiers_foreachObjectLink(obt, unlink_object__unlinkModifierLinks, ob); if ELEM(obt->type, OB_CURVE, OB_FONT) { @@ -2037,31 +2032,6 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) object_to_mat4(ob, ob->obmat); } - /* Handle tracking */ - if(ob->track) { - /* Try to remove this tracking relationship if we can easily detect that - * it is cyclic (i.e. direct tracking), and bound to cause us troubles. - * For the other cases (i.e. a cyclic triangle, and higher orders), we can't - * easily detect or know how to remove those relationships, safely, so just - * let them be (with warnings). - * Of course, this could also be a simple track that doesn't do anything bad either :) - */ - if (ob->track->track == ob) { - printf("Removed direct cyclic tracking between %s and %s\n", ob->id.name+2, ob->track->id.name+2); - ob->track->track = NULL; - ob->track = NULL; - } - else { - /* NOTE: disabled recursive recalc for tracking for now, since this causes crashes - * when users create cyclic dependencies (stack overflow). Really, this step ought - * not to be needed anymore with the depsgraph, though this may not be the case. - * -- Aligorith, 2010 Mar 26 - */ - //if( ctime != ob->track->ctime) where_is_object_time(scene, ob->track, ctime); - solve_tracking(ob, ob->track->obmat); - } - } - /* solve constraints */ if (ob->constraints.first && !(ob->flag & OB_NO_CONSTRAINTS)) { bConstraintOb *cob; @@ -2156,33 +2126,6 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ } } -} -void solve_tracking (Object *ob, float targetmat[][4]) -{ - float quat[4]; - float vec[3]; - float totmat[3][3]; - float tmat[4][4]; - - sub_v3_v3v3(vec, ob->obmat[3], targetmat[3]); - vec_to_quat( quat,vec, ob->trackflag, ob->upflag); - quat_to_mat3( totmat,quat); - - if(ob->parent && (ob->transflag & OB_POWERTRACK)) { - /* 'temporal' : clear parent info */ - object_to_mat4(ob, tmat); - tmat[0][3]= ob->obmat[0][3]; - tmat[1][3]= ob->obmat[1][3]; - tmat[2][3]= ob->obmat[2][3]; - tmat[3][0]= ob->obmat[3][0]; - tmat[3][1]= ob->obmat[3][1]; - tmat[3][2]= ob->obmat[3][2]; - tmat[3][3]= ob->obmat[3][3]; - } - else copy_m4_m4(tmat, ob->obmat); - - mul_m4_m3m4(ob->obmat, totmat, tmat); - } void where_is_object(struct Scene *scene, Object *ob) @@ -2204,12 +2147,6 @@ for a lamp that is the child of another object */ int a; /* NO TIMEOFFS */ - - /* no ipo! (because of dloc and realtime-ipos) */ - // XXX old animation system - //ipo= ob->ipo; - //ob->ipo= NULL; - if(ob->parent) { par= ob->parent; @@ -2231,9 +2168,6 @@ for a lamp that is the child of another object */ object_to_mat4(ob, ob->obmat); } - if(ob->track) - solve_tracking(ob, ob->track->obmat); - /* solve constraints */ if (ob->constraints.first) { bConstraintOb *cob; @@ -2242,10 +2176,6 @@ for a lamp that is the child of another object */ solve_constraints(&ob->constraints, cob, (float)scene->r.cfra); constraints_clear_evalob(cob); } - - /* WATCH IT!!! */ - // XXX old animation system - //ob->ipo= ipo; } /* for calculation of the inverse parent transform, only used for editor */ @@ -2257,7 +2187,6 @@ void what_does_parent(Scene *scene, Object *ob, Object *workob) unit_m4(workob->parentinv); unit_m4(workob->constinv); workob->parent= ob->parent; - workob->track= ob->track; workob->trackflag= ob->trackflag; workob->upflag= ob->upflag; -- cgit v1.2.3 From 386e97f73a891f7162cc578d05cf5720ef51df14 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 26 Mar 2010 03:10:58 +0000 Subject: Purging compiler warnings --- source/blender/blenkernel/intern/pointcache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 9f0c7289350..cbe294f1347 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1687,7 +1687,7 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra) return 0; if(cache->flag & PTCACHE_DISK_CACHE) { - int ofra, efra = cache->endframe; + int ofra=0, efra = cache->endframe; if(cfra==0) add = 1; @@ -2871,4 +2871,5 @@ void BKE_ptcache_invalidate(PointCache *cache) cache->flag &= ~PTCACHE_SIMULATION_VALID; cache->simframe = 0; cache->last_exact = 0; -} \ No newline at end of file +} + -- cgit v1.2.3 From 40e58c85092945ca71e974ce4062d90e44f7fb66 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 26 Mar 2010 10:33:53 +0000 Subject: Optimization for pose channel name lookups using a hash, makes playback in one particular scene with 3 characters go from 10 to 13 fps. (commit 27728 by Brecht from render25 branch) --- source/blender/blenkernel/BKE_action.h | 7 +++++++ source/blender/blenkernel/intern/action.c | 29 ++++++++++++++++++++++++++++- source/blender/blenkernel/intern/armature.c | 1 + source/blender/blenkernel/intern/object.c | 5 ++++- 4 files changed, 40 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h index 1b38e276ca4..214b5a32cd6 100644 --- a/source/blender/blenkernel/BKE_action.h +++ b/source/blender/blenkernel/BKE_action.h @@ -129,6 +129,13 @@ void free_pose_channel(struct bPoseChannel *pchan); */ void free_pose_channels(struct bPose *pose); +/** + * Removes the hash for quick lookup of channels, must + * be done when adding/removing channels. + */ +void make_pose_channels_hash(struct bPose *pose); +void free_pose_channels_hash(struct bPose *pose); + /** * Removes and deallocates all data from a pose, and also frees the pose. */ diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 52f59c1681a..2d52d6061b9 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -56,8 +56,9 @@ #include "BIK_api.h" -#include "BLI_math.h" #include "BLI_blenlib.h" +#include "BLI_ghash.h" +#include "BLI_math.h" #include "RNA_access.h" @@ -370,6 +371,9 @@ bPoseChannel *get_pose_channel(const bPose *pose, const char *name) if (ELEM(NULL, pose, name) || (name[0] == 0)) return NULL; + if(pose->chanhash) + return BLI_ghash_lookup(pose->chanhash, name); + return BLI_findstring(&((bPose *)pose)->chanbase, name, offsetof(bPoseChannel, name)); } @@ -405,6 +409,7 @@ bPoseChannel *verify_pose_channel(bPose *pose, const char *name) chan->protectflag = OB_LOCK_ROT4D; /* lock by components by default */ BLI_addtail(&pose->chanbase, chan); + free_pose_channels_hash(pose); return chan; } @@ -519,6 +524,26 @@ void init_pose_ikparam(bPose *pose) } } +void make_pose_channels_hash(bPose *pose) +{ + if(!pose->chanhash) { + bPoseChannel *pchan; + + pose->chanhash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp); + for(pchan=pose->chanbase.first; pchan; pchan=pchan->next) + BLI_ghash_insert(pose->chanhash, pchan->name, pchan); + } +} + +void free_pose_channels_hash(bPose *pose) +{ + if(pose->chanhash) { + BLI_ghash_free(pose->chanhash, NULL, NULL); + pose->chanhash= NULL; + } +} + + void free_pose_channel(bPoseChannel *pchan) { // XXX this case here will need to be removed when the new motionpaths are ready @@ -550,6 +575,8 @@ void free_pose_channels(bPose *pose) BLI_freelistN(&pose->chanbase); } + + free_pose_channels_hash(pose); } void free_pose(bPose *pose) diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 668ce9aadac..c1998d705ad 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1675,6 +1675,7 @@ void armature_rebuild_pose(Object *ob, bArmature *arm) next= pchan->next; if(pchan->bone==NULL) { free_pose_channel(pchan); + free_pose_channels_hash(pose); BLI_freelinkN(&pose->chanbase, pchan); } } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index b9e4894a868..bb7c77408ac 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2459,7 +2459,10 @@ void object_tfm_restore(Object *ob, void *obtfm_pt) void object_handle_update(Scene *scene, Object *ob) { if(ob->recalc & OB_RECALC) { - + /* speed optimization for animation lookups */ + if(ob->pose) + make_pose_channels_hash(ob->pose); + /* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers, which is only in where_is_object now */ if(ob->recalc & OB_RECALC) { -- cgit v1.2.3 From 666cca69e90bf1f5c1bfb5a6582c56c2e8311f04 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 26 Mar 2010 10:52:55 +0000 Subject: Cloth simulation can now use a group to specify which objects to collide with, in addition to the effectors group. (commit 27746 by Brecht from render25 branch) --- source/blender/blenkernel/BKE_collision.h | 13 +- source/blender/blenkernel/intern/collision.c | 261 ++++++++------------- source/blender/blenkernel/intern/effect.c | 2 +- source/blender/blenkernel/intern/implicit.c | 2 +- source/blender/blenkernel/intern/particle_system.c | 2 +- source/blender/blenkernel/intern/scene.c | 1 + 6 files changed, 109 insertions(+), 172 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h index 689fa96ffa6..91c5eb4afee 100644 --- a/source/blender/blenkernel/BKE_collision.h +++ b/source/blender/blenkernel/BKE_collision.h @@ -49,12 +49,13 @@ #include "BLI_kdopbvh.h" -struct Object; -struct Scene; struct Cloth; -struct MFace; -struct DerivedMesh; struct ClothModifierData; +struct DerivedMesh; +struct Group; +struct MFace; +struct Object; +struct Scene; //////////////////////////////////////// // used for collisions in collision.c @@ -139,7 +140,7 @@ void interpolateOnTriangle ( float to[3], float v1[3], float v2[3], float v3[3], ///////////////////////////////////////////////// // used in effect.c ///////////////////////////////////////////////// -Object **get_collisionobjects(struct Scene *scene, Object *self, int *numcollobj); +struct Object **get_collisionobjects(struct Scene *scene, struct Object *self, struct Group *group, int *numcollobj); typedef struct ColliderCache { struct ColliderCache *next, *prev; @@ -147,7 +148,7 @@ typedef struct ColliderCache { struct CollisionModifierData *collmd; } ColliderCache; -struct ListBase *get_collider_cache(struct Scene *scene, Object *self); +struct ListBase *get_collider_cache(struct Scene *scene, struct Object *self, struct Group *group); void free_collider_cache(struct ListBase **colliders); ///////////////////////////////////////////////// diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index b024ba5f4e1..c85bd2f90b3 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -1299,188 +1299,122 @@ static int cloth_collision_moving ( ClothModifierData *clmd, CollisionModifierDa } #endif - -// return all collision objects in scene -// collision object will exclude self -Object **get_collisionobjects(Scene *scene, Object *self, int *numcollobj) +static void add_collision_object(Object ***objs, int *numobj, int *maxobj, Object *ob, Object *self, int level) { - Base *base=NULL; - Object **objs = NULL; - Object *coll_ob = NULL; - CollisionModifierData *collmd = NULL; - int numobj = 0, maxobj = 100; + CollisionModifierData *cmd= NULL; + + if(ob == self) + return; + + /* only get objects with collision modifier */ + if(ob->pd && ob->pd->deflect) + cmd= (CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision); - objs = MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); - // check all collision objects - for ( base = scene->base.first; base; base = base->next ) - { - /*Only proceed for mesh object in same layer */ - if(!(base->object->type==OB_MESH && (base->lay & self->lay))) - continue; - - coll_ob = base->object; - - if(coll_ob == self) - continue; - - if(coll_ob->pd && coll_ob->pd->deflect) - { - collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision ); + if(cmd) { + /* extend array */ + if(*numobj >= *maxobj) { + *maxobj *= 2; + *objs= MEM_reallocN(*objs, sizeof(Object*)*(*maxobj)); } - else - collmd = NULL; - if ( collmd ) - { - if(numobj >= maxobj) - { - // realloc - int oldmax = maxobj; - Object **tmp; - maxobj *= 2; - tmp = MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); - memcpy(tmp, objs, sizeof(Object *)*oldmax); - MEM_freeN(objs); - objs = tmp; - - } - - objs[numobj] = coll_ob; - numobj++; - } - else - { - if ( coll_ob->dup_group ) - { - GroupObject *go; - Group *group = coll_ob->dup_group; + (*objs)[*numobj] = ob; + (*numobj)++; + } - for ( go= group->gobject.first; go; go= go->next ) - { - coll_ob = go->ob; - collmd = NULL; - - if(coll_ob == self) - continue; - - if(coll_ob->pd && coll_ob->pd->deflect) - { - collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision ); - } - else - collmd = NULL; + /* objects in dupli groups, one level only for now */ + if(ob->dup_group && level == 0) { + GroupObject *go; + Group *group= ob->dup_group; - if ( !collmd ) - continue; - - if( !collmd->bvhtree) - continue; + /* add objects */ + for(go= group->gobject.first; go; go= go->next) + add_collision_object(objs, numobj, maxobj, go->ob, self, level+1); + } +} - if(numobj >= maxobj) - { - // realloc - int oldmax = maxobj; - Object **tmp; - maxobj *= 2; - tmp = MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); - memcpy(tmp, objs, sizeof(Object *)*oldmax); - MEM_freeN(objs); - objs = tmp; - } - - objs[numobj] = coll_ob; - numobj++; - } - } - } +// return all collision objects in scene +// collision object will exclude self +Object **get_collisionobjects(Scene *scene, Object *self, Group *group, int *numcollobj) +{ + Base *base; + Object **objs; + GroupObject *go; + int numobj= 0, maxobj= 100; + + objs= MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); + + /* gather all collision objects */ + if(group) { + /* use specified group */ + for(go= group->gobject.first; go; go= go->next) + add_collision_object(&objs, &numobj, &maxobj, go->ob, self, 0); + } + else { + /* add objects in same layer in scene */ + for(base = scene->base.first; base; base = base->next) + if(base->lay & self->lay) + add_collision_object(&objs, &numobj, &maxobj, base->object, self, 0); } - *numcollobj = numobj; + + *numcollobj= numobj; + return objs; } -ListBase *get_collider_cache(Scene *scene, Object *self) +static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self, int level) { - Base *base=NULL; - ListBase *objs = NULL; - Object *coll_ob = NULL; - CollisionModifierData *collmd = NULL; + CollisionModifierData *cmd= NULL; ColliderCache *col; - - // check all collision objects - for ( base = scene->base.first; base; base = base->next ) - { - /*Only proceed for mesh object in same layer */ - if(base->object->type!=OB_MESH) - continue; - if(self && (base->lay & self->lay)==0) - continue; + if(ob == self) + return; - - coll_ob = base->object; - - if(coll_ob == self) - continue; - - if(coll_ob->pd && coll_ob->pd->deflect) - { - collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision ); - } - else - collmd = NULL; - - if ( collmd ) - { - if(objs == NULL) - objs = MEM_callocN(sizeof(ListBase), "ColliderCache array"); - - col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); - col->ob = coll_ob; - col->collmd = collmd; - /* make sure collider is properly set up */ - collision_move_object(collmd, 1.0, 0.0); - BLI_addtail(objs, col); - } - else if ( coll_ob->dup_group ) - { - GroupObject *go; - Group *group = coll_ob->dup_group; + if(ob->pd && ob->pd->deflect) + cmd =(CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision); + + if(cmd && cmd->bvhtree) { + if(*objs == NULL) + *objs = MEM_callocN(sizeof(ListBase), "ColliderCache array"); + + col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); + col->ob = ob; + col->collmd = cmd; + /* make sure collider is properly set up */ + collision_move_object(cmd, 1.0, 0.0); + BLI_addtail(*objs, col); + } - for ( go= group->gobject.first; go; go= go->next ) - { - coll_ob = go->ob; - collmd = NULL; - - if(coll_ob == self) - continue; - - if(coll_ob->pd && coll_ob->pd->deflect) - { - collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision ); - } - else - collmd = NULL; + /* objects in dupli groups, one level only for now */ + if(ob->dup_group && level == 0) { + GroupObject *go; + Group *group= ob->dup_group; - if ( !collmd ) - continue; - - if( !collmd->bvhtree) - continue; - - if(objs == NULL) - objs = MEM_callocN(sizeof(ListBase), "ColliderCache array"); - - col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); - col->ob = coll_ob; - col->collmd = collmd; - /* make sure collider is properly set up */ - collision_move_object(collmd, 1.0, 0.0); - BLI_addtail(objs, col); - } - } + /* add objects */ + for(go= group->gobject.first; go; go= go->next) + add_collider_cache_object(objs, go->ob, self, level+1); + } +} + +ListBase *get_collider_cache(Scene *scene, Object *self, Group *group) +{ + Base *base; + GroupObject *go; + ListBase *objs= NULL; + + /* add object in same layer in scene */ + if(group) { + for(go= group->gobject.first; go; go= go->next) + add_collider_cache_object(&objs, go->ob, self, 0); + } + else { + for(base = scene->base.first; base; base = base->next) + if(self && (base->lay & self->lay)==0) + add_collider_cache_object(&objs, base->object, self, 0); } + return objs; } + void free_collider_cache(ListBase **colliders) { if(*colliders) { @@ -1489,6 +1423,7 @@ void free_collider_cache(ListBase **colliders) *colliders = NULL; } } + static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, CollisionModifierData *collmd, CollPair **collisions, CollPair **collisions_index, int numresult, BVHTreeOverlap *overlap) { int i; @@ -1574,7 +1509,7 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl bvhtree_update_from_cloth ( clmd, 1 ); // 0 means STATIC, 1 means MOVING (see later in this function) bvhselftree_update_from_cloth ( clmd, 0 ); // 0 means STATIC, 1 means MOVING (see later in this function) - collobjs = get_collisionobjects(clmd->scene, ob, &numcollobj); + collobjs = get_collisionobjects(clmd->scene, ob, clmd->coll_parms->group, &numcollobj); if(!collobjs) return 0; diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 66e7f805f50..118f4885af4 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -429,7 +429,7 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect return visibility; if(!colls) - colls = get_collider_cache(eff->scene, NULL); + colls = get_collider_cache(eff->scene, NULL, NULL); if(!colls) return visibility; diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index b4fb34d8464..c625fb28840 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -1422,7 +1422,7 @@ static void hair_velocity_smoothing(ClothModifierData *clmd, lfVector *lF, lfVec /* 10x10x10 grid gives nice initial results */ HairGridVert grid[10][10][10]; HairGridVert colg[10][10][10]; - ListBase *colliders = get_collider_cache(clmd->scene, NULL); + ListBase *colliders = get_collider_cache(clmd->scene, NULL, NULL); ColliderCache *col = NULL; float gmin[3], gmax[3], density; /* 2.0f is an experimental value that seems to give good results */ diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index a99a8affbd3..a8446c0009f 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -3229,7 +3229,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) psys_update_effectors(sim); if(part->type != PART_HAIR) - sim->colliders = get_collider_cache(sim->scene, NULL); + sim->colliders = get_collider_cache(sim->scene, NULL, NULL); if(part->phystype==PART_PHYS_BOIDS){ ParticleTarget *pt = psys->targets.first; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 0bce2d004e3..dd2a3143d3d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -53,6 +53,7 @@ #include "BKE_animsys.h" #include "BKE_depsgraph.h" #include "BKE_global.h" +#include "BKE_group.h" #include "BKE_idprop.h" #include "BKE_library.h" #include "BKE_main.h" -- cgit v1.2.3 From 0912d84f2ab58a8073e5f66655260e799e1003b3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 26 Mar 2010 15:06:30 +0000 Subject: Fixed incorrect rendering result when bevel object has got modifiers enabled only for realtime display or only for rendering --- source/blender/blenkernel/BKE_curve.h | 2 +- source/blender/blenkernel/intern/curve.c | 17 +++++++++++++---- source/blender/blenkernel/intern/displist.c | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 7119a725630..a3232ac91d6 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -76,7 +76,7 @@ void makeNurbcurve(struct Nurb *nu, float *coord_array, float *tilt_array, float void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride); float *make_orco_curve(struct Scene *scene, struct Object *ob); float *make_orco_surf( struct Object *ob); -void makebevelcurve(struct Scene *scene, struct Object *ob, struct ListBase *disp); +void makebevelcurve(struct Scene *scene, struct Object *ob, struct ListBase *disp, int forRender); void makeBevelList( struct Object *ob); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 4fed662b6b4..9087a7ec4f2 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -1214,7 +1214,7 @@ float *make_orco_curve(Scene *scene, Object *ob) /* ***************** BEVEL ****************** */ -void makebevelcurve(Scene *scene, Object *ob, ListBase *disp) +void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender) { DispList *dl, *dlnew; Curve *bevcu, *cu; @@ -1231,14 +1231,21 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp) if(cu->bevobj->type==OB_CURVE) { bevcu= cu->bevobj->data; if(bevcu->ext1==0.0 && bevcu->ext2==0.0) { + ListBase bevdisp= {NULL, NULL}; facx= cu->bevobj->size[0]; facy= cu->bevobj->size[1]; - dl= bevcu->disp.first; - if(dl==0) { - makeDispListCurveTypes(scene, cu->bevobj, 0); + if (forRender) { + makeDispListCurveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0); + dl= bevdisp.first; + } else { dl= bevcu->disp.first; + if(dl==0) { + makeDispListCurveTypes(scene, cu->bevobj, 0); + dl= bevcu->disp.first; + } } + while(dl) { if ELEM(dl->type, DL_POLY, DL_SEGM) { dlnew= MEM_mallocN(sizeof(DispList), "makebevelcurve1"); @@ -1260,6 +1267,8 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp) } dl= dl->next; } + + freedisplist(&bevdisp); } } } diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 3480564e00e..3e28dcc7acd 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -1299,7 +1299,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba md = preTesselatePoint->next; } - if (*derivedFinal) { + if (derivedFinal && *derivedFinal) { (*derivedFinal)->release (*derivedFinal); } @@ -1354,6 +1354,13 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba } } } else { + if (!derivedFinal) { + /* makeDisplistCurveTypes could be used for beveling, where derived mesh */ + /* is totally unnecessary, so we could stop modifiers applying */ + /* when we found constructive modifier but derived mesh is unwanted result */ + break; + } + if (dm) { if (dmDeformedVerts) { DerivedMesh *tdm = CDDM_copy(dm); @@ -1405,7 +1412,9 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba MEM_freeN(dmDeformedVerts); } - (*derivedFinal) = dm; + if (derivedFinal) { + (*derivedFinal) = dm; + } if (deformedVerts) { curve_applyVertexCos(ob->data, nurb, originalVerts); @@ -1659,7 +1668,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba makeBevelList(ob); /* If curve has no bevel will return nothing */ - makebevelcurve(scene, ob, &dlbev); + makebevelcurve(scene, ob, &dlbev, forRender); /* no bevel or extrude, and no width correction? */ if (!dlbev.first && cu->width==1.0f) { -- cgit v1.2.3