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:
authorBastien Montagne <montagne29@wanadoo.fr>2015-10-20 15:44:57 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-10-20 15:44:57 +0300
commite5916187e808c1c22229589d103f4de4d4411b5b (patch)
treed2424f858d51a976d21d2e9339f7d53aa9ddeee4 /source/blender/blenkernel/intern
parentdcb56d79a87966d93fe0509e64ab51eb90c1d486 (diff)
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to create void placeholders for them. That way, you can work on your file, save it, and find again your missing data once lib becomes available again. Or you can edit missing lib's path (in Outliner), save and reload the file, and you are done. Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon. Future plans are also to be able to relocate missing libs and reload them at runtime. Code notes: - Placeholder ID is just a regular datablock of same type as expected linked one, with 'default' data, and a LIB_MISSING bitflag set. - To allow creation of such datablocks, creation of datablocks in BKE was split in two step: + Allocation of memory itself. + Setting of all internal data to default values. See also the design task (T43351). Reviewed by @campbellbarton, thanks a bunch! Differential Revision: https://developer.blender.org/D1394
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/brush.c18
-rw-r--r--source/blender/blenkernel/intern/camera.c15
-rw-r--r--source/blender/blenkernel/intern/curve.c20
-rw-r--r--source/blender/blenkernel/intern/font.c20
-rw-r--r--source/blender/blenkernel/intern/lamp.c18
-rw-r--r--source/blender/blenkernel/intern/lattice.c19
-rw-r--r--source/blender/blenkernel/intern/library.c124
-rw-r--r--source/blender/blenkernel/intern/linestyle.c6
-rw-r--r--source/blender/blenkernel/intern/material.c8
-rw-r--r--source/blender/blenkernel/intern/mball.c19
-rw-r--r--source/blender/blenkernel/intern/mesh.c17
-rw-r--r--source/blender/blenkernel/intern/node.c5
-rw-r--r--source/blender/blenkernel/intern/object.c31
-rw-r--r--source/blender/blenkernel/intern/scene.c15
-rw-r--r--source/blender/blenkernel/intern/speaker.c15
-rw-r--r--source/blender/blenkernel/intern/text.c19
-rw-r--r--source/blender/blenkernel/intern/texture.c2
-rw-r--r--source/blender/blenkernel/intern/world.c16
18 files changed, 312 insertions, 75 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index e0ffd830804..c2a66adbf92 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -131,11 +131,9 @@ static void brush_defaults(Brush *brush)
/* Datablock add/copy/free/make_local */
-Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
+void BKE_brush_init(Brush *brush)
{
- Brush *brush;
-
- brush = BKE_libblock_alloc(bmain, ID_BR, name);
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));
/* enable fake user by default */
brush->id.flag |= LIB_FAKEUSER;
@@ -143,10 +141,20 @@ Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
brush_defaults(brush);
brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
- brush->ob_mode = ob_mode;
/* the default alpha falloff curve */
BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
+}
+
+Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
+{
+ Brush *brush;
+
+ brush = BKE_libblock_alloc(bmain, ID_BR, name);
+
+ BKE_brush_init(brush);
+
+ brush->ob_mode = ob_mode;
return brush;
}
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 7e043df2808..46b74c58965 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -57,11 +57,9 @@
/****************************** Camera Datablock *****************************/
-void *BKE_camera_add(Main *bmain, const char *name)
+void BKE_camera_init(Camera *cam)
{
- Camera *cam;
-
- cam = BKE_libblock_alloc(bmain, ID_CA, name);
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cam, id));
cam->lens = 35.0f;
cam->sensor_x = DEFAULT_SENSOR_WIDTH;
@@ -78,6 +76,15 @@ void *BKE_camera_add(Main *bmain, const char *name)
/* stereoscopy 3d */
cam->stereo.interocular_distance = 0.065f;
cam->stereo.convergence_distance = 30.f * 0.065f;
+}
+
+void *BKE_camera_add(Main *bmain, const char *name)
+{
+ Camera *cam;
+
+ cam = BKE_libblock_alloc(bmain, ID_CA, name);
+
+ BKE_camera_init(cam);
return cam;
}
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 8d7d62be7e4..3e0bdbe31af 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -161,15 +161,14 @@ void BKE_curve_free(Curve *cu)
MEM_freeN(cu->tb);
}
-Curve *BKE_curve_add(Main *bmain, const char *name, int type)
+void BKE_curve_init(Curve *cu)
{
- Curve *cu;
+ /* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cu, id)); */ /* cu->type is already initialized... */
- cu = BKE_libblock_alloc(bmain, ID_CU, name);
copy_v3_fl(cu->size, 1.0f);
cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS;
cu->pathlen = 100;
- cu->resolu = cu->resolv = (type == OB_SURF) ? 4 : 12;
+ cu->resolu = cu->resolv = (cu->type == OB_SURF) ? 4 : 12;
cu->width = 1.0;
cu->wordspace = 1.0;
cu->spacing = cu->linedist = 1.0;
@@ -179,7 +178,6 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
cu->smallcaps_scale = 0.75f;
/* XXX: this one seems to be the best one in most cases, at least for curve deform... */
cu->twist_mode = CU_TWIST_MINIMUM;
- cu->type = type;
cu->bevfac1 = 0.0f;
cu->bevfac2 = 1.0f;
cu->bevfac1_mapping = CU_BEVFAC_MAP_RESOLU;
@@ -187,7 +185,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
cu->bb = BKE_boundbox_alloc_unit();
- if (type == OB_FONT) {
+ if (cu->type == OB_FONT) {
cu->vfont = cu->vfontb = cu->vfonti = cu->vfontbi = BKE_vfont_builtin_get();
cu->vfont->id.us += 4;
cu->str = MEM_mallocN(12, "str");
@@ -198,6 +196,16 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "textbox");
cu->tb[0].w = cu->tb[0].h = 0.0;
}
+}
+
+Curve *BKE_curve_add(Main *bmain, const char *name, int type)
+{
+ Curve *cu;
+
+ cu = BKE_libblock_alloc(bmain, ID_CU, name);
+ cu->type = type;
+
+ BKE_curve_init(cu);
return cu;
}
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index e3ebb7f908c..b12e16d9502 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -203,6 +203,26 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
return vfont->data;
}
+/* Bad naming actually in this case... */
+void BKE_vfont_init(VFont *vfont)
+{
+ PackedFile *pf = get_builtin_packedfile();
+
+ if (pf) {
+ VFontData *vfd;
+
+ vfd = BLI_vfontdata_from_freetypefont(pf);
+ if (vfd) {
+ vfont->data = vfd;
+
+ BLI_strncpy(vfont->name, FO_BUILTIN_NAME, sizeof(vfont->name));
+ }
+
+ /* Free the packed file */
+ freePackedFile(pf);
+ }
+}
+
VFont *BKE_vfont_load(Main *bmain, const char *filepath)
{
char filename[FILE_MAXFILE];
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 44e35c645de..8e350896eb8 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -53,12 +53,10 @@
#include "BKE_main.h"
#include "BKE_node.h"
-Lamp *BKE_lamp_add(Main *bmain, const char *name)
+void BKE_lamp_init(Lamp *la)
{
- Lamp *la;
-
- la = BKE_libblock_alloc(bmain, ID_LA, name);
-
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(la, id));
+
la->r = la->g = la->b = la->k = 1.0f;
la->haint = la->energy = 1.0f;
la->dist = 25.0f;
@@ -100,6 +98,16 @@ Lamp *BKE_lamp_add(Main *bmain, const char *name)
la->shadow_frustum_size = 10.0f;
curvemapping_initialize(la->curfalloff);
+}
+
+Lamp *BKE_lamp_add(Main *bmain, const char *name)
+{
+ Lamp *la;
+
+ la = BKE_libblock_alloc(bmain, ID_LA, name);
+
+ BKE_lamp_init(la);
+
return la;
}
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 009e1d20328..0e5228a6db4 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -251,12 +251,10 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
MEM_freeN(vertexCos);
}
-Lattice *BKE_lattice_add(Main *bmain, const char *name)
+void BKE_lattice_init(Lattice *lt)
{
- Lattice *lt;
-
- lt = BKE_libblock_alloc(bmain, ID_LT, name);
-
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(lt, id));
+
lt->flag = LT_GRID;
lt->typeu = lt->typev = lt->typew = KEY_BSPLINE;
@@ -264,7 +262,16 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name)
lt->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */
BKE_lattice_resize(lt, 2, 2, 2, NULL); /* creates a uniform lattice */
lt->actbp = LT_ACTBP_NONE;
-
+}
+
+Lattice *BKE_lattice_add(Main *bmain, const char *name)
+{
+ Lattice *lt;
+
+ lt = BKE_libblock_alloc(bmain, ID_LT, name);
+
+ BKE_lattice_init(lt);
+
return lt;
}
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index d6b2a3cea29..f8f92825479 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -59,6 +59,7 @@
#include "DNA_movieclip_types.h"
#include "DNA_mask_types.h"
#include "DNA_node_types.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_speaker_types.h"
@@ -648,7 +649,7 @@ int set_listbasepointers(Main *main, ListBase **lb)
* Allocates and returns memory of the right size for the specified block type,
* initialized to zero.
*/
-static ID *alloc_libblock_notest(short type)
+void *BKE_libblock_alloc_notest(short type)
{
ID *id = NULL;
@@ -770,7 +771,7 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name)
ID *id = NULL;
ListBase *lb = which_libbase(bmain, type);
- id = alloc_libblock_notest(type);
+ id = BKE_libblock_alloc_notest(type);
if (id) {
BKE_main_lock(bmain);
BLI_addtail(lb, id);
@@ -785,6 +786,121 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name)
return id;
}
+/**
+ * Initialize an ID of given type, such that it has valid 'empty' data.
+ * ID is assumed to be just calloc'ed.
+ */
+void BKE_libblock_init_empty(ID *id)
+{
+ /* Note that only ID types that are not valid when filled of zero should have a callback here. */
+ switch (GS(id->name)) {
+ case ID_SCE:
+ BKE_scene_init((Scene *)id);
+ break;
+ case ID_LI:
+ /* Nothing to do. */
+ break;
+ case ID_OB:
+ {
+ Object *ob = (Object *)id;
+ ob->type = OB_EMPTY;
+ BKE_object_init(ob);
+ break;
+ }
+ case ID_ME:
+ BKE_mesh_init((Mesh *)id);
+ break;
+ case ID_CU:
+ BKE_curve_init((Curve *)id);
+ break;
+ case ID_MB:
+ BKE_mball_init((MetaBall *)id);
+ break;
+ case ID_MA:
+ BKE_material_init((Material *)id);
+ break;
+ case ID_TE:
+ BKE_texture_default((Tex *)id);
+ break;
+ case ID_IM:
+ /* Image is a bit complicated, for now assume NULLified im is OK. */
+ break;
+ case ID_LT:
+ BKE_lattice_init((Lattice *)id);
+ break;
+ case ID_LA:
+ BKE_lamp_init((Lamp *)id);
+ break;
+ case ID_SPK:
+ BKE_speaker_init((Speaker *)id);
+ break;
+ case ID_CA:
+ BKE_camera_init((Camera *)id);
+ break;
+ case ID_IP:
+ /* Should not be needed - animation from lib pre-2.5 is broken anyway. */
+ BLI_assert(0);
+ break;
+ case ID_KE:
+ /* Shapekeys are a complex topic too - they depend on their 'user' data type...
+ * They are not linkable, though, so it should never reach here anyway. */
+ BLI_assert(0);
+ break;
+ case ID_WO:
+ BKE_world_init((World *)id);
+ break;
+ case ID_SCR:
+ /* Nothing to do. */
+ break;
+ case ID_VF:
+ BKE_vfont_init((VFont *)id);
+ break;
+ case ID_TXT:
+ BKE_text_init((Text *)id);
+ break;
+ case ID_SCRIPT:
+ BLI_assert(0);
+ break;
+ case ID_SO:
+ /* Another fuzzy case, think NULLified content is OK here... */
+ break;
+ case ID_GR:
+ /* Nothing to do. */
+ break;
+ case ID_AR:
+ /* Nothing to do. */
+ break;
+ case ID_AC:
+ /* Nothing to do. */
+ break;
+ case ID_NT:
+ ntreeInitDefault((bNodeTree *)id);
+ break;
+ case ID_BR:
+ BKE_brush_init((Brush *)id);
+ break;
+ case ID_PA:
+ /* Nothing to do. */
+ break;
+ case ID_PC:
+ /* Nothing to do. */
+ break;
+ case ID_WM:
+ /* We should never reach this. */
+ BLI_assert(0);
+ break;
+ case ID_GD:
+ /* Nothing to do. */
+ break;
+ case ID_MSK:
+ /* Nothing to do. */
+ break;
+ case ID_LS:
+ BKE_linestyle_init((FreestyleLineStyle *)id);
+ break;
+ }
+}
+
/* by spec, animdata is first item after ID */
/* and, trust that BKE_animdata_from_id() will only find AnimData for valid ID-types */
static void id_copy_animdata(ID *id, const bool do_action)
@@ -838,7 +954,7 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action)
ID *idn;
size_t idn_len;
- idn = alloc_libblock_notest(GS(id->name));
+ idn = BKE_libblock_alloc_notest(GS(id->name));
assert(idn != NULL);
BLI_strncpy(idn->name, id->name, sizeof(idn->name));
@@ -1720,7 +1836,7 @@ void rename_id(ID *id, const char *name)
*/
void name_uiprefix_id(char *name, const ID *id)
{
- name[0] = id->lib ? 'L' : ' ';
+ name[0] = id->lib ? (ID_MISSING(id) ? 'M' : 'L') : ' ';
name[1] = (id->flag & LIB_FAKEUSER) ? 'F' : ((id->us == 0) ? '0' : ' ');
name[2] = ' ';
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index ac2c4e35dce..93d2b549fee 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -80,8 +80,10 @@ static const char *modifier_name[LS_MODIFIER_NUM] = {
"3D Curvature",
};
-static void default_linestyle_settings(FreestyleLineStyle *linestyle)
+void BKE_linestyle_init(FreestyleLineStyle *linestyle)
{
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(linestyle, id));
+
linestyle->panel = LS_PANEL_STROKES;
linestyle->r = linestyle->g = linestyle->b = 0.0f;
linestyle->alpha = 1.0f;
@@ -118,7 +120,7 @@ FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name)
linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(bmain, ID_LS, name);
- default_linestyle_settings(linestyle);
+ BKE_linestyle_init(linestyle);
return linestyle;
}
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 3e7e98b4a1d..a69b5fd87b5 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -78,7 +78,7 @@ Material defmaterial;
/* called on startup, creator.c */
void init_def_material(void)
{
- init_material(&defmaterial);
+ BKE_material_init(&defmaterial);
}
/* not material itself */
@@ -122,8 +122,10 @@ void BKE_material_free_ex(Material *ma, bool do_id_user)
GPU_material_free(&ma->gpumaterial);
}
-void init_material(Material *ma)
+void BKE_material_init(Material *ma)
{
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ma, id));
+
ma->r = ma->g = ma->b = ma->ref = 0.8;
ma->specr = ma->specg = ma->specb = 1.0;
ma->mirr = ma->mirg = ma->mirb = 1.0;
@@ -221,7 +223,7 @@ Material *BKE_material_add(Main *bmain, const char *name)
ma = BKE_libblock_alloc(bmain, ID_MA, name);
- init_material(ma);
+ BKE_material_init(ma);
return ma;
}
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index c09cd1aabdc..bd9fd331584 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -91,19 +91,26 @@ void BKE_mball_free(MetaBall *mb)
if (mb->disp.first) BKE_displist_free(&mb->disp);
}
-MetaBall *BKE_mball_add(Main *bmain, const char *name)
+void BKE_mball_init(MetaBall *mb)
{
- MetaBall *mb;
-
- mb = BKE_libblock_alloc(bmain, ID_MB, name);
-
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(mb, id));
+
mb->size[0] = mb->size[1] = mb->size[2] = 1.0;
mb->texflag = MB_AUTOSPACE;
mb->wiresize = 0.4f;
mb->rendersize = 0.2f;
mb->thresh = 0.6f;
-
+}
+
+MetaBall *BKE_mball_add(Main *bmain, const char *name)
+{
+ MetaBall *mb;
+
+ mb = BKE_libblock_alloc(bmain, ID_MB, name);
+
+ BKE_mball_init(mb);
+
return mb;
}
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index b948ed56c56..318040db2be 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -490,12 +490,10 @@ static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
mesh->totface = 0;
}
-Mesh *BKE_mesh_add(Main *bmain, const char *name)
+void BKE_mesh_init(Mesh *me)
{
- Mesh *me;
-
- me = BKE_libblock_alloc(bmain, ID_ME, name);
-
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(me, id));
+
me->size[0] = me->size[1] = me->size[2] = 1.0;
me->smoothresh = 30;
me->texflag = ME_AUTOSPACE;
@@ -511,6 +509,15 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
CustomData_reset(&me->fdata);
CustomData_reset(&me->pdata);
CustomData_reset(&me->ldata);
+}
+
+Mesh *BKE_mesh_add(Main *bmain, const char *name)
+{
+ Mesh *me;
+
+ me = BKE_libblock_alloc(bmain, ID_ME, name);
+
+ BKE_mesh_init(me);
return me;
}
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index c656931d18b..d3460dcb481 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -1151,6 +1151,11 @@ void nodeDetachNode(struct bNode *node)
}
}
+void ntreeInitDefault(bNodeTree *ntree)
+{
+ ntree_set_typeinfo(ntree, NULL);
+}
+
bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname)
{
bNodeTree *ntree;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index e5f826f670d..ffb614fdf11 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -972,19 +972,10 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
}
}
-/* more general add: creates minimum required data, but without vertices etc. */
-Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
+void BKE_object_init(Object *ob)
{
- Object *ob;
+ /* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ob, id)); */ /* ob->type is already initialized... */
- if (!name)
- name = get_obdata_defname(type);
-
- ob = BKE_libblock_alloc(bmain, ID_OB, name);
-
- /* default object vars */
- ob->type = type;
-
ob->col[0] = ob->col[1] = ob->col[2] = 1.0;
ob->col[3] = 1.0;
@@ -1012,7 +1003,7 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
ob->empty_drawtype = OB_PLAINAXES;
ob->empty_drawsize = 1.0;
- if (ELEM(type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
+ if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
ob->trackflag = OB_NEGZ;
ob->upflag = OB_POSY;
}
@@ -1053,6 +1044,22 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
/* Animation Visualization defaults */
animviz_settings_init(&ob->avs);
+}
+
+/* more general add: creates minimum required data, but without vertices etc. */
+Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
+{
+ Object *ob;
+
+ if (!name)
+ name = get_obdata_defname(type);
+
+ ob = BKE_libblock_alloc(bmain, ID_OB, name);
+
+ /* default object vars */
+ ob->type = type;
+
+ BKE_object_init(ob);
return ob;
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 1ccc213006a..cc656775c14 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -464,15 +464,15 @@ void BKE_scene_free(Scene *sce)
BKE_previewimg_free(&sce->preview);
}
-Scene *BKE_scene_add(Main *bmain, const char *name)
+void BKE_scene_init(Scene *sce)
{
- Scene *sce;
ParticleEditSettings *pset;
int a;
const char *colorspace_name;
SceneRenderView *srv;
- sce = BKE_libblock_alloc(bmain, ID_SCE, name);
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(sce, id));
+
sce->lay = sce->layact = 1;
sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE;
@@ -743,6 +743,15 @@ Scene *BKE_scene_add(Main *bmain, const char *name)
copy_v2_fl2(sce->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
sce->preview = NULL;
+}
+
+Scene *BKE_scene_add(Main *bmain, const char *name)
+{
+ Scene *sce;
+
+ sce = BKE_libblock_alloc(bmain, ID_SCE, name);
+
+ BKE_scene_init(sce);
return sce;
}
diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c
index 7a800555144..30296c7813c 100644
--- a/source/blender/blenkernel/intern/speaker.c
+++ b/source/blender/blenkernel/intern/speaker.c
@@ -37,11 +37,9 @@
#include "BKE_main.h"
#include "BKE_speaker.h"
-void *BKE_speaker_add(Main *bmain, const char *name)
+void BKE_speaker_init(Speaker *spk)
{
- Speaker *spk;
-
- spk = BKE_libblock_alloc(bmain, ID_SPK, name);
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(spk, id));
spk->attenuation = 1.0f;
spk->cone_angle_inner = 360.0f;
@@ -55,6 +53,15 @@ void *BKE_speaker_add(Main *bmain, const char *name)
spk->volume = 1.0f;
spk->volume_max = 1.0f;
spk->volume_min = 0.0f;
+}
+
+void *BKE_speaker_add(Main *bmain, const char *name)
+{
+ Speaker *spk;
+
+ spk = BKE_libblock_alloc(bmain, ID_SPK, name);
+
+ BKE_speaker_init(spk);
return spk;
}
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 77d6043d6f3..6e41ed3f9a6 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -171,14 +171,12 @@ void BKE_text_free(Text *text)
#endif
}
-Text *BKE_text_add(Main *bmain, const char *name)
+void BKE_text_init(Text *ta)
{
- Text *ta;
TextLine *tmp;
-
- ta = BKE_libblock_alloc(bmain, ID_TXT, name);
- ta->id.us = 1;
-
+
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ta, id));
+
ta->name = NULL;
init_undo_text(ta);
@@ -206,6 +204,15 @@ Text *BKE_text_add(Main *bmain, const char *name)
ta->curc = 0;
ta->sell = ta->lines.first;
ta->selc = 0;
+}
+
+Text *BKE_text_add(Main *bmain, const char *name)
+{
+ Text *ta;
+
+ ta = BKE_libblock_alloc(bmain, ID_TXT, name);
+
+ BKE_text_init(ta);
return ta;
}
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 88a412d5e95..463ca250ad5 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -580,6 +580,8 @@ void BKE_texture_free(Tex *tex)
void BKE_texture_default(Tex *tex)
{
+ /* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(tex, id)); */ /* Not here, can be called with some pointers set. :/ */
+
tex->type = TEX_IMAGE;
tex->ima = NULL;
tex->stype = 0;
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index e4736b1f54c..88c98b6d9d8 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -31,6 +31,7 @@
#include <string.h>
+#include <stdlib.h>
#include <math.h>
#include "MEM_guardedalloc.h"
@@ -83,12 +84,10 @@ void BKE_world_free(World *wrld)
BKE_world_free_ex(wrld, true);
}
-World *add_world(Main *bmain, const char *name)
+void BKE_world_init(World *wrld)
{
- World *wrld;
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(wrld, id));
- wrld = BKE_libblock_alloc(bmain, ID_WO, name);
-
wrld->horr = 0.05f;
wrld->horg = 0.05f;
wrld->horb = 0.05f;
@@ -113,6 +112,15 @@ World *add_world(Main *bmain, const char *name)
wrld->preview = NULL;
wrld->miststa = 5.0f;
wrld->mistdist = 25.0f;
+}
+
+World *add_world(Main *bmain, const char *name)
+{
+ World *wrld;
+
+ wrld = BKE_libblock_alloc(bmain, ID_WO, name);
+
+ BKE_world_init(wrld);
return wrld;
}