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"
38 #include "BLI_kdopbvh.h"
40 #include "RNA_define.h"
42 #include "DNA_constraint_types.h"
43 #include "DNA_modifier_types.h"
44 #include "DNA_object_types.h"
46 #include "BKE_depsgraph.h"
48 #include "rna_internal.h" /* own include */
50 static const EnumPropertyItem space_items[] = {
51 {CONSTRAINT_SPACE_WORLD, "WORLD", 0, "World Space",
52 "The most gobal space in Blender"},
53 {CONSTRAINT_SPACE_POSE, "POSE", 0, "Pose Space",
54 "The pose space of a bone (its armature's object space)"},
55 {CONSTRAINT_SPACE_PARLOCAL, "LOCAL_WITH_PARENT", 0, "Local With Parent",
56 "The local space of a bone's parent bone"},
57 {CONSTRAINT_SPACE_LOCAL, "LOCAL", 0, "Local Space",
58 "The local space of an object/bone"},
59 {0, NULL, 0, NULL, NULL}
67 #include "BKE_bvhutils.h"
68 #include "BKE_cdderivedmesh.h"
69 #include "BKE_constraint.h"
70 #include "BKE_context.h"
71 #include "BKE_customdata.h"
73 #include "BKE_global.h"
76 #include "BKE_mball.h"
77 #include "BKE_modifier.h"
78 #include "BKE_object.h"
79 #include "BKE_report.h"
81 #include "ED_object.h"
83 #include "DNA_curve_types.h"
84 #include "DNA_mesh_types.h"
85 #include "DNA_meshdata_types.h"
86 #include "DNA_scene_types.h"
87 #include "DNA_view3d_types.h"
89 #include "MEM_guardedalloc.h"
91 #include "DEG_depsgraph.h"
93 /* Convert a given matrix from a space to another (using the object and/or a bone as reference). */
94 static void rna_Object_mat_convert_space(Object *ob, ReportList *reports, bPoseChannel *pchan,
95 float *mat, float *mat_ret, int from, int to)
97 copy_m4_m4((float (*)[4])mat_ret, (float (*)[4])mat);
99 /* Error in case of invalid from/to values when pchan is NULL */
101 if (ELEM(from, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_PARLOCAL)) {
102 const char *identifier = NULL;
103 RNA_enum_identifier(space_items, from, &identifier);
104 BKE_reportf(reports, RPT_ERROR, "'from_space' '%s' is invalid when no pose bone is given!", identifier);
107 if (ELEM(to, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_PARLOCAL)) {
108 const char *identifier = NULL;
109 RNA_enum_identifier(space_items, to, &identifier);
110 BKE_reportf(reports, RPT_ERROR, "'to_space' '%s' is invalid when no pose bone is given!", identifier);
115 BKE_constraint_mat_convertspace(ob, pchan, (float (*)[4])mat_ret, from, to, false);
118 static void rna_Object_calc_matrix_camera(
119 Object *ob, float mat_ret[16], int width, int height, float scalex, float scaley)
123 /* setup parameters */
124 BKE_camera_params_init(¶ms);
125 BKE_camera_params_from_object(¶ms, ob);
127 /* compute matrix, viewplane, .. */
128 BKE_camera_params_compute_viewplane(¶ms, width, height, scalex, scaley);
129 BKE_camera_params_compute_matrix(¶ms);
131 copy_m4_m4((float (*)[4])mat_ret, params.winmat);
134 static void rna_Object_camera_fit_coords(
135 Object *ob, Scene *scene, int num_cos, float *cos, float co_ret[3], float *scale_ret)
137 BKE_camera_view_frame_fit_to_coords(scene, (const float (*)[3])cos, num_cos / 3, ob, co_ret, scale_ret);
140 /* copied from Mesh_getFromObject and adapted to RNA interface */
141 /* settings: 0 - preview, 1 - render */
142 static Mesh *rna_Object_to_mesh(
143 Object *ob, ReportList *reports, Scene *sce,
144 int apply_modifiers, int settings, int calc_tessface, int calc_undeformed)
146 return rna_Main_meshes_new_from_object(G.main, reports, sce, ob, apply_modifiers, settings, calc_tessface, calc_undeformed);
149 /* mostly a copy from convertblender.c */
150 static void dupli_render_particle_set(Scene *scene, Object *ob, int level, int enable)
152 /* ugly function, but we need to set particle systems to their render
153 * settings before calling object_duplilist, to get render level duplis */
156 ParticleSystem *psys;
162 if (level >= MAX_DUPLI_RECUR)
165 if (ob->transflag & OB_DUPLIPARTS) {
166 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
167 if (ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
169 psys_render_set(ob, psys, mat, mat, 1, 1, 0.f);
171 psys_render_restore(ob, psys);
176 /* this is to make sure we get render level duplis in groups:
177 * the derivedmesh must be created before init_render_mesh,
178 * since object_duplilist does dupliparticles before that */
179 dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL);
182 for (psys = ob->particlesystem.first; psys; psys = psys->next)
183 psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
187 if (ob->dup_group == NULL) return;
188 group = ob->dup_group;
190 for (go = group->gobject.first; go; go = go->next)
191 dupli_render_particle_set(scene, go->ob, level + 1, enable);
193 /* When no longer needed, duplilist should be freed with Object.free_duplilist */
194 static void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce, int settings)
196 bool for_render = (settings == DAG_EVAL_RENDER);
197 EvaluationContext eval_ctx;
198 DEG_evaluation_context_init(&eval_ctx, settings);
200 if (!(ob->transflag & OB_DUPLI)) {
201 BKE_report(reports, RPT_ERROR, "Object does not have duplis");
205 /* free duplilist if a user forgets to */
207 BKE_report(reports, RPT_WARNING, "Object.dupli_list has not been freed");
209 free_object_duplilist(ob->duplilist);
210 ob->duplilist = NULL;
213 dupli_render_particle_set(sce, ob, 0, 1);
214 ob->duplilist = object_duplilist(&eval_ctx, sce, ob);
216 dupli_render_particle_set(sce, ob, 0, 0);
217 /* ob->duplilist should now be freed with Object.free_duplilist */
220 static void rna_Object_free_duplilist(Object *ob)
223 free_object_duplilist(ob->duplilist);
224 ob->duplilist = NULL;
228 static PointerRNA rna_Object_shape_key_add(Object *ob, bContext *C, ReportList *reports,
229 const char *name, int from_mix)
233 if ((kb = BKE_object_shapekey_insert(ob, name, from_mix))) {
236 RNA_pointer_create((ID *)ob->data, &RNA_ShapeKey, kb, &keyptr);
237 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
242 BKE_reportf(reports, RPT_ERROR, "Object '%s' does not support shapes", ob->id.name + 2);
243 return PointerRNA_NULL;
247 static void rna_Object_shape_key_remove(
248 Object *ob, Main *bmain, ReportList *reports,
251 KeyBlock *kb = kb_ptr->data;
252 Key *key = BKE_key_from_object(ob);
254 if ((key == NULL) || BLI_findindex(&key->block, kb) == -1) {
255 BKE_reportf(reports, RPT_ERROR, "ShapeKey not found");
259 if (!BKE_object_shapekey_remove(bmain, ob, kb)) {
260 BKE_reportf(reports, RPT_ERROR, "Could not remove ShapeKey");
264 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
265 WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
267 RNA_POINTER_INVALIDATE(kb_ptr);
270 static int rna_Object_is_visible(Object *ob, Scene *sce)
272 return !(ob->restrictflag & OB_RESTRICT_VIEW) && (ob->lay & sce->lay);
276 static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex,
277 float weight, int assignmode)
279 if (ob->type != OB_MESH) {
280 BKE_report(reports, RPT_ERROR, "Object should be of mesh type");
284 Mesh *me = (Mesh *)ob->data;
285 int group_index = BLI_findlink(&ob->defbase, group);
286 if (group_index == -1) {
287 BKE_report(reports, RPT_ERROR, "No vertex groups assigned to mesh");
291 if (assignmode != WEIGHT_REPLACE && assignmode != WEIGHT_ADD && assignmode != WEIGHT_SUBTRACT) {
292 BKE_report(reports, RPT_ERROR, "Bad assignment mode");
296 /* makes a set of dVerts corresponding to the mVerts */
298 create_dverts(&me->id);
300 /* loop list adding verts to group */
301 for (i = 0; i < totindex; i++) {
302 if (i < 0 || i >= me->totvert) {
303 BKE_report(reports, RPT_ERROR, "Bad vertex index in list");
307 add_vert_defnr(ob, group_index, i, weight, assignmode);
312 /* don't call inside a loop */
313 static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt)
315 const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
316 return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly;
319 static void rna_Object_ray_cast(
320 Object *ob, ReportList *reports,
321 float origin[3], float direction[3], float distance,
322 int *r_success, float r_location[3], float r_normal[3], int *r_index)
324 bool success = false;
326 if (ob->derivedFinal == NULL) {
327 BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for ray casting", ob->id.name + 2);
331 /* Test BoundBox first (efficiency) */
332 BoundBox *bb = BKE_object_boundbox_get(ob);
334 if (!bb || (isect_ray_aabb_v3_simple(origin, direction, bb->vec[0], bb->vec[6], &distmin, NULL) && distmin <= distance)) {
336 BVHTreeFromMesh treeData = {NULL};
338 /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
339 bvhtree_from_mesh_get(&treeData, ob->derivedFinal, BVHTREE_FROM_LOOPTRI, 4);
341 /* may fail if the mesh has no faces, in that case the ray-cast misses */
342 if (treeData.tree != NULL) {
348 normalize_v3(direction);
351 if (BLI_bvhtree_ray_cast(treeData.tree, origin, direction, 0.0f, &hit,
352 treeData.raycast_callback, &treeData) != -1)
354 if (hit.dist <= distance) {
355 *r_success = success = true;
357 copy_v3_v3(r_location, hit.co);
358 copy_v3_v3(r_normal, hit.no);
359 *r_index = dm_looptri_to_poly_index(ob->derivedFinal, &treeData.looptri[hit.index]);
363 free_bvhtree_from_mesh(&treeData);
366 if (success == false) {
375 static void rna_Object_closest_point_on_mesh(
376 Object *ob, ReportList *reports, float origin[3], float distance,
377 int *r_success, float r_location[3], float r_normal[3], int *r_index)
379 BVHTreeFromMesh treeData = {NULL};
381 if (ob->derivedFinal == NULL) {
382 BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for finding nearest point",
387 /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
388 bvhtree_from_mesh_get(&treeData, ob->derivedFinal, BVHTREE_FROM_LOOPTRI, 4);
390 if (treeData.tree == NULL) {
391 BKE_reportf(reports, RPT_ERROR, "Object '%s' could not create internal data for finding nearest point",
396 BVHTreeNearest nearest;
399 nearest.dist_sq = distance * distance;
401 if (BLI_bvhtree_find_nearest(treeData.tree, origin, &nearest, treeData.nearest_callback, &treeData) != -1) {
404 copy_v3_v3(r_location, nearest.co);
405 copy_v3_v3(r_normal, nearest.no);
406 *r_index = dm_looptri_to_poly_index(ob->derivedFinal, &treeData.looptri[nearest.index]);
419 free_bvhtree_from_mesh(&treeData);
424 static void rna_ObjectBase_layers_from_view(Base *base, View3D *v3d)
426 base->lay = base->object->lay = v3d->lay;
429 static int rna_Object_is_modified(Object *ob, Scene *scene, int settings)
431 return BKE_object_is_modified(scene, ob) & settings;
434 static int rna_Object_is_deform_modified(Object *ob, Scene *scene, int settings)
436 return BKE_object_is_deform_modified(scene, ob) & settings;
440 void rna_Object_dm_info(struct Object *ob, int type, char *result)
442 DerivedMesh *dm = NULL;
443 bool dm_release = false;
450 if (ob->type == OB_MESH) {
451 dm = CDDM_from_mesh(ob->data);
452 ret = DM_debug_info(dm);
457 dm = ob->derivedDeform;
460 dm = ob->derivedFinal;
465 ret = DM_debug_info(dm);
477 static int rna_Object_update_from_editmode(Object *ob)
479 return ED_object_editmode_load(ob);
481 #else /* RNA_RUNTIME */
483 void RNA_api_object(StructRNA *srna)
488 static const EnumPropertyItem mesh_type_items[] = {
489 {eModifierMode_Realtime, "PREVIEW", 0, "Preview", "Apply modifier preview settings"},
490 {eModifierMode_Render, "RENDER", 0, "Render", "Apply modifier render settings"},
491 {0, NULL, 0, NULL, NULL}
494 static const EnumPropertyItem dupli_eval_mode_items[] = {
495 {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Generate duplis using viewport settings"},
496 {DAG_EVAL_PREVIEW, "PREVIEW", 0, "Preview", "Generate duplis using preview settings"},
497 {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Generate duplis using render settings"},
498 {0, NULL, 0, NULL, NULL}
502 static const EnumPropertyItem mesh_dm_info_items[] = {
503 {0, "SOURCE", 0, "Source", "Source mesh"},
504 {1, "DEFORM", 0, "Deform", "Objects deform mesh"},
505 {2, "FINAL", 0, "Final", "Objects final mesh"},
506 {0, NULL, 0, NULL, NULL}
510 /* Matrix space conversion */
511 func = RNA_def_function(srna, "convert_space", "rna_Object_mat_convert_space");
512 RNA_def_function_ui_description(func, "Convert (transform) the given matrix from one space to another");
513 RNA_def_function_flag(func, FUNC_USE_REPORTS);
514 parm = RNA_def_pointer(func, "pose_bone", "PoseBone", "",
515 "Bone to use to define spaces (may be None, in which case only the two 'WORLD' and "
516 "'LOCAL' spaces are usable)");
517 parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
518 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
519 RNA_def_property_ui_text(parm, "", "The matrix to transform");
520 parm = RNA_def_property(func, "matrix_return", PROP_FLOAT, PROP_MATRIX);
521 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
522 RNA_def_property_ui_text(parm, "", "The transformed matrix");
523 RNA_def_function_output(func, parm);
524 parm = RNA_def_enum(func, "from_space", space_items, CONSTRAINT_SPACE_WORLD, "",
525 "The space in which 'matrix' is currently");
526 parm = RNA_def_enum(func, "to_space", space_items, CONSTRAINT_SPACE_WORLD, "",
527 "The space to which you want to transform 'matrix'");
529 /* Camera-related operations */
530 func = RNA_def_function(srna, "calc_matrix_camera", "rna_Object_calc_matrix_camera");
531 RNA_def_function_ui_description(func, "Generate the camera projection matrix of this object "
532 "(mostly useful for Camera and Lamp types)");
533 parm = RNA_def_property(func, "result", PROP_FLOAT, PROP_MATRIX);
534 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
535 RNA_def_property_ui_text(parm, "", "The camera projection matrix");
536 RNA_def_function_output(func, parm);
537 parm = RNA_def_int(func, "x", 1, 0, INT_MAX, "", "Width of the render area", 0, 10000);
538 parm = RNA_def_int(func, "y", 1, 0, INT_MAX, "", "Height of the render area", 0, 10000);
539 parm = RNA_def_float(func, "scale_x", 1.0f, 1.0e-6f, FLT_MAX, "", "Width scaling factor", 1.0e-2f, 100.0f);
540 parm = RNA_def_float(func, "scale_y", 1.0f, 1.0e-6f, FLT_MAX, "", "height scaling factor", 1.0e-2f, 100.0f);
542 func = RNA_def_function(srna, "camera_fit_coords", "rna_Object_camera_fit_coords");
543 RNA_def_function_ui_description(func, "Compute the coordinate (and scale for ortho cameras) "
544 "given object should be to 'see' all given coordinates");
545 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene to get render size information from, if available");
546 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
547 parm = RNA_def_float_array(func, "coordinates", 1, NULL, -FLT_MAX, FLT_MAX, "", "Coordinates to fit in",
549 RNA_def_parameter_flags(parm, PROP_NEVER_NULL | PROP_DYNAMIC, PARM_REQUIRED);
550 parm = RNA_def_property(func, "co_return", PROP_FLOAT, PROP_XYZ);
551 RNA_def_property_array(parm, 3);
552 RNA_def_property_ui_text(parm, "", "The location to aim to be able to see all given points");
553 RNA_def_parameter_flags(parm, 0, PARM_OUTPUT);
554 parm = RNA_def_property(func, "scale_return", PROP_FLOAT, PROP_NONE);
555 RNA_def_property_ui_text(parm, "", "The ortho scale to aim to be able to see all given points (if relevant)");
556 RNA_def_parameter_flags(parm, 0, PARM_OUTPUT);
559 func = RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
560 RNA_def_function_ui_description(func, "Create a Mesh data-block with modifiers applied");
561 RNA_def_function_flag(func, FUNC_USE_REPORTS);
562 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate modifiers");
563 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
564 parm = RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers");
565 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
566 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
567 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
568 RNA_def_boolean(func, "calc_tessface", true, "Calculate Tessellation", "Calculate tessellation faces");
569 RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
570 parm = RNA_def_pointer(func, "mesh", "Mesh", "",
571 "Mesh created from object, remove it if it is only used for export");
572 RNA_def_function_return(func, parm);
575 func = RNA_def_function(srna, "dupli_list_create", "rna_Object_create_duplilist");
576 RNA_def_function_ui_description(func, "Create a list of dupli objects for this object, needs to "
577 "be freed manually with free_dupli_list to restore the "
578 "objects real matrix and layers");
579 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate duplis");
580 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
581 RNA_def_enum(func, "settings", dupli_eval_mode_items, 0, "", "Generate texture coordinates for rendering");
582 RNA_def_function_flag(func, FUNC_USE_REPORTS);
584 func = RNA_def_function(srna, "dupli_list_clear", "rna_Object_free_duplilist");
585 RNA_def_function_ui_description(func, "Free the list of dupli objects");
588 func = RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
589 RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier");
590 parm = RNA_def_pointer(func, "ob_arm", "Object", "", "Armature object influencing this object or NULL");
591 RNA_def_function_return(func, parm);
594 func = RNA_def_function(srna, "shape_key_add", "rna_Object_shape_key_add");
595 RNA_def_function_ui_description(func, "Add shape key to this object");
596 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
597 RNA_def_string(func, "name", "Key", 0, "", "Unique name for the new keyblock"); /* optional */
598 RNA_def_boolean(func, "from_mix", 1, "", "Create new shape from existing mix of shapes");
599 parm = RNA_def_pointer(func, "key", "ShapeKey", "", "New shape keyblock");
600 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
601 RNA_def_function_return(func, parm);
603 func = RNA_def_function(srna, "shape_key_remove", "rna_Object_shape_key_remove");
604 RNA_def_function_ui_description(func, "Remove a Shape Key from this object");
605 RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
606 parm = RNA_def_pointer(func, "key", "ShapeKey", "", "Keyblock to be removed");
607 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
608 RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
611 func = RNA_def_function(srna, "ray_cast", "rna_Object_ray_cast");
612 RNA_def_function_ui_description(func, "Cast a ray onto in object space");
613 RNA_def_function_flag(func, FUNC_USE_REPORTS);
615 /* ray start and end */
616 parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
617 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
618 parm = RNA_def_float_vector(func, "direction", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
619 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
620 RNA_def_float(func, "distance", BVH_RAYCAST_DIST_MAX, 0.0, BVH_RAYCAST_DIST_MAX,
621 "", "Maximum distance", 0.0, BVH_RAYCAST_DIST_MAX);
623 /* return location and normal */
624 parm = RNA_def_boolean(func, "result", 0, "", "");
625 RNA_def_function_output(func, parm);
626 parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
627 "The hit location of this ray cast", -1e4, 1e4);
628 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
629 RNA_def_function_output(func, parm);
630 parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
631 "The face normal at the ray cast hit location", -1e4, 1e4);
632 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
633 RNA_def_function_output(func, parm);
634 parm = RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
635 RNA_def_function_output(func, parm);
638 func = RNA_def_function(srna, "closest_point_on_mesh", "rna_Object_closest_point_on_mesh");
639 RNA_def_function_ui_description(func, "Find the nearest point in object space");
640 RNA_def_function_flag(func, FUNC_USE_REPORTS);
642 /* location of point for test and max distance */
643 parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
644 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
645 /* default is sqrt(FLT_MAX) */
646 RNA_def_float(func, "distance", 1.844674352395373e+19, 0.0, FLT_MAX, "", "Maximum distance", 0.0, FLT_MAX);
648 /* return location and normal */
649 parm = RNA_def_boolean(func, "result", 0, "", "");
650 RNA_def_function_output(func, parm);
651 parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
652 "The location on the object closest to the point", -1e4, 1e4);
653 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
654 RNA_def_function_output(func, parm);
655 parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
656 "The face normal at the closest point", -1e4, 1e4);
657 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
658 RNA_def_function_output(func, parm);
660 parm = RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
661 RNA_def_function_output(func, parm);
664 func = RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
665 RNA_def_function_ui_description(func, "Determine if object is visible in a given scene");
666 parm = RNA_def_pointer(func, "scene", "Scene", "", "");
667 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
668 parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
669 RNA_def_function_return(func, parm);
671 /* utility function for checking if the object is modified */
672 func = RNA_def_function(srna, "is_modified", "rna_Object_is_modified");
673 RNA_def_function_ui_description(func, "Determine if this object is modified from the base mesh data");
674 parm = RNA_def_pointer(func, "scene", "Scene", "", "");
675 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
676 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
677 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
678 parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
679 RNA_def_function_return(func, parm);
681 func = RNA_def_function(srna, "is_deform_modified", "rna_Object_is_deform_modified");
682 RNA_def_function_ui_description(func, "Determine if this object is modified by a deformation from the base mesh data");
683 parm = RNA_def_pointer(func, "scene", "Scene", "", "");
684 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
685 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
686 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
687 parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
688 RNA_def_function_return(func, parm);
692 func = RNA_def_function(srna, "dm_info", "rna_Object_dm_info");
693 RNA_def_function_ui_description(func, "Returns a string for derived mesh data");
695 parm = RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply");
696 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
697 /* weak!, no way to return dynamic string type */
698 parm = RNA_def_string(func, "result", NULL, 16384, "result", "");
699 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
700 RNA_def_function_output(func, parm);
703 func = RNA_def_function(srna, "update_from_editmode", "rna_Object_update_from_editmode");
704 RNA_def_function_ui_description(func, "Load the objects edit-mode data into the object data");
705 parm = RNA_def_boolean(func, "result", 0, "", "Success");
706 RNA_def_function_return(func, parm);
708 func = RNA_def_function(srna, "cache_release", "BKE_object_free_caches");
709 RNA_def_function_ui_description(func, "Release memory used by caches associated with this object. Intended to be used by render engines only");
713 void RNA_api_object_base(StructRNA *srna)
718 func = RNA_def_function(srna, "layers_from_view", "rna_ObjectBase_layers_from_view");
719 RNA_def_function_ui_description(func,
720 "Sets the object layers from a 3D View (use when adding an object in local view)");
721 parm = RNA_def_pointer(func, "view", "SpaceView3D", "", "");
722 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
725 #endif /* RNA_RUNTIME */