BKE_object: add util to count number of scenes using an object.

Issue is, ob->id.us is not relevant anymore here, since several
collection might be referencing it inside of a same scene, that is still
only one usage from user perspective...

Note that for now we are just counting scenes instantiating an object,
time will say wether we need more refined/complete check (as a reminder,
most [all?] other Object usages are *not* refcounting ones).
This commit is contained in:
Bastien Montagne 2019-02-09 13:18:22 +01:00
parent 1bf8551f00
commit bf4f01779d
2 changed files with 14 additions and 0 deletions

View File

@ -301,6 +301,8 @@ bool BKE_object_is_animated(struct Scene *scene, struct Object *ob);
int BKE_object_is_modified(struct Scene *scene, struct Object *ob);
int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob);
int BKE_object_scenes_users_get(struct Main *bmain, struct Object *ob);
struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, bool use_default);
void BKE_object_runtime_reset(struct Object *object);

View File

@ -3514,6 +3514,18 @@ bool BKE_object_is_animated(Scene *scene, Object *ob)
return false;
}
/** Return the number of scenes using (instantiating) that object in their collections. */
int BKE_object_scenes_users_get(Main *bmain, Object *ob)
{
int num_scenes = 0;
for (Scene *scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
if (BKE_collection_has_object_recursive(BKE_collection_master(scene), ob)) {
num_scenes++;
}
}
return num_scenes;
}
MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default)
{
MovieClip *clip = use_default ? scene->clip : NULL;