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:
authorCampbell Barton <ideasman42@gmail.com>2019-09-09 15:32:34 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-09-09 16:17:03 +0300
commitf5e0dfe59c7e748907f955f848264751ed0967f0 (patch)
treea4bf4369b1076ffd7f449061f04d2813ce715a15 /source/blender
parente164afe9b5f98fe1ddb2ce063e1df9e9926cacfd (diff)
DNA: initial DNA defaults support
This provides an API to access structs with their members set to default values: - DNA_struct_default_get(name) - DNA_struct_default_alloc(name) Currently this is only used for scene & view shading initialization, eventually it can be used for RNA defaults and initializing DNA struct members on file reading.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/intern/scene.c273
-rw-r--r--source/blender/blenkernel/intern/screen.c21
-rw-r--r--source/blender/makesdna/DNA_defaults.h46
-rw-r--r--source/blender/makesdna/DNA_scene_defaults.h365
-rw-r--r--source/blender/makesdna/DNA_view3d_defaults.h62
-rw-r--r--source/blender/makesdna/intern/CMakeLists.txt6
-rw-r--r--source/blender/makesdna/intern/dna_defaults.c112
8 files changed, 610 insertions, 277 deletions
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index a1c47ba6d06..43baa00c5f5 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -50,6 +50,8 @@ set(INC
../../../intern/opensubdiv
../../../extern/curve_fit_nd
../../../intern/smoke/extern
+
+ ${CMAKE_CURRENT_BINARY_DIR}/../makesdna/intern
)
set(INC_SYS
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 8e728150ddf..dbb39184b1e 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -44,6 +44,7 @@
#include "DNA_workspace_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_world_types.h"
+#include "DNA_defaults.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
@@ -558,107 +559,20 @@ void BKE_scene_free(Scene *sce)
BKE_scene_free_ex(sce, true);
}
+/**
+ * \note Use DNA_scene_defaults.h where possible.
+ */
void BKE_scene_init(Scene *sce)
{
- ParticleEditSettings *pset;
- int a;
const char *colorspace_name;
SceneRenderView *srv;
CurveMapping *mblur_shutter_curve;
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(sce, id));
- sce->cursor.rotation_mode = ROT_MODE_XYZ;
- sce->cursor.rotation_quaternion[0] = 1.0f;
- sce->cursor.rotation_axis[1] = 1.0f;
-
- sce->r.mode = 0;
- sce->r.cfra = 1;
- sce->r.sfra = 1;
- sce->r.efra = 250;
- sce->r.frame_step = 1;
- sce->r.xsch = 1920;
- sce->r.ysch = 1080;
- sce->r.xasp = 1;
- sce->r.yasp = 1;
- sce->r.tilex = 256;
- sce->r.tiley = 256;
- sce->r.size = 100;
-
- sce->r.im_format.planes = R_IMF_PLANES_RGBA;
- sce->r.im_format.imtype = R_IMF_IMTYPE_PNG;
- sce->r.im_format.depth = R_IMF_CHAN_DEPTH_8;
- sce->r.im_format.quality = 90;
- sce->r.im_format.compress = 15;
-
- sce->r.displaymode = R_OUTPUT_WINDOW;
- sce->r.framapto = 100;
- sce->r.images = 100;
- sce->r.framelen = 1.0;
- sce->r.blurfac = 0.5;
- sce->r.frs_sec = 24;
- sce->r.frs_sec_base = 1;
-
- /* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used,
- * images would look in the same way as in current blender
- *
- * perhaps at some point should be completely deprecated?
- */
- sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
-
- sce->r.gauss = 1.5;
- sce->r.dither_intensity = 1.0f;
-
- sce->r.bake_mode = 0;
- sce->r.bake_filter = 16;
- sce->r.bake_flag = R_BAKE_CLEAR;
- sce->r.bake_samples = 256;
- sce->r.bake_biasdist = 0.001;
-
- sce->r.bake.flag = R_BAKE_CLEAR;
- sce->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
- sce->r.bake.width = 512;
- sce->r.bake.height = 512;
- sce->r.bake.margin = 16;
- sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
- sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
- sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
- sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
- BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
-
- sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
- sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
- sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
- sce->r.bake.im_format.quality = 90;
- sce->r.bake.im_format.compress = 15;
-
- sce->r.scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION;
- sce->r.stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE |
- R_STAMP_FILENAME | R_STAMP_RENDERTIME | R_STAMP_MEMORY;
- sce->r.stamp_font_id = 12;
- sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
- sce->r.fg_stamp[3] = 1.0f;
- sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f;
- sce->r.bg_stamp[3] = 0.25f;
-
- sce->r.seq_prev_type = OB_SOLID;
- sce->r.seq_rend_type = OB_SOLID;
- sce->r.seq_flag = 0;
+ MEMCPY_STRUCT_AFTER(sce, DNA_struct_default_get(Scene), id);
- sce->r.threads = 1;
-
- sce->r.simplify_subsurf = 6;
- sce->r.simplify_particles = 1.0f;
-
- sce->r.border.xmin = 0.0f;
- sce->r.border.ymin = 0.0f;
- sce->r.border.xmax = 1.0f;
- sce->r.border.ymax = 1.0f;
-
- sce->r.preview_start_resolution = 64;
-
- sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
- sce->r.unit_line_thickness = 1.0f;
+ BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
mblur_shutter_curve = &sce->r.mblur_shutter_curve;
BKE_curvemapping_set_defaults(mblur_shutter_curve, 1, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -668,49 +582,10 @@ void BKE_scene_init(Scene *sce)
CURVE_PRESET_MAX,
CURVEMAP_SLOPE_POS_NEG);
- sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
-
- sce->toolsettings->object_flag |= SCE_OBJECT_MODE_LOCK;
- sce->toolsettings->doublimit = 0.001;
- sce->toolsettings->vgroup_weight = 1.0f;
- sce->toolsettings->uvcalc_margin = 0.001f;
- sce->toolsettings->uvcalc_flag = UVCALC_TRANSFORM_CORRECT;
- sce->toolsettings->unwrapper = 1;
- sce->toolsettings->select_thresh = 0.01f;
+ sce->toolsettings = DNA_struct_default_alloc(ToolSettings);
- sce->toolsettings->selectmode = SCE_SELECT_VERTEX;
- sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX;
sce->toolsettings->autokey_mode = U.autokey_mode;
- sce->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEDIAN;
- sce->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT;
- sce->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
- sce->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT;
- sce->toolsettings->snap_transform_mode_flag = SCE_SNAP_TRANSFORM_MODE_TRANSLATE;
-
- sce->toolsettings->curve_paint_settings.curve_type = CU_BEZIER;
- sce->toolsettings->curve_paint_settings.flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
- sce->toolsettings->curve_paint_settings.error_threshold = 8;
- sce->toolsettings->curve_paint_settings.radius_max = 1.0f;
- sce->toolsettings->curve_paint_settings.corner_angle = DEG2RADF(70.0f);
-
- sce->toolsettings->statvis.overhang_axis = OB_NEGZ;
- sce->toolsettings->statvis.overhang_min = 0;
- sce->toolsettings->statvis.overhang_max = DEG2RADF(45.0f);
- sce->toolsettings->statvis.thickness_max = 0.1f;
- sce->toolsettings->statvis.thickness_samples = 1;
- sce->toolsettings->statvis.distort_min = DEG2RADF(5.0f);
- sce->toolsettings->statvis.distort_max = DEG2RADF(45.0f);
-
- sce->toolsettings->statvis.sharp_min = DEG2RADF(90.0f);
- sce->toolsettings->statvis.sharp_max = DEG2RADF(180.0f);
-
- sce->toolsettings->proportional_size = 1.0f;
-
- sce->toolsettings->imapaint.paint.flags |= PAINT_SHOW_BRUSH;
- sce->toolsettings->imapaint.normal_angle = 80;
- sce->toolsettings->imapaint.seam_bleed = 2;
-
/* grease pencil multiframe falloff curve */
sce->toolsettings->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
CurveMapping *gp_falloff_curve = sce->toolsettings->gp_sculpt.cur_falloff;
@@ -726,50 +601,23 @@ void BKE_scene_init(Scene *sce)
CURVE_PRESET_BELL,
CURVEMAP_SLOPE_POSITIVE);
- sce->toolsettings->gp_sculpt.guide.spacing = 20.0f;
-
- sce->physics_settings.gravity[0] = 0.0f;
- sce->physics_settings.gravity[1] = 0.0f;
- sce->physics_settings.gravity[2] = -9.81f;
- sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
-
sce->unit.system = USER_UNIT_METRIC;
sce->unit.scale_length = 1.0f;
sce->unit.length_unit = bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_LENGTH);
sce->unit.mass_unit = bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_MASS);
sce->unit.time_unit = bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_TIME);
- pset = &sce->toolsettings->particle;
- pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY;
- pset->emitterdist = 0.25f;
- pset->totrekey = 5;
- pset->totaddkey = 5;
- pset->brushtype = PE_BRUSH_COMB;
- pset->draw_step = 2;
- pset->fade_frames = 2;
- pset->selectmode = SCE_SELECT_PATH;
-
- for (a = 0; a < ARRAY_SIZE(pset->brush); a++) {
- pset->brush[a].strength = 0.5f;
- pset->brush[a].size = 50;
- pset->brush[a].step = 10;
- pset->brush[a].count = 10;
- }
- pset->brush[PE_BRUSH_CUT].strength = 1.0f;
-
- sce->r.ffcodecdata.audio_mixrate = 48000;
- sce->r.ffcodecdata.audio_volume = 1.0f;
- sce->r.ffcodecdata.audio_bitrate = 192;
- sce->r.ffcodecdata.audio_channels = 2;
+ {
+ ParticleEditSettings *pset;
+ pset = &sce->toolsettings->particle;
+ for (int i = 1; i < ARRAY_SIZE(pset->brush); i++) {
+ pset->brush[i] = pset->brush[0];
+ }
+ pset->brush[PE_BRUSH_CUT].strength = 1.0f;
+ }
BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(sce->r.engine));
- sce->audio.distance_model = 2.0f;
- sce->audio.doppler_factor = 1.0f;
- sce->audio.speed_of_sound = 343.3f;
- sce->audio.volume = 1.0f;
- sce->audio.flag = AUDIO_SYNC;
-
BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic));
/* Note; in header_info.c the scene copy happens...,
@@ -806,14 +654,6 @@ void BKE_scene_init(Scene *sce)
BKE_color_managed_view_settings_init_render(
&sce->r.bake.im_format.view_settings, &sce->r.bake.im_format.display_settings, "Filmic");
- /* Safe Areas */
- copy_v2_fl2(sce->safe_areas.title, 10.0f / 100.0f, 5.0f / 100.0f);
- copy_v2_fl2(sce->safe_areas.action, 3.5f / 100.0f, 3.5f / 100.0f);
- copy_v2_fl2(sce->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
- copy_v2_fl2(sce->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
-
- sce->preview = NULL;
-
/* GP Sculpt brushes */
{
GP_Sculpt_Settings *gset = &sce->toolsettings->gp_sculpt;
@@ -880,16 +720,6 @@ void BKE_scene_init(Scene *sce)
copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub);
}
- /* GP Stroke Placement */
- sce->toolsettings->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
- sce->toolsettings->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
- sce->toolsettings->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
- sce->toolsettings->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
-
- /* Annotations */
- sce->toolsettings->annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR;
- sce->toolsettings->annotate_thickness = 3;
-
for (int i = 0; i < ARRAY_SIZE(sce->orientation_slots); i++) {
sce->orientation_slots[i].index_custom = -1;
}
@@ -898,79 +728,6 @@ void BKE_scene_init(Scene *sce)
sce->master_collection = BKE_collection_master_add();
BKE_view_layer_add(sce, "View Layer");
-
- /* SceneDisplay */
- copy_v3_v3(sce->display.light_direction, (float[3]){M_SQRT1_3, M_SQRT1_3, M_SQRT1_3});
- sce->display.shadow_shift = 0.1f;
- sce->display.shadow_focus = 0.0f;
-
- sce->display.matcap_ssao_distance = 0.2f;
- sce->display.matcap_ssao_attenuation = 1.0f;
- sce->display.matcap_ssao_samples = 16;
-
- sce->display.render_aa = SCE_DISPLAY_AA_SAMPLES_8;
- sce->display.viewport_aa = SCE_DISPLAY_AA_FXAA;
-
- /* OpenGL Render. */
- BKE_screen_view3d_shading_init(&sce->display.shading);
-
- /* SceneEEVEE */
- sce->eevee.gi_diffuse_bounces = 3;
- sce->eevee.gi_cubemap_resolution = 512;
- sce->eevee.gi_visibility_resolution = 32;
- sce->eevee.gi_cubemap_draw_size = 0.3f;
- sce->eevee.gi_irradiance_draw_size = 0.1f;
- sce->eevee.gi_irradiance_smoothing = 0.1f;
- sce->eevee.gi_filter_quality = 3.0f;
-
- sce->eevee.taa_samples = 16;
- sce->eevee.taa_render_samples = 64;
-
- sce->eevee.sss_samples = 7;
- sce->eevee.sss_jitter_threshold = 0.3f;
-
- sce->eevee.ssr_quality = 0.25f;
- sce->eevee.ssr_max_roughness = 0.5f;
- sce->eevee.ssr_thickness = 0.2f;
- sce->eevee.ssr_border_fade = 0.075f;
- sce->eevee.ssr_firefly_fac = 10.0f;
-
- sce->eevee.volumetric_start = 0.1f;
- sce->eevee.volumetric_end = 100.0f;
- sce->eevee.volumetric_tile_size = 8;
- sce->eevee.volumetric_samples = 64;
- sce->eevee.volumetric_sample_distribution = 0.8f;
- sce->eevee.volumetric_light_clamp = 0.0f;
- sce->eevee.volumetric_shadow_samples = 16;
-
- sce->eevee.gtao_distance = 0.2f;
- sce->eevee.gtao_factor = 1.0f;
- sce->eevee.gtao_quality = 0.25f;
-
- sce->eevee.bokeh_max_size = 100.0f;
- sce->eevee.bokeh_threshold = 1.0f;
-
- copy_v3_fl(sce->eevee.bloom_color, 1.0f);
- sce->eevee.bloom_threshold = 0.8f;
- sce->eevee.bloom_knee = 0.5f;
- sce->eevee.bloom_intensity = 0.05f;
- sce->eevee.bloom_radius = 6.5f;
- sce->eevee.bloom_clamp = 0.0f;
-
- sce->eevee.motion_blur_samples = 8;
- sce->eevee.motion_blur_shutter = 0.5f;
-
- sce->eevee.shadow_cube_size = 512;
- sce->eevee.shadow_cascade_size = 1024;
-
- sce->eevee.light_cache = NULL;
- sce->eevee.light_threshold = 0.01f;
-
- sce->eevee.overscan = 3.0f;
-
- sce->eevee.flag = SCE_EEVEE_VOLUMETRIC_LIGHTS | SCE_EEVEE_GTAO_BENT_NORMALS |
- SCE_EEVEE_GTAO_BOUNCE | SCE_EEVEE_TAA_REPROJECTION |
- SCE_EEVEE_SSR_HALF_RESOLUTION | SCE_EEVEE_SHADOW_SOFT;
}
Scene *BKE_scene_add(Main *bmain, const char *name)
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 9f049b61b5a..1835fb2a523 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -36,6 +36,7 @@
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "DNA_workspace_types.h"
+#include "DNA_defaults.h"
#include "BLI_math_vector.h"
#include "BLI_listbase.h"
@@ -852,24 +853,8 @@ void BKE_screen_view3d_scene_sync(bScreen *sc, Scene *scene)
void BKE_screen_view3d_shading_init(View3DShading *shading)
{
- memset(shading, 0, sizeof(*shading));
-
- shading->type = OB_SOLID;
- shading->prev_type = OB_SOLID;
- shading->flag = V3D_SHADING_SPECULAR_HIGHLIGHT | V3D_SHADING_XRAY_WIREFRAME |
- V3D_SHADING_SCENE_LIGHTS_RENDER | V3D_SHADING_SCENE_WORLD_RENDER;
- shading->light = V3D_LIGHTING_STUDIO;
- shading->shadow_intensity = 0.5f;
- shading->xray_alpha = 0.5f;
- shading->xray_alpha_wire = 0.0f;
- shading->cavity_valley_factor = 1.0f;
- shading->cavity_ridge_factor = 1.0f;
- shading->cavity_type = V3D_SHADING_CAVITY_CURVATURE;
- shading->curvature_ridge_factor = 1.0f;
- shading->curvature_valley_factor = 1.0f;
- copy_v3_fl(shading->single_color, 0.8f);
- copy_v3_fl(shading->background_color, 0.05f);
- shading->studiolight_intensity = 1.0f;
+ const View3DShading *shading_default = DNA_struct_default_get(View3DShading);
+ memcpy(shading, shading_default, sizeof(*shading));
}
/* magic zoom calculation, no idea what
diff --git a/source/blender/makesdna/DNA_defaults.h b/source/blender/makesdna/DNA_defaults.h
new file mode 100644
index 00000000000..5b9297ce46a
--- /dev/null
+++ b/source/blender/makesdna/DNA_defaults.h
@@ -0,0 +1,46 @@
+
+/*
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup DNA
+ *
+ * \see dna_defaults.c for details on how to use this system.
+ */
+
+#ifndef __DNA_DEFAULTS_H__
+#define __DNA_DEFAULTS_H__
+
+#include "dna_type_offsets.h"
+
+extern const void *DNA_default_table[SDNA_TYPE_MAX];
+
+char *_DNA_struct_default_alloc_impl(const char *data_src, size_t size, const char *alloc_str);
+
+/**
+ * Wrap with macro that casts correctly.
+ */
+#define DNA_struct_default_get(struct_name) \
+ (const struct_name *)DNA_default_table[SDNA_TYPE_FROM_STRUCT(struct_name)]
+
+#define DNA_struct_default_alloc(struct_name) \
+ (struct_name *)_DNA_struct_default_alloc_impl( \
+ DNA_default_table[SDNA_TYPE_FROM_STRUCT(struct_name)], sizeof(struct_name), __func__)
+
+#endif /* __DNA_DEFAULTS_H__ */
diff --git a/source/blender/makesdna/DNA_scene_defaults.h b/source/blender/makesdna/DNA_scene_defaults.h
new file mode 100644
index 00000000000..c2ec290252f
--- /dev/null
+++ b/source/blender/makesdna/DNA_scene_defaults.h
@@ -0,0 +1,365 @@
+/*
+ * 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_SCENE_DEFAULTS_H__
+#define __DNA_SCENE_DEFAULTS_H__
+
+#include "DNA_view3d_defaults.h"
+
+/* Struct members on own line. */
+/* clang-format off */
+
+/* -------------------------------------------------------------------- */
+/** \name Scene Struct
+ * \{ */
+
+#define _DNA_DEFAULT_ImageFormatData \
+ { \
+ .planes = R_IMF_PLANES_RGBA, \
+ .imtype = R_IMF_IMTYPE_PNG, \
+ .depth = R_IMF_CHAN_DEPTH_8, \
+ .quality = 90, \
+ .compress = 15, \
+ }
+
+#define _DNA_DEFAULT_BakeData \
+ { \
+ .flag = R_BAKE_CLEAR, \
+ .pass_filter = R_BAKE_PASS_FILTER_ALL, \
+ .width = 512, \
+ .height = 512, \
+ .margin = 16, \
+ .normal_space = R_BAKE_SPACE_TANGENT, \
+ .normal_swizzle = {R_BAKE_POSX, R_BAKE_POSY, R_BAKE_POSZ}, \
+ \
+ .im_format = _DNA_DEFAULT_ImageFormatData, \
+ }
+
+#define _DNA_DEFAULT_FFMpegCodecData \
+ { \
+ .audio_mixrate = 48000, \
+ .audio_volume = 1.0f, \
+ .audio_bitrate = 192, \
+ .audio_channels = 2, \
+ }
+
+#define _DNA_DEFAULT_DisplaySafeAreas \
+ { \
+ .title = {10.0f / 100.0f, 5.0f / 100.0f}, \
+ .action = {3.5f / 100.0f, 3.5f / 100.0f}, \
+ .title_center = {17.5f / 100.0f, 5.0f / 100.0f}, \
+ .action_center = {15.0f / 100.0f, 5.0f / 100.0f}, \
+ }
+
+#define _DNA_DEFAULT_RenderData \
+ { \
+ .mode = 0, \
+ .cfra = 1, \
+ .sfra = 1, \
+ .efra = 250, \
+ .frame_step = 1, \
+ .xsch = 1920, \
+ .ysch = 1080, \
+ .xasp = 1, \
+ .yasp = 1, \
+ .tilex = 256, \
+ .tiley = 256, \
+ .size = 100, \
+ \
+ .im_format = _DNA_DEFAULT_ImageFormatData, \
+ \
+ .displaymode = R_OUTPUT_WINDOW, \
+ .framapto = 100, \
+ .images = 100, \
+ .framelen = 1.0, \
+ .blurfac = 0.5, \
+ .frs_sec = 24, \
+ .frs_sec_base = 1, \
+ \
+ /* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used, \
+ * images would look in the same way as in current blender \
+ * \
+ * perhaps at some point should be completely deprecated? \
+ */ \
+ .color_mgt_flag = R_COLOR_MANAGEMENT, \
+ \
+ .gauss = 1.5, \
+ .dither_intensity = 1.0f, \
+ \
+ .bake_mode = 0, \
+ .bake_filter = 16, \
+ .bake_flag = R_BAKE_CLEAR, \
+ .bake_samples = 256, \
+ .bake_biasdist = 0.001f, \
+ \
+ /* BakeData */ \
+ .bake = _DNA_DEFAULT_BakeData, \
+ \
+ .scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION, \
+ .stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE | \
+ R_STAMP_FILENAME | R_STAMP_RENDERTIME | R_STAMP_MEMORY, \
+ .stamp_font_id = 12, \
+ .fg_stamp = {0.8f, 0.8f, 0.8f, 1.0f}, \
+ .bg_stamp = {0.0f, 0.0f, 0.0f, 0.25f}, \
+ \
+ .seq_prev_type = OB_SOLID, \
+ .seq_rend_type = OB_SOLID, \
+ .seq_flag = 0, \
+ \
+ .threads = 1, \
+ \
+ .simplify_subsurf = 6, \
+ .simplify_particles = 1.0f, \
+ \
+ .border.xmin = 0.0f, \
+ .border.ymin = 0.0f, \
+ .border.xmax = 1.0f, \
+ .border.ymax = 1.0f, \
+ \
+ .preview_start_resolution = 64, \
+ \
+ .line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE, \
+ .unit_line_thickness = 1.0f, \
+ \
+ .ffcodecdata = _DNA_DEFAULT_FFMpegCodecData, \
+ }
+
+#define _DNA_DEFAULT_AudioData \
+ { \
+ .distance_model = 2.0f, \
+ .doppler_factor = 1.0f, \
+ .speed_of_sound = 343.3f, \
+ .volume = 1.0f, \
+ .flag = AUDIO_SYNC, \
+ }
+
+#define _DNA_DEFAULT_SceneDisplay \
+ { \
+ .light_direction = {M_SQRT1_3, M_SQRT1_3, M_SQRT1_3}, \
+ .shadow_shift = 0.1f, \
+ .shadow_focus = 0.0f, \
+ \
+ .matcap_ssao_distance = 0.2f, \
+ .matcap_ssao_attenuation = 1.0f, \
+ .matcap_ssao_samples = 16, \
+ \
+ .shading = _DNA_DEFAULT_View3DShading, \
+ \
+ .render_aa = SCE_DISPLAY_AA_SAMPLES_8, \
+ .viewport_aa = SCE_DISPLAY_AA_FXAA, \
+ }
+
+#define _DNA_DEFAULT_PhysicsSettings \
+ { \
+ .gravity = {0.0f, 0.0f -9.81f}, \
+ .flag = PHYS_GLOBAL_GRAVITY, \
+ }
+
+#define _DNA_DEFAULT_SceneEEVEE \
+ { \
+ .gi_diffuse_bounces = 3, \
+ .gi_cubemap_resolution = 512, \
+ .gi_visibility_resolution = 32, \
+ .gi_cubemap_draw_size = 0.3f, \
+ .gi_irradiance_draw_size = 0.1f, \
+ .gi_irradiance_smoothing = 0.1f, \
+ .gi_filter_quality = 3.0f, \
+ \
+ .taa_samples = 16, \
+ .taa_render_samples = 64, \
+ \
+ .sss_samples = 7, \
+ .sss_jitter_threshold = 0.3f, \
+ \
+ .ssr_quality = 0.25f, \
+ .ssr_max_roughness = 0.5f, \
+ .ssr_thickness = 0.2f, \
+ .ssr_border_fade = 0.075f, \
+ .ssr_firefly_fac = 10.0f, \
+ \
+ .volumetric_start = 0.1f, \
+ .volumetric_end = 100.0f, \
+ .volumetric_tile_size = 8, \
+ .volumetric_samples = 64, \
+ .volumetric_sample_distribution = 0.8f, \
+ .volumetric_light_clamp = 0.0f, \
+ .volumetric_shadow_samples = 16, \
+ \
+ .gtao_distance = 0.2f, \
+ .gtao_factor = 1.0f, \
+ .gtao_quality = 0.25f, \
+ \
+ .bokeh_max_size = 100.0f, \
+ .bokeh_threshold = 1.0f, \
+ \
+ .bloom_color = {1.0f, 1.0f, 1.0f}, \
+ .bloom_threshold = 0.8f, \
+ .bloom_knee = 0.5f, \
+ .bloom_intensity = 0.05f, \
+ .bloom_radius = 6.5f, \
+ .bloom_clamp = 0.0f, \
+ \
+ .motion_blur_samples = 8, \
+ .motion_blur_shutter = 0.5f, \
+ \
+ .shadow_cube_size = 512, \
+ .shadow_cascade_size = 1024, \
+ \
+ .light_cache = NULL, \
+ .light_threshold = 0.01f, \
+ \
+ .overscan = 3.0f, \
+ \
+ .flag = SCE_EEVEE_VOLUMETRIC_LIGHTS | SCE_EEVEE_GTAO_BENT_NORMALS | \
+ SCE_EEVEE_GTAO_BOUNCE | SCE_EEVEE_TAA_REPROJECTION | \
+ SCE_EEVEE_SSR_HALF_RESOLUTION | SCE_EEVEE_SHADOW_SOFT, \
+ }
+
+#define _DNA_DEFAULT_Scene \
+ { \
+ .cursor = _DNA_DEFAULT_View3DCursor, \
+ .r = _DNA_DEFAULT_RenderData, \
+ .audio = _DNA_DEFAULT_AudioData, \
+ \
+ .display = _DNA_DEFAULT_SceneDisplay, \
+ \
+ .physics_settings = _DNA_DEFAULT_PhysicsSettings, \
+ \
+ .safe_areas = _DNA_DEFAULT_DisplaySafeAreas, \
+ \
+ .eevee = _DNA_DEFAULT_SceneEEVEE, \
+ }
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name ToolSettings Struct
+ * \{ */
+
+#define _DNA_DEFAULTS_CurvePaintSettings \
+ { \
+ .curve_type = CU_BEZIER, \
+ .flag = CURVE_PAINT_FLAG_CORNERS_DETECT, \
+ .error_threshold = 8, \
+ .radius_max = 1.0f, \
+ .corner_angle = DEG2RADF(70.0f), \
+ }
+
+#define _DNA_DEFAULTS_ImagePaintSettings \
+ { \
+ .paint.flags = PAINT_SHOW_BRUSH, \
+ .normal_angle = 80, \
+ .seam_bleed = 2, \
+ }
+
+#define _DNA_DEFAULTS_ParticleBrushData \
+ { \
+ .strength = 0.5f, \
+ .size = 50, \
+ .step = 10, \
+ .count = 10, \
+ }
+
+#define _DNA_DEFAULTS_ParticleEditSettings \
+ { \
+ .flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY, \
+ .emitterdist = 0.25f, \
+ .totrekey = 5, \
+ .totaddkey = 5, \
+ .brushtype = PE_BRUSH_COMB, \
+ \
+ /* Scene init copies this to all other elements. */ \
+ .brush = {_DNA_DEFAULTS_ParticleBrushData}, \
+ \
+ .draw_step = 2, \
+ .fade_frames = 2, \
+ .selectmode = SCE_SELECT_PATH, \
+ }
+
+#define _DNA_DEFAULTS_GP_Sculpt_Guide \
+ { \
+ .spacing = 20.0f, \
+ }
+
+#define _DNA_DEFAULTS_GP_Sculpt_Settings \
+ { \
+ .guide = _DNA_DEFAULTS_GP_Sculpt_Guide, \
+ }
+
+#define _DNA_DEFAULTS_MeshStatVis \
+ { \
+ .overhang_axis = OB_NEGZ, \
+ .overhang_min = 0, \
+ .overhang_max = DEG2RADF(45.0f), \
+ .thickness_max = 0.1f, \
+ .thickness_samples = 1, \
+ .distort_min = DEG2RADF(5.0f), \
+ .distort_max = DEG2RADF(45.0f), \
+ \
+ .sharp_min = DEG2RADF(90.0f), \
+ .sharp_max = DEG2RADF(180.0f), \
+ }
+
+#define _DNA_DEFAULT_ToolSettings \
+ { \
+ .object_flag = SCE_OBJECT_MODE_LOCK, \
+ .doublimit = 0.001, \
+ .vgroup_weight = 1.0f, \
+ .uvcalc_margin = 0.001f, \
+ .uvcalc_flag = UVCALC_TRANSFORM_CORRECT, \
+ .unwrapper = 1, \
+ .select_thresh = 0.01f, \
+ \
+ .selectmode = SCE_SELECT_VERTEX, \
+ .uv_selectmode = UV_SELECT_VERTEX, \
+ .autokey_mode = AUTOKEY_MODE_NORMAL, \
+ \
+ .transform_pivot_point = V3D_AROUND_CENTER_MEDIAN, \
+ .snap_mode = SCE_SNAP_MODE_INCREMENT, \
+ .snap_node_mode = SCE_SNAP_MODE_GRID, \
+ .snap_uv_mode = SCE_SNAP_MODE_INCREMENT, \
+ .snap_transform_mode_flag = SCE_SNAP_TRANSFORM_MODE_TRANSLATE, \
+ \
+ .curve_paint_settings = _DNA_DEFAULTS_CurvePaintSettings, \
+ \
+ .statvis = _DNA_DEFAULTS_MeshStatVis, \
+ \
+ .proportional_size = 1.0f, \
+ \
+ .imapaint = _DNA_DEFAULTS_ImagePaintSettings, \
+ \
+ .particle = _DNA_DEFAULTS_ParticleEditSettings, \
+ \
+ .gp_sculpt = _DNA_DEFAULTS_GP_Sculpt_Settings, \
+ \
+ /* Annotations */ \
+ .annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR, \
+ .annotate_thickness = 3, \
+ \
+ /* GP Stroke Placement */ \
+ .gpencil_v3d_align = GP_PROJECT_VIEWSPACE, \
+ .gpencil_v2d_align = GP_PROJECT_VIEWSPACE, \
+ .gpencil_seq_align = GP_PROJECT_VIEWSPACE, \
+ .gpencil_ima_align = GP_PROJECT_VIEWSPACE, \
+ }
+
+/* clang-format off */
+
+#endif /* __DNA_SCENE_DEFAULTS_H__ */
diff --git a/source/blender/makesdna/DNA_view3d_defaults.h b/source/blender/makesdna/DNA_view3d_defaults.h
new file mode 100644
index 00000000000..2964e77a421
--- /dev/null
+++ b/source/blender/makesdna/DNA_view3d_defaults.h
@@ -0,0 +1,62 @@
+/*
+ * 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_VIEW3D_DEFAULTS_H__
+#define __DNA_VIEW3D_DEFAULTS_H__
+
+/* Struct members on own line. */
+/* clang-format off */
+
+/* -------------------------------------------------------------------- */
+/** \name Viewport Struct
+ * \{ */
+
+#define _DNA_DEFAULT_View3DShading \
+ { \
+ .type = OB_SOLID, \
+ .prev_type = OB_SOLID, \
+ .flag = V3D_SHADING_SPECULAR_HIGHLIGHT | V3D_SHADING_XRAY_WIREFRAME | \
+ V3D_SHADING_SCENE_LIGHTS_RENDER | V3D_SHADING_SCENE_WORLD_RENDER, \
+ .light = V3D_LIGHTING_STUDIO, \
+ .shadow_intensity = 0.5f, \
+ .xray_alpha = 0.5f, \
+ .xray_alpha_wire = 0.5f, \
+ .cavity_valley_factor = 1.0f, \
+ .cavity_ridge_factor = 1.0f, \
+ .cavity_type = V3D_SHADING_CAVITY_CURVATURE, \
+ .curvature_ridge_factor = 1.0f, \
+ .curvature_valley_factor = 1.0f, \
+ .single_color = {0.8f, 0.8f, 0.8f}, \
+ .background_color = {0.05f, 0.05f, 0.05f}, \
+ .studiolight_intensity = 1.0f, \
+ }
+
+#define _DNA_DEFAULT_View3DCursor \
+ { \
+ .rotation_mode = ROT_MODE_XYZ, \
+ .rotation_quaternion = {1, 0, 0, 0}, \
+ .rotation_axis = {0, 1, 0}, \
+ }
+
+/** \} */
+
+/* clang-format on */
+
+#endif /* __DNA_VIEW3D_DEFAULTS_H__ */
diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt
index 178ef219c4d..92ca09dcbca 100644
--- a/source/blender/makesdna/intern/CMakeLists.txt
+++ b/source/blender/makesdna/intern/CMakeLists.txt
@@ -77,7 +77,7 @@ add_custom_command(
# -----------------------------------------------------------------------------
# Build bf_dna library
set(INC
-
+ ${CMAKE_CURRENT_BINARY_DIR}
)
set(INC_SYS
@@ -85,6 +85,7 @@ set(INC_SYS
)
set(SRC
+ dna_defaults.c
dna_genfile.c
dna_utils.c
${CMAKE_CURRENT_BINARY_DIR}/dna.c
@@ -126,6 +127,9 @@ set(SRC
../../blenlib/intern/endian_switch.c
../../blenlib/intern/hash_mm2a.c
../../blenlib/intern/listbase.c
+
+ ../DNA_scene_defaults.h
+ ../DNA_view3d_defaults.h
)
set(LIB
diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c
new file mode 100644
index 00000000000..327411ab17f
--- /dev/null
+++ b/source/blender/makesdna/intern/dna_defaults.c
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ *
+ * DNA default value access.
+ */
+
+/** \file
+ * \ingroup DNA
+ *
+ * This API provides direct access to DNA default structs
+ * to avoid duplicating values for initialization, versioning and RNA.
+ * This allows DNA default definitions to be defined in a single header along side the types.
+ * So each `DNA_{name}_types.h` can have an optional `DNA_{name}_defaults.h` file along side it.
+ *
+ * Defining the defaults is optional since it doesn't make sense for some structs to have defaults.
+ *
+ * To create these defaults there is a GDB script which can be handy to get started:
+ * `./source/tools/utils/gdb_struct_repr_c99.py`
+ *
+ * Magic numbers should be replaced with flags before committing.
+ *
+ * The main functions to access these are:
+ * - #DNA_struct_default_get
+ * - #DNA_struct_default_alloc
+ *
+ * These access the struct table #DNA_default_table using the struct number.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_endian_switch.h"
+#include "BLI_memarena.h"
+#include "BLI_math.h"
+
+#include "DNA_defaults.h"
+#include "DNA_scene_types.h"
+#include "DNA_curve_types.h"
+
+#include "DNA_scene_defaults.h"
+
+const Scene DNA_DEFAULT_Scene = _DNA_DEFAULT_Scene;
+const ToolSettings DNA_DEFAULT_ToolSettings = _DNA_DEFAULT_ToolSettings;
+
+/**
+ * Prevent assigning the wrong struct types since all elements in #DNA_default_table are `void *`.
+ */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+# define SDNA_TYPE_CHECKED(v, t) (&(v) + (_Generic((v), t : 0)))
+#else
+# 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)
+
+#define SDNA_DEFAULT_DECL_EX(struct_name, struct_path) \
+ [SDNA_TYPE_FROM_STRUCT(struct_name)] = SDNA_TYPE_CHECKED(DNA_DEFAULT_##struct_path, struct_name)
+
+/** Keep headers sorted. */
+const void *DNA_default_table[SDNA_TYPE_MAX] = {
+ /* DNA_scene_defaults.h */
+ SDNA_DEFAULT_DECL(Scene),
+ SDNA_DEFAULT_DECL_EX(RenderData, Scene.r),
+ SDNA_DEFAULT_DECL_EX(ImageFormatData, Scene.r.im_format),
+ SDNA_DEFAULT_DECL_EX(BakeData, Scene.r.bake),
+ SDNA_DEFAULT_DECL_EX(FFMpegCodecData, Scene.r.ffcodecdata),
+ SDNA_DEFAULT_DECL_EX(DisplaySafeAreas, Scene.safe_areas),
+ SDNA_DEFAULT_DECL_EX(AudioData, Scene.audio),
+ SDNA_DEFAULT_DECL_EX(PhysicsSettings, Scene.physics_settings),
+ SDNA_DEFAULT_DECL_EX(SceneDisplay, Scene.display),
+
+ SDNA_DEFAULT_DECL(ToolSettings),
+ SDNA_DEFAULT_DECL_EX(CurvePaintSettings, ToolSettings.curve_paint_settings),
+ SDNA_DEFAULT_DECL_EX(ImagePaintSettings, ToolSettings.imapaint),
+ SDNA_DEFAULT_DECL_EX(ParticleEditSettings, ToolSettings.particle),
+ SDNA_DEFAULT_DECL_EX(ParticleBrushData, ToolSettings.particle.brush[0]),
+ SDNA_DEFAULT_DECL_EX(MeshStatVis, ToolSettings.statvis),
+ SDNA_DEFAULT_DECL_EX(GP_Sculpt_Settings, ToolSettings.gp_sculpt),
+ SDNA_DEFAULT_DECL_EX(GP_Sculpt_Guide, ToolSettings.gp_sculpt.guide),
+
+ /* DNA_view3d_defaults.h */
+ SDNA_DEFAULT_DECL_EX(View3DShading, Scene.display.shading),
+ SDNA_DEFAULT_DECL_EX(View3DCursor, Scene.cursor),
+};
+#undef SDNA_DEFAULT_DECL
+#undef SDNA_DEFAULT_DECL_EX
+
+char *_DNA_struct_default_alloc_impl(const char *data_src, size_t size, const char *alloc_str)
+{
+ char *data_dst = MEM_mallocN(size, alloc_str);
+ memcpy(data_dst, data_src, size);
+ return data_dst;
+}