Refactor readfile's liblink code.

Liblink specific ID type function was so far running a loop over all IDs
of relevant type, unlike almost any other 'ID-callback-like' functions
in Blender, which usually let the looping controll to calling code.

The latter approach is more convinient when one want to add generic
(i.e. type-agnostic) code, since it typically only has to change code in
one place (caller function) instead of tens of places (all the callback
functions).

This commit also changes/sanitizes a few things that had nothing to do
in main liblink code, like mesh conversion from tessfaces to polys
(which can be done in after-linking versionning code), or scenes' cycles
detection/check regarding background 'set' scenes.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D6727
This commit is contained in:
Bastien Montagne 2020-02-05 16:18:17 +01:00
parent c35d6b1854
commit b841167ee3
3 changed files with 796 additions and 1043 deletions

File diff suppressed because it is too large Load Diff

View File

@ -70,6 +70,7 @@
#include "BKE_customdata.h"
#include "BKE_fcurve.h"
#include "BKE_freestyle.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_key.h"
#include "BKE_library.h"
@ -1543,21 +1544,44 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
}
}
{
/* Update all ruler layers to set new flag. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
bGPdata *gpd = scene->gpd;
if (gpd == NULL) {
continue;
}
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if (STREQ(gpl->info, "RulerData3D")) {
gpl->flag |= GP_LAYER_IS_RULER;
break;
}
/* Update all ruler layers to set new flag. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
bGPdata *gpd = scene->gpd;
if (gpd == NULL) {
continue;
}
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if (STREQ(gpl->info, "RulerData3D")) {
gpl->flag |= GP_LAYER_IS_RULER;
break;
}
}
}
/* This versionning could probably be done only on earlier versions, not sure however
* which exact version fully deprecated tessfaces, so think we can keep that one here, no
* harm to be expected anyway for being over-conservative. */
for (Mesh *me = bmain->meshes.first; me != NULL; me = me->id.next) {
/*check if we need to convert mfaces to mpolys*/
if (me->totface && !me->totpoly) {
/* temporarily switch main so that reading from
* external CustomData works */
Main *gmain = G_MAIN;
G_MAIN = bmain;
BKE_mesh_do_versions_convert_mfaces_to_mpolys(me);
G_MAIN = gmain;
}
/* Deprecated, only kept for conversion. */
BKE_mesh_tessface_clear(me);
/* Moved from do_versions because we need updated polygons for calculating normals. */
if (MAIN_VERSION_OLDER(bmain, 256, 6)) {
BKE_mesh_calc_normals(me);
}
}
}
/**

View File

@ -2155,6 +2155,7 @@ typedef enum eVGroupSelect {
#define SCE_NLA_EDIT_ON (1 << 2)
#define SCE_FRAME_DROP (1 << 3)
#define SCE_KEYS_NO_SELONLY (1 << 4)
#define SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK (1 << 5)
/* return flag BKE_scene_base_iter_next functions */
/* #define F_ERROR -1 */ /* UNUSED */