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:
authorTon Roosendaal <ton@blender.org>2009-04-20 14:13:55 +0400
committerTon Roosendaal <ton@blender.org>2009-04-20 14:13:55 +0400
commit74b12d1d6df9d3ff5b9f258c81eda82fa37901cf (patch)
treec4ea60be8d93e413cd1fe4be5e2ed42e99902211 /source/blender/blenloader
parent332e00198914bb6cd34199fffb3832e170066959 (diff)
2.5
Patch from Joshua, converting Grease Pencil to 2.5. All GP data now is an ID block, allowing re-use, link and append. For better contextual control within 2.5, these GP ID's will get linked to actual data, like NodeTrees, Scenes, Images or Objects. That will ensure Undo works, and opens up exciting new use cases as well. :) Patch note: on reading files, GPencils linked from editors will get moved to the main library, using standard naming (indicating where it was used), and with "Fake User" set. That way the user can manually relink the pencils where appropriate. We can check on just linking GP to some default, like 3d window pencils to Scene? Nice to experiment with. Notes for Joshua: - for reading old GPencil, it has to use old code as well, meaning to tread data as "indirect data, within another ID". - Saving ID data means the chunk in file BHead needs the ID_GD code, and not "DATA", which indicates 'indirect data'. That's the file format spec. - I've added do_versions_gpencil_2_50(), feel free to further tweak things here, like linking things to scene or so. - Formerly GPencil saved 2.50 files won't convert gpencil
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/readblenentry.c1
-rw-r--r--source/blender/blenloader/intern/readfile.c85
-rw-r--r--source/blender/blenloader/intern/writefile.c37
3 files changed, 93 insertions, 30 deletions
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 23e334fbbd1..0c8b8a6b31d 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -86,6 +86,7 @@ static IDType idtypes[]= {
{ ID_BR, "Brush", IDTYPE_FLAGS_ISLINKABLE},
{ ID_CA, "Camera", IDTYPE_FLAGS_ISLINKABLE},
{ ID_CU, "Curve", IDTYPE_FLAGS_ISLINKABLE},
+ { ID_GD, "GPencil", IDTYPE_FLAGS_ISLINKABLE},
{ ID_GR, "Group", IDTYPE_FLAGS_ISLINKABLE},
{ ID_ID, "ID", 0},
{ ID_IM, "Image", IDTYPE_FLAGS_ISLINKABLE},
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f74f09a11ee..5ea83f0375f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4065,8 +4065,8 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
/* ****************** READ GREASE PENCIL ***************** */
-/* relinks grease-pencil data for 3d-view(s) - used for direct_link */
-static void link_gpencil(FileData *fd, bGPdata *gpd)
+/* relinks grease-pencil data - used for direct_link and old file linkage */
+static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
{
bGPDlayer *gpl;
bGPDframe *gpf;
@@ -4242,7 +4242,6 @@ static void lib_link_screen(FileData *fd, Main *main)
else if(GS(snode->id->name)==ID_TE)
snode->nodetree= ((Tex *)snode->id)->nodetree;
}
-
}
}
sa= sa->next;
@@ -4353,7 +4352,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
*/
}
else if(v3d->scenelock) v3d->lay= sc->scene->lay;
-
+
/* not very nice, but could help */
if((v3d->layact & v3d->lay)==0) v3d->layact= v3d->lay;
@@ -4592,7 +4591,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
v3d->bgpic->iuser.ok= 1;
if(v3d->gpd) {
v3d->gpd= newdataadr(fd, v3d->gpd);
- link_gpencil(fd, v3d->gpd);
+ direct_link_gpencil(fd, v3d->gpd);
}
v3d->localvd= newdataadr(fd, v3d->localvd);
v3d->afterdraw.first= v3d->afterdraw.last= NULL;
@@ -4621,11 +4620,11 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
SpaceImage *sima= (SpaceImage *)sl;
sima->cumap= newdataadr(fd, sima->cumap);
- if(sima->cumap)
- direct_link_curvemapping(fd, sima->cumap);
sima->gpd= newdataadr(fd, sima->gpd);
if (sima->gpd)
- link_gpencil(fd, sima->gpd);
+ direct_link_gpencil(fd, sima->gpd);
+ if(sima->cumap)
+ direct_link_curvemapping(fd, sima->cumap);
sima->iuser.ok= 1;
}
else if(sl->spacetype==SPACE_NODE) {
@@ -4633,7 +4632,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
if(snode->gpd) {
snode->gpd= newdataadr(fd, snode->gpd);
- link_gpencil(fd, snode->gpd);
+ direct_link_gpencil(fd, snode->gpd);
}
snode->nodetree= snode->edittree= NULL;
}
@@ -4641,7 +4640,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
SpaceSeq *sseq= (SpaceSeq *)sl;
if(sseq->gpd) {
sseq->gpd= newdataadr(fd, sseq->gpd);
- link_gpencil(fd, sseq->gpd);
+ direct_link_gpencil(fd, sseq->gpd);
}
}
}
@@ -4818,6 +4817,7 @@ static char *dataname(short id_code)
case ID_NT: return "Data from NT";
case ID_BR: return "Data from BR";
case ID_PA: return "Data from PA";
+ case ID_GD: return "Data from GD";
}
return "Data from Lib Block";
@@ -4974,6 +4974,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
case ID_SCRIPT:
direct_link_script(fd, (Script*)id);
break;
+ case ID_GD:
+ direct_link_gpencil(fd, (bGPdata *)id);
+ break;
}
/*link direct data of ID properties*/
@@ -5677,6 +5680,64 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
}
}
+static void versions_gpencil_add_main(ListBase *lb, ID *id, char *name)
+{
+
+ BLI_addtail(lb, id);
+ id->us= 1;
+ id->flag= LIB_FAKEUSER;
+ *( (short *)id->name )= ID_GD;
+
+ new_id(lb, id, name);
+ /* alphabetic insterion: is in new_id */
+
+ if(G.f & G_DEBUG)
+ printf("Converted GPencil to ID: %s\n", id->name+2);
+}
+
+static void do_versions_gpencil_2_50(Main *main, bScreen *screen)
+{
+ ScrArea *sa;
+ SpaceLink *sl;
+
+ /* add regions */
+ for(sa= screen->areabase.first; sa; sa= sa->next) {
+ sl= sa->spacedata.first;
+ for(sl; sl; sl= sl->next) {
+ if (sl->spacetype==SPACE_VIEW3D) {
+ View3D *v3d= (View3D*) sl;
+ if(v3d->gpd) {
+ versions_gpencil_add_main(&main->gpencil, (ID *)v3d->gpd, "GPencil View3D");
+ v3d->gpd= NULL;
+ }
+ }
+ else if (sl->spacetype==SPACE_NODE) {
+ SpaceNode *snode= (SpaceNode *)sl;
+ if(snode->gpd) {
+ versions_gpencil_add_main(&main->gpencil, (ID *)snode->gpd, "GPencil Node");
+ snode->gpd= NULL;
+ }
+ }
+ else if (sl->spacetype==SPACE_SEQ) {
+ SpaceSeq *sseq= (SpaceSeq *)sl;
+ if(sseq->gpd) {
+ versions_gpencil_add_main(&main->gpencil, (ID *)sseq->gpd, "GPencil Node");
+ sseq->gpd= NULL;
+ }
+ }
+ else if (sl->spacetype==SPACE_IMAGE) {
+ SpaceImage *sima= (SpaceImage *)sl;
+ if(sima->gpd) {
+ versions_gpencil_add_main(&main->gpencil, (ID *)sima->gpd, "GPencil Image");
+ sima->gpd= NULL;
+ }
+ }
+ }
+ }
+}
+
+
+
static void do_versions(FileData *fd, Library *lib, Main *main)
{
/* WATCH IT!!!: pointers from libdata have not been converted */
@@ -8748,8 +8809,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
Scene *sce;
Tex *tx;
- for(screen= main->screen.first; screen; screen= screen->id.next)
+ for(screen= main->screen.first; screen; screen= screen->id.next) {
do_versions_windowmanager_2_50(screen);
+ do_versions_gpencil_2_50(main, screen);
+ }
/* old Animation System (using IPO's) needs to be converted to the new Animato system
* (NOTE: conversion code in blenkernel/intern/ipo.c for now)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 10f88e4d291..d7d7ad79239 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1693,27 +1693,30 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
mywrite(wd, MYWRITE_FLUSH, 0);
}
-static void write_gpencil(WriteData *wd, bGPdata *gpd)
+static void write_gpencils(WriteData *wd, ListBase *lb)
{
+ bGPdata *gpd;
bGPDlayer *gpl;
bGPDframe *gpf;
bGPDstroke *gps;
- /* write gpd data block to file */
- writestruct(wd, DATA, "bGPdata", 1, gpd);
-
- /* write grease-pencil layers to file */
- for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
- writestruct(wd, DATA, "bGPDlayer", 1, gpl);
+ for (gpd= lb->first; gpd; gpd= gpd->id.next) {
+ /* write gpd data block to file */
+ writestruct(wd, ID_GD, "bGPdata", 1, gpd);
- /* write this layer's frames to file */
- for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
- writestruct(wd, DATA, "bGPDframe", 1, gpf);
+ /* write grease-pencil layers to file */
+ for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
+ writestruct(wd, DATA, "bGPDlayer", 1, gpl);
- /* write strokes */
- for (gps= gpf->strokes.first; gps; gps= gps->next) {
- writestruct(wd, DATA, "bGPDstroke", 1, gps);
- writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points);
+ /* write this layer's frames to file */
+ for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
+ writestruct(wd, DATA, "bGPDframe", 1, gpf);
+
+ /* write strokes */
+ for (gps= gpf->strokes.first; gps; gps= gps->next) {
+ writestruct(wd, DATA, "bGPDstroke", 1, gps);
+ writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points);
+ }
}
}
}
@@ -1808,7 +1811,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
writestruct(wd, DATA, "View3D", 1, v3d);
if(v3d->bgpic) writestruct(wd, DATA, "BGpic", 1, v3d->bgpic);
if(v3d->localvd) writestruct(wd, DATA, "View3D", 1, v3d->localvd);
- if(v3d->gpd) write_gpencil(wd, v3d->gpd);
}
else if(sl->spacetype==SPACE_IPO) {
SpaceIpo *sipo= (SpaceIpo *)sl;
@@ -1832,7 +1834,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
else if(sl->spacetype==SPACE_SEQ) {
SpaceSeq *sseq= (SpaceSeq *)sl;
writestruct(wd, DATA, "SpaceSeq", 1, sl);
- if(sseq->gpd) write_gpencil(wd, sseq->gpd);
}
else if(sl->spacetype==SPACE_OUTLINER) {
SpaceOops *so= (SpaceOops *)sl;
@@ -1852,8 +1853,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
writestruct(wd, DATA, "SpaceImage", 1, sl);
if(sima->cumap)
write_curvemapping(wd, sima->cumap);
- if(sima->gpd)
- write_gpencil(wd, sima->gpd);
}
else if(sl->spacetype==SPACE_IMASEL) {
writestruct(wd, DATA, "SpaceImaSel", 1, sl);
@@ -1881,7 +1880,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
else if(sl->spacetype==SPACE_NODE){
SpaceNode *snode= (SpaceNode *)sl;
writestruct(wd, DATA, "SpaceNode", 1, sl);
- if(snode->gpd) write_gpencil(wd, snode->gpd);
}
sl= sl->next;
}
@@ -2208,6 +2206,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
write_nodetrees(wd, &mainvar->nodetree);
write_brushes (wd, &mainvar->brush);
write_scripts (wd, &mainvar->script);
+ write_gpencils (wd, &mainvar->gpencil);
if(current==NULL)
write_libraries(wd, mainvar->next); /* no library save in undo */