Page MenuHome

DNA Defaults
Needs ReviewPublic

Authored by Campbell Barton (campbellbarton) on Mar 12 2019, 11:20 AM.



This patch adds initial support for DNA defaults,

  • Each DNA struct can optionally have a default struct assigned.
  • If this struct is assigned, it's used for defaults when old files are loaded which either.
    • Don't define the entire struct.
    • Define the struct but don't include a newly added struct member.

      So there is no need to loop over initializing values manually version patching.
  • This can also be used for initializing new data, by copying these structs into new data instead of setting each value.
  • TODO: RNA could automatically use these values instead of calling RNA_def_property_*_default.
  • To get the initial struct definitions we can use gdb see:

This avoids duplicating defaults 2x times (3x once RNA support is added).

This review is mainly to get feedback before spending more time on this and preparing it for inclusion.

Note, this was fun-weekend project, not a priority for 2.8x, nevertheless it could be useful long term.

Diff Detail

rB Blender
Build Status
Buildable 3245
Build 3245: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

The duplication of defaults would indeed be great to solve, and should simplify versioning nicely.

Maybe it makes sense to have files like DNA_scene_defaults.h next to DNA_scene_types.h?

Also not sure e.g. View3DShading defaults should be defined as nested struct in scene. Seems more clear if we define all struct defaults separately following DNA header organization, even if it's a bit more verbose.

@Brecht Van Lommel (brecht), do you mean to define the structs as macros?


#define DNA_DEFAULT_View3DCursor { \
    .rotation_mode = ROT_MODE_XYZ, \
    .rotation_quaternion = {1, 0, 0, 0}, \
    .rotation_axis = {0, 1, 0}, \

#define DNA_DEFAULT_RenderData { \
    .mode = R_OSA, \
    /* snip */ \

#define DNA_DEFAULT_Scene { \
    .cursor = DNA_DEFAULT_View3DCursor, \
    .r = DNA_DEFAULT_RenderData, \
    /* snip */ \

Think it can work nicely, it has the advantage that a struct like View3DShading thats used in multiple places can have a single define.

Note that we wouldn't want defines from from DNA_*_defaults.h being instantiated many times - ideally only once for ID types.

Ah, I thought .shading = DNA_Default_View3DShading, would work. Apparently in C++ but not C.

The macro seems like a good trick for structs that are embedded multiple times.

  • Use macros for defaults