diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-28 16:45:11 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-28 16:49:14 +0300 |
commit | 8815996418f0259b9abb9446da9bc137145de7d6 (patch) | |
tree | 7a62aa9cf197f1934a622ee8506ba0d0e024c8d2 /source/blender/blenloader/intern/writefile.c | |
parent | 5db5ac611a5cc2645d4c8638c640bc1c2372a6bd (diff) |
Refactor: move Mesh .blend I/O to IDTypeInfo callbacks
I'm also adding `BKE_id_blend_write`, so that it can be accessed
outside of `readfile.c`.
Diffstat (limited to 'source/blender/blenloader/intern/writefile.c')
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 136 |
1 files changed, 40 insertions, 96 deletions
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index c764f2d9e05..0c703f97f4d 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -659,33 +659,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co * These functions are used by blender's .blend system for file saving/loading. * \{ */ -static void write_iddata(BlendWriter *writer, ID *id) -{ - /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */ - if (id->properties && !ELEM(GS(id->name), ID_WM)) { - IDP_BlendWrite(writer, id->properties); - } - - if (id->override_library) { - BLO_write_struct(writer, IDOverrideLibrary, id->override_library); - - BLO_write_struct_list(writer, IDOverrideLibraryProperty, &id->override_library->properties); - LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) { - BLO_write_string(writer, op->rna_path); - - BLO_write_struct_list(writer, IDOverrideLibraryPropertyOperation, &op->operations); - LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) { - if (opop->subitem_reference_name) { - BLO_write_string(writer, opop->subitem_reference_name); - } - if (opop->subitem_local_name) { - BLO_write_string(writer, opop->subitem_local_name); - } - } - } - } -} - static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig) { /* Note we write previews also for undo steps. It takes up some memory, @@ -714,7 +687,7 @@ static void write_action(BlendWriter *writer, bAction *act, const void *id_addre { if (act->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, bAction, id_address, &act->id); - write_iddata(writer, &act->id); + BKE_id_blend_write(writer, &act->id); BKE_fcurve_blend_write(writer, &act->curves); @@ -1172,7 +1145,7 @@ static void write_particlesettings(BlendWriter *writer, if (part->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id); - write_iddata(writer, &part->id); + BKE_id_blend_write(writer, &part->id); if (part->adt) { BKE_animdata_blend_write(writer, part->adt); @@ -1594,7 +1567,7 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address /* write LibData */ BLO_write_id_struct(writer, Object, id_address, &ob->id); - write_iddata(writer, &ob->id); + BKE_id_blend_write(writer, &ob->id); if (ob->adt) { BKE_animdata_blend_write(writer, ob->adt); @@ -1662,7 +1635,7 @@ static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, VFont, id_address, &vf->id); - write_iddata(writer, &vf->id); + BKE_id_blend_write(writer, &vf->id); /* direct data */ if (vf->packedfile) { @@ -1678,7 +1651,7 @@ static void write_key(BlendWriter *writer, Key *key, const void *id_address) if (key->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Key, id_address, &key->id); - write_iddata(writer, &key->id); + BKE_id_blend_write(writer, &key->id); if (key->adt) { BKE_animdata_blend_write(writer, key->adt); @@ -1699,7 +1672,7 @@ static void write_camera(BlendWriter *writer, Camera *cam, const void *id_addres if (cam->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Camera, id_address, &cam->id); - write_iddata(writer, &cam->id); + BKE_id_blend_write(writer, &cam->id); if (cam->adt) { BKE_animdata_blend_write(writer, cam->adt); @@ -1724,7 +1697,7 @@ static void write_mball(BlendWriter *writer, MetaBall *mb, const void *id_addres /* write LibData */ BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); - write_iddata(writer, &mb->id); + BKE_id_blend_write(writer, &mb->id); /* direct data */ BLO_write_pointer_array(writer, mb->totcol, mb->mat); @@ -1748,7 +1721,7 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Curve, id_address, &cu->id); - write_iddata(writer, &cu->id); + BKE_id_blend_write(writer, &cu->id); /* direct data */ BLO_write_pointer_array(writer, cu->totcol, cu->mat); @@ -1785,35 +1758,6 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) } } -static void write_mesh(BlendWriter *writer, Mesh *mesh, const void *id_address) -{ - if (mesh->id.us > 0 || BLO_write_is_undo(writer)) { - /* cache only - don't write */ - mesh->mface = NULL; - mesh->totface = 0; - memset(&mesh->fdata, 0, sizeof(mesh->fdata)); - memset(&mesh->runtime, 0, sizeof(mesh->runtime)); - - BLO_write_id_struct(writer, Mesh, id_address, &mesh->id); - write_iddata(writer, &mesh->id); - - /* direct data */ - if (mesh->adt) { - BKE_animdata_blend_write(writer, mesh->adt); - } - - BLO_write_pointer_array(writer, mesh->totcol, mesh->mat); - BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect); - - CustomData_blend_write(writer, &mesh->vdata, mesh->totvert, CD_MASK_MESH.vmask, &mesh->id); - CustomData_blend_write(writer, &mesh->edata, mesh->totedge, CD_MASK_MESH.emask, &mesh->id); - /* fdata is really a dummy - written so slots align */ - CustomData_blend_write(writer, &mesh->fdata, mesh->totface, CD_MASK_MESH.fmask, &mesh->id); - CustomData_blend_write(writer, &mesh->ldata, mesh->totloop, CD_MASK_MESH.lmask, &mesh->id); - CustomData_blend_write(writer, &mesh->pdata, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id); - } -} - static void write_lattice(BlendWriter *writer, Lattice *lt, const void *id_address) { if (lt->id.us > 0 || BLO_write_is_undo(writer)) { @@ -1823,7 +1767,7 @@ static void write_lattice(BlendWriter *writer, Lattice *lt, const void *id_addre /* write LibData */ BLO_write_id_struct(writer, Lattice, id_address, <->id); - write_iddata(writer, <->id); + BKE_id_blend_write(writer, <->id); /* write animdata */ if (lt->adt) { @@ -1851,7 +1795,7 @@ static void write_image(BlendWriter *writer, Image *ima, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Image, id_address, &ima->id); - write_iddata(writer, &ima->id); + BKE_id_blend_write(writer, &ima->id); for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { BLO_write_struct(writer, ImagePackedFile, imapf); @@ -1882,7 +1826,7 @@ static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address) if (tex->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Tex, id_address, &tex->id); - write_iddata(writer, &tex->id); + BKE_id_blend_write(writer, &tex->id); if (tex->adt) { BKE_animdata_blend_write(writer, tex->adt); @@ -1912,7 +1856,7 @@ static void write_material(BlendWriter *writer, Material *ma, const void *id_add /* write LibData */ BLO_write_id_struct(writer, Material, id_address, &ma->id); - write_iddata(writer, &ma->id); + BKE_id_blend_write(writer, &ma->id); if (ma->adt) { BKE_animdata_blend_write(writer, ma->adt); @@ -1941,7 +1885,7 @@ static void write_world(BlendWriter *writer, World *wrld, const void *id_address /* write LibData */ BLO_write_id_struct(writer, World, id_address, &wrld->id); - write_iddata(writer, &wrld->id); + BKE_id_blend_write(writer, &wrld->id); if (wrld->adt) { BKE_animdata_blend_write(writer, wrld->adt); @@ -1962,7 +1906,7 @@ static void write_light(BlendWriter *writer, Light *la, const void *id_address) if (la->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Light, id_address, &la->id); - write_iddata(writer, &la->id); + BKE_id_blend_write(writer, &la->id); if (la->adt) { BKE_animdata_blend_write(writer, la->adt); @@ -2007,7 +1951,7 @@ static void write_collection(BlendWriter *writer, Collection *collection, const /* write LibData */ BLO_write_id_struct(writer, Collection, id_address, &collection->id); - write_iddata(writer, &collection->id); + BKE_id_blend_write(writer, &collection->id); write_collection_nolib(writer, collection); } @@ -2133,7 +2077,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Scene, id_address, &sce->id); - write_iddata(writer, &sce->id); + BKE_id_blend_write(writer, &sce->id); if (sce->adt) { BKE_animdata_blend_write(writer, sce->adt); @@ -2367,7 +2311,7 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr /* write gpd data block to file */ BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id); - write_iddata(writer, &gpd->id); + BKE_id_blend_write(writer, &gpd->id); if (gpd->adt) { BKE_animdata_blend_write(writer, gpd->adt); @@ -2641,7 +2585,7 @@ static void write_area_map(BlendWriter *writer, ScrAreaMap *area_map) static void write_windowmanager(BlendWriter *writer, wmWindowManager *wm, const void *id_address) { BLO_write_id_struct(writer, wmWindowManager, id_address, &wm->id); - write_iddata(writer, &wm->id); + BKE_id_blend_write(writer, &wm->id); write_wm_xr_data(writer, &wm->xr); LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { @@ -2676,7 +2620,7 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen); - write_iddata(writer, &screen->id); + BKE_id_blend_write(writer, &screen->id); write_previews(writer, screen->preview); @@ -2716,7 +2660,7 @@ static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_a arm->act_edbone = NULL; BLO_write_id_struct(writer, bArmature, id_address, &arm->id); - write_iddata(writer, &arm->id); + BKE_id_blend_write(writer, &arm->id); if (arm->adt) { BKE_animdata_blend_write(writer, arm->adt); @@ -2741,7 +2685,7 @@ static void write_text(BlendWriter *writer, Text *text, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Text, id_address, &text->id); - write_iddata(writer, &text->id); + BKE_id_blend_write(writer, &text->id); if (text->filepath) { BLO_write_string(writer, text->filepath); @@ -2764,7 +2708,7 @@ static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_addr if (spk->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Speaker, id_address, &spk->id); - write_iddata(writer, &spk->id); + BKE_id_blend_write(writer, &spk->id); if (spk->adt) { BKE_animdata_blend_write(writer, spk->adt); @@ -2783,7 +2727,7 @@ static void write_sound(BlendWriter *writer, bSound *sound, const void *id_addre /* write LibData */ BLO_write_id_struct(writer, bSound, id_address, &sound->id); - write_iddata(writer, &sound->id); + BKE_id_blend_write(writer, &sound->id); if (sound->packedfile) { PackedFile *pf = sound->packedfile; @@ -2798,7 +2742,7 @@ static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_add if (prb->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, LightProbe, id_address, &prb->id); - write_iddata(writer, &prb->id); + BKE_id_blend_write(writer, &prb->id); if (prb->adt) { BKE_animdata_blend_write(writer, prb->adt); @@ -2820,7 +2764,7 @@ static void write_nodetree(BlendWriter *writer, bNodeTree *ntree, const void *id BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id); /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ - write_iddata(writer, &ntree->id); + BKE_id_blend_write(writer, &ntree->id); write_nodetree_nolib(writer, ntree); } @@ -2830,7 +2774,7 @@ static void write_brush(BlendWriter *writer, Brush *brush, const void *id_addres { if (brush->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, Brush, id_address, &brush->id); - write_iddata(writer, &brush->id); + BKE_id_blend_write(writer, &brush->id); if (brush->curve) { BKE_curvemapping_blend_write(writer, brush->curve); @@ -2878,7 +2822,7 @@ static void write_palette(BlendWriter *writer, Palette *palette, const void *id_ if (palette->id.us > 0 || BLO_write_is_undo(writer)) { PaletteColor *color; BLO_write_id_struct(writer, Palette, id_address, &palette->id); - write_iddata(writer, &palette->id); + BKE_id_blend_write(writer, &palette->id); for (color = palette->colors.first; color; color = color->next) { BLO_write_struct(writer, PaletteColor, color); @@ -2890,7 +2834,7 @@ static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id { if (pc->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); - write_iddata(writer, &pc->id); + BKE_id_blend_write(writer, &pc->id); BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); } @@ -2946,7 +2890,7 @@ static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id MovieTrackingObject *object; BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); - write_iddata(writer, &clip->id); + BKE_id_blend_write(writer, &clip->id); if (clip->adt) { BKE_animdata_blend_write(writer, clip->adt); @@ -2975,7 +2919,7 @@ static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) MaskLayer *masklay; BLO_write_id_struct(writer, Mask, id_address, &mask->id); - write_iddata(writer, &mask->id); + BKE_id_blend_write(writer, &mask->id); if (mask->adt) { BKE_animdata_blend_write(writer, mask->adt); @@ -3285,7 +3229,7 @@ static void write_linestyle(BlendWriter *writer, { if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); - write_iddata(writer, &linestyle->id); + BKE_id_blend_write(writer, &linestyle->id); if (linestyle->adt) { BKE_animdata_blend_write(writer, linestyle->adt); @@ -3327,7 +3271,7 @@ static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const vo static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address) { BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id); - write_iddata(writer, &workspace->id); + BKE_id_blend_write(writer, &workspace->id); BLO_write_struct_list(writer, WorkSpaceLayout, &workspace->layouts); BLO_write_struct_list(writer, WorkSpaceDataRelation, &workspace->hook_layout_relations); BLO_write_struct_list(writer, wmOwnerID, &workspace->owner_ids); @@ -3344,7 +3288,7 @@ static void write_hair(BlendWriter *writer, Hair *hair, const void *id_address) if (hair->id.us > 0 || BLO_write_is_undo(writer)) { /* Write LibData */ BLO_write_id_struct(writer, Hair, id_address, &hair->id); - write_iddata(writer, &hair->id); + BKE_id_blend_write(writer, &hair->id); /* Direct data */ CustomData_blend_write(writer, &hair->pdata, hair->totpoint, CD_MASK_ALL, &hair->id); @@ -3365,7 +3309,7 @@ static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const /* Write LibData */ BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id); - write_iddata(writer, &pointcloud->id); + BKE_id_blend_write(writer, &pointcloud->id); /* Direct data */ CustomData_blend_write( @@ -3390,7 +3334,7 @@ static void write_volume(BlendWriter *writer, Volume *volume, const void *id_add /* write LibData */ BLO_write_id_struct(writer, Volume, id_address, &volume->id); - write_iddata(writer, &volume->id); + BKE_id_blend_write(writer, &volume->id); /* direct data */ BLO_write_pointer_array(writer, volume->totcol, volume->mat); @@ -3410,7 +3354,7 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const { if (simulation->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); - write_iddata(writer, &simulation->id); + BKE_id_blend_write(writer, &simulation->id); if (simulation->adt) { BKE_animdata_blend_write(writer, simulation->adt); @@ -3490,7 +3434,7 @@ static void write_libraries(WriteData *wd, Main *main) BlendWriter writer = {wd}; writestruct(wd, ID_LI, Library, 1, main->curlib); - write_iddata(&writer, &main->curlib->id); + BKE_id_blend_write(&writer, &main->curlib->id); if (main->curlib->packedfile) { PackedFile *pf = main->curlib->packedfile; @@ -3782,9 +3726,6 @@ static bool write_file_handle(Main *mainvar, case ID_TE: write_texture(&writer, (Tex *)id_buffer, id); break; - case ID_ME: - write_mesh(&writer, (Mesh *)id_buffer, id); - break; case ID_PA: write_particlesettings(&writer, (ParticleSettings *)id_buffer, id); break; @@ -3821,6 +3762,9 @@ static bool write_file_handle(Main *mainvar, case ID_SIM: write_simulation(&writer, (Simulation *)id_buffer, id); break; + case ID_ME: + /* Do nothing, handled in IDTypeInfo callback. */ + break; case ID_LI: /* Do nothing, handled below - and should never be reached. */ BLI_assert(0); |