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_layer_types.h"
44 #include "DNA_modifier_types.h"
45 #include "DNA_object_types.h"
47 #include "BKE_layer.h"
49 #include "DEG_depsgraph.h"
51 #include "rna_internal.h" /* own include */
53 static const EnumPropertyItem space_items[] = {
54 {CONSTRAINT_SPACE_WORLD, "WORLD", 0, "World Space",
55 "The most global space in Blender"},
56 {CONSTRAINT_SPACE_POSE, "POSE", 0, "Pose Space",
57 "The pose space of a bone (its armature's object space)"},
58 {CONSTRAINT_SPACE_PARLOCAL, "LOCAL_WITH_PARENT", 0, "Local With Parent",
59 "The local space of a bone's parent bone"},
60 {CONSTRAINT_SPACE_LOCAL, "LOCAL", 0, "Local Space",
61 "The local space of an object/bone"},
62 {0, NULL, 0, NULL, NULL}
70 #include "BKE_bvhutils.h"
71 #include "BKE_constraint.h"
72 #include "BKE_context.h"
73 #include "BKE_customdata.h"
75 #include "BKE_global.h"
78 #include "BKE_mball.h"
79 #include "BKE_modifier.h"
80 #include "BKE_object.h"
81 #include "BKE_report.h"
83 #include "ED_object.h"
85 #include "DNA_curve_types.h"
86 #include "DNA_mesh_types.h"
87 #include "DNA_meshdata_types.h"
88 #include "DNA_scene_types.h"
89 #include "DNA_view3d_types.h"
91 #include "DEG_depsgraph_query.h"
93 #include "MEM_guardedalloc.h"
95 static void rna_Object_select_set(
96 Object *ob, bContext *C, ReportList *reports,
97 bool select, ViewLayer *view_layer)
99 if (view_layer == NULL) {
100 view_layer = CTX_data_view_layer(C);
102 Base *base = BKE_view_layer_base_find(view_layer, ob);
105 BKE_reportf(reports, RPT_ERROR, "Object '%s' not in View Layer '%s'!", ob->id.name + 2, view_layer->name);
110 BKE_view_layer_base_select(base);
113 base->flag &= ~BASE_SELECTED;
116 Scene *scene = CTX_data_scene(C);
117 DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
118 WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene);
121 static bool rna_Object_select_get(Object *ob, bContext *C, ReportList *reports)
123 ViewLayer *view_layer = CTX_data_view_layer(C);
124 Base *base = BKE_view_layer_base_find(view_layer, ob);
127 BKE_reportf(reports, RPT_ERROR, "Object '%s' not in View Layer '%s'!", ob->id.name + 2, view_layer->name);
131 return ((base->flag & BASE_SELECTED) != 0);
134 static bool rna_Object_visible_get(Object *ob, bContext *C, ReportList *reports)
136 ViewLayer *view_layer = CTX_data_view_layer(C);
137 View3D *v3d = CTX_wm_view3d(C);
138 Base *base = BKE_view_layer_base_find(view_layer, ob);
141 BKE_reportf(reports, RPT_ERROR, "Object '%s' not in View Layer '%s'!", ob->id.name + 2, view_layer->name);
145 if (v3d && v3d->localvd && ((base->local_view_bits & v3d->local_view_uuid) == 0)) {
149 return ((base->flag & BASE_VISIBLE) != 0);
152 static bool rna_Object_holdout_get(Object *ob, ReportList *reports, ViewLayer *view_layer)
154 Base *base = BKE_view_layer_base_find(view_layer, ob);
157 BKE_reportf(reports, RPT_ERROR, "Object '%s' not in View Layer '%s'!", ob->id.name + 2, view_layer->name);
161 return ((base->flag & BASE_HOLDOUT) != 0);
164 static bool rna_Object_indirect_only_get(Object *ob, ReportList *reports, ViewLayer *view_layer)
166 Base *base = BKE_view_layer_base_find(view_layer, ob);
169 BKE_reportf(reports, RPT_ERROR, "Object '%s' not in View Layer '%s'!", ob->id.name + 2, view_layer->name);
173 return ((base->flag & BASE_INDIRECT_ONLY) != 0);
176 /* Convert a given matrix from a space to another (using the object and/or a bone as reference). */
177 static void rna_Object_mat_convert_space(Object *ob, ReportList *reports, bPoseChannel *pchan,
178 float *mat, float *mat_ret, int from, int to)
180 copy_m4_m4((float (*)[4])mat_ret, (float (*)[4])mat);
182 /* Error in case of invalid from/to values when pchan is NULL */
184 if (ELEM(from, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_PARLOCAL)) {
185 const char *identifier = NULL;
186 RNA_enum_identifier(space_items, from, &identifier);
187 BKE_reportf(reports, RPT_ERROR, "'from_space' '%s' is invalid when no pose bone is given!", identifier);
190 if (ELEM(to, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_PARLOCAL)) {
191 const char *identifier = NULL;
192 RNA_enum_identifier(space_items, to, &identifier);
193 BKE_reportf(reports, RPT_ERROR, "'to_space' '%s' is invalid when no pose bone is given!", identifier);
198 BKE_constraint_mat_convertspace(ob, pchan, (float (*)[4])mat_ret, from, to, false);
201 static void rna_Object_calc_matrix_camera(
202 Object *ob, Depsgraph *depsgraph, float mat_ret[16], int width, int height, float scalex, float scaley)
204 const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
207 /* setup parameters */
208 BKE_camera_params_init(¶ms);
209 BKE_camera_params_from_object(¶ms, ob_eval);
211 /* compute matrix, viewplane, .. */
212 BKE_camera_params_compute_viewplane(¶ms, width, height, scalex, scaley);
213 BKE_camera_params_compute_matrix(¶ms);
215 copy_m4_m4((float (*)[4])mat_ret, params.winmat);
218 static void rna_Object_camera_fit_coords(
219 Object *ob, Depsgraph *depsgraph, int num_cos, float *cos, float co_ret[3], float *scale_ret)
221 BKE_camera_view_frame_fit_to_coords(depsgraph, (const float (*)[3])cos, num_cos / 3, ob, co_ret, scale_ret);
224 /* copied from Mesh_getFromObject and adapted to RNA interface */
225 /* settings: 0 - preview, 1 - render */
226 static Mesh *rna_Object_to_mesh(
227 Object *ob, bContext *C, ReportList *reports, Depsgraph *depsgraph,
228 bool apply_modifiers, bool calc_undeformed)
230 Main *bmain = CTX_data_main(C);
232 return rna_Main_meshes_new_from_object(bmain, reports, depsgraph, ob, apply_modifiers, calc_undeformed);
235 static PointerRNA rna_Object_shape_key_add(Object *ob, bContext *C, ReportList *reports,
236 const char *name, bool from_mix)
238 Main *bmain = CTX_data_main(C);
241 if ((kb = BKE_object_shapekey_insert(bmain, ob, name, from_mix))) {
244 RNA_pointer_create((ID *)ob->data, &RNA_ShapeKey, kb, &keyptr);
245 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
250 BKE_reportf(reports, RPT_ERROR, "Object '%s' does not support shapes", ob->id.name + 2);
251 return PointerRNA_NULL;
255 static void rna_Object_shape_key_remove(
256 Object *ob, Main *bmain, ReportList *reports,
259 KeyBlock *kb = kb_ptr->data;
260 Key *key = BKE_key_from_object(ob);
262 if ((key == NULL) || BLI_findindex(&key->block, kb) == -1) {
263 BKE_reportf(reports, RPT_ERROR, "ShapeKey not found");
267 if (!BKE_object_shapekey_remove(bmain, ob, kb)) {
268 BKE_reportf(reports, RPT_ERROR, "Could not remove ShapeKey");
272 DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
273 WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
275 RNA_POINTER_INVALIDATE(kb_ptr);
279 static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex,
280 float weight, int assignmode)
282 if (ob->type != OB_MESH) {
283 BKE_report(reports, RPT_ERROR, "Object should be of mesh type");
287 Mesh *me = (Mesh *)ob->data;
288 int group_index = BLI_findlink(&ob->defbase, group);
289 if (group_index == -1) {
290 BKE_report(reports, RPT_ERROR, "No vertex groups assigned to mesh");
294 if (assignmode != WEIGHT_REPLACE && assignmode != WEIGHT_ADD && assignmode != WEIGHT_SUBTRACT) {
295 BKE_report(reports, RPT_ERROR, "Bad assignment mode");
299 /* makes a set of dVerts corresponding to the mVerts */
301 create_dverts(&me->id);
303 /* loop list adding verts to group */
304 for (i = 0; i < totindex; i++) {
305 if (i < 0 || i >= me->totvert) {
306 BKE_report(reports, RPT_ERROR, "Bad vertex index in list");
310 add_vert_defnr(ob, group_index, i, weight, assignmode);
315 /* don't call inside a loop */
316 static int mesh_looptri_to_poly_index(Mesh *me_eval, const MLoopTri *lt)
318 const int *index_mp_to_orig = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX);
319 return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly;
322 static Object *eval_object_ensure(Object *ob, bContext *C, ReportList *reports, PointerRNA *rnaptr_depsgraph)
324 if (ob->runtime.mesh_eval == NULL) {
325 Object *ob_orig = ob;
326 Depsgraph *depsgraph = rnaptr_depsgraph != NULL ? rnaptr_depsgraph->data : NULL;
327 if (depsgraph == NULL) {
328 depsgraph = CTX_data_depsgraph(C);
330 if (depsgraph != NULL) {
331 ob = DEG_get_evaluated_object(depsgraph, ob);
333 if (ob == NULL || ob->runtime.mesh_eval == NULL) {
334 BKE_reportf(reports, RPT_ERROR, "Object '%s' has no evaluated mesh data", ob_orig->id.name + 2);
341 static void rna_Object_ray_cast(
342 Object *ob, bContext *C, ReportList *reports,
343 float origin[3], float direction[3], float distance, PointerRNA *rnaptr_depsgraph,
344 bool *r_success, float r_location[3], float r_normal[3], int *r_index)
346 bool success = false;
348 if (ob->runtime.mesh_eval == NULL && (ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) {
352 /* Test BoundBox first (efficiency) */
353 BoundBox *bb = BKE_object_boundbox_get(ob);
355 normalize_v3(direction); /* Needed for valid distance check from isect_ray_aabb_v3_simple() call. */
357 (isect_ray_aabb_v3_simple(origin, direction, bb->vec[0], bb->vec[6], &distmin, NULL) && distmin <= distance))
359 BVHTreeFromMesh treeData = {NULL};
361 /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
362 BKE_bvhtree_from_mesh_get(&treeData, ob->runtime.mesh_eval, BVHTREE_FROM_LOOPTRI, 4);
364 /* may fail if the mesh has no faces, in that case the ray-cast misses */
365 if (treeData.tree != NULL) {
371 if (BLI_bvhtree_ray_cast(treeData.tree, origin, direction, 0.0f, &hit,
372 treeData.raycast_callback, &treeData) != -1)
374 if (hit.dist <= distance) {
375 *r_success = success = true;
377 copy_v3_v3(r_location, hit.co);
378 copy_v3_v3(r_normal, hit.no);
379 *r_index = mesh_looptri_to_poly_index(ob->runtime.mesh_eval, &treeData.looptri[hit.index]);
383 free_bvhtree_from_mesh(&treeData);
386 if (success == false) {
395 static void rna_Object_closest_point_on_mesh(
396 Object *ob, bContext *C, ReportList *reports, float origin[3], float distance, PointerRNA *rnaptr_depsgraph,
397 bool *r_success, float r_location[3], float r_normal[3], int *r_index)
399 BVHTreeFromMesh treeData = {NULL};
401 if (ob->runtime.mesh_eval == NULL && (ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) {
405 /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
406 BKE_bvhtree_from_mesh_get(&treeData, ob->runtime.mesh_eval, BVHTREE_FROM_LOOPTRI, 4);
408 if (treeData.tree == NULL) {
409 BKE_reportf(reports, RPT_ERROR, "Object '%s' could not create internal data for finding nearest point",
414 BVHTreeNearest nearest;
417 nearest.dist_sq = distance * distance;
419 if (BLI_bvhtree_find_nearest(treeData.tree, origin, &nearest, treeData.nearest_callback, &treeData) != -1) {
422 copy_v3_v3(r_location, nearest.co);
423 copy_v3_v3(r_normal, nearest.no);
424 *r_index = mesh_looptri_to_poly_index(ob->runtime.mesh_eval, &treeData.looptri[nearest.index]);
437 free_bvhtree_from_mesh(&treeData);
440 static bool rna_Object_is_modified(Object *ob, Scene *scene, int settings)
442 return BKE_object_is_modified(scene, ob) & settings;
445 static bool rna_Object_is_deform_modified(Object *ob, Scene *scene, int settings)
447 return BKE_object_is_deform_modified(scene, ob) & settings;
452 #include "BKE_mesh_runtime.h"
454 void rna_Object_me_eval_info(struct Object *ob, bContext *C, int type, PointerRNA *rnaptr_depsgraph, char *result)
456 Mesh *me_eval = NULL;
464 if (ob->runtime.mesh_eval == NULL && (ob = eval_object_ensure(ob, C, NULL, rnaptr_depsgraph)) == NULL) {
471 if (ob->type == OB_MESH) {
476 me_eval = ob->runtime.mesh_deform_eval;
479 me_eval = ob->runtime.mesh_eval;
484 ret = BKE_mesh_runtime_debug_info(me_eval);
493 static bool rna_Object_update_from_editmode(Object *ob, Main *bmain)
495 /* fail gracefully if we aren't in edit-mode. */
496 return ED_object_editmode_load(bmain, ob);
498 #else /* RNA_RUNTIME */
500 void RNA_api_object(StructRNA *srna)
505 static const EnumPropertyItem mesh_type_items[] = {
506 {eModifierMode_Realtime, "PREVIEW", 0, "Preview", "Apply modifier preview settings"},
507 {eModifierMode_Render, "RENDER", 0, "Render", "Apply modifier render settings"},
508 {0, NULL, 0, NULL, NULL}
512 static const EnumPropertyItem mesh_dm_info_items[] = {
513 {0, "SOURCE", 0, "Source", "Source mesh"},
514 {1, "DEFORM", 0, "Deform", "Objects deform mesh"},
515 {2, "FINAL", 0, "Final", "Objects final mesh"},
516 {0, NULL, 0, NULL, NULL}
520 /* Special wrapper to access the base selection value */
521 func = RNA_def_function(srna, "select_set", "rna_Object_select_set");
522 RNA_def_function_ui_description(func, "Select the object (for the active view layer)");
523 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
524 parm = RNA_def_boolean(func, "state", 0, "", "Selection state to define");
525 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
526 parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "Operate on this view layer instead of the context");
528 func = RNA_def_function(srna, "select_get", "rna_Object_select_get");
529 RNA_def_function_ui_description(func, "Get the object selection for the active view layer");
530 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
531 parm = RNA_def_boolean(func, "result", 0, "", "Object selected");
532 RNA_def_function_return(func, parm);
534 func = RNA_def_function(srna, "visible_get", "rna_Object_visible_get");
535 RNA_def_function_ui_description(func, "Get the object visibility for the active view layer and viewport");
536 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
537 parm = RNA_def_boolean(func, "result", 0, "", "Object visible");
538 RNA_def_function_return(func, parm);
540 func = RNA_def_function(srna, "holdout_get", "rna_Object_holdout_get");
541 RNA_def_function_ui_description(func, "Test if object is masked in the view layer");
542 RNA_def_function_flag(func, FUNC_USE_REPORTS);
543 parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "View layer to check against");
544 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
545 parm = RNA_def_boolean(func, "result", 0, "", "Object holdout");
546 RNA_def_function_return(func, parm);
548 func = RNA_def_function(srna, "indirect_only_get", "rna_Object_indirect_only_get");
549 RNA_def_function_ui_description(func, "Test if object is set to contribute only indirectly (through shadows and reflections) in the view layer");
550 RNA_def_function_flag(func, FUNC_USE_REPORTS);
551 parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "View layer to check against");
552 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
553 parm = RNA_def_boolean(func, "result", 0, "", "Object indirect only");
554 RNA_def_function_return(func, parm);
556 /* Matrix space conversion */
557 func = RNA_def_function(srna, "convert_space", "rna_Object_mat_convert_space");
558 RNA_def_function_ui_description(func, "Convert (transform) the given matrix from one space to another");
559 RNA_def_function_flag(func, FUNC_USE_REPORTS);
560 parm = RNA_def_pointer(func, "pose_bone", "PoseBone", "",
561 "Bone to use to define spaces (may be None, in which case only the two 'WORLD' and "
562 "'LOCAL' spaces are usable)");
563 parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
564 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
565 RNA_def_property_ui_text(parm, "", "The matrix to transform");
566 parm = RNA_def_property(func, "matrix_return", PROP_FLOAT, PROP_MATRIX);
567 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
568 RNA_def_property_ui_text(parm, "", "The transformed matrix");
569 RNA_def_function_output(func, parm);
570 parm = RNA_def_enum(func, "from_space", space_items, CONSTRAINT_SPACE_WORLD, "",
571 "The space in which 'matrix' is currently");
572 parm = RNA_def_enum(func, "to_space", space_items, CONSTRAINT_SPACE_WORLD, "",
573 "The space to which you want to transform 'matrix'");
575 /* Camera-related operations */
576 func = RNA_def_function(srna, "calc_matrix_camera", "rna_Object_calc_matrix_camera");
577 RNA_def_function_ui_description(func, "Generate the camera projection matrix of this object "
578 "(mostly useful for Camera and Light types)");
579 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "Depsgraph to get evaluated data from");
580 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
581 parm = RNA_def_property(func, "result", PROP_FLOAT, PROP_MATRIX);
582 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
583 RNA_def_property_ui_text(parm, "", "The camera projection matrix");
584 RNA_def_function_output(func, parm);
585 parm = RNA_def_int(func, "x", 1, 0, INT_MAX, "", "Width of the render area", 0, 10000);
586 parm = RNA_def_int(func, "y", 1, 0, INT_MAX, "", "Height of the render area", 0, 10000);
587 parm = RNA_def_float(func, "scale_x", 1.0f, 1.0e-6f, FLT_MAX, "", "Width scaling factor", 1.0e-2f, 100.0f);
588 parm = RNA_def_float(func, "scale_y", 1.0f, 1.0e-6f, FLT_MAX, "", "Height scaling factor", 1.0e-2f, 100.0f);
590 func = RNA_def_function(srna, "camera_fit_coords", "rna_Object_camera_fit_coords");
591 RNA_def_function_ui_description(func, "Compute the coordinate (and scale for ortho cameras) "
592 "given object should be to 'see' all given coordinates");
593 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "Depsgraph to get evaluated data from");
594 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
595 parm = RNA_def_float_array(func, "coordinates", 1, NULL, -FLT_MAX, FLT_MAX, "", "Coordinates to fit in",
597 RNA_def_parameter_flags(parm, PROP_NEVER_NULL | PROP_DYNAMIC, PARM_REQUIRED);
598 parm = RNA_def_property(func, "co_return", PROP_FLOAT, PROP_XYZ);
599 RNA_def_property_array(parm, 3);
600 RNA_def_property_ui_text(parm, "", "The location to aim to be able to see all given points");
601 RNA_def_parameter_flags(parm, 0, PARM_OUTPUT);
602 parm = RNA_def_property(func, "scale_return", PROP_FLOAT, PROP_NONE);
603 RNA_def_property_ui_text(parm, "", "The ortho scale to aim to be able to see all given points (if relevant)");
604 RNA_def_parameter_flags(parm, 0, PARM_OUTPUT);
607 func = RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
608 RNA_def_function_ui_description(func, "Create a Mesh data-block with modifiers applied");
609 RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_CONTEXT);
610 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "Dependency Graph", "Evaluated dependency graph within which to evaluate modifiers");
611 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
612 parm = RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers");
613 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
614 RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
615 parm = RNA_def_pointer(func, "mesh", "Mesh", "",
616 "Mesh created from object, remove it if it is only used for export");
617 RNA_def_function_return(func, parm);
620 func = RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
621 RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier");
622 parm = RNA_def_pointer(func, "ob_arm", "Object", "", "Armature object influencing this object or NULL");
623 RNA_def_function_return(func, parm);
626 func = RNA_def_function(srna, "shape_key_add", "rna_Object_shape_key_add");
627 RNA_def_function_ui_description(func, "Add shape key to this object");
628 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
629 RNA_def_string(func, "name", "Key", 0, "", "Unique name for the new keyblock"); /* optional */
630 RNA_def_boolean(func, "from_mix", 1, "", "Create new shape from existing mix of shapes");
631 parm = RNA_def_pointer(func, "key", "ShapeKey", "", "New shape keyblock");
632 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
633 RNA_def_function_return(func, parm);
635 func = RNA_def_function(srna, "shape_key_remove", "rna_Object_shape_key_remove");
636 RNA_def_function_ui_description(func, "Remove a Shape Key from this object");
637 RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
638 parm = RNA_def_pointer(func, "key", "ShapeKey", "", "Keyblock to be removed");
639 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
640 RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
645 func = RNA_def_function(srna, "ray_cast", "rna_Object_ray_cast");
646 RNA_def_function_ui_description(func, "Cast a ray onto evaluated geometry, in object space "
647 "(using context's or provided depsgraph to get evaluated mesh if needed)");
648 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
650 /* ray start and end */
651 parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX,
652 "", "Origin of the ray, in object space", -1e4, 1e4);
653 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
654 parm = RNA_def_float_vector(func, "direction", 3, NULL, -FLT_MAX, FLT_MAX,
655 "", "Direction of the ray, in object space", -1e4, 1e4);
656 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
657 RNA_def_float(func, "distance", BVH_RAYCAST_DIST_MAX, 0.0, BVH_RAYCAST_DIST_MAX,
658 "", "Maximum distance", 0.0, BVH_RAYCAST_DIST_MAX);
659 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "",
660 "Depsgraph to use to get evaluated data, when called from original object "
661 "(only needed if current Context's depsgraph is not suitable)");
662 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
664 /* return location and normal */
665 parm = RNA_def_boolean(func, "result", 0, "", "Wheter the ray successfully hit the geometry");
666 RNA_def_function_output(func, parm);
667 parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
668 "The hit location of this ray cast", -1e4, 1e4);
669 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
670 RNA_def_function_output(func, parm);
671 parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
672 "The face normal at the ray cast hit location", -1e4, 1e4);
673 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
674 RNA_def_function_output(func, parm);
675 parm = RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
676 RNA_def_function_output(func, parm);
681 func = RNA_def_function(srna, "closest_point_on_mesh", "rna_Object_closest_point_on_mesh");
682 RNA_def_function_ui_description(func, "Find the nearest point on evaluated geometry, in object space "
683 "(using context's or provided depsgraph to get evaluated mesh if needed)");
684 RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
686 /* location of point for test and max distance */
687 parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX,
688 "", "Point to find closest geometry from (in object space)", -1e4, 1e4);
689 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
690 /* default is sqrt(FLT_MAX) */
691 RNA_def_float(func, "distance", 1.844674352395373e+19, 0.0, FLT_MAX, "", "Maximum distance", 0.0, FLT_MAX);
692 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "",
693 "Depsgraph to use to get evaluated data, when called from original object "
694 "(only needed if current Context's depsgraph is not suitable)");
695 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
697 /* return location and normal */
698 parm = RNA_def_boolean(func, "result", 0, "", "Wheter closest point on geometry was found");
699 RNA_def_function_output(func, parm);
700 parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
701 "The location on the object closest to the point", -1e4, 1e4);
702 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
703 RNA_def_function_output(func, parm);
704 parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
705 "The face normal at the closest point", -1e4, 1e4);
706 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
707 RNA_def_function_output(func, parm);
709 parm = RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
710 RNA_def_function_output(func, parm);
716 /* utility function for checking if the object is modified */
717 func = RNA_def_function(srna, "is_modified", "rna_Object_is_modified");
718 RNA_def_function_ui_description(func, "Determine if this object is modified from the base mesh data");
719 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene in which to check the object");
720 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
721 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
722 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
723 parm = RNA_def_boolean(func, "result", 0, "", "Whether the object is modified");
724 RNA_def_function_return(func, parm);
726 func = RNA_def_function(srna, "is_deform_modified", "rna_Object_is_deform_modified");
727 RNA_def_function_ui_description(func, "Determine if this object is modified by a deformation from the base mesh data");
728 parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene in which to check the object");
729 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
730 parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
731 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
732 parm = RNA_def_boolean(func, "result", 0, "", "Whether the object is deform-modified");
733 RNA_def_function_return(func, parm);
737 func = RNA_def_function(srna, "dm_info", "rna_Object_me_eval_info");
738 RNA_def_function_ui_description(func, "Returns a string for original/evaluated mesh data (debug builds only, "
739 "using context's or provided depsgraph to get evaluated mesh if needed)");
740 RNA_def_function_flag(func, FUNC_USE_CONTEXT);
742 parm = RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply");
743 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
744 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "",
745 "Depsgraph to use to get evaluated data, when called from original object "
746 "(only needed if current Context's depsgraph is not suitable)");
747 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
748 /* weak!, no way to return dynamic string type */
749 parm = RNA_def_string(func, "result", NULL, 16384, "", "Requested informations");
750 RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
751 RNA_def_function_output(func, parm);
754 func = RNA_def_function(srna, "update_from_editmode", "rna_Object_update_from_editmode");
755 RNA_def_function_ui_description(func, "Load the objects edit-mode data into the object data");
756 RNA_def_function_flag(func, FUNC_USE_MAIN);
757 parm = RNA_def_boolean(func, "result", 0, "", "Success");
758 RNA_def_function_return(func, parm);
760 func = RNA_def_function(srna, "cache_release", "BKE_object_free_caches");
761 RNA_def_function_ui_description(func, "Release memory used by caches associated with this object. Intended to be used by render engines only");
764 #endif /* RNA_RUNTIME */