1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
/*
* 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
*
* DNA Defaults
* ============
*
* 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.
*
* Adding Defaults
* ---------------
*
* Adding/removing defaults for existing structs can be done by hand.
* When adding new defaults for larger structs you may want to write-out the in-memory data.
*
* 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.
*
* Public API
* ----------
*
* 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.
*
* \note Struct members only define their members (pointers are left as NULL set).
*
* Typical Usage
* -------------
*
* While there is no restriction for using these defaults,
* it's worth noting where these functions are typically used:
*
* - When creating/allocating new data.
* - RNA property defaults, used for "Set Default Value" in the buttons right-click context menu.
*
* These defaults are not used:
*
* - When loading old files that don't contain newly added struct members (these will be zeroed)
* to set their values use `versioning_{BLENDER_VERSION}.c` source files.
* - For startup file data, to update these defaults use
* #BLO_update_defaults_startup_blend & #BLO_version_defaults_userpref_blend.
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_endian_switch.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_utildefines.h"
#include "DNA_defaults.h"
#include "DNA_armature_types.h"
#include "DNA_brush_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_camera_types.h"
#include "DNA_curve_types.h"
#include "DNA_hair_types.h"
#include "DNA_image_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
#include "DNA_light_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_pointcloud_types.h"
#include "DNA_scene_types.h"
#include "DNA_simulation_types.h"
#include "DNA_space_types.h"
#include "DNA_speaker_types.h"
#include "DNA_texture_types.h"
#include "DNA_volume_types.h"
#include "DNA_world_types.h"
#include "DNA_brush_defaults.h"
#include "DNA_cachefile_defaults.h"
#include "DNA_camera_defaults.h"
#include "DNA_curve_defaults.h"
#include "DNA_hair_defaults.h"
#include "DNA_image_defaults.h"
#include "DNA_lattice_defaults.h"
#include "DNA_light_defaults.h"
#include "DNA_lightprobe_defaults.h"
#include "DNA_linestyle_defaults.h"
#include "DNA_material_defaults.h"
#include "DNA_mesh_defaults.h"
#include "DNA_meta_defaults.h"
#include "DNA_modifier_defaults.h"
#include "DNA_object_defaults.h"
#include "DNA_pointcloud_defaults.h"
#include "DNA_scene_defaults.h"
#include "DNA_simulation_defaults.h"
#include "DNA_speaker_defaults.h"
#include "DNA_texture_defaults.h"
#include "DNA_volume_defaults.h"
#include "DNA_world_defaults.h"
#define SDNA_DEFAULT_DECL_STRUCT(struct_name) \
static const struct_name DNA_DEFAULT_##struct_name = _DNA_DEFAULT_##struct_name
/* DNA_brush_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Brush);
/* DNA_cachefile_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(CacheFile);
/* DNA_camera_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Camera);
/* DNA_curve_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Curve);
/* DNA_image_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Image);
/* DNA_hair_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Hair);
/* DNA_lattice_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Lattice);
/* DNA_light_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Light);
/* DNA_lightprobe_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(LightProbe);
/* DNA_linestyle_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(FreestyleLineStyle);
/* DNA_material_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Material);
/* DNA_mesh_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Mesh);
/* DNA_meta_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(MetaBall);
/* DNA_object_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Object);
/* DNA_pointcloud_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(PointCloud);
/* DNA_scene_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Scene);
SDNA_DEFAULT_DECL_STRUCT(ToolSettings);
/* DNA_simulation_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Simulation);
/* DNA_speaker_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Speaker);
/* DNA_texture_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Tex);
/* DNA_view3d_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(View3D);
/* DNA_volume_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(Volume);
/* DNA_world_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(World);
/* DNA_modifier_defaults.h */
SDNA_DEFAULT_DECL_STRUCT(ArmatureModifierData);
SDNA_DEFAULT_DECL_STRUCT(ArrayModifierData);
SDNA_DEFAULT_DECL_STRUCT(BevelModifierData);
SDNA_DEFAULT_DECL_STRUCT(BooleanModifierData);
SDNA_DEFAULT_DECL_STRUCT(BuildModifierData);
SDNA_DEFAULT_DECL_STRUCT(CastModifierData);
/* Cloth modifier skipped for now. */
SDNA_DEFAULT_DECL_STRUCT(CollisionModifierData);
SDNA_DEFAULT_DECL_STRUCT(CorrectiveSmoothModifierData);
SDNA_DEFAULT_DECL_STRUCT(CurveModifierData);
// SDNA_DEFAULT_DECL_STRUCT(DataTransferModifierData);
SDNA_DEFAULT_DECL_STRUCT(DecimateModifierData);
SDNA_DEFAULT_DECL_STRUCT(DisplaceModifierData);
SDNA_DEFAULT_DECL_STRUCT(DynamicPaintModifierData);
SDNA_DEFAULT_DECL_STRUCT(EdgeSplitModifierData);
SDNA_DEFAULT_DECL_STRUCT(ExplodeModifierData);
/* Fluid modifier skipped for now. */
SDNA_DEFAULT_DECL_STRUCT(HookModifierData);
SDNA_DEFAULT_DECL_STRUCT(LaplacianDeformModifierData);
SDNA_DEFAULT_DECL_STRUCT(LaplacianSmoothModifierData);
SDNA_DEFAULT_DECL_STRUCT(LatticeModifierData);
SDNA_DEFAULT_DECL_STRUCT(MaskModifierData);
SDNA_DEFAULT_DECL_STRUCT(MeshCacheModifierData);
SDNA_DEFAULT_DECL_STRUCT(MeshDeformModifierData);
SDNA_DEFAULT_DECL_STRUCT(MeshSeqCacheModifierData);
SDNA_DEFAULT_DECL_STRUCT(MirrorModifierData);
SDNA_DEFAULT_DECL_STRUCT(MultiresModifierData);
SDNA_DEFAULT_DECL_STRUCT(NormalEditModifierData);
SDNA_DEFAULT_DECL_STRUCT(OceanModifierData);
SDNA_DEFAULT_DECL_STRUCT(ParticleInstanceModifierData);
SDNA_DEFAULT_DECL_STRUCT(ParticleSystemModifierData);
SDNA_DEFAULT_DECL_STRUCT(RemeshModifierData);
SDNA_DEFAULT_DECL_STRUCT(ScrewModifierData);
/* Shape key modifier has no items. */
SDNA_DEFAULT_DECL_STRUCT(ShrinkwrapModifierData);
SDNA_DEFAULT_DECL_STRUCT(SimpleDeformModifierData);
SDNA_DEFAULT_DECL_STRUCT(SimulationModifierData);
SDNA_DEFAULT_DECL_STRUCT(SkinModifierData);
SDNA_DEFAULT_DECL_STRUCT(SmoothModifierData);
/* Softbody modifier skipped for now. */
SDNA_DEFAULT_DECL_STRUCT(SolidifyModifierData);
SDNA_DEFAULT_DECL_STRUCT(SubsurfModifierData);
SDNA_DEFAULT_DECL_STRUCT(SurfaceModifierData);
SDNA_DEFAULT_DECL_STRUCT(SurfaceDeformModifierData);
SDNA_DEFAULT_DECL_STRUCT(TriangulateModifierData);
SDNA_DEFAULT_DECL_STRUCT(UVProjectModifierData);
SDNA_DEFAULT_DECL_STRUCT(UVWarpModifierData);
SDNA_DEFAULT_DECL_STRUCT(WarpModifierData);
SDNA_DEFAULT_DECL_STRUCT(WaveModifierData);
SDNA_DEFAULT_DECL_STRUCT(WeightedNormalModifierData);
SDNA_DEFAULT_DECL_STRUCT(WeightVGEditModifierData);
SDNA_DEFAULT_DECL_STRUCT(WeightVGMixModifierData);
SDNA_DEFAULT_DECL_STRUCT(WeightVGProximityModifierData);
SDNA_DEFAULT_DECL_STRUCT(WeldModifierData);
SDNA_DEFAULT_DECL_STRUCT(WireframeModifierData);
#undef SDNA_DEFAULT_DECL_STRUCT
/* Reuse existing definitions. */
extern const struct UserDef U_default;
#define DNA_DEFAULT_UserDef U_default
extern const bTheme U_theme_default;
#define DNA_DEFAULT_bTheme U_theme_default
/**
* 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_brush_defaults.h */
SDNA_DEFAULT_DECL(Brush),
/* DNA_cachefile_defaults.h */
SDNA_DEFAULT_DECL(CacheFile),
/* DNA_camera_defaults.h */
SDNA_DEFAULT_DECL(Camera),
SDNA_DEFAULT_DECL_EX(CameraDOFSettings, Camera.dof),
SDNA_DEFAULT_DECL_EX(CameraStereoSettings, Camera.stereo),
/* DNA_curve_defaults.h */
SDNA_DEFAULT_DECL(Curve),
/* DNA_image_defaults.h */
SDNA_DEFAULT_DECL(Image),
/* DNA_hair_defaults.h */
SDNA_DEFAULT_DECL(Hair),
/* DNA_lattice_defaults.h */
SDNA_DEFAULT_DECL(Lattice),
/* DNA_light_defaults.h */
SDNA_DEFAULT_DECL(Light),
/* DNA_lightprobe_defaults.h */
SDNA_DEFAULT_DECL(LightProbe),
/* DNA_linestyle_defaults.h */
SDNA_DEFAULT_DECL(FreestyleLineStyle),
/* DNA_material_defaults.h */
SDNA_DEFAULT_DECL(Material),
/* DNA_mesh_defaults.h */
SDNA_DEFAULT_DECL(Mesh),
/* DNA_meta_defaults.h */
SDNA_DEFAULT_DECL(MetaBall),
/* DNA_object_defaults.h */
SDNA_DEFAULT_DECL(Object),
/* DNA_pointcloud_defaults.h */
SDNA_DEFAULT_DECL(PointCloud),
/* 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_EX(SceneEEVEE, Scene.eevee),
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_simulation_defaults.h */
SDNA_DEFAULT_DECL(Simulation),
/* DNA_speaker_defaults.h */
SDNA_DEFAULT_DECL(Speaker),
/* DNA_texture_defaults.h */
SDNA_DEFAULT_DECL(Tex),
SDNA_DEFAULT_DECL_EX(MTex, Brush.mtex),
/* DNA_userdef_types.h */
SDNA_DEFAULT_DECL(UserDef),
SDNA_DEFAULT_DECL(bTheme),
SDNA_DEFAULT_DECL_EX(UserDef_SpaceData, UserDef.space_data),
SDNA_DEFAULT_DECL_EX(UserDef_FileSpaceData, UserDef.file_space_data),
SDNA_DEFAULT_DECL_EX(WalkNavigation, UserDef.walk_navigation),
/* DNA_view3d_defaults.h */
SDNA_DEFAULT_DECL(View3D),
SDNA_DEFAULT_DECL_EX(View3DOverlay, View3D.overlay),
SDNA_DEFAULT_DECL_EX(View3DShading, View3D.shading),
SDNA_DEFAULT_DECL_EX(View3DCursor, Scene.cursor),
/* DNA_volume_defaults.h */
SDNA_DEFAULT_DECL(Volume),
/* DNA_world_defaults.h */
SDNA_DEFAULT_DECL(World),
/* DNA_modifier_defaults.h */
SDNA_DEFAULT_DECL(ArmatureModifierData),
SDNA_DEFAULT_DECL(ArrayModifierData),
SDNA_DEFAULT_DECL(BevelModifierData),
SDNA_DEFAULT_DECL(BooleanModifierData),
SDNA_DEFAULT_DECL(BuildModifierData),
SDNA_DEFAULT_DECL(CastModifierData),
/* Cloth modifier skipped for now. */
SDNA_DEFAULT_DECL(CollisionModifierData),
SDNA_DEFAULT_DECL(CorrectiveSmoothModifierData),
SDNA_DEFAULT_DECL(CurveModifierData),
// SDNA_DEFAULT_DECL(DataTransferModifierData),
SDNA_DEFAULT_DECL(DecimateModifierData),
SDNA_DEFAULT_DECL(DisplaceModifierData),
SDNA_DEFAULT_DECL(DynamicPaintModifierData),
SDNA_DEFAULT_DECL(EdgeSplitModifierData),
SDNA_DEFAULT_DECL(ExplodeModifierData),
/* Fluid modifier skipped for now. */
SDNA_DEFAULT_DECL(HookModifierData),
SDNA_DEFAULT_DECL(LaplacianDeformModifierData),
SDNA_DEFAULT_DECL(LaplacianSmoothModifierData),
SDNA_DEFAULT_DECL(LatticeModifierData),
SDNA_DEFAULT_DECL(MaskModifierData),
SDNA_DEFAULT_DECL(MeshCacheModifierData),
SDNA_DEFAULT_DECL(MeshDeformModifierData),
SDNA_DEFAULT_DECL(MeshSeqCacheModifierData),
SDNA_DEFAULT_DECL(MirrorModifierData),
SDNA_DEFAULT_DECL(MultiresModifierData),
SDNA_DEFAULT_DECL(NormalEditModifierData),
SDNA_DEFAULT_DECL(OceanModifierData),
SDNA_DEFAULT_DECL(ParticleInstanceModifierData),
SDNA_DEFAULT_DECL(ParticleSystemModifierData),
SDNA_DEFAULT_DECL(RemeshModifierData),
SDNA_DEFAULT_DECL(ScrewModifierData),
/* Shape key modifier has no items. */
SDNA_DEFAULT_DECL(ShrinkwrapModifierData),
SDNA_DEFAULT_DECL(SimpleDeformModifierData),
SDNA_DEFAULT_DECL(SimulationModifierData),
SDNA_DEFAULT_DECL(SkinModifierData),
SDNA_DEFAULT_DECL(SmoothModifierData),
/* Softbody modifier skipped for now. */
SDNA_DEFAULT_DECL(SolidifyModifierData),
SDNA_DEFAULT_DECL(SubsurfModifierData),
SDNA_DEFAULT_DECL(SurfaceModifierData),
SDNA_DEFAULT_DECL(SurfaceDeformModifierData),
SDNA_DEFAULT_DECL(TriangulateModifierData),
SDNA_DEFAULT_DECL(UVProjectModifierData),
SDNA_DEFAULT_DECL(UVWarpModifierData),
SDNA_DEFAULT_DECL(WarpModifierData),
SDNA_DEFAULT_DECL(WaveModifierData),
SDNA_DEFAULT_DECL(WeightedNormalModifierData),
SDNA_DEFAULT_DECL(WeightVGEditModifierData),
SDNA_DEFAULT_DECL(WeightVGMixModifierData),
SDNA_DEFAULT_DECL(WeightVGProximityModifierData),
SDNA_DEFAULT_DECL(WeldModifierData),
SDNA_DEFAULT_DECL(WireframeModifierData),
};
#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;
}
|