Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_callbacks.h3
-rw-r--r--source/blender/blenkernel/BKE_collection.h12
-rw-r--r--source/blender/blenkernel/BKE_fcurve.h35
-rw-r--r--source/blender/blenkernel/BKE_sound.h2
-rw-r--r--source/blender/blenkernel/intern/collection.c28
-rw-r--r--source/blender/blenkernel/intern/fcurve.c130
-rw-r--r--source/blender/blenkernel/intern/object.cc8
-rw-r--r--source/blender/blenkernel/intern/sound.c23
8 files changed, 172 insertions, 69 deletions
diff --git a/source/blender/blenkernel/BKE_callbacks.h b/source/blender/blenkernel/BKE_callbacks.h
index 8b2af96a063..d8c67c52edc 100644
--- a/source/blender/blenkernel/BKE_callbacks.h
+++ b/source/blender/blenkernel/BKE_callbacks.h
@@ -97,6 +97,9 @@ typedef enum {
BKE_CB_EVT_XR_SESSION_START_PRE,
BKE_CB_EVT_ANNOTATION_PRE,
BKE_CB_EVT_ANNOTATION_POST,
+ BKE_CB_EVT_OBJECT_BAKE_PRE,
+ BKE_CB_EVT_OBJECT_BAKE_COMPLETE,
+ BKE_CB_EVT_OBJECT_BAKE_CANCEL,
BKE_CB_EVT_TOT,
} eCbEvent;
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index a3bbcc8687a..41d369ae9b2 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -115,6 +115,18 @@ bool BKE_collection_is_empty(const struct Collection *collection);
bool BKE_collection_object_add(struct Main *bmain,
struct Collection *collection,
struct Object *ob);
+
+/**
+ * Add object to given collection, similar to #BKE_collection_object_add.
+ *
+ * However, it additionnally ensures that the selected collection is also part of the given
+ * `view_layer`, if non-NULL. Otherwise, the object is not added to any collection.
+ */
+bool BKE_collection_viewlayer_object_add(struct Main *bmain,
+ const struct ViewLayer *view_layer,
+ struct Collection *collection,
+ struct Object *ob);
+
/**
* Same as #BKE_collection_object_add, but unconditionally adds the object to the given collection.
*
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 78d80ce200e..30c73e0fcc6 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -259,6 +259,18 @@ struct FCurve *BKE_fcurve_iter_step(struct FCurve *fcu_iter, const char rna_path
/**
* High level function to get an f-curve from C without having the RNA.
+ *
+ * If there is an action assigned to the `id`'s #AnimData, it will be searched for a matching
+ * F-curve first. Drivers are searched only if no valid action F-curve could be found.
+ *
+ * \note: Return pointer parameter (`r_driven`) is optional and may be NULL.
+ *
+ * \warning: In case no animation (from an Action) F-curve is found, returned value is always NULL.
+ * This means that this function will set `r_driven` to True in case a valid driver F-curve is
+ * found, but will not return said F-curve. In other words:
+ * - Animated with FCurve: returns the `FCurve*` and `*r_driven = false`.
+ * - Animated with driver: returns `NULL` and `*r_driven = true`.
+ * - Not animated: returns `NULL` and `*r_driven = false`.
*/
struct FCurve *id_data_find_fcurve(
ID *id, void *data, struct StructRNA *type, const char *prop_name, int index, bool *r_driven);
@@ -279,6 +291,25 @@ struct FCurve *id_data_find_fcurve(
int BKE_fcurves_filter(ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName);
/**
+ * Find an F-Curve from its rna path and index.
+ *
+ * If there is an action assigned to the `animdata`, it will be searched for a matching F-curve
+ * first. Drivers are searched only if no valid action F-curve could be found.
+ *
+ * \note: Typically, indices in RNA arrays are stored separately in F-curves, so the rna_path
+ * should not include them (e.g. `rna_path='location[0]'` will not match any F-Curve on an Object,
+ * but `rna_path='location', rna_index=0` will if it exists).
+ *
+ * \note: Return pointer parameters (`r_action`, `r_driven` and `r_special`) are all optional and
+ * may be NULL.
+ */
+struct FCurve *BKE_animadata_fcurve_find_by_rna_path(struct AnimData *animdata,
+ const char *rna_path,
+ const int rna_index,
+ struct bAction **r_action,
+ bool *r_driven);
+
+/**
* Find an f-curve based on an rna property.
*/
struct FCurve *BKE_fcurve_find_by_rna(struct PointerRNA *ptr,
@@ -291,7 +322,9 @@ struct FCurve *BKE_fcurve_find_by_rna(struct PointerRNA *ptr,
/**
* Same as above, but takes a context data,
* temp hack needed for complex paths like texture ones.
- */
+ *
+ * \param r_special Optional, ignored when NULL. Set to `true` if the given RNA `ptr` is a NLA
+ * strip, and the returned F-curve comes from this NLA strip. */
struct FCurve *BKE_fcurve_find_by_rna_context_ui(struct bContext *C,
const struct PointerRNA *ptr,
struct PropertyRNA *prop,
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index edb301f06bf..9965b6f1351 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -136,7 +136,7 @@ void BKE_sound_remove_scene_sound(struct Scene *scene, void *handle);
void BKE_sound_mute_scene_sound(void *handle, char mute);
-void BKE_sound_move_scene_sound(struct Scene *scene,
+void BKE_sound_move_scene_sound(const struct Scene *scene,
void *handle,
int startframe,
int endframe,
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 76c6dc1d5e7..b71bcef229a 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -996,9 +996,11 @@ static void collection_tag_update_parent_recursive(Main *bmain,
}
}
-static Collection *collection_parent_editable_find_recursive(Collection *collection)
+static Collection *collection_parent_editable_find_recursive(const ViewLayer *view_layer,
+ Collection *collection)
{
- if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY(collection)) {
+ if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY(collection) &&
+ (view_layer == NULL || BKE_view_layer_has_collection(view_layer, collection))) {
return collection;
}
@@ -1009,10 +1011,16 @@ static Collection *collection_parent_editable_find_recursive(Collection *collect
LISTBASE_FOREACH (CollectionParent *, collection_parent, &collection->parents) {
if (!ID_IS_LINKED(collection_parent->collection) &&
!ID_IS_OVERRIDE_LIBRARY(collection_parent->collection)) {
+ if (view_layer != NULL &&
+ !BKE_view_layer_has_collection(view_layer, collection_parent->collection)) {
+ /* In case this parent collection is not in given view_layer, there is no point in
+ * searching in its ancestors either, we can skip that whole parenting branch. */
+ continue;
+ }
return collection_parent->collection;
}
Collection *editable_collection = collection_parent_editable_find_recursive(
- collection_parent->collection);
+ view_layer, collection_parent->collection);
if (editable_collection != NULL) {
return editable_collection;
}
@@ -1110,11 +1118,23 @@ bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Objec
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
{
+ return BKE_collection_viewlayer_object_add(bmain, NULL, collection, ob);
+}
+
+bool BKE_collection_viewlayer_object_add(Main *bmain,
+ const ViewLayer *view_layer,
+ Collection *collection,
+ Object *ob)
+{
if (collection == NULL) {
return false;
}
- collection = collection_parent_editable_find_recursive(collection);
+ collection = collection_parent_editable_find_recursive(view_layer, collection);
+
+ if (collection == NULL) {
+ return false;
+ }
return BKE_collection_object_add_notest(bmain, collection, ob);
}
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 952d5df299c..98a2b977d4e 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -229,16 +229,13 @@ FCurve *id_data_find_fcurve(
return NULL;
}
- /* Animation takes priority over drivers. */
- if (adt->action && adt->action->curves.first) {
- fcu = BKE_fcurve_find(&adt->action->curves, path, index);
- }
-
- /* If not animated, check if driven. */
- if (fcu == NULL && adt->drivers.first) {
- fcu = BKE_fcurve_find(&adt->drivers, path, index);
- if (fcu && r_driven) {
- *r_driven = true;
+ /* FIXME: The way drivers are handled here (always NULL-ifying `fcu`) is very weird, this needs
+ * to be re-checked I think?. */
+ bool is_driven = false;
+ fcu = BKE_animadata_fcurve_find_by_rna_path(adt, path, index, NULL, &is_driven);
+ if (is_driven) {
+ if (r_driven != NULL) {
+ *r_driven = is_driven;
}
fcu = NULL;
}
@@ -339,6 +336,47 @@ int BKE_fcurves_filter(ListBase *dst, ListBase *src, const char *dataPrefix, con
return matches;
}
+FCurve *BKE_animadata_fcurve_find_by_rna_path(
+ AnimData *animdata, const char *rna_path, int rna_index, bAction **r_action, bool *r_driven)
+{
+ if (r_driven != NULL) {
+ *r_driven = false;
+ }
+ if (r_action != NULL) {
+ *r_action = NULL;
+ }
+
+ const bool has_action_fcurves = animdata->action != NULL &&
+ !BLI_listbase_is_empty(&animdata->action->curves);
+ const bool has_drivers = !BLI_listbase_is_empty(&animdata->drivers);
+
+ /* Animation takes priority over drivers. */
+ if (has_action_fcurves) {
+ FCurve *fcu = BKE_fcurve_find(&animdata->action->curves, rna_path, rna_index);
+
+ if (fcu != NULL) {
+ if (r_action != NULL) {
+ *r_action = animdata->action;
+ }
+ return fcu;
+ }
+ }
+
+ /* If not animated, check if driven. */
+ if (has_drivers) {
+ FCurve *fcu = BKE_fcurve_find(&animdata->drivers, rna_path, rna_index);
+
+ if (fcu != NULL) {
+ if (r_driven != NULL) {
+ *r_driven = true;
+ }
+ return fcu;
+ }
+ }
+
+ return NULL;
+}
+
FCurve *BKE_fcurve_find_by_rna(PointerRNA *ptr,
PropertyRNA *prop,
int rnaindex,
@@ -360,17 +398,18 @@ FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *UNUSED(C),
bool *r_driven,
bool *r_special)
{
- FCurve *fcu = NULL;
-
- *r_driven = false;
- *r_special = false;
-
- if (r_animdata) {
+ if (r_animdata != NULL) {
*r_animdata = NULL;
}
- if (r_action) {
+ if (r_action != NULL) {
*r_action = NULL;
}
+ if (r_driven != NULL) {
+ *r_driven = false;
+ }
+ if (r_special) {
+ *r_special = false;
+ }
/* Special case for NLA Control Curves... */
if (BKE_nlastrip_has_curves_for_property(ptr, prop)) {
@@ -379,59 +418,46 @@ FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *UNUSED(C),
/* Set the special flag, since it cannot be a normal action/driver
* if we've been told to start looking here...
*/
- *r_special = true;
+ if (r_special) {
+ *r_special = true;
+ }
+
+ *r_driven = false;
+ if (r_animdata) {
+ *r_animdata = NULL;
+ }
+ if (r_action) {
+ *r_action = NULL;
+ }
/* The F-Curve either exists or it doesn't here... */
- fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), rnaindex);
- return fcu;
+ return BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), rnaindex);
}
/* There must be some RNA-pointer + property combo. */
if (!prop || !ptr->owner_id || !RNA_property_animateable(ptr, prop)) {
- return fcu;
+ return NULL;
}
AnimData *adt = BKE_animdata_from_id(ptr->owner_id);
if (adt == NULL) {
- return fcu;
+ return NULL;
}
- const bool has_action_fcurves = adt->action != NULL &&
- !BLI_listbase_is_empty(&adt->action->curves);
- const bool has_drivers = !BLI_listbase_is_empty(&adt->drivers);
-
/* XXX This function call can become a performance bottleneck. */
- char *path = RNA_path_from_ID_to_property(ptr, prop);
-
- /* Standard F-Curve - Animation (Action) or Drivers. */
- /* Animation takes priority over drivers. */
- /* XXX: The logic here is duplicated with a function up above. */
- if (has_action_fcurves) {
- fcu = BKE_fcurve_find(&adt->action->curves, path, rnaindex);
-
- if (fcu) {
- if (r_action) {
- *r_action = adt->action;
- }
- if (r_animdata) {
- *r_animdata = adt;
- }
- }
+ char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
+ if (rna_path == NULL) {
+ return NULL;
}
- /* If not animated, check if driven. */
- if (fcu == NULL && has_drivers) {
- fcu = BKE_fcurve_find(&adt->drivers, path, rnaindex);
+ /* Standard F-Curve from animdata - Animation (Action) or Drivers. */
+ FCurve *fcu = BKE_animadata_fcurve_find_by_rna_path(adt, rna_path, rnaindex, r_action, r_driven);
- if (fcu) {
- if (r_animdata) {
- *r_animdata = adt;
- }
- *r_driven = true;
- }
+ if (fcu != NULL && r_animdata != NULL) {
+ *r_animdata = adt;
}
- MEM_SAFE_FREE(path);
+ MEM_freeN(rna_path);
return fcu;
}
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 55b9951c52d..52b25399e32 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -2271,10 +2271,14 @@ Object *BKE_object_add(Main *bmain, ViewLayer *view_layer, int type, const char
Object *ob = object_add_common(bmain, view_layer, type, name);
LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
- BKE_collection_object_add(bmain, layer_collection->collection, ob);
+ BKE_collection_viewlayer_object_add(bmain, view_layer, layer_collection->collection, ob);
+ /* Note: There is no way to be sure that #BKE_collection_viewlayer_object_add will actually
+ * manage to find a valid collection in given `view_layer` to add the new object to. */
Base *base = BKE_view_layer_base_find(view_layer, ob);
- BKE_view_layer_base_select_and_set_active(view_layer, base);
+ if (base != nullptr) {
+ BKE_view_layer_base_select_and_set_active(view_layer, base);
+ }
return ob;
}
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index de5589cf5dc..5bafce15b34 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -54,6 +54,7 @@
#include "SEQ_sequencer.h"
#include "SEQ_sound.h"
+#include "SEQ_time.h"
static void sound_free_audio(bSound *sound);
@@ -719,8 +720,8 @@ void *BKE_sound_scene_add_scene_sound_defaults(Scene *scene, Sequence *sequence)
{
return BKE_sound_scene_add_scene_sound(scene,
sequence,
- sequence->startdisp,
- sequence->enddisp,
+ SEQ_time_left_handle_frame_get(sequence),
+ SEQ_time_right_handle_frame_get(sequence),
sequence->startofs + sequence->anim_startofs);
}
@@ -745,8 +746,8 @@ void *BKE_sound_add_scene_sound_defaults(Scene *scene, Sequence *sequence)
{
return BKE_sound_add_scene_sound(scene,
sequence,
- sequence->startdisp,
- sequence->enddisp,
+ SEQ_time_left_handle_frame_get(sequence),
+ SEQ_time_right_handle_frame_get(sequence),
sequence->startofs + sequence->anim_startofs);
}
@@ -760,8 +761,12 @@ void BKE_sound_mute_scene_sound(void *handle, char mute)
AUD_SequenceEntry_setMuted(handle, mute);
}
-void BKE_sound_move_scene_sound(
- Scene *scene, void *handle, int startframe, int endframe, int frameskip, double audio_offset)
+void BKE_sound_move_scene_sound(const Scene *scene,
+ void *handle,
+ int startframe,
+ int endframe,
+ int frameskip,
+ double audio_offset)
{
sound_verify_evaluated_id(&scene->id);
const double fps = FPS;
@@ -774,8 +779,8 @@ void BKE_sound_move_scene_sound_defaults(Scene *scene, Sequence *sequence)
if (sequence->scene_sound) {
BKE_sound_move_scene_sound(scene,
sequence->scene_sound,
- sequence->startdisp,
- sequence->enddisp,
+ SEQ_time_left_handle_frame_get(sequence),
+ SEQ_time_right_handle_frame_get(sequence),
sequence->startofs + sequence->anim_startofs,
0.0);
}
@@ -1344,7 +1349,7 @@ void BKE_sound_remove_scene_sound(Scene *UNUSED(scene), void *UNUSED(handle))
void BKE_sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute))
{
}
-void BKE_sound_move_scene_sound(Scene *UNUSED(scene),
+void BKE_sound_move_scene_sound(const Scene *UNUSED(scene),
void *UNUSED(handle),
int UNUSED(startframe),
int UNUSED(endframe),