DNA: use defaults for Object, Mesh, Material
This commit is contained in:
parent
b24fdaed65
commit
9f859528e9
|
@ -110,7 +110,7 @@ typedef enum eObjectVisibilityResult {
|
|||
|
||||
int BKE_object_visibility(const struct Object *ob, const int dag_eval_mode);
|
||||
|
||||
void BKE_object_init(struct Object *ob);
|
||||
void BKE_object_init(struct Object *ob, const short ob_type);
|
||||
struct Object *BKE_object_add_only_object(struct Main *bmain, int type, const char *name)
|
||||
ATTR_NONNULL(1) ATTR_RETURNS_NONNULL;
|
||||
struct Object *BKE_object_add(struct Main *bmain,
|
||||
|
|
|
@ -1264,8 +1264,7 @@ void BKE_libblock_init_empty(ID *id)
|
|||
break;
|
||||
case ID_OB: {
|
||||
Object *ob = (Object *)id;
|
||||
ob->type = OB_EMPTY;
|
||||
BKE_object_init(ob);
|
||||
BKE_object_init(ob, OB_EMPTY);
|
||||
break;
|
||||
}
|
||||
case ID_ME:
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "DNA_node_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_defaults.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_listbase.h"
|
||||
|
@ -136,20 +137,7 @@ void BKE_material_init(Material *ma)
|
|||
{
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ma, id));
|
||||
|
||||
ma->r = ma->g = ma->b = 0.8;
|
||||
ma->specr = ma->specg = ma->specb = 1.0;
|
||||
ma->a = 1.0f;
|
||||
ma->spec = 0.5;
|
||||
|
||||
ma->roughness = 0.4f;
|
||||
|
||||
ma->pr_type = MA_SPHERE;
|
||||
|
||||
ma->preview = NULL;
|
||||
|
||||
ma->alpha_threshold = 0.5f;
|
||||
|
||||
ma->blend_shadow = MA_BS_SOLID;
|
||||
MEMCPY_STRUCT_AFTER(ma, DNA_struct_default_get(Material), id);
|
||||
}
|
||||
|
||||
void BKE_material_gpencil_init(Material *ma)
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "DNA_key_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_defaults.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_bitmap.h"
|
||||
|
@ -533,10 +534,7 @@ void BKE_mesh_init(Mesh *me)
|
|||
{
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(me, id));
|
||||
|
||||
me->size[0] = me->size[1] = me->size[2] = 1.0;
|
||||
me->smoothresh = DEG2RADF(30);
|
||||
me->texflag = ME_AUTOSPACE;
|
||||
me->remesh_voxel_size = 0.1f;
|
||||
MEMCPY_STRUCT_AFTER(me, DNA_struct_default_get(Mesh), id);
|
||||
|
||||
CustomData_reset(&me->vdata);
|
||||
CustomData_reset(&me->edata);
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "DNA_object_types.h"
|
||||
#include "DNA_lightprobe_types.h"
|
||||
#include "DNA_rigidbody_types.h"
|
||||
#include "DNA_defaults.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_math.h"
|
||||
|
@ -803,38 +804,16 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
|
|||
}
|
||||
}
|
||||
|
||||
void BKE_object_init(Object *ob)
|
||||
void BKE_object_init(Object *ob, const short ob_type)
|
||||
{
|
||||
/* BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ob, id)); */ /* ob->type is already initialized... */
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ob, id));
|
||||
|
||||
copy_v4_fl(ob->color, 1.0f);
|
||||
MEMCPY_STRUCT_AFTER(ob, DNA_struct_default_get(Object), id);
|
||||
|
||||
ob->scale[0] = ob->scale[1] = ob->scale[2] = 1.0;
|
||||
ob->dscale[0] = ob->dscale[1] = ob->dscale[2] = 1.0;
|
||||
ob->type = ob_type;
|
||||
|
||||
/* objects should default to having Euler XYZ rotations,
|
||||
* but rotations default to quaternions
|
||||
*/
|
||||
ob->rotmode = ROT_MODE_EUL;
|
||||
|
||||
unit_axis_angle(ob->rotAxis, &ob->rotAngle);
|
||||
unit_axis_angle(ob->drotAxis, &ob->drotAngle);
|
||||
|
||||
unit_qt(ob->quat);
|
||||
unit_qt(ob->dquat);
|
||||
|
||||
/* rotation locks should be 4D for 4 component rotations by default... */
|
||||
ob->protectflag = OB_LOCK_ROT4D;
|
||||
|
||||
unit_m4(ob->constinv);
|
||||
unit_m4(ob->parentinv);
|
||||
unit_m4(ob->obmat);
|
||||
ob->dt = OB_TEXTURE;
|
||||
ob->empty_drawtype = OB_PLAINAXES;
|
||||
ob->empty_drawsize = 1.0;
|
||||
ob->empty_image_depth = OB_EMPTY_IMAGE_DEPTH_DEFAULT;
|
||||
if (ob->type == OB_EMPTY) {
|
||||
copy_v2_fl(ob->ima_ofs, -0.5f);
|
||||
if (ob->type != OB_EMPTY) {
|
||||
zero_v2(ob->ima_ofs);
|
||||
}
|
||||
|
||||
if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
|
||||
|
@ -846,18 +825,6 @@ void BKE_object_init(Object *ob)
|
|||
ob->upflag = OB_POSZ;
|
||||
}
|
||||
|
||||
ob->instance_faces_scale = 1.0;
|
||||
|
||||
ob->col_group = 0x01;
|
||||
ob->col_mask = 0xffff;
|
||||
ob->preview = NULL;
|
||||
ob->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
|
||||
|
||||
/* NT fluid sim defaults */
|
||||
ob->fluidsimSettings = NULL;
|
||||
|
||||
BLI_listbase_clear(&ob->pc_ids);
|
||||
|
||||
/* Animation Visualization defaults */
|
||||
animviz_settings_init(&ob->avs);
|
||||
}
|
||||
|
@ -877,9 +844,7 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
|
|||
id_us_min(&ob->id);
|
||||
|
||||
/* default object vars */
|
||||
ob->type = type;
|
||||
|
||||
BKE_object_init(ob);
|
||||
BKE_object_init(ob, type);
|
||||
|
||||
return ob;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \ingroup DNA
|
||||
*/
|
||||
|
||||
#ifndef __DNA_MATERIAL_DEFAULTS_H__
|
||||
#define __DNA_MATERIAL_DEFAULTS_H__
|
||||
|
||||
/* Struct members on own line. */
|
||||
/* clang-format off */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Material Struct
|
||||
* \{ */
|
||||
|
||||
#define _DNA_DEFAULT_Material \
|
||||
{ \
|
||||
.r = 0.8, \
|
||||
.g = 0.8, \
|
||||
.b = 0.8, \
|
||||
.specr = 1.0, \
|
||||
.specg = 1.0, \
|
||||
.specb = 1.0, \
|
||||
.a = 1.0f, \
|
||||
.spec = 0.5, \
|
||||
\
|
||||
.roughness = 0.4f, \
|
||||
\
|
||||
.pr_type = MA_SPHERE, \
|
||||
\
|
||||
.alpha_threshold = 0.5f, \
|
||||
\
|
||||
.blend_shadow = MA_BS_SOLID, \
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* __DNA_MATERIAL_DEFAULTS_H__ */
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \ingroup DNA
|
||||
*/
|
||||
|
||||
#ifndef __DNA_MESH_DEFAULTS_H__
|
||||
#define __DNA_MESH_DEFAULTS_H__
|
||||
|
||||
/* Struct members on own line. */
|
||||
/* clang-format off */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Mesh Struct
|
||||
* \{ */
|
||||
|
||||
#define _DNA_DEFAULT_Mesh \
|
||||
{ \
|
||||
.size = {1.0f, 1.0f, 1.0f}, \
|
||||
.smoothresh = DEG2RADF(30), \
|
||||
.texflag = ME_AUTOSPACE, \
|
||||
.remesh_voxel_size = 0.1f, \
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* __DNA_MESH_DEFAULTS_H__ */
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \ingroup DNA
|
||||
*/
|
||||
|
||||
#ifndef __DNA_OBJECT_DEFAULTS_H__
|
||||
#define __DNA_OBJECT_DEFAULTS_H__
|
||||
|
||||
#include "DNA_vec_defaults.h"
|
||||
|
||||
/* Struct members on own line. */
|
||||
/* clang-format off */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Object Struct
|
||||
* \{ */
|
||||
|
||||
#define _DNA_DEFAULT_Object \
|
||||
{ \
|
||||
/* Type is not very meaningful as a default, normally changed. */ \
|
||||
.type = OB_EMPTY, \
|
||||
.color = {1, 1, 1, 1}, \
|
||||
\
|
||||
.constinv = _DNA_DEFAULT_UNIT_M4, \
|
||||
.parentinv = _DNA_DEFAULT_UNIT_M4, \
|
||||
.obmat = _DNA_DEFAULT_UNIT_M4, \
|
||||
\
|
||||
.scale = {1, 1, 1}, \
|
||||
.dscale = {1, 1, 1}, \
|
||||
/* Objects should default to having Euler XYZ rotations, \
|
||||
* but rotations default to quaternions. */ \
|
||||
.rotmode = ROT_MODE_EUL, \
|
||||
/** See #unit_axis_angle. */ \
|
||||
.rotAxis = {0, 1, 0}, \
|
||||
.rotAngle = 0, \
|
||||
.drotAxis = {0, 1, 0}, \
|
||||
.drotAngle = 0, \
|
||||
.quat = _DNA_DEFAULT_UNIT_QT, \
|
||||
.dquat = _DNA_DEFAULT_UNIT_QT, \
|
||||
.protectflag = OB_LOCK_ROT4D, \
|
||||
\
|
||||
.dt = OB_TEXTURE, \
|
||||
\
|
||||
.empty_drawtype = OB_PLAINAXES, \
|
||||
.empty_drawsize = 1.0, \
|
||||
.empty_image_depth = OB_EMPTY_IMAGE_DEPTH_DEFAULT, \
|
||||
.ima_ofs = {-0.5, -0.5}, \
|
||||
\
|
||||
.instance_faces_scale = 1, \
|
||||
.col_group = 0x01, \
|
||||
.col_mask = 0xffff, \
|
||||
.preview = NULL, \
|
||||
.duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER, \
|
||||
.fluidsimSettings = NULL, \
|
||||
.pc_ids = {NULL, NULL}, \
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* __DNA_OBJECT_DEFAULTS_H__ */
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \ingroup DNA
|
||||
*/
|
||||
|
||||
#ifndef __DNA_VEC_DEFAULTS_H__
|
||||
#define __DNA_VEC_DEFAULTS_H__
|
||||
|
||||
/* Struct members on own line. */
|
||||
/* clang-format off */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Generic Defaults
|
||||
* \{ */
|
||||
|
||||
/** See #unit_m4. */
|
||||
#define _DNA_DEFAULT_UNIT_M4 \
|
||||
{ \
|
||||
{1, 0, 0, 0}, \
|
||||
{0, 1, 0, 0}, \
|
||||
{0, 0, 1, 0}, \
|
||||
{0, 0, 0, 1}, \
|
||||
}
|
||||
|
||||
#define _DNA_DEFAULT_UNIT_M3 \
|
||||
{ \
|
||||
{1, 0, 0}, \
|
||||
{0, 1, 0}, \
|
||||
{0, 0, 1}, \
|
||||
}
|
||||
|
||||
/** See #unit_qt. */
|
||||
#define _DNA_DEFAULT_UNIT_QT \
|
||||
{1, 0, 0, 0}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* __DNA_VEC_DEFAULTS_H__ */
|
|
@ -128,7 +128,11 @@ set(SRC
|
|||
../../blenlib/intern/hash_mm2a.c
|
||||
../../blenlib/intern/listbase.c
|
||||
|
||||
../DNA_material_defaults.h
|
||||
../DNA_mesh_defaults.h
|
||||
../DNA_object_defaults.h
|
||||
../DNA_scene_defaults.h
|
||||
../DNA_vec_defaults.h
|
||||
../DNA_view3d_defaults.h
|
||||
)
|
||||
|
||||
|
|
|
@ -53,13 +53,35 @@
|
|||
#include "BLI_math.h"
|
||||
|
||||
#include "DNA_defaults.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "DNA_material_defaults.h"
|
||||
#include "DNA_mesh_defaults.h"
|
||||
#include "DNA_object_defaults.h"
|
||||
#include "DNA_scene_defaults.h"
|
||||
|
||||
const Scene DNA_DEFAULT_Scene = _DNA_DEFAULT_Scene;
|
||||
const ToolSettings DNA_DEFAULT_ToolSettings = _DNA_DEFAULT_ToolSettings;
|
||||
#define SDNA_DEFAULT_DECL_STRUCT(struct_name) \
|
||||
const struct_name DNA_DEFAULT_##struct_name = _DNA_DEFAULT_##struct_name
|
||||
|
||||
/* DNA_scene_material.h */
|
||||
SDNA_DEFAULT_DECL_STRUCT(Material);
|
||||
|
||||
/* DNA_scene_mesh.h */
|
||||
SDNA_DEFAULT_DECL_STRUCT(Mesh);
|
||||
|
||||
/* DNA_scene_object.h */
|
||||
SDNA_DEFAULT_DECL_STRUCT(Object);
|
||||
|
||||
/* DNA_scene_defaults.h */
|
||||
SDNA_DEFAULT_DECL_STRUCT(Scene);
|
||||
SDNA_DEFAULT_DECL_STRUCT(ToolSettings);
|
||||
|
||||
#undef SDNA_DEFAULT_DECL_STRUCT
|
||||
|
||||
/* Reuse existing definitions. */
|
||||
extern const struct UserDef U_default;
|
||||
|
@ -77,7 +99,6 @@ extern const bTheme U_theme_default;
|
|||
# define SDNA_TYPE_CHECKED(v, t) (&(v))
|
||||
#endif
|
||||
|
||||
/* */
|
||||
#define SDNA_DEFAULT_DECL(struct_name) \
|
||||
[SDNA_TYPE_FROM_STRUCT(struct_name)] = SDNA_TYPE_CHECKED(DNA_DEFAULT_##struct_name, struct_name)
|
||||
|
||||
|
@ -86,6 +107,16 @@ extern const bTheme U_theme_default;
|
|||
|
||||
/** Keep headers sorted. */
|
||||
const void *DNA_default_table[SDNA_TYPE_MAX] = {
|
||||
|
||||
/* DNA_material_defaults.h */
|
||||
SDNA_DEFAULT_DECL(Material),
|
||||
|
||||
/* DNA_mesh_defaults.h */
|
||||
SDNA_DEFAULT_DECL(Mesh),
|
||||
|
||||
/* DNA_object_defaults.h */
|
||||
SDNA_DEFAULT_DECL(Object),
|
||||
|
||||
/* DNA_scene_defaults.h */
|
||||
SDNA_DEFAULT_DECL(Scene),
|
||||
SDNA_DEFAULT_DECL_EX(RenderData, Scene.r),
|
||||
|
|
Loading…
Reference in New Issue