Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-04-11 13:57:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-04-11 13:57:26 +0400
commitbf77ad00b3545107417104fc4f20e1f2a1ff0884 (patch)
tree30511e8ecf7e89f4fb2715dcc9cb8c5d3218f53c /source/blender/makesrna/intern/rna_scene_api.c
parent548f0fb88ce5a0b1e6de28574d428bad10d46214 (diff)
py api:
ray cast function, very useful to be able to cast rays into the scene for scripts. hit_co, hit_no, success = scene.ray_cast(start_co, end_co)
Diffstat (limited to 'source/blender/makesrna/intern/rna_scene_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_scene_api.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c
index 82f054e62e0..207aaa4eb7a 100644
--- a/source/blender/makesrna/intern/rna_scene_api.c
+++ b/source/blender/makesrna/intern/rna_scene_api.c
@@ -52,7 +52,7 @@
#include "BKE_scene.h"
#include "BKE_writeavi.h"
-
+#include "ED_transform.h"
static void rna_Scene_frame_set(Scene *scene, int frame, float subframe)
{
@@ -91,6 +91,28 @@ static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, char *name
rd->scemode & R_EXTENSION, TRUE);
}
+static void rna_Scene_ray_cast(Scene *scene, ReportList *reports, float ray_start[3], float ray_end[3],
+ float r_location[3], float r_normal[3], int *r_success)
+{
+ float dummy_dist_px = 0;
+ float ray_nor[3];
+
+ sub_v3_v3v3(ray_nor, ray_end, ray_start);
+
+ if (snapObjectsRayEx(scene, NULL, NULL, NULL, NULL, SCE_SNAP_MODE_FACE,
+ ray_start, ray_nor,
+ NULL, &dummy_dist_px, r_location, r_normal, SNAP_ALL))
+ {
+ *r_success = true;
+ }
+ else {
+ zero_v3(r_location);
+ zero_v3(r_normal);
+
+ *r_success = false;
+ }
+}
+
#ifdef WITH_COLLADA
/* don't remove this, as COLLADA exporting cannot be done through operators in render() callback. */
#include "../../collada/collada.h"
@@ -143,6 +165,30 @@ void RNA_api_scene(StructRNA *srna)
RNA_def_function_ui_description(func,
"Update data tagged to be updated from previous access to data or operators");
+ /* Ray Cast */
+ func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
+ RNA_def_function_ui_description(func, "Cast a ray onto in object space");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+
+ /* ray start and end */
+ parm = RNA_def_float_vector(func, "start", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_float_vector(func, "end", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+
+ /* return location and normal */
+ parm = RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
+ "The hit location of this ray cast", -1e4, 1e4);
+ RNA_def_property_flag(parm, PROP_THICK_WRAP);
+ RNA_def_function_output(func, parm);
+ parm = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
+ "The face normal at the ray cast hit location", -1e4, 1e4);
+ RNA_def_property_flag(parm, PROP_THICK_WRAP);
+ RNA_def_function_output(func, parm);
+
+ parm = RNA_def_boolean(func, "result", 0, "", "");
+ RNA_def_function_output(func, parm);
+
#ifdef WITH_COLLADA
/* don't remove this, as COLLADA exporting cannot be done through operators in render() callback. */
func = RNA_def_function(srna, "collada_export", "rna_Scene_collada_export");