1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 /** \file
18  * \ingroup RNA
19  */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #include "DNA_action_types.h"
25 #include "DNA_brush_types.h"
26 #include "DNA_collection_types.h"
27 #include "DNA_customdata_types.h"
28 #include "DNA_gpencil_modifier_types.h"
29 #include "DNA_lightprobe_types.h"
30 #include "DNA_material_types.h"
31 #include "DNA_mesh_types.h"
32 #include "DNA_meta_types.h"
33 #include "DNA_object_force_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_shader_fx_types.h"
37 #include "DNA_workspace_types.h"
38 
39 #include "BLI_utildefines.h"
40 
41 #include "BLT_translation.h"
42 
43 #include "BKE_camera.h"
44 #include "BKE_collection.h"
45 #include "BKE_editlattice.h"
46 #include "BKE_editmesh.h"
47 #include "BKE_layer.h"
48 #include "BKE_object_deform.h"
49 #include "BKE_object_facemap.h"
50 #include "BKE_paint.h"
51 
52 #include "RNA_access.h"
53 #include "RNA_define.h"
54 #include "RNA_enum_types.h"
55 
56 #include "rna_internal.h"
57 
58 #include "BLI_sys_types.h" /* needed for intptr_t used in ED_mesh.h */
59 #include "ED_mesh.h"
60 
61 #include "WM_api.h"
62 #include "WM_types.h"
63 
64 const EnumPropertyItem rna_enum_object_mode_items[] = {
65     {OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object Mode", ""},
66     {OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit Mode", ""},
67     {OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""},
68     {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""},
69     {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
70     {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
71     {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
72     {OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", ICON_PARTICLEMODE, "Particle Edit", ""},
73     {OB_MODE_EDIT_GPENCIL,
74      "EDIT_GPENCIL",
75      ICON_EDITMODE_HLT,
76      "Edit Mode",
77      "Edit Grease Pencil Strokes"},
78     {OB_MODE_SCULPT_GPENCIL,
79      "SCULPT_GPENCIL",
80      ICON_SCULPTMODE_HLT,
81      "Sculpt Mode",
82      "Sculpt Grease Pencil Strokes"},
83     {OB_MODE_PAINT_GPENCIL,
84      "PAINT_GPENCIL",
85      ICON_GREASEPENCIL,
86      "Draw",
87      "Paint Grease Pencil Strokes"},
88     {OB_MODE_VERTEX_GPENCIL,
89      "VERTEX_GPENCIL",
90      ICON_VPAINT_HLT,
91      "Vertex Paint",
92      "Grease Pencil Vertex Paint Strokes"},
93     {OB_MODE_WEIGHT_GPENCIL,
94      "WEIGHT_GPENCIL",
95      ICON_WPAINT_HLT,
96      "Weight Paint",
97      "Grease Pencil Weight Paint Strokes"},
98     {0, NULL, 0, NULL, NULL},
99 };
100 
101 /* Same as above, but with names that distinguish grease pencil. */
102 const EnumPropertyItem rna_enum_workspace_object_mode_items[] = {
103     {OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object Mode", ""},
104     {OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit Mode", ""},
105     {OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""},
106     {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""},
107     {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
108     {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
109     {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
110     {OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", ICON_PARTICLEMODE, "Particle Edit", ""},
111     {OB_MODE_EDIT_GPENCIL,
112      "EDIT_GPENCIL",
113      ICON_EDITMODE_HLT,
114      "Grease Pencil Edit Mode",
115      "Edit Grease Pencil Strokes"},
116     {OB_MODE_SCULPT_GPENCIL,
117      "SCULPT_GPENCIL",
118      ICON_SCULPTMODE_HLT,
119      "Grease Pencil Sculpt Mode",
120      "Sculpt Grease Pencil Strokes"},
121     {OB_MODE_PAINT_GPENCIL,
122      "PAINT_GPENCIL",
123      ICON_GREASEPENCIL,
124      "Grease Pencil Draw",
125      "Paint Grease Pencil Strokes"},
126     {OB_MODE_VERTEX_GPENCIL,
127      "VERTEX_GPENCIL",
128      ICON_VPAINT_HLT,
129      "Grease Pencil Vertex Paint",
130      "Grease Pencil Vertex Paint Strokes"},
131     {OB_MODE_WEIGHT_GPENCIL,
132      "WEIGHT_GPENCIL",
133      ICON_WPAINT_HLT,
134      "Grease Pencil Weight Paint",
135      "Grease Pencil Weight Paint Strokes"},
136     {0, NULL, 0, NULL, NULL},
137 };
138 
139 const EnumPropertyItem rna_enum_object_empty_drawtype_items[] = {
140     {OB_PLAINAXES, "PLAIN_AXES", ICON_EMPTY_AXIS, "Plain Axes", ""},
141     {OB_ARROWS, "ARROWS", ICON_EMPTY_ARROWS, "Arrows", ""},
142     {OB_SINGLE_ARROW, "SINGLE_ARROW", ICON_EMPTY_SINGLE_ARROW, "Single Arrow", ""},
143     {OB_CIRCLE, "CIRCLE", ICON_MESH_CIRCLE, "Circle", ""},
144     {OB_CUBE, "CUBE", ICON_CUBE, "Cube", ""},
145     {OB_EMPTY_SPHERE, "SPHERE", ICON_SPHERE, "Sphere", ""},
146     {OB_EMPTY_CONE, "CONE", ICON_CONE, "Cone", ""},
147     {OB_EMPTY_IMAGE, "IMAGE", ICON_FILE_IMAGE, "Image", ""},
148     {0, NULL, 0, NULL, NULL},
149 };
150 
151 static const EnumPropertyItem rna_enum_object_empty_image_depth_items[] = {
152     {OB_EMPTY_IMAGE_DEPTH_DEFAULT, "DEFAULT", 0, "Default", ""},
153     {OB_EMPTY_IMAGE_DEPTH_FRONT, "FRONT", 0, "Front", ""},
154     {OB_EMPTY_IMAGE_DEPTH_BACK, "BACK", 0, "Back", ""},
155     {0, NULL, 0, NULL, NULL},
156 };
157 
158 const EnumPropertyItem rna_enum_object_gpencil_type_items[] = {
159     {GP_EMPTY, "EMPTY", ICON_EMPTY_AXIS, "Blank", "Create an empty grease pencil object"},
160     {GP_STROKE, "STROKE", ICON_STROKE, "Stroke", "Create a simple stroke with basic colors"},
161     {GP_MONKEY, "MONKEY", ICON_MONKEY, "Monkey", "Construct a Suzanne grease pencil object"},
162     {0, NULL, 0, NULL, NULL}};
163 
164 static const EnumPropertyItem parent_type_items[] = {
165     {PAROBJECT, "OBJECT", 0, "Object", "The object is parented to an object"},
166     {PARSKEL, "ARMATURE", 0, "Armature", ""},
167     /* PARSKEL reuse will give issues. */
168     {PARSKEL, "LATTICE", 0, "Lattice", "The object is parented to a lattice"},
169     {PARVERT1, "VERTEX", 0, "Vertex", "The object is parented to a vertex"},
170     {PARVERT3, "VERTEX_3", 0, "3 Vertices", ""},
171     {PARBONE, "BONE", 0, "Bone", "The object is parented to a bone"},
172     {0, NULL, 0, NULL, NULL},
173 };
174 
175 #define INSTANCE_ITEMS_SHARED \
176   {0, "NONE", 0, "None", ""}, \
177       {OB_DUPLIVERTS, "VERTS", 0, "Vertices", "Instantiate child objects on all vertices"}, \
178   { \
179     OB_DUPLIFACES, "FACES", 0, "Faces", "Instantiate child objects on all faces" \
180   }
181 
182 #define INSTANCE_ITEM_COLLECTION \
183   { \
184     OB_DUPLICOLLECTION, "COLLECTION", 0, "Collection", "Enable collection instancing" \
185   }
186 static const EnumPropertyItem instance_items[] = {
187     INSTANCE_ITEMS_SHARED,
188     INSTANCE_ITEM_COLLECTION,
189     {0, NULL, 0, NULL, NULL},
190 };
191 #ifdef RNA_RUNTIME
192 static EnumPropertyItem instance_items_nogroup[] = {
193     INSTANCE_ITEMS_SHARED,
194     {0, NULL, 0, NULL, NULL},
195 };
196 
197 static EnumPropertyItem instance_items_pointcloud[] = {
198     {0, "NONE", 0, "None", ""},
199     {OB_DUPLIVERTS, "POINTS", 0, "Points", "Instantiate child objects on all points"},
200     {0, NULL, 0, NULL, NULL},
201 };
202 #endif
203 #undef INSTANCE_ITEMS_SHARED
204 #undef INSTANCE_ITEM_COLLECTION
205 
206 const EnumPropertyItem rna_enum_metaelem_type_items[] = {
207     {MB_BALL, "BALL", ICON_META_BALL, "Ball", ""},
208     {MB_TUBE, "CAPSULE", ICON_META_CAPSULE, "Capsule", ""},
209     {MB_PLANE, "PLANE", ICON_META_PLANE, "Plane", ""},
210     /* NOTE: typo at original definition! */
211     {MB_ELIPSOID, "ELLIPSOID", ICON_META_ELLIPSOID, "Ellipsoid", ""},
212     {MB_CUBE, "CUBE", ICON_META_CUBE, "Cube", ""},
213     {0, NULL, 0, NULL, NULL},
214 };
215 
216 const EnumPropertyItem rna_enum_lightprobes_type_items[] = {
217     {LIGHTPROBE_TYPE_CUBE, "CUBE", ICON_LIGHTPROBE_CUBEMAP, "Cube", ""},
218     {LIGHTPROBE_TYPE_PLANAR, "PLANAR", ICON_LIGHTPROBE_PLANAR, "Planar", ""},
219     {LIGHTPROBE_TYPE_GRID, "GRID", ICON_LIGHTPROBE_GRID, "Grid", ""},
220     {0, NULL, 0, NULL, NULL},
221 };
222 
223 /* used for 2 enums */
224 #define OBTYPE_CU_CURVE \
225   { \
226     OB_CURVE, "CURVE", ICON_OUTLINER_OB_CURVE, "Curve", "" \
227   }
228 #define OBTYPE_CU_SURF \
229   { \
230     OB_SURF, "SURFACE", ICON_OUTLINER_OB_SURFACE, "Surface", "" \
231   }
232 #define OBTYPE_CU_FONT \
233   { \
234     OB_FONT, "FONT", ICON_OUTLINER_OB_FONT, "Text", "" \
235   }
236 
237 const EnumPropertyItem rna_enum_object_type_items[] = {
238     {OB_MESH, "MESH", ICON_OUTLINER_OB_MESH, "Mesh", ""},
239     OBTYPE_CU_CURVE,
240     OBTYPE_CU_SURF,
241     {OB_MBALL, "META", ICON_OUTLINER_OB_META, "Metaball", ""},
242     OBTYPE_CU_FONT,
243     {OB_HAIR, "HAIR", ICON_OUTLINER_OB_HAIR, "Hair", ""},
244     {OB_POINTCLOUD, "POINTCLOUD", ICON_OUTLINER_OB_POINTCLOUD, "Point Cloud", ""},
245     {OB_VOLUME, "VOLUME", ICON_OUTLINER_OB_VOLUME, "Volume", ""},
246     {OB_GPENCIL, "GPENCIL", ICON_OUTLINER_OB_GREASEPENCIL, "Grease Pencil", ""},
247     {0, "", 0, NULL, NULL},
248     {OB_ARMATURE, "ARMATURE", ICON_OUTLINER_OB_ARMATURE, "Armature", ""},
249     {OB_LATTICE, "LATTICE", ICON_OUTLINER_OB_LATTICE, "Lattice", ""},
250     {0, "", 0, NULL, NULL},
251     {OB_EMPTY, "EMPTY", ICON_OUTLINER_OB_EMPTY, "Empty", ""},
252     {0, "", 0, NULL, NULL},
253     {OB_LAMP, "LIGHT", ICON_OUTLINER_OB_LIGHT, "Light", ""},
254     {OB_LIGHTPROBE, "LIGHT_PROBE", ICON_OUTLINER_OB_LIGHTPROBE, "Light Probe", ""},
255     {0, "", 0, NULL, NULL},
256     {OB_CAMERA, "CAMERA", ICON_OUTLINER_OB_CAMERA, "Camera", ""},
257     {0, "", 0, NULL, NULL},
258     {OB_SPEAKER, "SPEAKER", ICON_OUTLINER_OB_SPEAKER, "Speaker", ""},
259     {0, NULL, 0, NULL, NULL},
260 };
261 
262 const EnumPropertyItem rna_enum_object_type_curve_items[] = {
263     OBTYPE_CU_CURVE,
264     OBTYPE_CU_SURF,
265     OBTYPE_CU_FONT,
266     {0, NULL, 0, NULL, NULL},
267 };
268 
269 const EnumPropertyItem rna_enum_object_rotation_mode_items[] = {
270     {ROT_MODE_QUAT, "QUATERNION", 0, "Quaternion (WXYZ)", "No Gimbal Lock"},
271     {ROT_MODE_XYZ, "XYZ", 0, "XYZ Euler", "XYZ Rotation Order - prone to Gimbal Lock (default)"},
272     {ROT_MODE_XZY, "XZY", 0, "XZY Euler", "XZY Rotation Order - prone to Gimbal Lock"},
273     {ROT_MODE_YXZ, "YXZ", 0, "YXZ Euler", "YXZ Rotation Order - prone to Gimbal Lock"},
274     {ROT_MODE_YZX, "YZX", 0, "YZX Euler", "YZX Rotation Order - prone to Gimbal Lock"},
275     {ROT_MODE_ZXY, "ZXY", 0, "ZXY Euler", "ZXY Rotation Order - prone to Gimbal Lock"},
276     {ROT_MODE_ZYX, "ZYX", 0, "ZYX Euler", "ZYX Rotation Order - prone to Gimbal Lock"},
277     {ROT_MODE_AXISANGLE,
278      "AXIS_ANGLE",
279      0,
280      "Axis Angle",
281      "Axis Angle (W+XYZ), defines a rotation around some axis defined by 3D-Vector"},
282     {0, NULL, 0, NULL, NULL},
283 };
284 
285 const EnumPropertyItem rna_enum_object_axis_items[] = {
286     {OB_POSX, "POS_X", 0, "+X", ""},
287     {OB_POSY, "POS_Y", 0, "+Y", ""},
288     {OB_POSZ, "POS_Z", 0, "+Z", ""},
289     {OB_NEGX, "NEG_X", 0, "-X", ""},
290     {OB_NEGY, "NEG_Y", 0, "-Y", ""},
291     {OB_NEGZ, "NEG_Z", 0, "-Z", ""},
292     {0, NULL, 0, NULL, NULL},
293 };
294 
295 #ifdef RNA_RUNTIME
296 
297 #  include "BLI_math.h"
298 
299 #  include "DNA_ID.h"
300 #  include "DNA_constraint_types.h"
301 #  include "DNA_gpencil_types.h"
302 #  include "DNA_key_types.h"
303 #  include "DNA_lattice_types.h"
304 #  include "DNA_node_types.h"
305 
306 #  include "BKE_armature.h"
307 #  include "BKE_brush.h"
308 #  include "BKE_constraint.h"
309 #  include "BKE_context.h"
310 #  include "BKE_curve.h"
311 #  include "BKE_deform.h"
312 #  include "BKE_effect.h"
313 #  include "BKE_global.h"
314 #  include "BKE_key.h"
315 #  include "BKE_material.h"
316 #  include "BKE_mesh.h"
317 #  include "BKE_modifier.h"
318 #  include "BKE_object.h"
319 #  include "BKE_particle.h"
320 #  include "BKE_scene.h"
321 
322 #  include "DEG_depsgraph.h"
323 #  include "DEG_depsgraph_build.h"
324 
325 #  include "ED_curve.h"
326 #  include "ED_lattice.h"
327 #  include "ED_object.h"
328 #  include "ED_particle.h"
329 
rna_Object_internal_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)330 static void rna_Object_internal_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
331 {
332   DEG_id_tag_update(ptr->owner_id, ID_RECALC_TRANSFORM);
333 }
334 
rna_Object_internal_update_draw(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)335 static void rna_Object_internal_update_draw(Main *UNUSED(bmain),
336                                             Scene *UNUSED(scene),
337                                             PointerRNA *ptr)
338 {
339   DEG_id_tag_update(ptr->owner_id, ID_RECALC_SHADING);
340   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ptr->owner_id);
341 }
342 
rna_Object_matrix_world_update(Main * bmain,Scene * scene,PointerRNA * ptr)343 static void rna_Object_matrix_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
344 {
345   /* don't use compat so we get predictable rotation */
346   BKE_object_apply_mat4((Object *)ptr->owner_id, ((Object *)ptr->owner_id)->obmat, false, true);
347   rna_Object_internal_update(bmain, scene, ptr);
348 }
349 
rna_Object_hide_update(Main * bmain,Scene * UNUSED (scene),PointerRNA * ptr)350 static void rna_Object_hide_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
351 {
352   Object *ob = (Object *)ptr->owner_id;
353   BKE_main_collection_sync_remap(bmain);
354   DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
355   DEG_relations_tag_update(bmain);
356   WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
357 }
358 
rna_Object_duplicator_visibility_flag_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)359 static void rna_Object_duplicator_visibility_flag_update(Main *UNUSED(bmain),
360                                                          Scene *UNUSED(scene),
361                                                          PointerRNA *ptr)
362 {
363   Object *ob = (Object *)ptr->owner_id;
364   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
365 }
366 
rna_MaterialIndex_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)367 static void rna_MaterialIndex_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
368 {
369   Object *ob = (Object *)ptr->owner_id;
370   if (ob && ob->type == OB_GPENCIL) {
371     /* notifying material property in topbar */
372     WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL);
373   }
374 }
375 
rna_GPencil_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)376 static void rna_GPencil_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
377 {
378   Object *ob = (Object *)ptr->owner_id;
379   if (ob && ob->type == OB_GPENCIL) {
380     bGPdata *gpd = (bGPdata *)ob->data;
381     DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
382     WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
383   }
384 }
385 
rna_Object_matrix_local_get(PointerRNA * ptr,float values[16])386 static void rna_Object_matrix_local_get(PointerRNA *ptr, float values[16])
387 {
388   Object *ob = (Object *)ptr->owner_id;
389   BKE_object_matrix_local_get(ob, (float(*)[4])values);
390 }
391 
rna_Object_matrix_local_set(PointerRNA * ptr,const float values[16])392 static void rna_Object_matrix_local_set(PointerRNA *ptr, const float values[16])
393 {
394   Object *ob = (Object *)ptr->owner_id;
395   float local_mat[4][4];
396 
397   /* Localspace matrix is truly relative to the parent,
398    * but parameters stored in object are relative to parentinv matrix.
399    * Undo the parent inverse part before applying it as local matrix. */
400   if (ob->parent) {
401     float invmat[4][4];
402     invert_m4_m4(invmat, ob->parentinv);
403     mul_m4_m4m4(local_mat, invmat, (float(*)[4])values);
404   }
405   else {
406     copy_m4_m4(local_mat, (float(*)[4])values);
407   }
408 
409   /* Don't use compatible so we get predictable rotation, and do not use parenting either,
410    * because it's a local matrix! */
411   BKE_object_apply_mat4(ob, local_mat, false, false);
412 }
413 
rna_Object_matrix_basis_get(PointerRNA * ptr,float values[16])414 static void rna_Object_matrix_basis_get(PointerRNA *ptr, float values[16])
415 {
416   Object *ob = (Object *)ptr->owner_id;
417   BKE_object_to_mat4(ob, (float(*)[4])values);
418 }
419 
rna_Object_matrix_basis_set(PointerRNA * ptr,const float values[16])420 static void rna_Object_matrix_basis_set(PointerRNA *ptr, const float values[16])
421 {
422   Object *ob = (Object *)ptr->owner_id;
423   BKE_object_apply_mat4(ob, (float(*)[4])values, false, false);
424 }
425 
rna_Object_internal_update_data_impl(PointerRNA * ptr)426 void rna_Object_internal_update_data_impl(PointerRNA *ptr)
427 {
428   DEG_id_tag_update(ptr->owner_id, ID_RECALC_GEOMETRY);
429   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ptr->owner_id);
430 }
431 
rna_Object_internal_update_data(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)432 void rna_Object_internal_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
433 {
434   rna_Object_internal_update_data_impl(ptr);
435 }
436 
rna_Object_internal_update_data_dependency(Main * bmain,Scene * UNUSED (scene),PointerRNA * ptr)437 void rna_Object_internal_update_data_dependency(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
438 {
439   DEG_relations_tag_update(bmain);
440   rna_Object_internal_update_data_impl(ptr);
441 }
442 
rna_Object_active_shape_update(Main * bmain,Scene * UNUSED (scene),PointerRNA * ptr)443 static void rna_Object_active_shape_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
444 {
445   Object *ob = (Object *)ptr->owner_id;
446 
447   if (BKE_object_is_in_editmode(ob)) {
448     /* exit/enter editmode to get new shape */
449     switch (ob->type) {
450       case OB_MESH: {
451         Mesh *me = ob->data;
452         BMEditMesh *em = me->edit_mesh;
453         int select_mode = em->selectmode;
454         EDBM_mesh_load(bmain, ob);
455         EDBM_mesh_make(ob, select_mode, true);
456         em = me->edit_mesh;
457 
458         DEG_id_tag_update(&me->id, 0);
459 
460         EDBM_mesh_normals_update(em);
461         BKE_editmesh_looptri_calc(em);
462         break;
463       }
464       case OB_CURVE:
465       case OB_SURF:
466         ED_curve_editnurb_load(bmain, ob);
467         ED_curve_editnurb_make(ob);
468         break;
469       case OB_LATTICE:
470         BKE_editlattice_load(ob);
471         BKE_editlattice_make(ob);
472         break;
473     }
474   }
475 
476   rna_Object_internal_update_data_impl(ptr);
477 }
478 
rna_Object_dependency_update(Main * bmain,Scene * UNUSED (scene),PointerRNA * ptr)479 static void rna_Object_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
480 {
481   DEG_id_tag_update(ptr->owner_id, ID_RECALC_TRANSFORM);
482   DEG_relations_tag_update(bmain);
483   WM_main_add_notifier(NC_OBJECT | ND_PARENT, ptr->owner_id);
484 }
485 
rna_Object_data_set(PointerRNA * ptr,PointerRNA value,struct ReportList * reports)486 static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value, struct ReportList *reports)
487 {
488   Object *ob = (Object *)ptr->data;
489   ID *id = value.data;
490 
491   if (ob->mode & OB_MODE_EDIT) {
492     return;
493   }
494 
495   /* assigning NULL only for empties */
496   if ((id == NULL) && (ob->type != OB_EMPTY)) {
497     return;
498   }
499 
500   if (id && ((id->tag & LIB_TAG_NO_MAIN) != (ob->id.tag & LIB_TAG_NO_MAIN))) {
501     BKE_report(reports,
502                RPT_ERROR,
503                "Can only assign evaluated data to evaluated object, or original data to "
504                "original object");
505     return;
506   }
507 
508   if (ob->type == OB_EMPTY) {
509     if (ob->data) {
510       id_us_min((ID *)ob->data);
511       ob->data = NULL;
512     }
513 
514     if (!id || GS(id->name) == ID_IM) {
515       id_us_plus(id);
516       ob->data = id;
517     }
518   }
519   else if (ob->type == OB_MESH) {
520     BKE_mesh_assign_object(G_MAIN, ob, (Mesh *)id);
521   }
522   else {
523     if (ob->data) {
524       id_us_min((ID *)ob->data);
525     }
526 
527     /* no need to type-check here ID. this is done in the _typef() function */
528     BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
529     id_us_plus(id);
530 
531     ob->data = id;
532     BKE_object_materials_test(G_MAIN, ob, id);
533 
534     if (GS(id->name) == ID_CU) {
535       BKE_curve_type_test(ob);
536     }
537     else if (ob->type == OB_ARMATURE) {
538       BKE_pose_rebuild(G_MAIN, ob, ob->data, true);
539     }
540   }
541 }
542 
rna_Object_data_typef(PointerRNA * ptr)543 static StructRNA *rna_Object_data_typef(PointerRNA *ptr)
544 {
545   Object *ob = (Object *)ptr->data;
546 
547   /* keep in sync with OB_DATA_SUPPORT_ID() macro */
548   switch (ob->type) {
549     case OB_EMPTY:
550       return &RNA_Image;
551     case OB_MESH:
552       return &RNA_Mesh;
553     case OB_CURVE:
554       return &RNA_Curve;
555     case OB_SURF:
556       return &RNA_Curve;
557     case OB_FONT:
558       return &RNA_Curve;
559     case OB_MBALL:
560       return &RNA_MetaBall;
561     case OB_LAMP:
562       return &RNA_Light;
563     case OB_CAMERA:
564       return &RNA_Camera;
565     case OB_LATTICE:
566       return &RNA_Lattice;
567     case OB_ARMATURE:
568       return &RNA_Armature;
569     case OB_SPEAKER:
570       return &RNA_Speaker;
571     case OB_LIGHTPROBE:
572       return &RNA_LightProbe;
573     case OB_GPENCIL:
574       return &RNA_GreasePencil;
575     case OB_HAIR:
576 #  ifdef WITH_HAIR_NODES
577       return &RNA_Hair;
578 #  else
579       return &RNA_ID;
580 #  endif
581     case OB_POINTCLOUD:
582 #  ifdef WITH_POINT_CLOUD
583       return &RNA_PointCloud;
584 #  else
585       return &RNA_ID;
586 #  endif
587     case OB_VOLUME:
588       return &RNA_Volume;
589     default:
590       return &RNA_ID;
591   }
592 }
593 
rna_Object_data_poll(PointerRNA * ptr,const PointerRNA value)594 static bool rna_Object_data_poll(PointerRNA *ptr, const PointerRNA value)
595 {
596   Object *ob = (Object *)ptr->data;
597 
598   if (ob->type == OB_GPENCIL) {
599     /* GP Object - Don't allow using "Annotation" GP datablocks here */
600     bGPdata *gpd = value.data;
601     return (gpd->flag & GP_DATA_ANNOTATIONS) == 0;
602   }
603 
604   return true;
605 }
606 
rna_Object_parent_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))607 static void rna_Object_parent_set(PointerRNA *ptr,
608                                   PointerRNA value,
609                                   struct ReportList *UNUSED(reports))
610 {
611   Object *ob = (Object *)ptr->data;
612   Object *par = (Object *)value.data;
613 
614   {
615     ED_object_parent(ob, par, ob->partype, ob->parsubstr);
616   }
617 }
618 
rna_Object_parent_override_apply(Main * UNUSED (bmain),PointerRNA * ptr_dst,PointerRNA * ptr_src,PointerRNA * ptr_storage,PropertyRNA * prop_dst,PropertyRNA * prop_src,PropertyRNA * UNUSED (prop_storage),const int len_dst,const int len_src,const int len_storage,PointerRNA * UNUSED (ptr_item_dst),PointerRNA * UNUSED (ptr_item_src),PointerRNA * UNUSED (ptr_item_storage),IDOverrideLibraryPropertyOperation * opop)619 static bool rna_Object_parent_override_apply(Main *UNUSED(bmain),
620                                              PointerRNA *ptr_dst,
621                                              PointerRNA *ptr_src,
622                                              PointerRNA *ptr_storage,
623                                              PropertyRNA *prop_dst,
624                                              PropertyRNA *prop_src,
625                                              PropertyRNA *UNUSED(prop_storage),
626                                              const int len_dst,
627                                              const int len_src,
628                                              const int len_storage,
629                                              PointerRNA *UNUSED(ptr_item_dst),
630                                              PointerRNA *UNUSED(ptr_item_src),
631                                              PointerRNA *UNUSED(ptr_item_storage),
632                                              IDOverrideLibraryPropertyOperation *opop)
633 {
634   BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage) && len_dst == 0);
635   BLI_assert(opop->operation == IDOVERRIDE_LIBRARY_OP_REPLACE &&
636              "Unsupported RNA override operation on object parent pointer");
637   UNUSED_VARS_NDEBUG(ptr_storage, len_dst, len_src, len_storage, opop);
638 
639   /* We need a special handling here because setting parent resets invert parent matrix,
640    * which is evil in our case. */
641   Object *ob = (Object *)ptr_dst->data;
642   Object *parent_dst = RNA_property_pointer_get(ptr_dst, prop_dst).data;
643   Object *parent_src = RNA_property_pointer_get(ptr_src, prop_src).data;
644 
645   if (parent_src == parent_dst) {
646     return false;
647   }
648 
649   if (parent_src == NULL) {
650     /* The only case where we do want default behavior (with matrix reset). */
651     ED_object_parent(ob, parent_src, ob->partype, ob->parsubstr);
652   }
653   else {
654     ob->parent = parent_src;
655   }
656   return true;
657 }
658 
rna_Object_parent_type_set(PointerRNA * ptr,int value)659 static void rna_Object_parent_type_set(PointerRNA *ptr, int value)
660 {
661   Object *ob = (Object *)ptr->data;
662 
663   ED_object_parent(ob, ob->parent, value, ob->parsubstr);
664 }
665 
rna_Object_parent_type_itemf(bContext * UNUSED (C),PointerRNA * ptr,PropertyRNA * UNUSED (prop),bool * r_free)666 static const EnumPropertyItem *rna_Object_parent_type_itemf(bContext *UNUSED(C),
667                                                             PointerRNA *ptr,
668                                                             PropertyRNA *UNUSED(prop),
669                                                             bool *r_free)
670 {
671   Object *ob = (Object *)ptr->data;
672   EnumPropertyItem *item = NULL;
673   int totitem = 0;
674 
675   RNA_enum_items_add_value(&item, &totitem, parent_type_items, PAROBJECT);
676 
677   if (ob->parent) {
678     Object *par = ob->parent;
679 
680     if (par->type == OB_LATTICE) {
681       /* special hack: prevents this overriding others */
682       RNA_enum_items_add_value(&item, &totitem, &parent_type_items[2], PARSKEL);
683     }
684     else if (par->type == OB_ARMATURE) {
685       /* special hack: prevents this being overridden */
686       RNA_enum_items_add_value(&item, &totitem, &parent_type_items[1], PARSKEL);
687       RNA_enum_items_add_value(&item, &totitem, parent_type_items, PARBONE);
688     }
689 
690     if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
691       RNA_enum_items_add_value(&item, &totitem, parent_type_items, PARVERT1);
692       RNA_enum_items_add_value(&item, &totitem, parent_type_items, PARVERT3);
693     }
694   }
695 
696   RNA_enum_item_end(&item, &totitem);
697   *r_free = true;
698 
699   return item;
700 }
701 
rna_Object_empty_display_type_set(PointerRNA * ptr,int value)702 static void rna_Object_empty_display_type_set(PointerRNA *ptr, int value)
703 {
704   Object *ob = (Object *)ptr->data;
705 
706   BKE_object_empty_draw_type_set(ob, value);
707 }
708 
rna_Object_parent_bone_set(PointerRNA * ptr,const char * value)709 static void rna_Object_parent_bone_set(PointerRNA *ptr, const char *value)
710 {
711   Object *ob = (Object *)ptr->data;
712 
713   ED_object_parent(ob, ob->parent, ob->partype, value);
714 }
715 
rna_Object_instance_type_itemf(bContext * UNUSED (C),PointerRNA * ptr,PropertyRNA * UNUSED (prop),bool * UNUSED (r_free))716 static const EnumPropertyItem *rna_Object_instance_type_itemf(bContext *UNUSED(C),
717                                                               PointerRNA *ptr,
718                                                               PropertyRNA *UNUSED(prop),
719                                                               bool *UNUSED(r_free))
720 {
721   Object *ob = (Object *)ptr->data;
722   const EnumPropertyItem *item;
723 
724   if (ob->type == OB_EMPTY) {
725     item = instance_items;
726   }
727   else if (ob->type == OB_POINTCLOUD) {
728     item = instance_items_pointcloud;
729   }
730   else {
731     item = instance_items_nogroup;
732   }
733 
734   return item;
735 }
736 
rna_Object_dup_collection_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))737 static void rna_Object_dup_collection_set(PointerRNA *ptr,
738                                           PointerRNA value,
739                                           struct ReportList *UNUSED(reports))
740 {
741   Object *ob = (Object *)ptr->data;
742   Collection *grp = (Collection *)value.data;
743 
744   /* Must not let this be set if the object belongs in this group already,
745    * thus causing a cycle/infinite-recursion leading to crashes on load T25298. */
746   if (BKE_collection_has_object_recursive(grp, ob) == 0) {
747     if (ob->type == OB_EMPTY) {
748       id_us_min(&ob->instance_collection->id);
749       ob->instance_collection = grp;
750       id_us_plus(&ob->instance_collection->id);
751     }
752     else {
753       BKE_report(NULL, RPT_ERROR, "Only empty objects support collection instances");
754     }
755   }
756   else {
757     BKE_report(NULL,
758                RPT_ERROR,
759                "Cannot set instance-collection as object belongs in group being instanced, thus "
760                "causing a cycle");
761   }
762 }
763 
rna_VertexGroup_name_set(PointerRNA * ptr,const char * value)764 static void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value)
765 {
766   Object *ob = (Object *)ptr->owner_id;
767   bDeformGroup *dg = (bDeformGroup *)ptr->data;
768   BLI_strncpy_utf8(dg->name, value, sizeof(dg->name));
769   BKE_object_defgroup_unique_name(dg, ob);
770 }
771 
rna_VertexGroup_index_get(PointerRNA * ptr)772 static int rna_VertexGroup_index_get(PointerRNA *ptr)
773 {
774   Object *ob = (Object *)ptr->owner_id;
775 
776   return BLI_findindex(&ob->defbase, ptr->data);
777 }
778 
rna_Object_active_vertex_group_get(PointerRNA * ptr)779 static PointerRNA rna_Object_active_vertex_group_get(PointerRNA *ptr)
780 {
781   Object *ob = (Object *)ptr->owner_id;
782   return rna_pointer_inherit_refine(
783       ptr, &RNA_VertexGroup, BLI_findlink(&ob->defbase, ob->actdef - 1));
784 }
785 
rna_Object_active_vertex_group_set(PointerRNA * ptr,PointerRNA value,struct ReportList * reports)786 static void rna_Object_active_vertex_group_set(PointerRNA *ptr,
787                                                PointerRNA value,
788                                                struct ReportList *reports)
789 {
790   Object *ob = (Object *)ptr->owner_id;
791   int index = BLI_findindex(&ob->defbase, value.data);
792   if (index == -1) {
793     BKE_reportf(reports,
794                 RPT_ERROR,
795                 "VertexGroup '%s' not found in object '%s'",
796                 ((bDeformGroup *)value.data)->name,
797                 ob->id.name + 2);
798     return;
799   }
800 
801   ob->actdef = index + 1;
802 }
803 
rna_Object_active_vertex_group_index_get(PointerRNA * ptr)804 static int rna_Object_active_vertex_group_index_get(PointerRNA *ptr)
805 {
806   Object *ob = (Object *)ptr->owner_id;
807   return ob->actdef - 1;
808 }
809 
rna_Object_active_vertex_group_index_set(PointerRNA * ptr,int value)810 static void rna_Object_active_vertex_group_index_set(PointerRNA *ptr, int value)
811 {
812   Object *ob = (Object *)ptr->owner_id;
813   ob->actdef = value + 1;
814 }
815 
rna_Object_active_vertex_group_index_range(PointerRNA * ptr,int * min,int * max,int * UNUSED (softmin),int * UNUSED (softmax))816 static void rna_Object_active_vertex_group_index_range(
817     PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
818 {
819   Object *ob = (Object *)ptr->owner_id;
820 
821   *min = 0;
822   *max = max_ii(0, BLI_listbase_count(&ob->defbase) - 1);
823 }
824 
rna_object_vgroup_name_index_get(PointerRNA * ptr,char * value,int index)825 void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index)
826 {
827   Object *ob = (Object *)ptr->owner_id;
828   bDeformGroup *dg;
829 
830   dg = BLI_findlink(&ob->defbase, index - 1);
831 
832   if (dg) {
833     BLI_strncpy(value, dg->name, sizeof(dg->name));
834   }
835   else {
836     value[0] = '\0';
837   }
838 }
839 
rna_object_vgroup_name_index_length(PointerRNA * ptr,int index)840 int rna_object_vgroup_name_index_length(PointerRNA *ptr, int index)
841 {
842   Object *ob = (Object *)ptr->owner_id;
843   bDeformGroup *dg;
844 
845   dg = BLI_findlink(&ob->defbase, index - 1);
846   return (dg) ? strlen(dg->name) : 0;
847 }
848 
rna_object_vgroup_name_index_set(PointerRNA * ptr,const char * value,short * index)849 void rna_object_vgroup_name_index_set(PointerRNA *ptr, const char *value, short *index)
850 {
851   Object *ob = (Object *)ptr->owner_id;
852   *index = BKE_object_defgroup_name_index(ob, value) + 1;
853 }
854 
rna_object_vgroup_name_set(PointerRNA * ptr,const char * value,char * result,int maxlen)855 void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
856 {
857   Object *ob = (Object *)ptr->owner_id;
858   bDeformGroup *dg = BKE_object_defgroup_find_name(ob, value);
859   if (dg) {
860     /* No need for BLI_strncpy_utf8, since this matches an existing group. */
861     BLI_strncpy(result, value, maxlen);
862     return;
863   }
864 
865   result[0] = '\0';
866 }
867 
rna_FaceMap_name_set(PointerRNA * ptr,const char * value)868 static void rna_FaceMap_name_set(PointerRNA *ptr, const char *value)
869 {
870   Object *ob = (Object *)ptr->owner_id;
871   bFaceMap *fmap = (bFaceMap *)ptr->data;
872   BLI_strncpy_utf8(fmap->name, value, sizeof(fmap->name));
873   BKE_object_facemap_unique_name(ob, fmap);
874 }
875 
rna_FaceMap_index_get(PointerRNA * ptr)876 static int rna_FaceMap_index_get(PointerRNA *ptr)
877 {
878   Object *ob = (Object *)ptr->owner_id;
879 
880   return BLI_findindex(&ob->fmaps, ptr->data);
881 }
882 
rna_Object_active_face_map_get(PointerRNA * ptr)883 static PointerRNA rna_Object_active_face_map_get(PointerRNA *ptr)
884 {
885   Object *ob = (Object *)ptr->owner_id;
886   return rna_pointer_inherit_refine(ptr, &RNA_FaceMap, BLI_findlink(&ob->fmaps, ob->actfmap - 1));
887 }
888 
rna_Object_active_face_map_index_get(PointerRNA * ptr)889 static int rna_Object_active_face_map_index_get(PointerRNA *ptr)
890 {
891   Object *ob = (Object *)ptr->owner_id;
892   return ob->actfmap - 1;
893 }
894 
rna_Object_active_face_map_index_set(PointerRNA * ptr,int value)895 static void rna_Object_active_face_map_index_set(PointerRNA *ptr, int value)
896 {
897   Object *ob = (Object *)ptr->owner_id;
898   ob->actfmap = value + 1;
899 }
900 
rna_Object_active_face_map_index_range(PointerRNA * ptr,int * min,int * max,int * UNUSED (softmin),int * UNUSED (softmax))901 static void rna_Object_active_face_map_index_range(
902     PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
903 {
904   Object *ob = (Object *)ptr->owner_id;
905 
906   *min = 0;
907   *max = max_ii(0, BLI_listbase_count(&ob->fmaps) - 1);
908 }
909 
rna_object_BKE_object_facemap_name_index_get(PointerRNA * ptr,char * value,int index)910 void rna_object_BKE_object_facemap_name_index_get(PointerRNA *ptr, char *value, int index)
911 {
912   Object *ob = (Object *)ptr->owner_id;
913   bFaceMap *fmap;
914 
915   fmap = BLI_findlink(&ob->fmaps, index - 1);
916 
917   if (fmap) {
918     BLI_strncpy(value, fmap->name, sizeof(fmap->name));
919   }
920   else {
921     value[0] = '\0';
922   }
923 }
924 
rna_object_BKE_object_facemap_name_index_length(PointerRNA * ptr,int index)925 int rna_object_BKE_object_facemap_name_index_length(PointerRNA *ptr, int index)
926 {
927   Object *ob = (Object *)ptr->owner_id;
928   bFaceMap *fmap;
929 
930   fmap = BLI_findlink(&ob->fmaps, index - 1);
931   return (fmap) ? strlen(fmap->name) : 0;
932 }
933 
rna_object_BKE_object_facemap_name_index_set(PointerRNA * ptr,const char * value,short * index)934 void rna_object_BKE_object_facemap_name_index_set(PointerRNA *ptr, const char *value, short *index)
935 {
936   Object *ob = (Object *)ptr->owner_id;
937   *index = BKE_object_facemap_name_index(ob, value) + 1;
938 }
939 
rna_object_fmap_name_set(PointerRNA * ptr,const char * value,char * result,int maxlen)940 void rna_object_fmap_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
941 {
942   Object *ob = (Object *)ptr->owner_id;
943   bFaceMap *fmap = BKE_object_facemap_find_name(ob, value);
944   if (fmap) {
945     /* No need for BLI_strncpy_utf8, since this matches an existing group. */
946     BLI_strncpy(result, value, maxlen);
947     return;
948   }
949 
950   result[0] = '\0';
951 }
952 
rna_object_uvlayer_name_set(PointerRNA * ptr,const char * value,char * result,int maxlen)953 void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
954 {
955   Object *ob = (Object *)ptr->owner_id;
956   Mesh *me;
957   CustomDataLayer *layer;
958   int a;
959 
960   if (ob->type == OB_MESH && ob->data) {
961     me = (Mesh *)ob->data;
962 
963     for (a = 0; a < me->ldata.totlayer; a++) {
964       layer = &me->ldata.layers[a];
965 
966       if (layer->type == CD_MLOOPUV && STREQ(layer->name, value)) {
967         BLI_strncpy(result, value, maxlen);
968         return;
969       }
970     }
971   }
972 
973   result[0] = '\0';
974 }
975 
rna_object_vcollayer_name_set(PointerRNA * ptr,const char * value,char * result,int maxlen)976 void rna_object_vcollayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
977 {
978   Object *ob = (Object *)ptr->owner_id;
979   Mesh *me;
980   CustomDataLayer *layer;
981   int a;
982 
983   if (ob->type == OB_MESH && ob->data) {
984     me = (Mesh *)ob->data;
985 
986     for (a = 0; a < me->fdata.totlayer; a++) {
987       layer = &me->fdata.layers[a];
988 
989       if (layer->type == CD_MCOL && STREQ(layer->name, value)) {
990         BLI_strncpy(result, value, maxlen);
991         return;
992       }
993     }
994   }
995 
996   result[0] = '\0';
997 }
998 
rna_Object_active_material_index_get(PointerRNA * ptr)999 static int rna_Object_active_material_index_get(PointerRNA *ptr)
1000 {
1001   Object *ob = (Object *)ptr->owner_id;
1002   return MAX2(ob->actcol - 1, 0);
1003 }
1004 
rna_Object_active_material_index_set(PointerRNA * ptr,int value)1005 static void rna_Object_active_material_index_set(PointerRNA *ptr, int value)
1006 {
1007   Object *ob = (Object *)ptr->owner_id;
1008   ob->actcol = value + 1;
1009 
1010   if (ob->type == OB_MESH) {
1011     Mesh *me = ob->data;
1012 
1013     if (me->edit_mesh) {
1014       me->edit_mesh->mat_nr = value;
1015     }
1016   }
1017 }
1018 
rna_Object_active_material_index_range(PointerRNA * ptr,int * min,int * max,int * UNUSED (softmin),int * UNUSED (softmax))1019 static void rna_Object_active_material_index_range(
1020     PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
1021 {
1022   Object *ob = (Object *)ptr->owner_id;
1023   *min = 0;
1024   *max = max_ii(ob->totcol - 1, 0);
1025 }
1026 
1027 /* returns active base material */
rna_Object_active_material_get(PointerRNA * ptr)1028 static PointerRNA rna_Object_active_material_get(PointerRNA *ptr)
1029 {
1030   Object *ob = (Object *)ptr->owner_id;
1031   Material *ma;
1032 
1033   ma = (ob->totcol) ? BKE_object_material_get(ob, ob->actcol) : NULL;
1034   return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
1035 }
1036 
rna_Object_active_material_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))1037 static void rna_Object_active_material_set(PointerRNA *ptr,
1038                                            PointerRNA value,
1039                                            struct ReportList *UNUSED(reports))
1040 {
1041   Object *ob = (Object *)ptr->owner_id;
1042 
1043   DEG_id_tag_update(value.data, 0);
1044   BLI_assert(BKE_id_is_in_global_main(&ob->id));
1045   BLI_assert(BKE_id_is_in_global_main(value.data));
1046   BKE_object_material_assign(G_MAIN, ob, value.data, ob->actcol, BKE_MAT_ASSIGN_EXISTING);
1047 
1048   if (ob && ob->type == OB_GPENCIL) {
1049     /* notifying material property in topbar */
1050     WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL);
1051   }
1052 }
1053 
rna_Object_active_material_editable(PointerRNA * ptr,const char ** UNUSED (r_info))1054 static int rna_Object_active_material_editable(PointerRNA *ptr, const char **UNUSED(r_info))
1055 {
1056   Object *ob = (Object *)ptr->owner_id;
1057   bool is_editable;
1058 
1059   if ((ob->matbits == NULL) || (ob->actcol == 0) || ob->matbits[ob->actcol - 1]) {
1060     is_editable = !ID_IS_LINKED(ob);
1061   }
1062   else {
1063     is_editable = ob->data ? !ID_IS_LINKED(ob->data) : false;
1064   }
1065 
1066   return is_editable ? PROP_EDITABLE : 0;
1067 }
1068 
rna_Object_active_particle_system_index_range(PointerRNA * ptr,int * min,int * max,int * UNUSED (softmin),int * UNUSED (softmax))1069 static void rna_Object_active_particle_system_index_range(
1070     PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
1071 {
1072   Object *ob = (Object *)ptr->owner_id;
1073   *min = 0;
1074   *max = max_ii(0, BLI_listbase_count(&ob->particlesystem) - 1);
1075 }
1076 
rna_Object_active_particle_system_index_get(PointerRNA * ptr)1077 static int rna_Object_active_particle_system_index_get(PointerRNA *ptr)
1078 {
1079   Object *ob = (Object *)ptr->owner_id;
1080   return psys_get_current_num(ob);
1081 }
1082 
rna_Object_active_particle_system_index_set(PointerRNA * ptr,int value)1083 static void rna_Object_active_particle_system_index_set(PointerRNA *ptr, int value)
1084 {
1085   Object *ob = (Object *)ptr->owner_id;
1086   psys_set_current_num(ob, value);
1087 }
1088 
rna_Object_particle_update(Main * UNUSED (bmain),Scene * scene,PointerRNA * ptr)1089 static void rna_Object_particle_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
1090 {
1091   /* TODO: Disabled for now, because bContext is not available. */
1092 #  if 0
1093   Object *ob = (Object *)ptr->owner_id;
1094   PE_current_changed(NULL, scene, ob);
1095 #  else
1096   (void)scene;
1097   (void)ptr;
1098 #  endif
1099 }
1100 
1101 /* rotation - axis-angle */
rna_Object_rotation_axis_angle_get(PointerRNA * ptr,float * value)1102 static void rna_Object_rotation_axis_angle_get(PointerRNA *ptr, float *value)
1103 {
1104   Object *ob = ptr->data;
1105 
1106   /* for now, assume that rotation mode is axis-angle */
1107   value[0] = ob->rotAngle;
1108   copy_v3_v3(&value[1], ob->rotAxis);
1109 }
1110 
1111 /* rotation - axis-angle */
rna_Object_rotation_axis_angle_set(PointerRNA * ptr,const float * value)1112 static void rna_Object_rotation_axis_angle_set(PointerRNA *ptr, const float *value)
1113 {
1114   Object *ob = ptr->data;
1115 
1116   /* for now, assume that rotation mode is axis-angle */
1117   ob->rotAngle = value[0];
1118   copy_v3_v3(ob->rotAxis, &value[1]);
1119 
1120   /* TODO: validate axis? */
1121 }
1122 
rna_Object_rotation_mode_set(PointerRNA * ptr,int value)1123 static void rna_Object_rotation_mode_set(PointerRNA *ptr, int value)
1124 {
1125   Object *ob = ptr->data;
1126 
1127   /* use API Method for conversions... */
1128   BKE_rotMode_change_values(
1129       ob->quat, ob->rot, ob->rotAxis, &ob->rotAngle, ob->rotmode, (short)value);
1130 
1131   /* finally, set the new rotation type */
1132   ob->rotmode = value;
1133 }
1134 
rna_Object_dimensions_get(PointerRNA * ptr,float * value)1135 static void rna_Object_dimensions_get(PointerRNA *ptr, float *value)
1136 {
1137   Object *ob = ptr->data;
1138   BKE_object_dimensions_get(ob, value);
1139 }
1140 
rna_Object_dimensions_set(PointerRNA * ptr,const float * value)1141 static void rna_Object_dimensions_set(PointerRNA *ptr, const float *value)
1142 {
1143   Object *ob = ptr->data;
1144   BKE_object_dimensions_set(ob, value, 0);
1145 }
1146 
rna_Object_location_editable(PointerRNA * ptr,int index)1147 static int rna_Object_location_editable(PointerRNA *ptr, int index)
1148 {
1149   Object *ob = (Object *)ptr->data;
1150 
1151   /* only if the axis in question is locked, not editable... */
1152   if ((index == 0) && (ob->protectflag & OB_LOCK_LOCX)) {
1153     return 0;
1154   }
1155   else if ((index == 1) && (ob->protectflag & OB_LOCK_LOCY)) {
1156     return 0;
1157   }
1158   else if ((index == 2) && (ob->protectflag & OB_LOCK_LOCZ)) {
1159     return 0;
1160   }
1161   else {
1162     return PROP_EDITABLE;
1163   }
1164 }
1165 
rna_Object_scale_editable(PointerRNA * ptr,int index)1166 static int rna_Object_scale_editable(PointerRNA *ptr, int index)
1167 {
1168   Object *ob = (Object *)ptr->data;
1169 
1170   /* only if the axis in question is locked, not editable... */
1171   if ((index == 0) && (ob->protectflag & OB_LOCK_SCALEX)) {
1172     return 0;
1173   }
1174   else if ((index == 1) && (ob->protectflag & OB_LOCK_SCALEY)) {
1175     return 0;
1176   }
1177   else if ((index == 2) && (ob->protectflag & OB_LOCK_SCALEZ)) {
1178     return 0;
1179   }
1180   else {
1181     return PROP_EDITABLE;
1182   }
1183 }
1184 
rna_Object_rotation_euler_editable(PointerRNA * ptr,int index)1185 static int rna_Object_rotation_euler_editable(PointerRNA *ptr, int index)
1186 {
1187   Object *ob = (Object *)ptr->data;
1188 
1189   /* only if the axis in question is locked, not editable... */
1190   if ((index == 0) && (ob->protectflag & OB_LOCK_ROTX)) {
1191     return 0;
1192   }
1193   else if ((index == 1) && (ob->protectflag & OB_LOCK_ROTY)) {
1194     return 0;
1195   }
1196   else if ((index == 2) && (ob->protectflag & OB_LOCK_ROTZ)) {
1197     return 0;
1198   }
1199   else {
1200     return PROP_EDITABLE;
1201   }
1202 }
1203 
rna_Object_rotation_4d_editable(PointerRNA * ptr,int index)1204 static int rna_Object_rotation_4d_editable(PointerRNA *ptr, int index)
1205 {
1206   Object *ob = (Object *)ptr->data;
1207 
1208   /* only consider locks if locking components individually... */
1209   if (ob->protectflag & OB_LOCK_ROT4D) {
1210     /* only if the axis in question is locked, not editable... */
1211     if ((index == 0) && (ob->protectflag & OB_LOCK_ROTW)) {
1212       return 0;
1213     }
1214     else if ((index == 1) && (ob->protectflag & OB_LOCK_ROTX)) {
1215       return 0;
1216     }
1217     else if ((index == 2) && (ob->protectflag & OB_LOCK_ROTY)) {
1218       return 0;
1219     }
1220     else if ((index == 3) && (ob->protectflag & OB_LOCK_ROTZ)) {
1221       return 0;
1222     }
1223   }
1224 
1225   return PROP_EDITABLE;
1226 }
1227 
rna_MaterialSlot_material_editable(PointerRNA * ptr,const char ** UNUSED (r_info))1228 static int rna_MaterialSlot_material_editable(PointerRNA *ptr, const char **UNUSED(r_info))
1229 {
1230   Object *ob = (Object *)ptr->owner_id;
1231   const int index = (Material **)ptr->data - ob->mat;
1232   bool is_editable;
1233 
1234   if ((ob->matbits == NULL) || ob->matbits[index]) {
1235     is_editable = !ID_IS_LINKED(ob);
1236   }
1237   else {
1238     is_editable = ob->data ? !ID_IS_LINKED(ob->data) : false;
1239   }
1240 
1241   return is_editable ? PROP_EDITABLE : 0;
1242 }
1243 
rna_MaterialSlot_material_get(PointerRNA * ptr)1244 static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr)
1245 {
1246   Object *ob = (Object *)ptr->owner_id;
1247   Material *ma;
1248   const int index = (Material **)ptr->data - ob->mat;
1249 
1250   ma = BKE_object_material_get(ob, index + 1);
1251   return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
1252 }
1253 
rna_MaterialSlot_material_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))1254 static void rna_MaterialSlot_material_set(PointerRNA *ptr,
1255                                           PointerRNA value,
1256                                           struct ReportList *UNUSED(reports))
1257 {
1258   Object *ob = (Object *)ptr->owner_id;
1259   int index = (Material **)ptr->data - ob->mat;
1260 
1261   BLI_assert(BKE_id_is_in_global_main(&ob->id));
1262   BLI_assert(BKE_id_is_in_global_main(value.data));
1263   BKE_object_material_assign(G_MAIN, ob, value.data, index + 1, BKE_MAT_ASSIGN_EXISTING);
1264 }
1265 
rna_MaterialSlot_material_poll(PointerRNA * ptr,PointerRNA value)1266 static bool rna_MaterialSlot_material_poll(PointerRNA *ptr, PointerRNA value)
1267 {
1268   Object *ob = (Object *)ptr->owner_id;
1269   Material *ma = (Material *)value.data;
1270 
1271   if (ob->type == OB_GPENCIL) {
1272     /* GP Materials only */
1273     return (ma->gp_style != NULL);
1274   }
1275   else {
1276     /* Everything except GP materials */
1277     return (ma->gp_style == NULL);
1278   }
1279 }
1280 
rna_MaterialSlot_link_get(PointerRNA * ptr)1281 static int rna_MaterialSlot_link_get(PointerRNA *ptr)
1282 {
1283   Object *ob = (Object *)ptr->owner_id;
1284   int index = (Material **)ptr->data - ob->mat;
1285 
1286   return ob->matbits[index] != 0;
1287 }
1288 
rna_MaterialSlot_link_set(PointerRNA * ptr,int value)1289 static void rna_MaterialSlot_link_set(PointerRNA *ptr, int value)
1290 {
1291   Object *ob = (Object *)ptr->owner_id;
1292   int index = (Material **)ptr->data - ob->mat;
1293 
1294   if (value) {
1295     ob->matbits[index] = 1;
1296     /* ob->colbits |= (1 << index); */ /* DEPRECATED */
1297   }
1298   else {
1299     ob->matbits[index] = 0;
1300     /* ob->colbits &= ~(1 << index); */ /* DEPRECATED */
1301   }
1302 }
1303 
rna_MaterialSlot_name_length(PointerRNA * ptr)1304 static int rna_MaterialSlot_name_length(PointerRNA *ptr)
1305 {
1306   Object *ob = (Object *)ptr->owner_id;
1307   Material *ma;
1308   int index = (Material **)ptr->data - ob->mat;
1309 
1310   ma = BKE_object_material_get(ob, index + 1);
1311 
1312   if (ma) {
1313     return strlen(ma->id.name + 2);
1314   }
1315 
1316   return 0;
1317 }
1318 
rna_MaterialSlot_name_get(PointerRNA * ptr,char * str)1319 static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str)
1320 {
1321   Object *ob = (Object *)ptr->owner_id;
1322   Material *ma;
1323   int index = (Material **)ptr->data - ob->mat;
1324 
1325   ma = BKE_object_material_get(ob, index + 1);
1326 
1327   if (ma) {
1328     strcpy(str, ma->id.name + 2);
1329   }
1330   else {
1331     str[0] = '\0';
1332   }
1333 }
1334 
rna_MaterialSlot_update(Main * bmain,Scene * scene,PointerRNA * ptr)1335 static void rna_MaterialSlot_update(Main *bmain, Scene *scene, PointerRNA *ptr)
1336 {
1337   rna_Object_internal_update(bmain, scene, ptr);
1338 
1339   WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, ptr->owner_id);
1340   WM_main_add_notifier(NC_MATERIAL | ND_SHADING_LINKS, NULL);
1341   DEG_relations_tag_update(bmain);
1342 }
1343 
rna_MaterialSlot_path(PointerRNA * ptr)1344 static char *rna_MaterialSlot_path(PointerRNA *ptr)
1345 {
1346   Object *ob = (Object *)ptr->owner_id;
1347   int index = (Material **)ptr->data - ob->mat;
1348 
1349   return BLI_sprintfN("material_slots[%d]", index);
1350 }
1351 
rna_Object_display_get(PointerRNA * ptr)1352 static PointerRNA rna_Object_display_get(PointerRNA *ptr)
1353 {
1354   return rna_pointer_inherit_refine(ptr, &RNA_ObjectDisplay, ptr->data);
1355 }
1356 
rna_ObjectDisplay_path(PointerRNA * UNUSED (ptr))1357 static char *rna_ObjectDisplay_path(PointerRNA *UNUSED(ptr))
1358 {
1359   return BLI_strdup("display");
1360 }
1361 
rna_Object_active_particle_system_get(PointerRNA * ptr)1362 static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr)
1363 {
1364   Object *ob = (Object *)ptr->owner_id;
1365   ParticleSystem *psys = psys_get_current(ob);
1366   return rna_pointer_inherit_refine(ptr, &RNA_ParticleSystem, psys);
1367 }
1368 
rna_Object_active_shape_key_index_range(PointerRNA * ptr,int * min,int * max,int * UNUSED (softmin),int * UNUSED (softmax))1369 static void rna_Object_active_shape_key_index_range(
1370     PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
1371 {
1372   Object *ob = (Object *)ptr->owner_id;
1373   Key *key = BKE_key_from_object(ob);
1374 
1375   *min = 0;
1376   if (key) {
1377     *max = BLI_listbase_count(&key->block) - 1;
1378     if (*max < 0) {
1379       *max = 0;
1380     }
1381   }
1382   else {
1383     *max = 0;
1384   }
1385 }
1386 
rna_Object_active_shape_key_index_get(PointerRNA * ptr)1387 static int rna_Object_active_shape_key_index_get(PointerRNA *ptr)
1388 {
1389   Object *ob = (Object *)ptr->owner_id;
1390 
1391   return MAX2(ob->shapenr - 1, 0);
1392 }
1393 
rna_Object_active_shape_key_index_set(PointerRNA * ptr,int value)1394 static void rna_Object_active_shape_key_index_set(PointerRNA *ptr, int value)
1395 {
1396   Object *ob = (Object *)ptr->owner_id;
1397 
1398   ob->shapenr = value + 1;
1399 }
1400 
rna_Object_active_shape_key_get(PointerRNA * ptr)1401 static PointerRNA rna_Object_active_shape_key_get(PointerRNA *ptr)
1402 {
1403   Object *ob = (Object *)ptr->owner_id;
1404   Key *key = BKE_key_from_object(ob);
1405   KeyBlock *kb;
1406   PointerRNA keyptr;
1407 
1408   if (key == NULL) {
1409     return PointerRNA_NULL;
1410   }
1411 
1412   kb = BLI_findlink(&key->block, ob->shapenr - 1);
1413   RNA_pointer_create((ID *)key, &RNA_ShapeKey, kb, &keyptr);
1414   return keyptr;
1415 }
1416 
rna_Object_field_get(PointerRNA * ptr)1417 static PointerRNA rna_Object_field_get(PointerRNA *ptr)
1418 {
1419   Object *ob = (Object *)ptr->owner_id;
1420 
1421   /* weak */
1422   if (!ob->pd) {
1423     ob->pd = BKE_partdeflect_new(0);
1424   }
1425 
1426   return rna_pointer_inherit_refine(ptr, &RNA_FieldSettings, ob->pd);
1427 }
1428 
rna_Object_collision_get(PointerRNA * ptr)1429 static PointerRNA rna_Object_collision_get(PointerRNA *ptr)
1430 {
1431   Object *ob = (Object *)ptr->owner_id;
1432 
1433   if (ob->type != OB_MESH) {
1434     return PointerRNA_NULL;
1435   }
1436 
1437   /* weak */
1438   if (!ob->pd) {
1439     ob->pd = BKE_partdeflect_new(0);
1440   }
1441 
1442   return rna_pointer_inherit_refine(ptr, &RNA_CollisionSettings, ob->pd);
1443 }
1444 
rna_Object_active_constraint_get(PointerRNA * ptr)1445 static PointerRNA rna_Object_active_constraint_get(PointerRNA *ptr)
1446 {
1447   Object *ob = (Object *)ptr->owner_id;
1448   bConstraint *con = BKE_constraints_active_get(&ob->constraints);
1449   return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con);
1450 }
1451 
rna_Object_active_constraint_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))1452 static void rna_Object_active_constraint_set(PointerRNA *ptr,
1453                                              PointerRNA value,
1454                                              struct ReportList *UNUSED(reports))
1455 {
1456   Object *ob = (Object *)ptr->owner_id;
1457   BKE_constraints_active_set(&ob->constraints, (bConstraint *)value.data);
1458 }
1459 
rna_Object_constraints_new(Object * object,Main * bmain,int type)1460 static bConstraint *rna_Object_constraints_new(Object *object, Main *bmain, int type)
1461 {
1462   bConstraint *new_con = BKE_constraint_add_for_object(object, NULL, type);
1463 
1464   ED_object_constraint_tag_update(bmain, object, new_con);
1465   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, object);
1466 
1467   return new_con;
1468 }
1469 
rna_Object_constraints_remove(Object * object,Main * bmain,ReportList * reports,PointerRNA * con_ptr)1470 static void rna_Object_constraints_remove(Object *object,
1471                                           Main *bmain,
1472                                           ReportList *reports,
1473                                           PointerRNA *con_ptr)
1474 {
1475   bConstraint *con = con_ptr->data;
1476   if (BLI_findindex(&object->constraints, con) == -1) {
1477     BKE_reportf(reports,
1478                 RPT_ERROR,
1479                 "Constraint '%s' not found in object '%s'",
1480                 con->name,
1481                 object->id.name + 2);
1482     return;
1483   }
1484 
1485   BKE_constraint_remove(&object->constraints, con);
1486   RNA_POINTER_INVALIDATE(con_ptr);
1487 
1488   ED_object_constraint_update(bmain, object);
1489   ED_object_constraint_active_set(object, NULL);
1490   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, object);
1491 }
1492 
rna_Object_constraints_clear(Object * object,Main * bmain)1493 static void rna_Object_constraints_clear(Object *object, Main *bmain)
1494 {
1495   BKE_constraints_free(&object->constraints);
1496 
1497   ED_object_constraint_update(bmain, object);
1498   ED_object_constraint_active_set(object, NULL);
1499 
1500   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, object);
1501 }
1502 
rna_Object_constraints_move(Object * object,Main * bmain,ReportList * reports,int from,int to)1503 static void rna_Object_constraints_move(
1504     Object *object, Main *bmain, ReportList *reports, int from, int to)
1505 {
1506   if (from == to) {
1507     return;
1508   }
1509 
1510   if (!BLI_listbase_move_index(&object->constraints, from, to)) {
1511     BKE_reportf(reports, RPT_ERROR, "Could not move constraint from index '%d' to '%d'", from, to);
1512     return;
1513   }
1514 
1515   ED_object_constraint_tag_update(bmain, object, NULL);
1516   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT, object);
1517 }
1518 
rna_Object_constraints_copy(Object * object,Main * bmain,PointerRNA * con_ptr)1519 static bConstraint *rna_Object_constraints_copy(Object *object, Main *bmain, PointerRNA *con_ptr)
1520 {
1521   bConstraint *con = con_ptr->data;
1522   bConstraint *new_con = BKE_constraint_copy_for_object(object, con);
1523 
1524   ED_object_constraint_tag_update(bmain, object, new_con);
1525   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, object);
1526 
1527   return new_con;
1528 }
1529 
rna_Object_constraints_override_apply(Main * UNUSED (bmain),PointerRNA * ptr_dst,PointerRNA * ptr_src,PointerRNA * UNUSED (ptr_storage),PropertyRNA * UNUSED (prop_dst),PropertyRNA * UNUSED (prop_src),PropertyRNA * UNUSED (prop_storage),const int UNUSED (len_dst),const int UNUSED (len_src),const int UNUSED (len_storage),PointerRNA * UNUSED (ptr_item_dst),PointerRNA * UNUSED (ptr_item_src),PointerRNA * UNUSED (ptr_item_storage),IDOverrideLibraryPropertyOperation * opop)1530 bool rna_Object_constraints_override_apply(Main *UNUSED(bmain),
1531                                            PointerRNA *ptr_dst,
1532                                            PointerRNA *ptr_src,
1533                                            PointerRNA *UNUSED(ptr_storage),
1534                                            PropertyRNA *UNUSED(prop_dst),
1535                                            PropertyRNA *UNUSED(prop_src),
1536                                            PropertyRNA *UNUSED(prop_storage),
1537                                            const int UNUSED(len_dst),
1538                                            const int UNUSED(len_src),
1539                                            const int UNUSED(len_storage),
1540                                            PointerRNA *UNUSED(ptr_item_dst),
1541                                            PointerRNA *UNUSED(ptr_item_src),
1542                                            PointerRNA *UNUSED(ptr_item_storage),
1543                                            IDOverrideLibraryPropertyOperation *opop)
1544 {
1545   BLI_assert(opop->operation == IDOVERRIDE_LIBRARY_OP_INSERT_AFTER &&
1546              "Unsupported RNA override operation on constraints collection");
1547 
1548   Object *ob_dst = (Object *)ptr_dst->owner_id;
1549   Object *ob_src = (Object *)ptr_src->owner_id;
1550 
1551   /* Remember that insertion operations are defined and stored in correct order, which means that
1552    * even if we insert several items in a row, we always insert first one, then second one, etc.
1553    * So we should always find 'anchor' constraint in both _src *and* _dst. */
1554   bConstraint *con_anchor = NULL;
1555   if (opop->subitem_local_name && opop->subitem_local_name[0]) {
1556     con_anchor = BLI_findstring(
1557         &ob_dst->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
1558   }
1559   if (con_anchor == NULL && opop->subitem_local_index >= 0) {
1560     con_anchor = BLI_findlink(&ob_dst->constraints, opop->subitem_local_index);
1561   }
1562   /* Otherwise we just insert in first position. */
1563 
1564   bConstraint *con_src = NULL;
1565   if (opop->subitem_local_name && opop->subitem_local_name[0]) {
1566     con_src = BLI_findstring(
1567         &ob_src->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
1568   }
1569   if (con_src == NULL && opop->subitem_local_index >= 0) {
1570     con_src = BLI_findlink(&ob_src->constraints, opop->subitem_local_index);
1571   }
1572   con_src = con_src ? con_src->next : ob_src->constraints.first;
1573 
1574   BLI_assert(con_src != NULL);
1575 
1576   bConstraint *con_dst = BKE_constraint_duplicate_ex(con_src, 0, true);
1577 
1578   /* This handles NULL anchor as expected by adding at head of list. */
1579   BLI_insertlinkafter(&ob_dst->constraints, con_anchor, con_dst);
1580 
1581   /* This should actually *not* be needed in typical cases.
1582    * However, if overridden source was edited, we *may* have some new conflicting names. */
1583   BKE_constraint_unique_name(con_dst, &ob_dst->constraints);
1584 
1585   //  printf("%s: We inserted a constraint...\n", __func__);
1586   return true;
1587 }
1588 
rna_Object_modifier_new(Object * object,bContext * C,ReportList * reports,const char * name,int type)1589 static ModifierData *rna_Object_modifier_new(
1590     Object *object, bContext *C, ReportList *reports, const char *name, int type)
1591 {
1592   return ED_object_modifier_add(reports, CTX_data_main(C), CTX_data_scene(C), object, name, type);
1593 }
1594 
rna_Object_modifier_remove(Object * object,bContext * C,ReportList * reports,PointerRNA * md_ptr)1595 static void rna_Object_modifier_remove(Object *object,
1596                                        bContext *C,
1597                                        ReportList *reports,
1598                                        PointerRNA *md_ptr)
1599 {
1600   ModifierData *md = md_ptr->data;
1601   if (ED_object_modifier_remove(reports, CTX_data_main(C), CTX_data_scene(C), object, md) ==
1602       false) {
1603     /* error is already set */
1604     return;
1605   }
1606 
1607   RNA_POINTER_INVALIDATE(md_ptr);
1608 
1609   WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
1610 }
1611 
rna_Object_modifier_clear(Object * object,bContext * C)1612 static void rna_Object_modifier_clear(Object *object, bContext *C)
1613 {
1614   ED_object_modifier_clear(CTX_data_main(C), CTX_data_scene(C), object);
1615 
1616   WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
1617 }
1618 
rna_Object_modifiers_override_apply(Main * bmain,PointerRNA * ptr_dst,PointerRNA * ptr_src,PointerRNA * UNUSED (ptr_storage),PropertyRNA * UNUSED (prop_dst),PropertyRNA * UNUSED (prop_src),PropertyRNA * UNUSED (prop_storage),const int UNUSED (len_dst),const int UNUSED (len_src),const int UNUSED (len_storage),PointerRNA * UNUSED (ptr_item_dst),PointerRNA * UNUSED (ptr_item_src),PointerRNA * UNUSED (ptr_item_storage),IDOverrideLibraryPropertyOperation * opop)1619 bool rna_Object_modifiers_override_apply(Main *bmain,
1620                                          PointerRNA *ptr_dst,
1621                                          PointerRNA *ptr_src,
1622                                          PointerRNA *UNUSED(ptr_storage),
1623                                          PropertyRNA *UNUSED(prop_dst),
1624                                          PropertyRNA *UNUSED(prop_src),
1625                                          PropertyRNA *UNUSED(prop_storage),
1626                                          const int UNUSED(len_dst),
1627                                          const int UNUSED(len_src),
1628                                          const int UNUSED(len_storage),
1629                                          PointerRNA *UNUSED(ptr_item_dst),
1630                                          PointerRNA *UNUSED(ptr_item_src),
1631                                          PointerRNA *UNUSED(ptr_item_storage),
1632                                          IDOverrideLibraryPropertyOperation *opop)
1633 {
1634   BLI_assert(opop->operation == IDOVERRIDE_LIBRARY_OP_INSERT_AFTER &&
1635              "Unsupported RNA override operation on modifiers collection");
1636 
1637   Object *ob_dst = (Object *)ptr_dst->owner_id;
1638   Object *ob_src = (Object *)ptr_src->owner_id;
1639 
1640   /* Remember that insertion operations are defined and stored in correct order, which means that
1641    * even if we insert several items in a row, we always insert first one, then second one, etc.
1642    * So we should always find 'anchor' modifier in both _src *and* _dst. */
1643   ModifierData *mod_anchor = NULL;
1644   if (opop->subitem_local_name && opop->subitem_local_name[0]) {
1645     mod_anchor = BLI_findstring(
1646         &ob_dst->modifiers, opop->subitem_local_name, offsetof(ModifierData, name));
1647   }
1648   if (mod_anchor == NULL && opop->subitem_local_index >= 0) {
1649     mod_anchor = BLI_findlink(&ob_dst->modifiers, opop->subitem_local_index);
1650   }
1651   /* Otherwise we just insert in first position. */
1652 
1653   ModifierData *mod_src = NULL;
1654   if (opop->subitem_local_name && opop->subitem_local_name[0]) {
1655     mod_src = BLI_findstring(
1656         &ob_src->modifiers, opop->subitem_local_name, offsetof(ModifierData, name));
1657   }
1658   if (mod_src == NULL && opop->subitem_local_index >= 0) {
1659     mod_src = BLI_findlink(&ob_src->modifiers, opop->subitem_local_index);
1660   }
1661   mod_src = mod_src ? mod_src->next : ob_src->modifiers.first;
1662 
1663   if (mod_src == NULL) {
1664     BLI_assert(mod_src != NULL);
1665     return false;
1666   }
1667 
1668   /* While it would be nicer to use lower-level BKE_modifier_new() here, this one is lacking
1669    * special-cases handling (particles and other physics modifiers mostly), so using the ED version
1670    * instead, to avoid duplicating code. */
1671   ModifierData *mod_dst = ED_object_modifier_add(
1672       NULL, bmain, NULL, ob_dst, mod_src->name, mod_src->type);
1673 
1674   /* XXX Current handling of 'copy' from particle-system modifier is *very* bad (it keeps same psys
1675    * pointer as source, then calling code copies psys of object separately and do some magic
1676    * remapping of pointers...), unfortunately several pieces of code in Object editing area rely on
1677    * this behavior. So for now, hacking around it to get it doing what we want it to do, as getting
1678    * a proper behavior would be everything but trivial, and this whole particle thingy is
1679    * end-of-life. */
1680   ParticleSystem *psys_dst = (mod_dst->type == eModifierType_ParticleSystem) ?
1681                                  ((ParticleSystemModifierData *)mod_dst)->psys :
1682                                  NULL;
1683   BKE_modifier_copydata(mod_src, mod_dst);
1684   if (mod_dst->type == eModifierType_ParticleSystem) {
1685     psys_dst->flag &= ~PSYS_DELETE;
1686     ((ParticleSystemModifierData *)mod_dst)->psys = psys_dst;
1687   }
1688 
1689   BLI_remlink(&ob_dst->modifiers, mod_dst);
1690   /* This handles NULL anchor as expected by adding at head of list. */
1691   BLI_insertlinkafter(&ob_dst->modifiers, mod_anchor, mod_dst);
1692 
1693   //  printf("%s: We inserted a modifier '%s'...\n", __func__, mod_dst->name);
1694   return true;
1695 }
1696 
rna_Object_greasepencil_modifier_new(Object * object,bContext * C,ReportList * reports,const char * name,int type)1697 static GpencilModifierData *rna_Object_greasepencil_modifier_new(
1698     Object *object, bContext *C, ReportList *reports, const char *name, int type)
1699 {
1700   return ED_object_gpencil_modifier_add(
1701       reports, CTX_data_main(C), CTX_data_scene(C), object, name, type);
1702 }
1703 
rna_Object_greasepencil_modifier_remove(Object * object,bContext * C,ReportList * reports,PointerRNA * gmd_ptr)1704 static void rna_Object_greasepencil_modifier_remove(Object *object,
1705                                                     bContext *C,
1706                                                     ReportList *reports,
1707                                                     PointerRNA *gmd_ptr)
1708 {
1709   GpencilModifierData *gmd = gmd_ptr->data;
1710   if (ED_object_gpencil_modifier_remove(reports, CTX_data_main(C), object, gmd) == false) {
1711     /* error is already set */
1712     return;
1713   }
1714 
1715   RNA_POINTER_INVALIDATE(gmd_ptr);
1716 
1717   WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
1718 }
1719 
rna_Object_greasepencil_modifier_clear(Object * object,bContext * C)1720 static void rna_Object_greasepencil_modifier_clear(Object *object, bContext *C)
1721 {
1722   ED_object_gpencil_modifier_clear(CTX_data_main(C), object);
1723   WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
1724 }
1725 
rna_Object_greasepencil_modifiers_override_apply(Main * bmain,PointerRNA * ptr_dst,PointerRNA * ptr_src,PointerRNA * UNUSED (ptr_storage),PropertyRNA * UNUSED (prop_dst),PropertyRNA * UNUSED (prop_src),PropertyRNA * UNUSED (prop_storage),const int UNUSED (len_dst),const int UNUSED (len_src),const int UNUSED (len_storage),PointerRNA * UNUSED (ptr_item_dst),PointerRNA * UNUSED (ptr_item_src),PointerRNA * UNUSED (ptr_item_storage),IDOverrideLibraryPropertyOperation * opop)1726 bool rna_Object_greasepencil_modifiers_override_apply(Main *bmain,
1727                                                       PointerRNA *ptr_dst,
1728                                                       PointerRNA *ptr_src,
1729                                                       PointerRNA *UNUSED(ptr_storage),
1730                                                       PropertyRNA *UNUSED(prop_dst),
1731                                                       PropertyRNA *UNUSED(prop_src),
1732                                                       PropertyRNA *UNUSED(prop_storage),
1733                                                       const int UNUSED(len_dst),
1734                                                       const int UNUSED(len_src),
1735                                                       const int UNUSED(len_storage),
1736                                                       PointerRNA *UNUSED(ptr_item_dst),
1737                                                       PointerRNA *UNUSED(ptr_item_src),
1738                                                       PointerRNA *UNUSED(ptr_item_storage),
1739                                                       IDOverrideLibraryPropertyOperation *opop)
1740 {
1741   BLI_assert(opop->operation == IDOVERRIDE_LIBRARY_OP_INSERT_AFTER &&
1742              "Unsupported RNA override operation on modifiers collection");
1743 
1744   Object *ob_dst = (Object *)ptr_dst->owner_id;
1745   Object *ob_src = (Object *)ptr_src->owner_id;
1746 
1747   /* Remember that insertion operations are defined and stored in correct order, which means that
1748    * even if we insert several items in a row, we always insert first one, then second one, etc.
1749    * So we should always find 'anchor' modifier in both _src *and* _dst. */
1750   GpencilModifierData *mod_anchor = NULL;
1751   if (opop->subitem_local_name && opop->subitem_local_name[0]) {
1752     mod_anchor = BLI_findstring(
1753         &ob_dst->greasepencil_modifiers, opop->subitem_local_name, offsetof(ModifierData, name));
1754   }
1755   if (mod_anchor == NULL && opop->subitem_local_index >= 0) {
1756     mod_anchor = BLI_findlink(&ob_dst->greasepencil_modifiers, opop->subitem_local_index);
1757   }
1758   /* Otherwise we just insert in first position. */
1759 
1760   GpencilModifierData *mod_src = NULL;
1761   if (opop->subitem_local_name && opop->subitem_local_name[0]) {
1762     mod_src = BLI_findstring(
1763         &ob_src->greasepencil_modifiers, opop->subitem_local_name, offsetof(ModifierData, name));
1764   }
1765   if (mod_src == NULL && opop->subitem_local_index >= 0) {
1766     mod_src = BLI_findlink(&ob_src->greasepencil_modifiers, opop->subitem_local_index);
1767   }
1768   mod_src = mod_src ? mod_src->next : ob_src->greasepencil_modifiers.first;
1769 
1770   if (mod_src == NULL) {
1771     BLI_assert(mod_src != NULL);
1772     return false;
1773   }
1774 
1775   /* While it would be nicer to use lower-level BKE_modifier_new() here, this one is lacking
1776    * special-cases handling (particles and other physics modifiers mostly), so using the ED version
1777    * instead, to avoid duplicating code. */
1778   GpencilModifierData *mod_dst = ED_object_gpencil_modifier_add(
1779       NULL, bmain, NULL, ob_dst, mod_src->name, mod_src->type);
1780 
1781   BLI_remlink(&ob_dst->modifiers, mod_dst);
1782   /* This handles NULL anchor as expected by adding at head of list. */
1783   BLI_insertlinkafter(&ob_dst->greasepencil_modifiers, mod_anchor, mod_dst);
1784 
1785   //  printf("%s: We inserted a gpencil modifier '%s'...\n", __func__, mod_dst->name);
1786   return true;
1787 }
1788 
1789 /* shader fx */
rna_Object_shaderfx_new(Object * object,bContext * C,ReportList * reports,const char * name,int type)1790 static ShaderFxData *rna_Object_shaderfx_new(
1791     Object *object, bContext *C, ReportList *reports, const char *name, int type)
1792 {
1793   return ED_object_shaderfx_add(reports, CTX_data_main(C), CTX_data_scene(C), object, name, type);
1794 }
1795 
rna_Object_shaderfx_remove(Object * object,bContext * C,ReportList * reports,PointerRNA * gmd_ptr)1796 static void rna_Object_shaderfx_remove(Object *object,
1797                                        bContext *C,
1798                                        ReportList *reports,
1799                                        PointerRNA *gmd_ptr)
1800 {
1801   ShaderFxData *gmd = gmd_ptr->data;
1802   if (ED_object_shaderfx_remove(reports, CTX_data_main(C), object, gmd) == false) {
1803     /* error is already set */
1804     return;
1805   }
1806 
1807   RNA_POINTER_INVALIDATE(gmd_ptr);
1808 
1809   WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
1810 }
1811 
rna_Object_shaderfx_clear(Object * object,bContext * C)1812 static void rna_Object_shaderfx_clear(Object *object, bContext *C)
1813 {
1814   ED_object_shaderfx_clear(CTX_data_main(C), object);
1815   WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
1816 }
1817 
rna_Object_boundbox_get(PointerRNA * ptr,float * values)1818 static void rna_Object_boundbox_get(PointerRNA *ptr, float *values)
1819 {
1820   Object *ob = (Object *)ptr->owner_id;
1821   BoundBox *bb = BKE_object_boundbox_get(ob);
1822   if (bb) {
1823     memcpy(values, bb->vec, sizeof(bb->vec));
1824   }
1825   else {
1826     copy_vn_fl(values, sizeof(bb->vec) / sizeof(float), 0.0f);
1827   }
1828 }
1829 
rna_Object_vgroup_new(Object * ob,Main * bmain,ReportList * reports,const char * name)1830 static bDeformGroup *rna_Object_vgroup_new(Object *ob,
1831                                            Main *bmain,
1832                                            ReportList *reports,
1833                                            const char *name)
1834 {
1835   if (!OB_TYPE_SUPPORT_VGROUP(ob->type)) {
1836     const char *ob_type_name = "Unknown";
1837     RNA_enum_name_from_value(rna_enum_object_type_items, ob->type, &ob_type_name);
1838     BKE_reportf(
1839         reports, RPT_ERROR, "VertexGroups.new(): is not supported for '%s' objects", ob_type_name);
1840     return NULL;
1841   }
1842 
1843   bDeformGroup *defgroup = BKE_object_defgroup_add_name(ob, name);
1844 
1845   DEG_relations_tag_update(bmain);
1846   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
1847 
1848   return defgroup;
1849 }
1850 
rna_Object_vgroup_remove(Object * ob,Main * bmain,ReportList * reports,PointerRNA * defgroup_ptr)1851 static void rna_Object_vgroup_remove(Object *ob,
1852                                      Main *bmain,
1853                                      ReportList *reports,
1854                                      PointerRNA *defgroup_ptr)
1855 {
1856   bDeformGroup *defgroup = defgroup_ptr->data;
1857   if (BLI_findindex(&ob->defbase, defgroup) == -1) {
1858     BKE_reportf(reports,
1859                 RPT_ERROR,
1860                 "DeformGroup '%s' not in object '%s'",
1861                 defgroup->name,
1862                 ob->id.name + 2);
1863     return;
1864   }
1865 
1866   BKE_object_defgroup_remove(ob, defgroup);
1867   RNA_POINTER_INVALIDATE(defgroup_ptr);
1868 
1869   DEG_relations_tag_update(bmain);
1870   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
1871 }
1872 
rna_Object_vgroup_clear(Object * ob,Main * bmain)1873 static void rna_Object_vgroup_clear(Object *ob, Main *bmain)
1874 {
1875   BKE_object_defgroup_remove_all(ob);
1876 
1877   DEG_relations_tag_update(bmain);
1878   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
1879 }
1880 
rna_VertexGroup_vertex_add(ID * id,bDeformGroup * def,ReportList * reports,int index_len,int * index,float weight,int assignmode)1881 static void rna_VertexGroup_vertex_add(ID *id,
1882                                        bDeformGroup *def,
1883                                        ReportList *reports,
1884                                        int index_len,
1885                                        int *index,
1886                                        float weight,
1887                                        int assignmode)
1888 {
1889   Object *ob = (Object *)id;
1890 
1891   if (BKE_object_is_in_editmode_vgroup(ob)) {
1892     BKE_report(
1893         reports, RPT_ERROR, "VertexGroup.add(): cannot be called while object is in edit mode");
1894     return;
1895   }
1896 
1897   while (index_len--) {
1898     ED_vgroup_vert_add(
1899         ob, def, *index++, weight, assignmode); /* XXX, not efficient calling within loop*/
1900   }
1901 
1902   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
1903   WM_main_add_notifier(NC_GEOM | ND_DATA, (ID *)ob->data);
1904 }
1905 
rna_VertexGroup_vertex_remove(ID * id,bDeformGroup * dg,ReportList * reports,int index_len,int * index)1906 static void rna_VertexGroup_vertex_remove(
1907     ID *id, bDeformGroup *dg, ReportList *reports, int index_len, int *index)
1908 {
1909   Object *ob = (Object *)id;
1910 
1911   if (BKE_object_is_in_editmode_vgroup(ob)) {
1912     BKE_report(
1913         reports, RPT_ERROR, "VertexGroup.remove(): cannot be called while object is in edit mode");
1914     return;
1915   }
1916 
1917   while (index_len--) {
1918     ED_vgroup_vert_remove(ob, dg, *index++);
1919   }
1920 
1921   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
1922   WM_main_add_notifier(NC_GEOM | ND_DATA, (ID *)ob->data);
1923 }
1924 
rna_VertexGroup_weight(ID * id,bDeformGroup * dg,ReportList * reports,int index)1925 static float rna_VertexGroup_weight(ID *id, bDeformGroup *dg, ReportList *reports, int index)
1926 {
1927   float weight = ED_vgroup_vert_weight((Object *)id, dg, index);
1928 
1929   if (weight < 0) {
1930     BKE_report(reports, RPT_ERROR, "Vertex not in group");
1931   }
1932   return weight;
1933 }
1934 
rna_Object_fmap_new(Object * ob,const char * name)1935 static bFaceMap *rna_Object_fmap_new(Object *ob, const char *name)
1936 {
1937   bFaceMap *fmap = BKE_object_facemap_add_name(ob, name);
1938 
1939   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
1940 
1941   return fmap;
1942 }
1943 
rna_Object_fmap_remove(Object * ob,ReportList * reports,PointerRNA * fmap_ptr)1944 static void rna_Object_fmap_remove(Object *ob, ReportList *reports, PointerRNA *fmap_ptr)
1945 {
1946   bFaceMap *fmap = fmap_ptr->data;
1947   if (BLI_findindex(&ob->fmaps, fmap) == -1) {
1948     BKE_reportf(
1949         reports, RPT_ERROR, "FaceMap '%s' not in object '%s'", fmap->name, ob->id.name + 2);
1950     return;
1951   }
1952 
1953   BKE_object_facemap_remove(ob, fmap);
1954   RNA_POINTER_INVALIDATE(fmap_ptr);
1955 
1956   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
1957 }
1958 
rna_Object_fmap_clear(Object * ob)1959 static void rna_Object_fmap_clear(Object *ob)
1960 {
1961   BKE_object_facemap_clear(ob);
1962 
1963   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
1964 }
1965 
rna_FaceMap_face_add(ID * id,bFaceMap * fmap,ReportList * reports,int index_len,int * index)1966 static void rna_FaceMap_face_add(
1967     ID *id, bFaceMap *fmap, ReportList *reports, int index_len, int *index)
1968 {
1969   Object *ob = (Object *)id;
1970 
1971   if (BKE_object_is_in_editmode(ob)) {
1972     BKE_report(reports, RPT_ERROR, "FaceMap.add(): cannot be called while object is in edit mode");
1973     return;
1974   }
1975 
1976   while (index_len--) {
1977     ED_object_facemap_face_add(ob, fmap, *index++);
1978   }
1979 
1980   WM_main_add_notifier(NC_GEOM | ND_DATA, (ID *)ob->data);
1981 }
1982 
rna_FaceMap_face_remove(ID * id,bFaceMap * fmap,ReportList * reports,int index_len,int * index)1983 static void rna_FaceMap_face_remove(
1984     ID *id, bFaceMap *fmap, ReportList *reports, int index_len, int *index)
1985 {
1986   Object *ob = (Object *)id;
1987 
1988   if (BKE_object_is_in_editmode(ob)) {
1989     BKE_report(reports, RPT_ERROR, "FaceMap.add(): cannot be called while object is in edit mode");
1990     return;
1991   }
1992 
1993   while (index_len--) {
1994     ED_object_facemap_face_remove(ob, fmap, *index++);
1995   }
1996 
1997   WM_main_add_notifier(NC_GEOM | ND_DATA, (ID *)ob->data);
1998 }
1999 
2000 /* generic poll functions */
rna_Lattice_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2001 bool rna_Lattice_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2002 {
2003   return ((Object *)value.owner_id)->type == OB_LATTICE;
2004 }
2005 
rna_Curve_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2006 bool rna_Curve_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2007 {
2008   return ((Object *)value.owner_id)->type == OB_CURVE;
2009 }
2010 
rna_Armature_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2011 bool rna_Armature_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2012 {
2013   return ((Object *)value.owner_id)->type == OB_ARMATURE;
2014 }
2015 
rna_Mesh_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2016 bool rna_Mesh_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2017 {
2018   return ((Object *)value.owner_id)->type == OB_MESH;
2019 }
2020 
rna_Camera_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2021 bool rna_Camera_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2022 {
2023   return ((Object *)value.owner_id)->type == OB_CAMERA;
2024 }
2025 
rna_Light_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2026 bool rna_Light_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2027 {
2028   return ((Object *)value.owner_id)->type == OB_LAMP;
2029 }
2030 
rna_GPencil_object_poll(PointerRNA * UNUSED (ptr),PointerRNA value)2031 bool rna_GPencil_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
2032 {
2033   return ((Object *)value.owner_id)->type == OB_GPENCIL;
2034 }
2035 
rna_Object_use_dynamic_topology_sculpting_get(PointerRNA * ptr)2036 int rna_Object_use_dynamic_topology_sculpting_get(PointerRNA *ptr)
2037 {
2038   SculptSession *ss = ((Object *)ptr->owner_id)->sculpt;
2039   return (ss && ss->bm);
2040 }
2041 
2042 #else
2043 
rna_def_vertex_group(BlenderRNA * brna)2044 static void rna_def_vertex_group(BlenderRNA *brna)
2045 {
2046   StructRNA *srna;
2047   PropertyRNA *prop;
2048   FunctionRNA *func;
2049   PropertyRNA *parm;
2050 
2051   static const EnumPropertyItem assign_mode_items[] = {
2052       {WEIGHT_REPLACE, "REPLACE", 0, "Replace", "Replace"},
2053       {WEIGHT_ADD, "ADD", 0, "Add", "Add"},
2054       {WEIGHT_SUBTRACT, "SUBTRACT", 0, "Subtract", "Subtract"},
2055       {0, NULL, 0, NULL, NULL},
2056   };
2057 
2058   srna = RNA_def_struct(brna, "VertexGroup", NULL);
2059   RNA_def_struct_sdna(srna, "bDeformGroup");
2060   RNA_def_struct_ui_text(
2061       srna, "Vertex Group", "Group of vertices, used for armature deform and other purposes");
2062   RNA_def_struct_ui_icon(srna, ICON_GROUP_VERTEX);
2063 
2064   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2065   RNA_def_property_ui_text(prop, "Name", "Vertex group name");
2066   RNA_def_struct_name_property(srna, prop);
2067   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_VertexGroup_name_set");
2068   /* update data because modifiers may use T24761. */
2069   RNA_def_property_update(
2070       prop, NC_GEOM | ND_DATA | NA_RENAME, "rna_Object_internal_update_data_dependency");
2071 
2072   prop = RNA_def_property(srna, "lock_weight", PROP_BOOLEAN, PROP_NONE);
2073   RNA_def_property_ui_text(prop, "", "Maintain the relative weights for the group");
2074   RNA_def_property_boolean_sdna(prop, NULL, "flag", 0);
2075   /* update data because modifiers may use T24761. */
2076   RNA_def_property_update(prop, NC_GEOM | ND_DATA | NA_RENAME, "rna_Object_internal_update_data");
2077 
2078   prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2079   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2080   RNA_def_property_int_funcs(prop, "rna_VertexGroup_index_get", NULL, NULL);
2081   RNA_def_property_ui_text(prop, "Index", "Index number of the vertex group");
2082 
2083   func = RNA_def_function(srna, "add", "rna_VertexGroup_vertex_add");
2084   RNA_def_function_ui_description(func, "Add vertices to the group");
2085   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
2086   /* TODO, see how array size of 0 works, this shouldnt be used */
2087   parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List", 0, 0);
2088   RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
2089   parm = RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight", 0.0f, 1.0f);
2090   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2091   parm = RNA_def_enum(func, "type", assign_mode_items, 0, "", "Vertex assign mode");
2092   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2093 
2094   func = RNA_def_function(srna, "remove", "rna_VertexGroup_vertex_remove");
2095   RNA_def_function_ui_description(func, "Remove a vertex from the group");
2096   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
2097   /* TODO, see how array size of 0 works, this shouldnt be used */
2098   parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List", 0, 0);
2099   RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
2100 
2101   func = RNA_def_function(srna, "weight", "rna_VertexGroup_weight");
2102   RNA_def_function_ui_description(func, "Get a vertex weight from the group");
2103   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
2104   parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "The index of the vertex", 0, INT_MAX);
2105   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2106   parm = RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight", 0.0f, 1.0f);
2107   RNA_def_function_return(func, parm);
2108 }
2109 
rna_def_face_map(BlenderRNA * brna)2110 static void rna_def_face_map(BlenderRNA *brna)
2111 {
2112   StructRNA *srna;
2113   PropertyRNA *prop;
2114 
2115   FunctionRNA *func;
2116   PropertyRNA *parm;
2117 
2118   srna = RNA_def_struct(brna, "FaceMap", NULL);
2119   RNA_def_struct_sdna(srna, "bFaceMap");
2120   RNA_def_struct_ui_text(
2121       srna, "Face Map", "Group of faces, each face can only be part of one map");
2122   RNA_def_struct_ui_icon(srna, ICON_MOD_TRIANGULATE);
2123 
2124   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2125   RNA_def_property_ui_text(prop, "Name", "Face map name");
2126   RNA_def_struct_name_property(srna, prop);
2127   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_FaceMap_name_set");
2128   /* update data because modifiers may use T24761. */
2129   RNA_def_property_update(prop, NC_GEOM | ND_DATA | NA_RENAME, "rna_Object_internal_update_data");
2130 
2131   prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
2132   RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
2133   RNA_def_property_ui_text(prop, "Select", "Face-map selection state (for tools to use)");
2134   /* important not to use a notifier here, creates a feedback loop! */
2135 
2136   prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2137   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2138   RNA_def_property_int_funcs(prop, "rna_FaceMap_index_get", NULL, NULL);
2139   RNA_def_property_ui_text(prop, "Index", "Index number of the face map");
2140 
2141   func = RNA_def_function(srna, "add", "rna_FaceMap_face_add");
2142   RNA_def_function_ui_description(func, "Add vertices to the group");
2143   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
2144   /* TODO, see how array size of 0 works, this shouldnt be used */
2145   parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List", 0, 0);
2146   RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
2147 
2148   func = RNA_def_function(srna, "remove", "rna_FaceMap_face_remove");
2149   RNA_def_function_ui_description(func, "Remove a vertex from the group");
2150   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
2151   /* TODO, see how array size of 0 works, this shouldnt be used */
2152   parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List", 0, 0);
2153   RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
2154 }
2155 
rna_def_material_slot(BlenderRNA * brna)2156 static void rna_def_material_slot(BlenderRNA *brna)
2157 {
2158   StructRNA *srna;
2159   PropertyRNA *prop;
2160 
2161   static const EnumPropertyItem link_items[] = {
2162       {1, "OBJECT", 0, "Object", ""},
2163       {0, "DATA", 0, "Data", ""},
2164       {0, NULL, 0, NULL, NULL},
2165   };
2166 
2167   /* NOTE: there is no MaterialSlot equivalent in DNA, so the internal
2168    * pointer data points to ob->mat + index, and we manually implement
2169    * get/set for the properties. */
2170 
2171   srna = RNA_def_struct(brna, "MaterialSlot", NULL);
2172   RNA_def_struct_ui_text(srna, "Material Slot", "Material slot in an object");
2173   RNA_def_struct_ui_icon(srna, ICON_MATERIAL_DATA);
2174 
2175   RNA_define_lib_overridable(true);
2176 
2177   /* WARNING! Order is crucial for override to work properly here... :/
2178    * 'link' must come before material pointer,
2179    * since it defines where (in object or obdata) that one is set! */
2180   prop = RNA_def_property(srna, "link", PROP_ENUM, PROP_NONE);
2181   RNA_def_property_enum_items(prop, link_items);
2182   RNA_def_property_enum_funcs(
2183       prop, "rna_MaterialSlot_link_get", "rna_MaterialSlot_link_set", NULL);
2184   RNA_def_property_ui_text(prop, "Link", "Link material to object or the object's data");
2185   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_MaterialSlot_update");
2186 
2187   prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
2188   RNA_def_property_struct_type(prop, "Material");
2189   RNA_def_property_flag(prop, PROP_EDITABLE);
2190   RNA_def_property_editable_func(prop, "rna_MaterialSlot_material_editable");
2191   RNA_def_property_pointer_funcs(prop,
2192                                  "rna_MaterialSlot_material_get",
2193                                  "rna_MaterialSlot_material_set",
2194                                  NULL,
2195                                  "rna_MaterialSlot_material_poll");
2196   RNA_def_property_ui_text(prop, "Material", "Material data-block used by this material slot");
2197   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_MaterialSlot_update");
2198 
2199   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2200   RNA_def_property_string_funcs(
2201       prop, "rna_MaterialSlot_name_get", "rna_MaterialSlot_name_length", NULL);
2202   RNA_def_property_ui_text(prop, "Name", "Material slot name");
2203   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2204   RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2205   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2206   RNA_def_struct_name_property(srna, prop);
2207 
2208   RNA_define_lib_overridable(false);
2209 
2210   RNA_def_struct_path_func(srna, "rna_MaterialSlot_path");
2211 }
2212 
rna_def_object_constraints(BlenderRNA * brna,PropertyRNA * cprop)2213 static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
2214 {
2215   StructRNA *srna;
2216   PropertyRNA *prop;
2217 
2218   FunctionRNA *func;
2219   PropertyRNA *parm;
2220 
2221   RNA_def_property_srna(cprop, "ObjectConstraints");
2222   srna = RNA_def_struct(brna, "ObjectConstraints", NULL);
2223   RNA_def_struct_sdna(srna, "Object");
2224   RNA_def_struct_ui_text(srna, "Object Constraints", "Collection of object constraints");
2225 
2226   /* Collection active property */
2227   prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2228   RNA_def_property_struct_type(prop, "Constraint");
2229   RNA_def_property_pointer_funcs(
2230       prop, "rna_Object_active_constraint_get", "rna_Object_active_constraint_set", NULL, NULL);
2231   RNA_def_property_flag(prop, PROP_EDITABLE);
2232   RNA_def_property_ui_text(prop, "Active Constraint", "Active Object constraint");
2233 
2234   /* Constraint collection */
2235   func = RNA_def_function(srna, "new", "rna_Object_constraints_new");
2236   RNA_def_function_ui_description(func, "Add a new constraint to this object");
2237   RNA_def_function_flag(func, FUNC_USE_MAIN);
2238   /* object to add */
2239   parm = RNA_def_enum(
2240       func, "type", rna_enum_constraint_type_items, 1, "", "Constraint type to add");
2241   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2242   /* return type */
2243   parm = RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint");
2244   RNA_def_function_return(func, parm);
2245 
2246   func = RNA_def_function(srna, "remove", "rna_Object_constraints_remove");
2247   RNA_def_function_ui_description(func, "Remove a constraint from this object");
2248   RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
2249   /* constraint to remove */
2250   parm = RNA_def_pointer(func, "constraint", "Constraint", "", "Removed constraint");
2251   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2252   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
2253 
2254   func = RNA_def_function(srna, "clear", "rna_Object_constraints_clear");
2255   RNA_def_function_flag(func, FUNC_USE_MAIN);
2256   RNA_def_function_ui_description(func, "Remove all constraint from this object");
2257 
2258   func = RNA_def_function(srna, "move", "rna_Object_constraints_move");
2259   RNA_def_function_ui_description(func, "Move a constraint to a different position");
2260   RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
2261   parm = RNA_def_int(
2262       func, "from_index", -1, INT_MIN, INT_MAX, "From Index", "Index to move", 0, 10000);
2263   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2264   parm = RNA_def_int(func, "to_index", -1, INT_MIN, INT_MAX, "To Index", "Target index", 0, 10000);
2265   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2266 
2267   func = RNA_def_function(srna, "copy", "rna_Object_constraints_copy");
2268   RNA_def_function_ui_description(func, "Add a new constraint that is a copy of the given one");
2269   RNA_def_function_flag(func, FUNC_USE_MAIN);
2270   /* constraint to copy */
2271   parm = RNA_def_pointer(func,
2272                          "constraint",
2273                          "Constraint",
2274                          "",
2275                          "Constraint to copy - may belong to a different object");
2276   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2277   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
2278   /* return type */
2279   parm = RNA_def_pointer(func, "new_constraint", "Constraint", "", "New constraint");
2280   RNA_def_function_return(func, parm);
2281 }
2282 
2283 /* object.modifiers */
rna_def_object_modifiers(BlenderRNA * brna,PropertyRNA * cprop)2284 static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
2285 {
2286   StructRNA *srna;
2287 
2288   FunctionRNA *func;
2289   PropertyRNA *parm;
2290 
2291   RNA_def_property_srna(cprop, "ObjectModifiers");
2292   srna = RNA_def_struct(brna, "ObjectModifiers", NULL);
2293   RNA_def_struct_sdna(srna, "Object");
2294   RNA_def_struct_ui_text(srna, "Object Modifiers", "Collection of object modifiers");
2295 
2296 #  if 0
2297   prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2298   RNA_def_property_struct_type(prop, "EditBone");
2299   RNA_def_property_pointer_sdna(prop, NULL, "act_edbone");
2300   RNA_def_property_flag(prop, PROP_EDITABLE);
2301   RNA_def_property_ui_text(prop, "Active EditBone", "Armatures active edit bone");
2302   /*RNA_def_property_update(prop, 0, "rna_Armature_act_editbone_update"); */
2303   RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_edit_bone_set", NULL, NULL);
2304 
2305   /* todo, redraw */
2306 /*      RNA_def_property_collection_active(prop, prop_act); */
2307 #  endif
2308 
2309   /* add modifier */
2310   func = RNA_def_function(srna, "new", "rna_Object_modifier_new");
2311   RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
2312   RNA_def_function_ui_description(func, "Add a new modifier");
2313   parm = RNA_def_string(func, "name", "Name", 0, "", "New name for the modifier");
2314   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2315   /* modifier to add */
2316   parm = RNA_def_enum(
2317       func, "type", rna_enum_object_modifier_type_items, 1, "", "Modifier type to add");
2318   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2319   /* return type */
2320   parm = RNA_def_pointer(func, "modifier", "Modifier", "", "Newly created modifier");
2321   RNA_def_function_return(func, parm);
2322 
2323   /* remove modifier */
2324   func = RNA_def_function(srna, "remove", "rna_Object_modifier_remove");
2325   RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
2326   RNA_def_function_ui_description(func, "Remove an existing modifier from the object");
2327   /* modifier to remove */
2328   parm = RNA_def_pointer(func, "modifier", "Modifier", "", "Modifier to remove");
2329   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2330   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
2331 
2332   /* clear all modifiers */
2333   func = RNA_def_function(srna, "clear", "rna_Object_modifier_clear");
2334   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
2335   RNA_def_function_ui_description(func, "Remove all modifiers from the object");
2336 }
2337 
2338 /* object.grease_pencil_modifiers */
rna_def_object_grease_pencil_modifiers(BlenderRNA * brna,PropertyRNA * cprop)2339 static void rna_def_object_grease_pencil_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
2340 {
2341   StructRNA *srna;
2342 
2343   FunctionRNA *func;
2344   PropertyRNA *parm;
2345 
2346   RNA_def_property_srna(cprop, "ObjectGpencilModifiers");
2347   srna = RNA_def_struct(brna, "ObjectGpencilModifiers", NULL);
2348   RNA_def_struct_sdna(srna, "Object");
2349   RNA_def_struct_ui_text(
2350       srna, "Object Grease Pencil Modifiers", "Collection of object grease pencil modifiers");
2351 
2352   /* add greasepencil modifier */
2353   func = RNA_def_function(srna, "new", "rna_Object_greasepencil_modifier_new");
2354   RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
2355   RNA_def_function_ui_description(func, "Add a new greasepencil_modifier");
2356   parm = RNA_def_string(func, "name", "Name", 0, "", "New name for the greasepencil_modifier");
2357   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2358   /* greasepencil_modifier to add */
2359   parm = RNA_def_enum(func,
2360                       "type",
2361                       rna_enum_object_greasepencil_modifier_type_items,
2362                       1,
2363                       "",
2364                       "Modifier type to add");
2365   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2366   /* return type */
2367   parm = RNA_def_pointer(
2368       func, "greasepencil_modifier", "GpencilModifier", "", "Newly created modifier");
2369   RNA_def_function_return(func, parm);
2370 
2371   /* remove greasepencil_modifier */
2372   func = RNA_def_function(srna, "remove", "rna_Object_greasepencil_modifier_remove");
2373   RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
2374   RNA_def_function_ui_description(func,
2375                                   "Remove an existing greasepencil_modifier from the object");
2376   /* greasepencil_modifier to remove */
2377   parm = RNA_def_pointer(
2378       func, "greasepencil_modifier", "GpencilModifier", "", "Modifier to remove");
2379   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2380   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
2381 
2382   /* clear all greasepencil modifiers */
2383   func = RNA_def_function(srna, "clear", "rna_Object_greasepencil_modifier_clear");
2384   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
2385   RNA_def_function_ui_description(func, "Remove all grease pencil modifiers from the object");
2386 }
2387 
2388 /* object.shaderfxs */
rna_def_object_shaderfxs(BlenderRNA * brna,PropertyRNA * cprop)2389 static void rna_def_object_shaderfxs(BlenderRNA *brna, PropertyRNA *cprop)
2390 {
2391   StructRNA *srna;
2392 
2393   FunctionRNA *func;
2394   PropertyRNA *parm;
2395 
2396   RNA_def_property_srna(cprop, "ObjectShaderFx");
2397   srna = RNA_def_struct(brna, "ObjectShaderFx", NULL);
2398   RNA_def_struct_sdna(srna, "Object");
2399   RNA_def_struct_ui_text(srna, "Object Shader Effects", "Collection of object effects");
2400 
2401   /* add shader_fx */
2402   func = RNA_def_function(srna, "new", "rna_Object_shaderfx_new");
2403   RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
2404   RNA_def_function_ui_description(func, "Add a new shader fx");
2405   parm = RNA_def_string(func, "name", "Name", 0, "", "New name for the effect");
2406   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2407   /* shader to add */
2408   parm = RNA_def_enum(
2409       func, "type", rna_enum_object_shaderfx_type_items, 1, "", "Effect type to add");
2410   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2411   /* return type */
2412   parm = RNA_def_pointer(func, "shader_fx", "ShaderFx", "", "Newly created effect");
2413   RNA_def_function_return(func, parm);
2414 
2415   /* remove shader_fx */
2416   func = RNA_def_function(srna, "remove", "rna_Object_shaderfx_remove");
2417   RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
2418   RNA_def_function_ui_description(func, "Remove an existing effect from the object");
2419   /* shader to remove */
2420   parm = RNA_def_pointer(func, "shader_fx", "ShaderFx", "", "Effect to remove");
2421   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2422   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
2423 
2424   /* clear all shader fx */
2425   func = RNA_def_function(srna, "clear", "rna_Object_shaderfx_clear");
2426   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
2427   RNA_def_function_ui_description(func, "Remove all effects from the object");
2428 }
2429 
2430 /* object.particle_systems */
rna_def_object_particle_systems(BlenderRNA * brna,PropertyRNA * cprop)2431 static void rna_def_object_particle_systems(BlenderRNA *brna, PropertyRNA *cprop)
2432 {
2433   StructRNA *srna;
2434 
2435   PropertyRNA *prop;
2436 
2437   /* FunctionRNA *func; */
2438   /* PropertyRNA *parm; */
2439 
2440   RNA_def_property_srna(cprop, "ParticleSystems");
2441   srna = RNA_def_struct(brna, "ParticleSystems", NULL);
2442   RNA_def_struct_sdna(srna, "Object");
2443   RNA_def_struct_ui_text(srna, "Particle Systems", "Collection of particle systems");
2444 
2445   prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2446   RNA_def_property_struct_type(prop, "ParticleSystem");
2447   RNA_def_property_pointer_funcs(prop, "rna_Object_active_particle_system_get", NULL, NULL, NULL);
2448   RNA_def_property_ui_text(
2449       prop, "Active Particle System", "Active particle system being displayed");
2450   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
2451 
2452   prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2453   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2454   RNA_def_property_int_funcs(prop,
2455                              "rna_Object_active_particle_system_index_get",
2456                              "rna_Object_active_particle_system_index_set",
2457                              "rna_Object_active_particle_system_index_range");
2458   RNA_def_property_ui_text(
2459       prop, "Active Particle System Index", "Index of active particle system slot");
2460   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_particle_update");
2461 }
2462 
2463 /* object.vertex_groups */
rna_def_object_vertex_groups(BlenderRNA * brna,PropertyRNA * cprop)2464 static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop)
2465 {
2466   StructRNA *srna;
2467 
2468   PropertyRNA *prop;
2469 
2470   FunctionRNA *func;
2471   PropertyRNA *parm;
2472 
2473   RNA_def_property_srna(cprop, "VertexGroups");
2474   srna = RNA_def_struct(brna, "VertexGroups", NULL);
2475   RNA_def_struct_sdna(srna, "Object");
2476   RNA_def_struct_ui_text(srna, "Vertex Groups", "Collection of vertex groups");
2477 
2478   prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2479   RNA_def_property_struct_type(prop, "VertexGroup");
2480   RNA_def_property_pointer_funcs(prop,
2481                                  "rna_Object_active_vertex_group_get",
2482                                  "rna_Object_active_vertex_group_set",
2483                                  NULL,
2484                                  NULL);
2485   RNA_def_property_flag(prop, PROP_EDITABLE);
2486   RNA_def_property_ui_text(prop, "Active Vertex Group", "Vertex groups of the object");
2487   RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Object_internal_update_data");
2488 
2489   prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2490   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2491   RNA_def_property_int_sdna(prop, NULL, "actdef");
2492   RNA_def_property_int_funcs(prop,
2493                              "rna_Object_active_vertex_group_index_get",
2494                              "rna_Object_active_vertex_group_index_set",
2495                              "rna_Object_active_vertex_group_index_range");
2496   RNA_def_property_ui_text(
2497       prop, "Active Vertex Group Index", "Active index in vertex group array");
2498   RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Object_internal_update_data");
2499 
2500   /* vertex groups */ /* add_vertex_group */
2501   func = RNA_def_function(srna, "new", "rna_Object_vgroup_new");
2502   RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
2503   RNA_def_function_ui_description(func, "Add vertex group to object");
2504   RNA_def_string(func, "name", "Group", 0, "", "Vertex group name"); /* optional */
2505   parm = RNA_def_pointer(func, "group", "VertexGroup", "", "New vertex group");
2506   RNA_def_function_return(func, parm);
2507 
2508   func = RNA_def_function(srna, "remove", "rna_Object_vgroup_remove");
2509   RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
2510   RNA_def_function_ui_description(func, "Delete vertex group from object");
2511   parm = RNA_def_pointer(func, "group", "VertexGroup", "", "Vertex group to remove");
2512   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2513   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
2514 
2515   func = RNA_def_function(srna, "clear", "rna_Object_vgroup_clear");
2516   RNA_def_function_flag(func, FUNC_USE_MAIN);
2517   RNA_def_function_ui_description(func, "Delete all vertex groups from object");
2518 }
2519 
2520 /* object.face_maps */
rna_def_object_face_maps(BlenderRNA * brna,PropertyRNA * cprop)2521 static void rna_def_object_face_maps(BlenderRNA *brna, PropertyRNA *cprop)
2522 {
2523   StructRNA *srna;
2524 
2525   PropertyRNA *prop;
2526 
2527   FunctionRNA *func;
2528   PropertyRNA *parm;
2529 
2530   RNA_def_property_srna(cprop, "FaceMaps");
2531   srna = RNA_def_struct(brna, "FaceMaps", NULL);
2532   RNA_def_struct_sdna(srna, "Object");
2533   RNA_def_struct_ui_text(srna, "Face Maps", "Collection of face maps");
2534 
2535   prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2536   RNA_def_property_struct_type(prop, "FaceMap");
2537   RNA_def_property_pointer_funcs(
2538       prop, "rna_Object_active_face_map_get", "rna_Object_active_face_map_set", NULL, NULL);
2539   RNA_def_property_ui_text(prop, "Active Face Map", "Face maps of the object");
2540   RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Object_internal_update_data");
2541 
2542   prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2543   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2544   RNA_def_property_int_sdna(prop, NULL, "actfmap");
2545   RNA_def_property_int_funcs(prop,
2546                              "rna_Object_active_face_map_index_get",
2547                              "rna_Object_active_face_map_index_set",
2548                              "rna_Object_active_face_map_index_range");
2549   RNA_def_property_ui_text(prop, "Active Face Map Index", "Active index in face map array");
2550   RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Object_internal_update_data");
2551 
2552   /* face maps */ /* add_face_map */
2553   func = RNA_def_function(srna, "new", "rna_Object_fmap_new");
2554   RNA_def_function_ui_description(func, "Add face map to object");
2555   RNA_def_string(func, "name", "Map", 0, "", "face map name"); /* optional */
2556   parm = RNA_def_pointer(func, "fmap", "FaceMap", "", "New face map");
2557   RNA_def_function_return(func, parm);
2558 
2559   func = RNA_def_function(srna, "remove", "rna_Object_fmap_remove");
2560   RNA_def_function_flag(func, FUNC_USE_REPORTS);
2561   RNA_def_function_ui_description(func, "Delete vertex group from object");
2562   parm = RNA_def_pointer(func, "group", "FaceMap", "", "Face map to remove");
2563   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
2564   RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
2565 
2566   func = RNA_def_function(srna, "clear", "rna_Object_fmap_clear");
2567   RNA_def_function_ui_description(func, "Delete all vertex groups from object");
2568 }
2569 
rna_def_object_display(BlenderRNA * brna)2570 static void rna_def_object_display(BlenderRNA *brna)
2571 {
2572   StructRNA *srna;
2573   PropertyRNA *prop;
2574 
2575   srna = RNA_def_struct(brna, "ObjectDisplay", NULL);
2576   RNA_def_struct_ui_text(srna, "Object Display", "Object display settings for 3d viewport");
2577   RNA_def_struct_sdna(srna, "Object");
2578   RNA_def_struct_nested(brna, srna, "Object");
2579   RNA_def_struct_path_func(srna, "rna_ObjectDisplay_path");
2580 
2581   RNA_define_lib_overridable(true);
2582 
2583   prop = RNA_def_property(srna, "show_shadows", PROP_BOOLEAN, PROP_NONE);
2584   RNA_def_property_boolean_negative_sdna(prop, NULL, "dtx", OB_DRAW_NO_SHADOW_CAST);
2585   RNA_def_property_boolean_default(prop, true);
2586   RNA_def_property_ui_text(prop, "Shadow", "Object cast shadows in the 3d viewport");
2587   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
2588 
2589   RNA_define_lib_overridable(false);
2590 }
2591 
rna_def_object(BlenderRNA * brna)2592 static void rna_def_object(BlenderRNA *brna)
2593 {
2594   StructRNA *srna;
2595   PropertyRNA *prop;
2596 
2597   static const EnumPropertyItem up_items[] = {
2598       {OB_POSX, "X", 0, "X", ""},
2599       {OB_POSY, "Y", 0, "Y", ""},
2600       {OB_POSZ, "Z", 0, "Z", ""},
2601       {0, NULL, 0, NULL, NULL},
2602   };
2603 
2604   static const EnumPropertyItem drawtype_items[] = {
2605       {OB_BOUNDBOX, "BOUNDS", 0, "Bounds", "Display the bounds of the object"},
2606       {OB_WIRE, "WIRE", 0, "Wire", "Display the object as a wireframe"},
2607       {OB_SOLID,
2608        "SOLID",
2609        0,
2610        "Solid",
2611        "Display the object as a solid (if solid drawing is enabled in the viewport)"},
2612       {OB_TEXTURE,
2613        "TEXTURED",
2614        0,
2615        "Textured",
2616        "Display the object with textures (if textures are enabled in the viewport)"},
2617       {0, NULL, 0, NULL, NULL},
2618   };
2619 
2620   static const EnumPropertyItem boundtype_items[] = {
2621       {OB_BOUND_BOX, "BOX", 0, "Box", "Display bounds as box"},
2622       {OB_BOUND_SPHERE, "SPHERE", 0, "Sphere", "Display bounds as sphere"},
2623       {OB_BOUND_CYLINDER, "CYLINDER", 0, "Cylinder", "Display bounds as cylinder"},
2624       {OB_BOUND_CONE, "CONE", 0, "Cone", "Display bounds as cone"},
2625       {OB_BOUND_CAPSULE, "CAPSULE", 0, "Capsule", "Display bounds as capsule"},
2626       {0, NULL, 0, NULL, NULL},
2627   };
2628 
2629   static int boundbox_dimsize[] = {8, 3};
2630 
2631   srna = RNA_def_struct(brna, "Object", "ID");
2632   RNA_def_struct_ui_text(srna, "Object", "Object data-block defining an object in a scene");
2633   RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
2634   RNA_def_struct_ui_icon(srna, ICON_OBJECT_DATA);
2635 
2636   RNA_define_lib_overridable(true);
2637 
2638   prop = RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE);
2639   RNA_def_property_struct_type(prop, "ID");
2640   RNA_def_property_pointer_funcs(
2641       prop, NULL, "rna_Object_data_set", "rna_Object_data_typef", "rna_Object_data_poll");
2642   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
2643   RNA_def_property_ui_text(prop, "Data", "Object data");
2644   RNA_def_property_update(prop, 0, "rna_Object_internal_update_data_dependency");
2645 
2646   prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
2647   RNA_def_property_enum_sdna(prop, NULL, "type");
2648   RNA_def_property_enum_items(prop, rna_enum_object_type_items);
2649   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2650   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2651   RNA_def_property_ui_text(prop, "Type", "Type of Object");
2652   RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_ID);
2653 
2654   prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
2655   RNA_def_property_enum_sdna(prop, NULL, "mode");
2656   RNA_def_property_enum_items(prop, rna_enum_object_mode_items);
2657   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2658   RNA_def_property_ui_text(prop, "Mode", "Object interaction mode");
2659 
2660   /* for data access */
2661   prop = RNA_def_property(srna, "bound_box", PROP_FLOAT, PROP_NONE);
2662   RNA_def_property_multi_array(prop, 2, boundbox_dimsize);
2663   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2664   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2665   RNA_def_property_float_funcs(prop, "rna_Object_boundbox_get", NULL, NULL);
2666   RNA_def_property_ui_text(
2667       prop,
2668       "Bounding Box",
2669       "Object's bounding box in object-space coordinates, all values are -1.0 when "
2670       "not available");
2671 
2672   /* parent */
2673   prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
2674   RNA_def_property_pointer_funcs(prop, NULL, "rna_Object_parent_set", NULL, NULL);
2675   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
2676   RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Object_parent_override_apply");
2677   RNA_def_property_ui_text(prop, "Parent", "Parent Object");
2678   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
2679 
2680   prop = RNA_def_property(srna, "parent_type", PROP_ENUM, PROP_NONE);
2681   RNA_def_property_enum_bitflag_sdna(prop, NULL, "partype");
2682   RNA_def_property_enum_items(prop, parent_type_items);
2683   RNA_def_property_enum_funcs(
2684       prop, NULL, "rna_Object_parent_type_set", "rna_Object_parent_type_itemf");
2685   RNA_def_property_ui_text(prop, "Parent Type", "Type of parent relation");
2686   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
2687 
2688   prop = RNA_def_property(srna, "parent_vertices", PROP_INT, PROP_UNSIGNED);
2689   RNA_def_property_int_sdna(prop, NULL, "par1");
2690   RNA_def_property_array(prop, 3);
2691   RNA_def_property_ui_text(
2692       prop, "Parent Vertices", "Indices of vertices in case of a vertex parenting relation");
2693   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
2694 
2695   prop = RNA_def_property(srna, "parent_bone", PROP_STRING, PROP_NONE);
2696   RNA_def_property_string_sdna(prop, NULL, "parsubstr");
2697   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Object_parent_bone_set");
2698   RNA_def_property_ui_text(
2699       prop, "Parent Bone", "Name of parent bone in case of a bone parenting relation");
2700   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
2701 
2702   /* Track and Up flags */
2703   /* XXX: these have been saved here for a bit longer (after old track was removed),
2704    *      since some other tools still refer to this */
2705   prop = RNA_def_property(srna, "track_axis", PROP_ENUM, PROP_NONE);
2706   RNA_def_property_enum_sdna(prop, NULL, "trackflag");
2707   RNA_def_property_enum_items(prop, rna_enum_object_axis_items);
2708   RNA_def_property_ui_text(
2709       prop,
2710       "Track Axis",
2711       "Axis that points in 'forward' direction (applies to InstanceFrame when "
2712       "parent 'Follow' is enabled)");
2713   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
2714 
2715   prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
2716   RNA_def_property_enum_sdna(prop, NULL, "upflag");
2717   RNA_def_property_enum_items(prop, up_items);
2718   RNA_def_property_ui_text(
2719       prop,
2720       "Up Axis",
2721       "Axis that points in the upward direction (applies to InstanceFrame when "
2722       "parent 'Follow' is enabled)");
2723   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
2724 
2725   /* proxy */
2726   prop = RNA_def_property(srna, "proxy", PROP_POINTER, PROP_NONE);
2727   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
2728   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2729   RNA_def_property_ui_text(prop, "Proxy", "Library object this proxy object controls");
2730 
2731   prop = RNA_def_property(srna, "proxy_collection", PROP_POINTER, PROP_NONE);
2732   RNA_def_property_pointer_sdna(prop, NULL, "proxy_group");
2733   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
2734   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2735   RNA_def_property_ui_text(
2736       prop, "Proxy Collection", "Library collection duplicator object this proxy object controls");
2737 
2738   /* materials */
2739   prop = RNA_def_property(srna, "material_slots", PROP_COLLECTION, PROP_NONE);
2740   RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
2741   RNA_def_property_struct_type(prop, "MaterialSlot");
2742   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_PROP_NAME);
2743   /* don't dereference pointer! */
2744   RNA_def_property_collection_funcs(
2745       prop, NULL, NULL, NULL, "rna_iterator_array_get", NULL, NULL, NULL, NULL);
2746   RNA_def_property_ui_text(prop, "Material Slots", "Material slots in the object");
2747 
2748   prop = RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE);
2749   RNA_def_property_struct_type(prop, "Material");
2750   RNA_def_property_pointer_funcs(prop,
2751                                  "rna_Object_active_material_get",
2752                                  "rna_Object_active_material_set",
2753                                  NULL,
2754                                  "rna_MaterialSlot_material_poll");
2755   RNA_def_property_flag(prop, PROP_EDITABLE);
2756   RNA_def_property_editable_func(prop, "rna_Object_active_material_editable");
2757   RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed");
2758   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_MaterialSlot_update");
2759 
2760   prop = RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED);
2761   RNA_def_property_int_sdna(prop, NULL, "actcol");
2762   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2763   RNA_def_property_int_funcs(prop,
2764                              "rna_Object_active_material_index_get",
2765                              "rna_Object_active_material_index_set",
2766                              "rna_Object_active_material_index_range");
2767   RNA_def_property_ui_text(prop, "Active Material Index", "Index of active material slot");
2768   RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, "rna_MaterialIndex_update");
2769 
2770   /* transform */
2771   prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
2772   RNA_def_property_float_sdna(prop, NULL, "loc");
2773   RNA_def_property_editable_array_func(prop, "rna_Object_location_editable");
2774   RNA_def_property_ui_text(prop, "Location", "Location of the object");
2775   RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
2776   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2777 
2778   prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
2779   RNA_def_property_float_sdna(prop, NULL, "quat");
2780   RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable");
2781   RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
2782   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2783 
2784   /* XXX: for axis-angle, it would have been nice to have 2 separate fields for UI purposes, but
2785    * having a single one is better for Keyframing and other property-management situations...
2786    */
2787   prop = RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
2788   RNA_def_property_array(prop, 4);
2789   RNA_def_property_float_funcs(
2790       prop, "rna_Object_rotation_axis_angle_get", "rna_Object_rotation_axis_angle_set", NULL);
2791   RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable");
2792   RNA_def_property_float_array_default(prop, rna_default_axis_angle);
2793   RNA_def_property_ui_text(
2794       prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
2795   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2796 
2797   prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
2798   RNA_def_property_float_sdna(prop, NULL, "rot");
2799   RNA_def_property_editable_array_func(prop, "rna_Object_rotation_euler_editable");
2800   RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
2801   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2802 
2803   prop = RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
2804   RNA_def_property_enum_sdna(prop, NULL, "rotmode");
2805   RNA_def_property_enum_items(prop, rna_enum_object_rotation_mode_items);
2806   RNA_def_property_enum_funcs(prop, NULL, "rna_Object_rotation_mode_set", NULL);
2807   RNA_def_property_ui_text(prop, "Rotation Mode", "");
2808   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2809 
2810   prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
2811   RNA_def_property_flag(prop, PROP_PROPORTIONAL);
2812   RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable");
2813   RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
2814   RNA_def_property_ui_text(prop, "Scale", "Scaling of the object");
2815   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2816 
2817   prop = RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ_LENGTH);
2818   RNA_def_property_array(prop, 3);
2819   /* Only as convenient helper for py API, and conflicts with animating scale. */
2820   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2821   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
2822   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2823   RNA_def_property_float_funcs(
2824       prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", NULL);
2825   RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
2826   RNA_def_property_ui_text(
2827       prop,
2828       "Dimensions",
2829       "Absolute bounding box dimensions of the object (WARNING: assigning to it or "
2830       "its members multiple consecutive times will not work correctly, "
2831       "as this needs up-to-date evaluated data)");
2832   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2833 
2834   /* delta transforms */
2835   prop = RNA_def_property(srna, "delta_location", PROP_FLOAT, PROP_TRANSLATION);
2836   RNA_def_property_float_sdna(prop, NULL, "dloc");
2837   RNA_def_property_ui_text(
2838       prop, "Delta Location", "Extra translation added to the location of the object");
2839   RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
2840   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2841 
2842   prop = RNA_def_property(srna, "delta_rotation_euler", PROP_FLOAT, PROP_EULER);
2843   RNA_def_property_float_sdna(prop, NULL, "drot");
2844   RNA_def_property_ui_text(
2845       prop,
2846       "Delta Rotation (Euler)",
2847       "Extra rotation added to the rotation of the object (when using Euler rotations)");
2848   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2849 
2850   prop = RNA_def_property(srna, "delta_rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
2851   RNA_def_property_float_sdna(prop, NULL, "dquat");
2852   RNA_def_property_ui_text(
2853       prop,
2854       "Delta Rotation (Quaternion)",
2855       "Extra rotation added to the rotation of the object (when using Quaternion rotations)");
2856   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2857 
2858 #  if 0 /* XXX not supported well yet... */
2859   prop = RNA_def_property(srna, "delta_rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
2860   /* FIXME: this is not a single field any more! (drotAxis and drotAngle) */
2861   RNA_def_property_float_sdna(prop, NULL, "dquat");
2862   RNA_def_property_float_array_default(prop, rna_default_axis_angle);
2863   RNA_def_property_ui_text(
2864       prop,
2865       "Delta Rotation (Axis Angle)",
2866       "Extra rotation added to the rotation of the object (when using Axis-Angle rotations)");
2867   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2868 #  endif
2869 
2870   prop = RNA_def_property(srna, "delta_scale", PROP_FLOAT, PROP_XYZ);
2871   RNA_def_property_float_sdna(prop, NULL, "dscale");
2872   RNA_def_property_flag(prop, PROP_PROPORTIONAL);
2873   RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
2874   RNA_def_property_ui_text(prop, "Delta Scale", "Extra scaling added to the scale of the object");
2875   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2876 
2877   /* transform locks */
2878   prop = RNA_def_property(srna, "lock_location", PROP_BOOLEAN, PROP_NONE);
2879   RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_LOCX);
2880   RNA_def_property_array(prop, 3);
2881   RNA_def_property_ui_text(prop, "Lock Location", "Lock editing of location when transforming");
2882   RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
2883   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2884 
2885   prop = RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_NONE);
2886   RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
2887   RNA_def_property_array(prop, 3);
2888   RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation when transforming");
2889   RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
2890   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2891 
2892   /* XXX this is sub-optimal - it really should be included above,
2893    *     but due to technical reasons we can't do this! */
2894   prop = RNA_def_property(srna, "lock_rotation_w", PROP_BOOLEAN, PROP_NONE);
2895   RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTW);
2896   RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
2897   RNA_def_property_ui_text(
2898       prop,
2899       "Lock Rotation (4D Angle)",
2900       "Lock editing of 'angle' component of four-component rotations when transforming");
2901   /* XXX this needs a better name */
2902   prop = RNA_def_property(srna, "lock_rotations_4d", PROP_BOOLEAN, PROP_NONE);
2903   RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROT4D);
2904   RNA_def_property_ui_text(
2905       prop,
2906       "Lock Rotations (4D)",
2907       "Lock editing of four component rotations by components (instead of as Eulers)");
2908 
2909   prop = RNA_def_property(srna, "lock_scale", PROP_BOOLEAN, PROP_NONE);
2910   RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_SCALEX);
2911   RNA_def_property_array(prop, 3);
2912   RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale when transforming");
2913   RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
2914   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2915 
2916   /* matrix */
2917   prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
2918   RNA_def_property_float_sdna(prop, NULL, "obmat");
2919   RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
2920   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2921   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
2922   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2923   RNA_def_property_ui_text(prop, "Matrix World", "Worldspace transformation matrix");
2924   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_matrix_world_update");
2925 
2926   prop = RNA_def_property(srna, "matrix_local", PROP_FLOAT, PROP_MATRIX);
2927   RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
2928   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2929   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
2930   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2931   RNA_def_property_ui_text(
2932       prop,
2933       "Local Matrix",
2934       "Parent relative transformation matrix - "
2935       "WARNING: Only takes into account 'Object' parenting, so e.g. in case of bone parenting "
2936       "you get a matrix relative to the Armature object, not to the actual parent bone");
2937   RNA_def_property_float_funcs(
2938       prop, "rna_Object_matrix_local_get", "rna_Object_matrix_local_set", NULL);
2939   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2940 
2941   prop = RNA_def_property(srna, "matrix_basis", PROP_FLOAT, PROP_MATRIX);
2942   RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
2943   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
2944   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
2945   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2946   RNA_def_property_ui_text(prop,
2947                            "Input Matrix",
2948                            "Matrix access to location, rotation and scale (including deltas), "
2949                            "before constraints and parenting are applied");
2950   RNA_def_property_float_funcs(
2951       prop, "rna_Object_matrix_basis_get", "rna_Object_matrix_basis_set", NULL);
2952   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2953 
2954   /*parent_inverse*/
2955   prop = RNA_def_property(srna, "matrix_parent_inverse", PROP_FLOAT, PROP_MATRIX);
2956   RNA_def_property_float_sdna(prop, NULL, "parentinv");
2957   RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
2958   RNA_def_property_ui_text(
2959       prop, "Parent Inverse Matrix", "Inverse of object's parent matrix at time of parenting");
2960   RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
2961 
2962   /* modifiers */
2963   prop = RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
2964   RNA_def_property_struct_type(prop, "Modifier");
2965   RNA_def_property_ui_text(
2966       prop, "Modifiers", "Modifiers affecting the geometric data of the object");
2967   RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Object_modifiers_override_apply");
2968   RNA_def_property_override_flag(prop, PROPOVERRIDE_LIBRARY_INSERTION);
2969   rna_def_object_modifiers(brna, prop);
2970 
2971   /* Grease Pencil modifiers. */
2972   prop = RNA_def_property(srna, "grease_pencil_modifiers", PROP_COLLECTION, PROP_NONE);
2973   RNA_def_property_collection_sdna(prop, NULL, "greasepencil_modifiers", NULL);
2974   RNA_def_property_struct_type(prop, "GpencilModifier");
2975   RNA_def_property_ui_text(
2976       prop, "Grease Pencil Modifiers", "Modifiers affecting the data of the grease pencil object");
2977   RNA_def_property_override_funcs(
2978       prop, NULL, NULL, "rna_Object_greasepencil_modifiers_override_apply");
2979   RNA_def_property_override_flag(prop, PROPOVERRIDE_LIBRARY_INSERTION);
2980   rna_def_object_grease_pencil_modifiers(brna, prop);
2981 
2982   /* Shader FX. */
2983   prop = RNA_def_property(srna, "shader_effects", PROP_COLLECTION, PROP_NONE);
2984   RNA_def_property_collection_sdna(prop, NULL, "shader_fx", NULL);
2985   RNA_def_property_struct_type(prop, "ShaderFx");
2986   RNA_def_property_ui_text(prop, "Shader Effects", "Effects affecting display of object");
2987   RNA_define_lib_overridable(false);
2988   rna_def_object_shaderfxs(brna, prop);
2989   RNA_define_lib_overridable(true);
2990 
2991   /* constraints */
2992   prop = RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
2993   RNA_def_property_struct_type(prop, "Constraint");
2994   RNA_def_property_override_flag(prop, PROPOVERRIDE_LIBRARY_INSERTION);
2995   RNA_def_property_ui_text(
2996       prop, "Constraints", "Constraints affecting the transformation of the object");
2997   RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Object_constraints_override_apply");
2998 #  if 0
2999   RNA_def_property_collection_funcs(
3000       prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "constraints__add", "constraints__remove");
3001 #  endif
3002   rna_def_object_constraints(brna, prop);
3003 
3004   /* vertex groups */
3005   prop = RNA_def_property(srna, "vertex_groups", PROP_COLLECTION, PROP_NONE);
3006   RNA_def_property_collection_sdna(prop, NULL, "defbase", NULL);
3007   RNA_def_property_struct_type(prop, "VertexGroup");
3008   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3009   RNA_def_property_ui_text(prop, "Vertex Groups", "Vertex groups of the object");
3010   rna_def_object_vertex_groups(brna, prop);
3011 
3012   /* face maps */
3013   prop = RNA_def_property(srna, "face_maps", PROP_COLLECTION, PROP_NONE);
3014   RNA_def_property_collection_sdna(prop, NULL, "fmaps", NULL);
3015   RNA_def_property_struct_type(prop, "FaceMap");
3016   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3017   RNA_def_property_ui_text(prop, "Face Maps", "Maps of faces of the object");
3018   rna_def_object_face_maps(brna, prop);
3019 
3020   /* empty */
3021   prop = RNA_def_property(srna, "empty_display_type", PROP_ENUM, PROP_NONE);
3022   RNA_def_property_enum_sdna(prop, NULL, "empty_drawtype");
3023   RNA_def_property_enum_items(prop, rna_enum_object_empty_drawtype_items);
3024   RNA_def_property_enum_funcs(prop, NULL, "rna_Object_empty_display_type_set", NULL);
3025   RNA_def_property_ui_text(prop, "Empty Display Type", "Viewport display style for empties");
3026   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3027 
3028   prop = RNA_def_property(srna, "empty_display_size", PROP_FLOAT, PROP_DISTANCE);
3029   RNA_def_property_float_sdna(prop, NULL, "empty_drawsize");
3030   RNA_def_property_range(prop, 0.0001f, 1000.0f);
3031   RNA_def_property_ui_range(prop, 0.01, 100, 1, 2);
3032   RNA_def_property_ui_text(
3033       prop, "Empty Display Size", "Size of display for empties in the viewport");
3034   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3035 
3036   prop = RNA_def_property(srna, "empty_image_offset", PROP_FLOAT, PROP_NONE);
3037   RNA_def_property_float_sdna(prop, NULL, "ima_ofs");
3038   RNA_def_property_ui_text(prop, "Origin Offset", "Origin offset distance");
3039   RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 0.1f, 2);
3040   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3041 
3042   prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
3043   RNA_def_property_flag(prop, PROP_NEVER_NULL);
3044   RNA_def_property_pointer_sdna(prop, NULL, "iuser");
3045   RNA_def_property_ui_text(
3046       prop,
3047       "Image User",
3048       "Parameters defining which layer, pass and frame of the image is displayed");
3049   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3050 
3051   prop = RNA_def_property(srna, "empty_image_depth", PROP_ENUM, PROP_NONE);
3052   RNA_def_property_enum_items(prop, rna_enum_object_empty_image_depth_items);
3053   RNA_def_property_ui_text(
3054       prop, "Empty Image Depth", "Determine which other objects will occlude the image");
3055   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3056 
3057   prop = RNA_def_property(srna, "show_empty_image_perspective", PROP_BOOLEAN, PROP_NONE);
3058   RNA_def_property_boolean_negative_sdna(
3059       prop, NULL, "empty_image_visibility_flag", OB_EMPTY_IMAGE_HIDE_PERSPECTIVE);
3060   RNA_def_property_ui_text(
3061       prop, "Display in Perspective Mode", "Display image in perspective mode");
3062   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3063 
3064   prop = RNA_def_property(srna, "show_empty_image_orthographic", PROP_BOOLEAN, PROP_NONE);
3065   RNA_def_property_boolean_negative_sdna(
3066       prop, NULL, "empty_image_visibility_flag", OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC);
3067   RNA_def_property_ui_text(
3068       prop, "Display in Orthographic Mode", "Display image in orthographic mode");
3069   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3070 
3071   prop = RNA_def_property(srna, "show_empty_image_only_axis_aligned", PROP_BOOLEAN, PROP_NONE);
3072   RNA_def_property_boolean_sdna(
3073       prop, NULL, "empty_image_visibility_flag", OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED);
3074   RNA_def_property_ui_text(prop,
3075                            "Display Only Axis Aligned",
3076                            "Only display the image when it is aligned with the view axis");
3077   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3078 
3079   prop = RNA_def_property(srna, "use_empty_image_alpha", PROP_BOOLEAN, PROP_NONE);
3080   RNA_def_property_boolean_sdna(prop, NULL, "empty_image_flag", OB_EMPTY_IMAGE_USE_ALPHA_BLEND);
3081   RNA_def_property_ui_text(
3082       prop,
3083       "Use Alpha",
3084       "Use alpha blending instead of alpha test (can produce sorting artifacts)");
3085   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3086 
3087   static EnumPropertyItem prop_empty_image_side_items[] = {
3088       {0, "DOUBLE_SIDED", 0, "Both", ""},
3089       {OB_EMPTY_IMAGE_HIDE_BACK, "FRONT", 0, "Front", ""},
3090       {OB_EMPTY_IMAGE_HIDE_FRONT, "BACK", 0, "Back", ""},
3091       {0, NULL, 0, NULL, NULL},
3092   };
3093   prop = RNA_def_property(srna, "empty_image_side", PROP_ENUM, PROP_NONE);
3094   RNA_def_property_enum_bitflag_sdna(prop, NULL, "empty_image_visibility_flag");
3095   RNA_def_property_enum_items(prop, prop_empty_image_side_items);
3096   RNA_def_property_ui_text(prop, "Empty Image Side", "Show front/back side");
3097   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3098 
3099   /* render */
3100   prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_UNSIGNED);
3101   RNA_def_property_int_sdna(prop, NULL, "index");
3102   RNA_def_property_ui_text(
3103       prop, "Pass Index", "Index number for the \"Object Index\" render pass");
3104   RNA_def_property_update(prop, NC_OBJECT, "rna_Object_internal_update_draw");
3105 
3106   prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
3107   RNA_def_property_ui_text(
3108       prop, "Color", "Object color and alpha, used when faces have the ObColor mode enabled");
3109   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update_draw");
3110 
3111   /* physics */
3112   prop = RNA_def_property(srna, "field", PROP_POINTER, PROP_NONE);
3113   RNA_def_property_pointer_sdna(prop, NULL, "pd");
3114   RNA_def_property_struct_type(prop, "FieldSettings");
3115   RNA_def_property_pointer_funcs(prop, "rna_Object_field_get", NULL, NULL, NULL);
3116   RNA_def_property_ui_text(
3117       prop, "Field Settings", "Settings for using the object as a field in physics simulation");
3118 
3119   prop = RNA_def_property(srna, "collision", PROP_POINTER, PROP_NONE);
3120   RNA_def_property_pointer_sdna(prop, NULL, "pd");
3121   RNA_def_property_struct_type(prop, "CollisionSettings");
3122   RNA_def_property_pointer_funcs(prop, "rna_Object_collision_get", NULL, NULL, NULL);
3123   RNA_def_property_ui_text(prop,
3124                            "Collision Settings",
3125                            "Settings for using the object as a collider in physics simulation");
3126 
3127   prop = RNA_def_property(srna, "soft_body", PROP_POINTER, PROP_NONE);
3128   RNA_def_property_pointer_sdna(prop, NULL, "soft");
3129   RNA_def_property_struct_type(prop, "SoftBodySettings");
3130   RNA_def_property_ui_text(prop, "Soft Body Settings", "Settings for soft body simulation");
3131 
3132   prop = RNA_def_property(srna, "particle_systems", PROP_COLLECTION, PROP_NONE);
3133   RNA_def_property_collection_sdna(prop, NULL, "particlesystem", NULL);
3134   RNA_def_property_struct_type(prop, "ParticleSystem");
3135   RNA_def_property_ui_text(prop, "Particle Systems", "Particle systems emitted from the object");
3136   rna_def_object_particle_systems(brna, prop);
3137 
3138   prop = RNA_def_property(srna, "rigid_body", PROP_POINTER, PROP_NONE);
3139   RNA_def_property_pointer_sdna(prop, NULL, "rigidbody_object");
3140   RNA_def_property_struct_type(prop, "RigidBodyObject");
3141   RNA_def_property_ui_text(prop, "Rigid Body Settings", "Settings for rigid body simulation");
3142 
3143   prop = RNA_def_property(srna, "rigid_body_constraint", PROP_POINTER, PROP_NONE);
3144   RNA_def_property_pointer_sdna(prop, NULL, "rigidbody_constraint");
3145   RNA_def_property_struct_type(prop, "RigidBodyConstraint");
3146   RNA_def_property_ui_text(prop, "Rigid Body Constraint", "Constraint constraining rigid bodies");
3147 
3148   /* restrict */
3149   prop = RNA_def_property(srna, "hide_viewport", PROP_BOOLEAN, PROP_NONE);
3150   RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_VIEWPORT);
3151   RNA_def_property_ui_text(prop, "Disable in Viewports", "Globally disable in viewports");
3152   RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, -1);
3153   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
3154 
3155   prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE);
3156   RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_SELECT);
3157   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
3158   RNA_def_property_ui_text(prop, "Disable Selection", "Disable selection in viewport");
3159   RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, -1);
3160   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
3161 
3162   prop = RNA_def_property(srna, "hide_render", PROP_BOOLEAN, PROP_NONE);
3163   RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_RENDER);
3164   RNA_def_property_ui_text(prop, "Disable in Renders", "Globally disable in renders");
3165   RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, -1);
3166   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
3167 
3168   prop = RNA_def_property(srna, "show_instancer_for_render", PROP_BOOLEAN, PROP_NONE);
3169   RNA_def_property_boolean_sdna(prop, NULL, "duplicator_visibility_flag", OB_DUPLI_FLAG_RENDER);
3170   RNA_def_property_ui_text(prop, "Render Instancer", "Make instancer visible when rendering");
3171   RNA_def_property_update(
3172       prop, NC_OBJECT | ND_DRAW, "rna_Object_duplicator_visibility_flag_update");
3173 
3174   prop = RNA_def_property(srna, "show_instancer_for_viewport", PROP_BOOLEAN, PROP_NONE);
3175   RNA_def_property_boolean_sdna(prop, NULL, "duplicator_visibility_flag", OB_DUPLI_FLAG_VIEWPORT);
3176   RNA_def_property_ui_text(prop, "Display Instancer", "Make instancer visible in the viewport");
3177   RNA_def_property_update(
3178       prop, NC_OBJECT | ND_DRAW, "rna_Object_duplicator_visibility_flag_update");
3179 
3180   /* instancing */
3181   prop = RNA_def_property(srna, "instance_type", PROP_ENUM, PROP_NONE);
3182   RNA_def_property_enum_bitflag_sdna(prop, NULL, "transflag");
3183   RNA_def_property_enum_items(prop, instance_items);
3184   RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Object_instance_type_itemf");
3185   RNA_def_property_ui_text(prop, "Instance Type", "If not None, object instancing method to use");
3186   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
3187 
3188   prop = RNA_def_property(srna, "use_instance_vertices_rotation", PROP_BOOLEAN, PROP_NONE);
3189   RNA_def_property_boolean_sdna(prop, NULL, "transflag", OB_DUPLIROT);
3190   RNA_def_property_ui_text(
3191       prop, "Orient with Normals", "Rotate instance according to vertex normal");
3192   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3193 
3194   prop = RNA_def_property(srna, "use_instance_faces_scale", PROP_BOOLEAN, PROP_NONE);
3195   RNA_def_property_boolean_sdna(prop, NULL, "transflag", OB_DUPLIFACES_SCALE);
3196   RNA_def_property_ui_text(prop, "Scale to Face Sizes", "Scale instance based on face size");
3197   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
3198 
3199   prop = RNA_def_property(srna, "instance_faces_scale", PROP_FLOAT, PROP_NONE);
3200   RNA_def_property_float_sdna(prop, NULL, "instance_faces_scale");
3201   RNA_def_property_range(prop, 0.001f, 10000.0f);
3202   RNA_def_property_ui_text(prop, "Instance Faces Scale", "Scale the face instance objects");
3203   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
3204 
3205   prop = RNA_def_property(srna, "instance_collection", PROP_POINTER, PROP_NONE);
3206   RNA_def_property_struct_type(prop, "Collection");
3207   RNA_def_property_pointer_sdna(prop, NULL, "instance_collection");
3208   RNA_def_property_flag(prop, PROP_EDITABLE);
3209   RNA_def_property_pointer_funcs(prop, NULL, "rna_Object_dup_collection_set", NULL, NULL);
3210   RNA_def_property_ui_text(prop, "Instance Collection", "Instance an existing collection");
3211   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
3212 
3213   prop = RNA_def_property(srna, "is_instancer", PROP_BOOLEAN, PROP_NONE);
3214   RNA_def_property_boolean_sdna(prop, NULL, "transflag", OB_DUPLI);
3215   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3216   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
3217   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3218 
3219   /* drawing */
3220   prop = RNA_def_property(srna, "display_type", PROP_ENUM, PROP_NONE);
3221   RNA_def_property_enum_sdna(prop, NULL, "dt");
3222   RNA_def_property_enum_items(prop, drawtype_items);
3223   RNA_def_property_ui_text(prop, "Display As", "How to display object in viewport");
3224   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
3225 
3226   prop = RNA_def_property(srna, "show_bounds", PROP_BOOLEAN, PROP_NONE);
3227   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_DRAWBOUNDOX);
3228   RNA_def_property_ui_text(prop, "Display Bounds", "Display the object's bounds");
3229   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3230 
3231   prop = RNA_def_property(srna, "display_bounds_type", PROP_ENUM, PROP_NONE);
3232   RNA_def_property_enum_sdna(prop, NULL, "boundtype");
3233   RNA_def_property_enum_items(prop, boundtype_items);
3234   RNA_def_property_ui_text(prop, "Display Bounds Type", "Object boundary display type");
3235   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3236 
3237   prop = RNA_def_property(srna, "show_name", PROP_BOOLEAN, PROP_NONE);
3238   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_DRAWNAME);
3239   RNA_def_property_ui_text(prop, "Display Name", "Display the object's name");
3240   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3241 
3242   prop = RNA_def_property(srna, "show_axis", PROP_BOOLEAN, PROP_NONE);
3243   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_AXIS);
3244   RNA_def_property_ui_text(prop, "Display Axes", "Display the object's origin and axes");
3245   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3246 
3247   prop = RNA_def_property(srna, "show_texture_space", PROP_BOOLEAN, PROP_NONE);
3248   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_TEXSPACE);
3249   RNA_def_property_ui_text(prop, "Display Texture Space", "Display the object's texture space");
3250   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3251 
3252   prop = RNA_def_property(srna, "show_wire", PROP_BOOLEAN, PROP_NONE);
3253   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_DRAWWIRE);
3254   RNA_def_property_ui_text(prop, "Display Wire", "Add the object's wireframe over solid drawing");
3255   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3256 
3257   prop = RNA_def_property(srna, "show_all_edges", PROP_BOOLEAN, PROP_NONE);
3258   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_DRAW_ALL_EDGES);
3259   RNA_def_property_ui_text(prop, "Display All Edges", "Display all edges for mesh objects");
3260   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3261 
3262   prop = RNA_def_property(srna, "use_grease_pencil_lights", PROP_BOOLEAN, PROP_NONE);
3263   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_USE_GPENCIL_LIGHTS);
3264   RNA_def_property_boolean_default(prop, true);
3265   RNA_def_property_ui_text(prop, "Use Lights", "Lights affect grease pencil object");
3266   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_GPencil_update");
3267 
3268   prop = RNA_def_property(srna, "show_transparent", PROP_BOOLEAN, PROP_NONE);
3269   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_DRAWTRANSP);
3270   RNA_def_property_ui_text(
3271       prop, "Display Transparent", "Display material transparency in the object");
3272   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
3273 
3274   prop = RNA_def_property(srna, "show_in_front", PROP_BOOLEAN, PROP_NONE);
3275   RNA_def_property_boolean_sdna(prop, NULL, "dtx", OB_DRAW_IN_FRONT);
3276   RNA_def_property_ui_text(prop, "In Front", "Make the object draw in front of others");
3277   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_GPencil_update");
3278 
3279   /* pose */
3280   prop = RNA_def_property(srna, "pose_library", PROP_POINTER, PROP_NONE);
3281   RNA_def_property_pointer_sdna(prop, NULL, "poselib");
3282   RNA_def_property_struct_type(prop, "Action");
3283   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
3284   RNA_def_property_ui_text(prop, "Pose Library", "Action used as a pose library for armatures");
3285 
3286   prop = RNA_def_property(srna, "pose", PROP_POINTER, PROP_NONE);
3287   RNA_def_property_pointer_sdna(prop, NULL, "pose");
3288   RNA_def_property_struct_type(prop, "Pose");
3289   RNA_def_property_ui_text(prop, "Pose", "Current pose for armatures");
3290 
3291   /* shape keys */
3292   prop = RNA_def_property(srna, "show_only_shape_key", PROP_BOOLEAN, PROP_NONE);
3293   RNA_def_property_boolean_sdna(prop, NULL, "shapeflag", OB_SHAPE_LOCK);
3294   RNA_def_property_ui_text(
3295       prop, "Shape Key Lock", "Always show the current Shape for this Object");
3296   RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
3297   RNA_def_property_update(prop, 0, "rna_Object_internal_update_data");
3298 
3299   prop = RNA_def_property(srna, "use_shape_key_edit_mode", PROP_BOOLEAN, PROP_NONE);
3300   RNA_def_property_boolean_sdna(prop, NULL, "shapeflag", OB_SHAPE_EDIT_MODE);
3301   RNA_def_property_ui_text(
3302       prop, "Shape Key Edit Mode", "Apply shape keys in edit mode (for Meshes only)");
3303   RNA_def_property_ui_icon(prop, ICON_EDITMODE_HLT, 0);
3304   RNA_def_property_update(prop, 0, "rna_Object_internal_update_data");
3305 
3306   prop = RNA_def_property(srna, "active_shape_key", PROP_POINTER, PROP_NONE);
3307   RNA_def_property_struct_type(prop, "ShapeKey");
3308   RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE | PROPOVERRIDE_NO_COMPARISON);
3309   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3310   RNA_def_property_pointer_funcs(prop, "rna_Object_active_shape_key_get", NULL, NULL, NULL);
3311   RNA_def_property_ui_text(prop, "Active Shape Key", "Current shape key");
3312 
3313   prop = RNA_def_property(srna, "active_shape_key_index", PROP_INT, PROP_NONE);
3314   RNA_def_property_int_sdna(prop, NULL, "shapenr");
3315   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); /* XXX this is really unpredictable... */
3316   RNA_def_property_int_funcs(prop,
3317                              "rna_Object_active_shape_key_index_get",
3318                              "rna_Object_active_shape_key_index_set",
3319                              "rna_Object_active_shape_key_index_range");
3320   RNA_def_property_ui_text(prop, "Active Shape Key Index", "Current shape key index");
3321   RNA_def_property_update(prop, 0, "rna_Object_active_shape_update");
3322 
3323   /* sculpt */
3324   prop = RNA_def_property(srna, "use_dynamic_topology_sculpting", PROP_BOOLEAN, PROP_NONE);
3325   RNA_def_property_boolean_funcs(prop, "rna_Object_use_dynamic_topology_sculpting_get", NULL);
3326   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3327   RNA_def_property_ui_text(prop, "Dynamic Topology Sculpting", NULL);
3328 
3329   /* Base Settings */
3330   prop = RNA_def_property(srna, "is_from_instancer", PROP_BOOLEAN, PROP_NONE);
3331   RNA_def_property_boolean_sdna(prop, NULL, "base_flag", BASE_FROM_DUPLI);
3332   RNA_def_property_ui_text(prop, "Base from Instancer", "Object comes from a instancer");
3333   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3334   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
3335   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3336 
3337   prop = RNA_def_property(srna, "is_from_set", PROP_BOOLEAN, PROP_NONE);
3338   RNA_def_property_boolean_sdna(prop, NULL, "base_flag", BASE_FROM_SET);
3339   RNA_def_property_ui_text(prop, "Base from Set", "Object comes from a background set");
3340   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3341   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
3342   RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3343 
3344   /* Object Display */
3345   prop = RNA_def_property(srna, "display", PROP_POINTER, PROP_NONE);
3346   RNA_def_property_flag(prop, PROP_NEVER_NULL);
3347   RNA_def_property_struct_type(prop, "ObjectDisplay");
3348   RNA_def_property_pointer_funcs(prop, "rna_Object_display_get", NULL, NULL, NULL);
3349   RNA_def_property_ui_text(prop, "Object Display", "Object display settings for 3d viewport");
3350 
3351   RNA_define_lib_overridable(false);
3352 
3353   /* anim */
3354   rna_def_animdata_common(srna);
3355 
3356   rna_def_animviz_common(srna);
3357   rna_def_motionpath_common(srna);
3358 
3359   RNA_api_object(srna);
3360 }
3361 
RNA_def_object(BlenderRNA * brna)3362 void RNA_def_object(BlenderRNA *brna)
3363 {
3364   rna_def_object(brna);
3365 
3366   RNA_define_animate_sdna(false);
3367   rna_def_vertex_group(brna);
3368   rna_def_face_map(brna);
3369   rna_def_material_slot(brna);
3370   rna_def_object_display(brna);
3371   RNA_define_animate_sdna(true);
3372 }
3373 
3374 #endif
3375