[Bf-blender-cvs] [9f859528e99] master: DNA: use defaults for Object, Mesh, Material

Campbell Barton noreply at git.blender.org
Mon Sep 9 19:32:34 CEST 2019


Commit: 9f859528e99c0ab4d21154ebb55a008c00a861db
Author: Campbell Barton
Date:   Tue Sep 10 03:16:18 2019 +1000
Branches: master
https://developer.blender.org/rB9f859528e99c0ab4d21154ebb55a008c00a861db

DNA: use defaults for Object, Mesh, Material

===================================================================

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/object.c
A	source/blender/makesdna/DNA_material_defaults.h
A	source/blender/makesdna/DNA_mesh_defaults.h
A	source/blender/makesdna/DNA_object_defaults.h
A	source/blender/makesdna/DNA_vec_defaults.h
M	source/blender/makesdna/intern/CMakeLists.txt
M	source/blender/makesdna/intern/dna_defaults.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 5162e1cf51d..dcd926e9e19 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -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,
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index f45eba2b53f..f6a5504acb2 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -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:
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index c12541b3b22..fc936e0fae2 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -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)
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 61b841591a4..ae9c3400ace 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index acfa6085d45..7b43f281c73 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -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;
 }
diff --git a/source/blender/makesdna/DNA_material_defaults.h b/source/blender/makesdna/DNA_material_defaults.h
new file mode 100644
index 00000000000..cdcb1dd45f7
--- /dev/null
+++ b/source/blender/makesdna/DNA_material_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_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__ */
diff --git a/source/blender/makesdna/DNA_mesh_defaults.h b/source/blender/makesdna/DNA_mesh_defaults.h
new file mode 100644
index 00000000000..40b8e2c9247
--- /dev/null
+++ b/source/blender/makesdna/DNA_mesh_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__ */
diff --git a/source/blender/makesdna/DNA_object_defaults.h b/source/blender/makesdna/DNA_object_defaults.h
new file mode 100644
index 00000000000..1105a8fd4e1
--- /dev/null
+++ b/source/blender/makesdna/DNA_object_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

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list