WIP: Improved implementation of DEG_get_evaluated_rna_pointer()

This now works by getting the RNA Path from the given PointerRNA to go from the
ID block to the data it points to, then uses this path to find the new data
relative to the COW ID.

Note: This currently still has all the debug prints left in - As can be seen,
I was testing this against the earlier PoseBone hack/special case. We may still
need to bring such special cases back in future, since looking up RNA Paths
like this can be slow.
This commit is contained in:
Joshua Leung
2018-05-19 19:12:26 +02:00
parent 6ba28ff8b1
commit 4a0dea88bf
2 changed files with 30 additions and 5 deletions

View File

@@ -87,7 +87,7 @@ struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
/* Get evaluated version of data pointed to by RNA pointer */
void DEG_get_evaluated_rna_pointer(const struct Depsgraph *depsgraph,
const struct PointerRNA *ptr,
struct PointerRNA *ptr,
struct PointerRNA *r_ptr_eval);
/* Get original version of object for given evaluated one. */

View File

@@ -159,7 +159,7 @@ ID *DEG_get_evaluated_id(const Depsgraph *depsgraph, ID *id)
}
/* Get evaluated version of data pointed to by RNA pointer */
void DEG_get_evaluated_rna_pointer(const Depsgraph *depsgraph, const PointerRNA *ptr, PointerRNA *r_ptr_eval)
void DEG_get_evaluated_rna_pointer(const Depsgraph *depsgraph, PointerRNA *ptr, PointerRNA *r_ptr_eval)
{
if ((ptr == NULL) || (r_ptr_eval == NULL)) {
return;
@@ -174,20 +174,45 @@ void DEG_get_evaluated_rna_pointer(const Depsgraph *depsgraph, const PointerRNA
}
else {
/* XXX: Hack for common cases... Proper fix needs to be made still... A very tricky problem though! */
printf("DEG get evaluated ptr ----------------------\n");
if (ptr->type == &RNA_PoseBone) {
const Object *ob_eval = (Object *)DEG_get_evaluated_id(depsgraph, (ID *)ptr->id.data);
bPoseChannel *pchan = (bPoseChannel *)ptr->data;
const bPoseChannel *pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, pchan->name);
/* XXX: Hack - This is just temporary... but this case must be supported. */
r_ptr_eval->id.data = (void *)&ob_eval->id;
r_ptr_eval->data = (void *)pchan_eval;
r_ptr_eval->type = ptr->type;
// r_ptr_eval->id.data = (void *)&ob_eval->id;
// r_ptr_eval->data = (void *)pchan_eval;
// r_ptr_eval->type = ptr->type;
printf(" orig id = %p, pchan = %p || eval id = %p, pchan = %p\n",
ptr->id.data, (void*)pchan, (void*)ob_eval, (void*)pchan_eval);
}
else {
/* FIXME: Maybe we should try resolving paths, or using some kind of depsgraph lookup? */
// XXX: For now, just use dirty hack, and hope it doesn't cause nasty issues.
*r_ptr_eval = *ptr;
}
/* For everything else, try to get RNA Path of the BMain-pointer,
* then use that to look up what the COW-domain one should be
* given the COW ID pointer as the new lookup point
*/
char *path = RNA_path_from_ID_to_struct(ptr);
printf(" path = '%s' (%p)\n", path, path);
if (path) {
ID *orig_id = (ID *)ptr->id.data;
ID *cow_id = DEG_get_evaluated_id(depsgraph, orig_id);
PointerRNA cow_id_ptr;
RNA_id_pointer_create(cow_id, &cow_id_ptr);
if (RNA_path_resolve(&cow_id_ptr, path, r_ptr_eval, NULL)) {
printf(" new pointer set - eval id = %p, ptr = %p\n",
r_ptr_eval->id.data, r_ptr_eval->data);
}
else {
printf(" resolve failed\n");
}
}
printf("----------------------------------------------\n");
}
}