2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2009 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/makesrna/intern/rna_object_api.c
37 #include "BLI_utildefines.h"
39 #include "RNA_define.h"
41 #include "DNA_constraint_types.h"
42 #include "DNA_modifier_types.h"
43 #include "DNA_object_types.h"
45 #include "BKE_depsgraph.h"
47 #include "rna_internal.h" /* own include */
49 static EnumPropertyItem space_items[] = {
50 {CONSTRAINT_SPACE_WORLD, "WORLD", 0, "World Space",
51 "The most gobal space in Blender"},
52 {CONSTRAINT_SPACE_POSE, "POSE", 0, "Pose Space",
53 "The pose space of a bone (its armature's object space)"},
54 {CONSTRAINT_SPACE_PARLOCAL, "LOCAL_WITH_PARENT", 0, "Local With Parent",
55 "The local space of a bone's parent bone"},
56 {CONSTRAINT_SPACE_LOCAL, "LOCAL", 0, "Local Space",
57 "The local space of an object/bone"},
58 {0, NULL, 0, NULL, NULL}
66 #include "BKE_bvhutils.h"
67 #include "BKE_cdderivedmesh.h"
68 #include "BKE_constraint.h"
69 #include "BKE_context.h"
70 #include "BKE_customdata.h"
72 #include "BKE_global.h"
75 #include "BKE_mball.h"
76 #include "BKE_modifier.h"
77 #include "BKE_object.h"
78 #include "BKE_report.h"
80 #include "ED_object.h"
82 #include "DNA_curve_types.h"
83 #include "DNA_mesh_types.h"
84 #include "DNA_meshdata_types.h"
85 #include "DNA_scene_types.h"
86 #include "DNA_view3d_types.h"
88 #include "MEM_guardedalloc.h"
90 #include "DEG_depsgraph.h"
92 /* Convert a given matrix from a space to another (using the object and/or a bone as reference). */
93 static void rna_Scene_mat_convert_space(Object *ob, ReportList *reports, bPoseChannel *pchan,
94 float *mat, float *mat_ret, int from, int to)
96 copy_m4_m4((float (*)[4])mat_ret, (float (*)[4])mat);
98 /* Error in case of invalid from/to values when pchan is NULL */
100 if (ELEM(from, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_PARLOCAL)) {
101 const char *identifier = NULL;
102 RNA_enum_identifier(space_items, from, &identifier);
103 BKE_reportf(reports, RPT_ERROR, "'from_space' '%s' is invalid when no pose bone is given!", identifier);
106 if (ELEM(to, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_PARLOCAL)) {
107 const char *identifier = NULL;
108 RNA_enum_identifier(space_items, to, &identifier);
109 BKE_reportf(reports, RPT_ERROR, "'to_space' '%s' is invalid when no pose bone is given!", identifier);
114 BKE_constraint_mat_convertspace(ob, pchan, (float (*)[4])mat_ret, from, to, false);
117 static void rna_Object_calc_matrix_camera(
118 Object *ob, float mat_ret[16], int width, int height, float scalex, float scaley)
122 /* setup parameters */
123 BKE_camera_params_init(¶ms);
124 BKE_camera_params_from_object(¶ms, ob);
126 /* compute matrix, viewplane, .. */
127 BKE_camera_params_compute_viewplane(¶ms, width, height, scalex, scaley);
128 BKE_camera_params_compute_matrix(¶ms);
130 copy_m4_m4((float (*)[4])mat_ret, params.winmat);
133 static void rna_Object_camera_fit_coords(
134 Object *ob, Scene *scene, int num_cos, float *cos, float co_ret[3], float *scale_ret)
136 BKE_camera_view_frame_fit_to_coords(scene, (const float (*)[3])cos, num_cos / 3, ob, co_ret, scale_ret);
139 /* copied from Mesh_getFromObject and adapted to RNA interface */
140 /* settings: 0 - preview, 1 - render */
141 static Mesh *rna_Object_to_mesh(
142 Object *ob, ReportList *reports, Scene *sce,
143 int apply_modifiers, int settings, int calc_tessface, int calc_undeformed)
145 return rna_Main_meshes_new_from_object(G.main, reports, sce, ob, apply_modifiers, settings, calc_tessface, calc_undeformed);
148 /* mostly a copy from convertblender.c */
149 static void dupli_render_particle_set(Scene *scene, Object *ob, int level, int enable)
151 /* ugly function, but we need to set particle systems to their render
152 * settings before calling object_duplilist, to get render level duplis */
155 ParticleSystem *psys;
161 if (level >= MAX_DUPLI_RECUR)
164 if (ob->transflag & OB_DUPLIPARTS) {
165 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
166 if (ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
168 psys_render_set(ob, psys, mat, mat, 1, 1, 0.f);
170 psys_render_restore(scene, ob, psys);
175 /* this is to make sure we get render level duplis in groups:
176 * the derivedmesh must be created before init_render_mesh,
177 * since object_duplilist does dupliparticles before that */
178 dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL);
181 for (psys = ob->particlesystem.first; psys; psys = psys->next)
182 psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
186 if (ob->dup_group == NULL) return;
187 group = ob->dup_group;
189 for (go = group->gobject.first; go; go = go->next)
190 dupli_render_particle_set(scene, go->ob, level + 1, enable);
192 /* When no longer needed, duplilist should be freed with Object.free_duplilist */
193 static void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce, int settings)
195 bool for_render = (settings == DAG_EVAL_RENDER);
196 EvaluationContext eval_ctx;
197 DEG_evaluation_context_init(&eval_ctx, settings);
199 if (!(ob->transflag & OB_DUPLI)) {
200 BKE_report(reports, RPT_ERROR, "Object does not have duplis");
204 /* free duplilist if a user forgets to */
206 BKE_report(reports, RPT_WARNING, "Object.dupli_list has not been freed");
208 free_object_duplilist(ob->duplilist);
209 ob->duplilist = NULL;
212 dupli_render_particle_set(sce, ob, 0, 1);
213 ob->duplilist = object_duplilist(&eval_ctx, sce, ob);
215 dupli_render_particle_set(sce, ob, 0, 0);
216 /* ob->duplilist should now be freed with Object.free_duplilist */
219 static void rna_Object_free_duplilist(Object *ob)
222 free_object_duplilist(ob->duplilist);
223 ob->duplilist = NULL;
227 static PointerRNA rna_Object_shape_key_add(Object *ob, bContext *C, ReportList *reports,
228 const char *name, int from_mix)
232 if ((kb = BKE_object_shapekey_insert(ob, name, from_mix))) {
235 RNA_pointer_create((ID *)ob->data, &RNA_ShapeKey, kb, &keyptr);
236 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
241 BKE_reportf(reports, RPT_ERROR, "Object '%s' does not support shapes", ob->id.name + 2);
242 return PointerRNA_NULL;
246 static void rna_Object_shape_key_remove(
247 Object *ob, Main *bmain, ReportList *reports,
250 KeyBlock *kb = kb_ptr->data;
251 Key *key = BKE_key_from_object(ob);
253 if ((key == NULL) || BLI_findindex(&key->block, kb) == -1) {
254 BKE_reportf(reports, RPT_ERROR, "ShapeKey not found");
258 if (!BKE_object_shapekey_remove(bmain, ob, kb)) {
259 BKE_reportf(reports, RPT_ERROR, "Could not remove ShapeKey");
263 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
264 WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
266 RNA_POINTER_INVALIDATE(kb_ptr);
269 static int rna_Object_is_visible(Object *ob, Scene *sce)
271 return !(ob->restrictflag & OB_RESTRICT_VIEW) && (ob->lay & sce->lay);
275 static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex,
276 float weight, int assignmode)
278 if (ob->type != OB_MESH) {
279 BKE_report(reports, RPT_ERROR, "Object should be of mesh type");
283 Mesh *me = (Mesh *)ob->data;
284 int group_index = BLI_findlink(&ob->defbase, group);
285 if (group_index == -1) {
286 BKE_report(reports, RPT_ERROR, "No vertex groups assigned to mesh");
290 if (assignmode != WEIGHT_REPLACE && assignmode != WEIGHT_ADD && assignmode != WEIGHT_SUBTRACT) {
291 BKE_report(reports, RPT_ERROR, "Bad assignment mode");
295 /* makes a set of dVerts corresponding to the mVerts */
297 create_dverts(&me->id);
299 /* loop list adding verts to group */
300 for (i = 0; i < totindex; i++) {
301 if (i < 0 || i >= me->totvert) {
302 BKE_report(reports, RPT_ERROR, "Bad vertex index in list");
306 add_vert_defnr(ob, group_index, i, weight, assignmode);
311 /* don't call inside a loop */
312 static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt)
314 const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
315 return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly;
318 static void rna_Object_ray_cast(
319 Object *ob, ReportList *reports,
320 float origin[3], float direction[3], float distance,
321 int *r_success, float r_location[3], float r_normal[3], int *r_index)
323 BVHTreeFromMesh treeData = {NULL};
325 if (ob->derivedFinal == NULL) {
326 BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for ray casting", ob->id.name + 2);
330 /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
331 bvhtree_from_mesh_looptri(&treeData, ob->derivedFinal, 0.0f, 4, 6);
333 /* may fail if the mesh has no faces, in that case the ray-cast misses */
334 if (treeData.tree != NULL) {
340 normalize_v3(direction);
343 if (BLI_bvhtree_ray_cast(treeData.tree, origin, direction, 0.0f, &hit,
344 treeData.raycast_callback, &treeData) != -1)
346 if (hit.dist <= distance) {
349 copy_v3_v3(r_location, hit.co);
350 copy_v3_v3(r_normal, hit.no);
351 *r_index = dm_looptri_to_poly_index(ob->derivedFinal, &treeData.looptri[hit.index]);
365 free_bvhtree_from_mesh(&treeData);
368 static void rna_Object_closest_point_on_mesh(
369 Object *ob, ReportList *reports, float origin[3], float distance,
370 int *r_success, float r_location[3], float r_normal[3], int *r_index)
372 BVHTreeFromMesh treeData = {NULL};
374 if (ob->derivedFinal == NULL) {
375 BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for finding nearest point",
380 /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
381 bvhtree_from_mesh_looptri(&treeData, ob->derivedFinal, 0.0f, 4, 6);
383 if (treeData.tree == NULL) {
384 BKE_reportf(reports, RPT_ERROR, "Object '%s' could not create internal data for finding nearest point",
389 BVHTreeNearest nearest;
392 nearest.dist_sq = distance * distance;
394 if (BLI_bvhtree_find_nearest(treeData.tree, origin, &nearest, treeData.nearest_callback, &treeData) != -1) {
397 copy_v3_v3(r_location, nearest.co);
398 copy_v3_v3(r_normal, nearest.no);
399 *r_index = dm_looptri_to_poly_index(ob->derivedFinal, &treeData.looptri[nearest.index]);
412 free_bvhtree_from_mesh(&treeData);
417 static void rna_ObjectBase_layers_from_view(Base *base, View3D *v3d)
419 base->lay = base->object->lay = v3d->lay;
422 static int rna_Object_is_modified(Object *ob, Scene *scene, int settings)
424 return BKE_object_is_modified(scene, ob) & settings;
427 static int rna_Object_is_deform_modified(Object *ob, Scene *scene, int settings)
429 return BKE_object_is_deform_modified(scene, ob) & settings;
433 void rna_Object_dm_info(struct Object *ob, int type, char *result)
435 DerivedMesh *dm = NULL;
436 bool dm_release = false;
443 if (ob->type == OB_MESH) {
444 dm = CDDM_from_mesh(ob->data);
445 ret = DM_debug_info(dm);
450 dm = ob->derivedDeform;
453 dm = ob->derivedFinal;
458 ret = DM_debug_info(dm);
470 static int rna_Object_update_from_editmode(Object *ob)
472 if (ob->mode & OB_MODE_EDIT) {
473 return ED_object_editmode_load(ob);
477 #else /* RNA_RUNTIME */
479 void RNA_api_object(StructRNA *srna)
484 static EnumPropertyItem mesh_type_items[] = {
485 {eModifierMode_Realtime, "PREVIEW", 0, "Preview", "Apply modifier preview settings"},
486 {eModifierMode_Render, "RENDER", 0, "Render", "Apply modifier render settings"},
487 {0, NULL, 0, NULL, NULL}
490 static EnumPropertyItem dupli_eval_mode_items[] = {
491 {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Generate duplis using viewport settings"},
492 {DAG_EVAL_PREVIEW, "PREVIEW", 0, "Preview", "Generate duplis using preview settings"},
493 {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Generate duplis using render settings"},
494 {0, NULL, 0, NULL, NULL}
498 static EnumPropertyItem mesh_dm_info_items[] = {
499 {0, "SOURCE", 0, "Source", "Source mesh"},
500 {1, "DEFORM", 0, "Deform", "Objects deform mesh"},
501 {2, "FINAL", 0, "Final", "Objects final mesh"},
502 {0, NULL, 0, NULL, NULL}
506 /* Matrix space conversion */
507 func = RNA_def_function(srna, "convert_space", "rna_Scene_mat_convert_space");
508 RNA_def_function_ui_description(func, "Convert (transform) the given matrix from one space to another");
509 RNA_def_function_flag(func, FUNC_USE_REPORTS);
510 parm = RNA_def_pointer(func, "pose_bone", "PoseBone", "",
511 "Bone to use to define spaces (may be None, in which case only the two 'WORLD' and "
512 "'LOCAL' spaces are usable)");
513 parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
514 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
515 RNA_def_property_ui_text(parm, "", "The matrix to transform");
516 parm = RNA_def_property(func, "matrix_return", PROP_FLOAT, PROP_MATRIX);
517 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
518 RNA_def_property_ui_text(parm, "", "The transformed matrix");
519 RNA_def_function_output(func, parm);
520 parm = RNA_def_enum(func, "from_space", space_items, CONSTRAINT_SPACE_WORLD, "",
521 "The space in which 'matrix' is currently");
522 parm = RNA_def_enum(func, "to_space", space_items, CONSTRAINT_SPACE_WORLD, "",
523 "The space to which you want to transform 'matrix'");
525 /* Camera-related operations */
526 func = RNA_def_function(srna, "calc_matrix_camera", "rna_Object_calc_matrix_camera");
527 RNA_def_function_ui_description(func, "Generate the camera projection matrix of this object "
528 "(mostly useful for Camera and Lamp types)");
529 parm = RNA_def_property(func, "result", PROP_FLOAT, PROP_MATRIX);
530 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
531 RNA_def_property_ui_text(parm, "", "The camera projection matrix");
532 RNA_def_function_output(func, parm);
533 parm = RNA_def_int(func, "x", 1, 0, INT_MAX, "", "Width of the render area", 0, 10000);
534 parm = RNA_def_int(func, "y", 1, 0, INT_MAX, "", "Height of the render area", 0, 10000);
535 parm = RNA_def_float(func, "scale_x", 1.0f, 1.0e-6f, FLT_MAX, "", "Width scaling factor", 1.0e-2f, 100.0f);
536 parm = RNA_def_float(func, "scale_y", 1.0f, 1.0e-6f, FLT_MAX, "", "height scaling factor", 1.0e-2f, 100.0f);
538 func = RNA_def_function(srna, "camera_fit_coords", "rna_Object_camera_fit_coords");
539 RNA_def_function_ui_description(func, "Compute the coordinate (and scale for ortho cameras) "
540 "given object should be to 'see' all given coordinates");
541 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene to get render size information from, if available");
542 RNA_def_property_flag(parm, PROP_REQUIRED);
543 parm = RNA_def_float_array(func, "coordinates", 1, NULL, -FLT_MAX, FLT_MAX, "", "Coordinates to fit in",
545 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_DYNAMIC);
546 parm = RNA_def_property(func, "co_return", PROP_FLOAT, PROP_XYZ);
547 RNA_def_property_array(parm, 3);
548 RNA_def_property_ui_text(parm, "", "The location to aim to be able to see all given points");
549 RNA_def_property_flag(parm, PROP_OUTPUT);
550 parm = RNA_def_property(func, "scale_return", PROP_FLOAT, PROP_NONE);
551 RNA_def_property_ui_text(parm, "", "The ortho scale to aim to be able to see all given points (if relevant)");
552 RNA_def_property_flag(parm, PROP_OUTPUT);
555 func = RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
556 RNA_def_function_ui_description(func, "Create a Mesh data-block with modifiers applied");
557 RNA_def_function_flag(func, FUNC_USE_REPORTS);
558 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate modifiers");
559 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
560 parm = RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers");
561 RNA_def_property_flag(parm, PROP_REQUIRED);
562 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
563 RNA_def_property_flag(parm, PROP_REQUIRED);
564 RNA_def_boolean(func, "calc_tessface", true, "Calculate Tessellation", "Calculate tessellation faces");
565 RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
566 parm = RNA_def_pointer(func, "mesh", "Mesh", "",
567 "Mesh created from object, remove it if it is only used for export");
568 RNA_def_function_return(func, parm);
571 func = RNA_def_function(srna, "dupli_list_create", "rna_Object_create_duplilist");
572 RNA_def_function_ui_description(func, "Create a list of dupli objects for this object, needs to "
573 "be freed manually with free_dupli_list to restore the "
574 "objects real matrix and layers");
575 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate duplis");
576 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
577 RNA_def_enum(func, "settings", dupli_eval_mode_items, 0, "", "Generate texture coordinates for rendering");
578 RNA_def_function_flag(func, FUNC_USE_REPORTS);
580 func = RNA_def_function(srna, "dupli_list_clear", "rna_Object_free_duplilist");
581 RNA_def_function_ui_description(func, "Free the list of dupli objects");
584 func = RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
585 RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier");
586 parm = RNA_def_pointer(func, "ob_arm", "Object", "", "Armature object influencing this object or NULL");
587 RNA_def_function_return(func, parm);
590 func = RNA_def_function(srna, "shape_key_add", "rna_Object_shape_key_add");
591 RNA_def_function_ui_description(func, "Add shape key to this object");
592 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
593 RNA_def_string(func, "name", "Key", 0, "", "Unique name for the new keyblock"); /* optional */
594 RNA_def_boolean(func, "from_mix", 1, "", "Create new shape from existing mix of shapes");
595 parm = RNA_def_pointer(func, "key", "ShapeKey", "", "New shape keyblock");
596 RNA_def_property_flag(parm, PROP_RNAPTR);
597 RNA_def_function_return(func, parm);
599 func = RNA_def_function(srna, "shape_key_remove", "rna_Object_shape_key_remove");
600 RNA_def_function_ui_description(func, "Remove a Shape Key from this object");
601 RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
602 parm = RNA_def_pointer(func, "key", "ShapeKey", "", "Keyblock to be removed");
603 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
604 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
607 func = RNA_def_function(srna, "ray_cast", "rna_Object_ray_cast");
608 RNA_def_function_ui_description(func, "Cast a ray onto in object space");
609 RNA_def_function_flag(func, FUNC_USE_REPORTS);
611 /* ray start and end */
612 parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
613 RNA_def_property_flag(parm, PROP_REQUIRED);
614 parm = RNA_def_float_vector(func, "direction", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
615 RNA_def_property_flag(parm, PROP_REQUIRED);
616 RNA_def_float(func, "distance", FLT_MAX, 0.0, FLT_MAX, "", "Maximum distance", 0.0, FLT_MAX);
618 /* return location and normal */
619 parm = RNA_def_boolean(func, "result", 0, "", "");
620 RNA_def_function_output(func, parm);
621 parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
622 "The hit location of this ray cast", -1e4, 1e4);
623 RNA_def_property_flag(parm, PROP_THICK_WRAP);
624 RNA_def_function_output(func, parm);
625 parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
626 "The face normal at the ray cast hit location", -1e4, 1e4);
627 RNA_def_property_flag(parm, PROP_THICK_WRAP);
628 RNA_def_function_output(func, parm);
629 parm = RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
630 RNA_def_function_output(func, parm);
633 func = RNA_def_function(srna, "closest_point_on_mesh", "rna_Object_closest_point_on_mesh");
634 RNA_def_function_ui_description(func, "Find the nearest point in object space");
635 RNA_def_function_flag(func, FUNC_USE_REPORTS);
637 /* location of point for test and max distance */
638 parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
639 RNA_def_property_flag(parm, PROP_REQUIRED);
640 /* default is sqrt(FLT_MAX) */
641 RNA_def_float(func, "distance", 1.844674352395373e+19, 0.0, FLT_MAX, "", "Maximum distance", 0.0, FLT_MAX);
643 /* return location and normal */
644 parm = RNA_def_boolean(func, "result", 0, "", "");
645 RNA_def_function_output(func, parm);
646 parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
647 "The location on the object closest to the point", -1e4, 1e4);
648 RNA_def_property_flag(parm, PROP_THICK_WRAP);
649 RNA_def_function_output(func, parm);
650 parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
651 "The face normal at the closest point", -1e4, 1e4);
652 RNA_def_property_flag(parm, PROP_THICK_WRAP);
653 RNA_def_function_output(func, parm);
655 parm = RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
656 RNA_def_function_output(func, parm);
659 func = RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
660 RNA_def_function_ui_description(func, "Determine if object is visible in a given scene");
661 parm = RNA_def_pointer(func, "scene", "Scene", "", "");
662 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
663 parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
664 RNA_def_function_return(func, parm);
666 /* utility function for checking if the object is modified */
667 func = RNA_def_function(srna, "is_modified", "rna_Object_is_modified");
668 RNA_def_function_ui_description(func, "Determine if this object is modified from the base mesh data");
669 parm = RNA_def_pointer(func, "scene", "Scene", "", "");
670 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
671 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
672 RNA_def_property_flag(parm, PROP_REQUIRED);
673 parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
674 RNA_def_function_return(func, parm);
676 func = RNA_def_function(srna, "is_deform_modified", "rna_Object_is_deform_modified");
677 RNA_def_function_ui_description(func, "Determine if this object is modified by a deformation from the base mesh data");
678 parm = RNA_def_pointer(func, "scene", "Scene", "", "");
679 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
680 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
681 RNA_def_property_flag(parm, PROP_REQUIRED);
682 parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
683 RNA_def_function_return(func, parm);
687 func = RNA_def_function(srna, "dm_info", "rna_Object_dm_info");
688 RNA_def_function_ui_description(func, "Returns a string for derived mesh data");
690 parm = RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply");
691 RNA_def_property_flag(parm, PROP_REQUIRED);
692 /* weak!, no way to return dynamic string type */
693 parm = RNA_def_string(func, "result", NULL, 16384, "result", "");
694 RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */
695 RNA_def_function_output(func, parm);
698 func = RNA_def_function(srna, "update_from_editmode", "rna_Object_update_from_editmode");
699 RNA_def_function_ui_description(func, "Load the objects edit-mode data intp the object data");
700 parm = RNA_def_boolean(func, "result", 0, "", "Success");
701 RNA_def_function_return(func, parm);
703 func = RNA_def_function(srna, "cache_release", "BKE_object_free_caches");
704 RNA_def_function_ui_description(func, "Release memory used by caches associated with this object. Intended to be used by render engines only");
708 void RNA_api_object_base(StructRNA *srna)
713 func = RNA_def_function(srna, "layers_from_view", "rna_ObjectBase_layers_from_view");
714 RNA_def_function_ui_description(func,
715 "Sets the object layers from a 3D View (use when adding an object in local view)");
716 parm = RNA_def_pointer(func, "view", "SpaceView3D", "", "");
717 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
720 #endif /* RNA_RUNTIME */