WIP: Onion Skinning Prototype #107641

Closed
Christoph Lendenfeld wants to merge 22 commits from ChrisLend/blender:onion_skin_test into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 38 additions and 8 deletions
Showing only changes of commit 0a225f8895 - Show all commits

View File

@ -1,3 +1,4 @@
#include "BKE_mesh.h"
#include "DRW_render.h"
#include "draw_cache_impl.h"
#include "overlay_private.hh"
@ -27,8 +28,13 @@ void OVERLAY_onion_skin_populate(OVERLAY_Data *vedata, Object *ob)
DRW_shgroup_uniform_vec3_copy(grp, "color", draw_ctx->scene->onion_skin_cache.color);
DRW_shgroup_uniform_float_copy(grp, "alpha", draw_ctx->scene->onion_skin_cache.alpha);
LISTBASE_FOREACH (OnionSkinMeshLink *, mesh_link, &draw_ctx->scene->onion_skin_cache.meshes) {
struct GPUBatch *geom = DRW_mesh_batch_cache_get_surface((Mesh *)mesh_link->mesh);
LISTBASE_FOREACH (OnionSkinMeshLink *, mesh_link, &draw_ctx->scene->onion_skin_cache.objects) {
if (ob != mesh_link->object) {
continue;
}
Mesh *mesh = BKE_mesh_from_object(ob);
struct GPUBatch *geom = DRW_mesh_batch_cache_get_surface(mesh);
if (geom) {
DRW_shgroup_call(pd->onion_skin_grp, geom, ob);
}

View File

@ -1,9 +1,15 @@
#include "BKE_context.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DNA_scene_types.h"
#include "DNA_windowmanager_types.h"
#include "ED_onion_skin.h"
#include "ED_outliner.h"
#include "MEM_guardedalloc.h"
#include "WM_api.h"
#include "WM_types.h"
@ -30,6 +36,9 @@ static void graveyard()
static int onion_skin_add_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Main *bmain = CTX_data_main(C);
BKE_main_id_newptr_and_tag_clear(bmain);
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = CTX_data_active_object(C);
if (!ob) {
@ -40,11 +49,26 @@ static int onion_skin_add_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* Mesh *copy = BKE_mesh_copy_for_eval(mesh); */
Mesh *copy = (Mesh *)BKE_id_copy_ex(NULL, &mesh->id, NULL, LIB_ID_COPY_LOCALIZE);
/* Mesh *copy = (Mesh *)BKE_id_copy_ex(bmain, &mesh->id, NULL, LIB_ID_COPY_DEFAULT); */
Object *ob_new = BKE_object_duplicate(bmain,
ob,
(eDupli_ID_Flags)U.dupflag,
LIB_ID_DUPLICATE_IS_SUBPROCESS |
LIB_ID_DUPLICATE_IS_ROOT_ID);
LayerCollection *layer_collection = BKE_layer_collection_from_index(view_layer, 2);
BKE_collection_object_add(bmain, layer_collection->collection, ob_new);
OnionSkinMeshLink *link = MEM_callocN(sizeof(OnionSkinMeshLink), "onion skin mesh link");
link->mesh = copy;
BLI_addtail(&scene->onion_skin_cache.meshes, link);
link->object = ob_new;
ob_new->adt = NULL;
BLI_addtail(&scene->onion_skin_cache.objects, link);
ED_outliner_select_sync_from_object_tag(C);
DEG_relations_tag_update(bmain);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
return OPERATOR_FINISHED;
}

View File

@ -1852,13 +1852,13 @@ typedef struct SceneGpencil {
typedef struct OnionSkinMeshLink {
struct OnionSkinMeshLink *prev, *next;
/* Having a Mesh pointer here breaks compilation. Complains about "extern C" issues. */
void *mesh;
struct Object *object;
} OnionSkinMeshLink;
typedef struct SceneOnionSkin {
float color[3];
float alpha;
ListBase meshes /* OnionSkinMeshLink */;
ListBase objects /* OnionSkinMeshLink */;
} SceneOnionSkin;
/** \} */