[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55957] trunk/blender/source/blender: py api:
Campbell Barton
ideasman42 at gmail.com
Thu Apr 11 11:57:26 CEST 2013
Revision: 55957
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55957
Author: campbellbarton
Date: 2013-04-11 09:57:26 +0000 (Thu, 11 Apr 2013)
Log Message:
-----------
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)
Modified Paths:
--------------
trunk/blender/source/blender/editors/transform/transform_snap.c
trunk/blender/source/blender/makesdna/DNA_scene_types.h
trunk/blender/source/blender/makesrna/intern/rna_scene_api.c
Modified: trunk/blender/source/blender/editors/transform/transform_snap.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_snap.c 2013-04-11 09:37:52 UTC (rev 55956)
+++ trunk/blender/source/blender/editors/transform/transform_snap.c 2013-04-11 09:57:26 UTC (rev 55957)
@@ -1573,7 +1573,7 @@
}
for (base = FIRSTBASE; base != NULL; base = base->next) {
- if ((BASE_VISIBLE(v3d, base)) &&
+ if ((BASE_VISIBLE_BGMODE(v3d, scene, base)) &&
(base->flag & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 &&
((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) ||
Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h 2013-04-11 09:37:52 UTC (rev 55956)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h 2013-04-11 09:57:26 UTC (rev 55957)
@@ -1394,6 +1394,9 @@
#define BASE_VISIBLE(v3d, base) ( \
(base->lay & v3d->lay) && \
(base->object->restrictflag & OB_RESTRICT_VIEW) == 0)
+#define BASE_VISIBLE_BGMODE(v3d, scene, base) ( \
+ (base->lay & (v3d ? v3d->lay : scene->lay)) && \
+ (base->object->restrictflag & OB_RESTRICT_VIEW) == 0)
#define FIRSTBASE scene->base.first
#define LASTBASE scene->base.last
Modified: trunk/blender/source/blender/makesrna/intern/rna_scene_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_scene_api.c 2013-04-11 09:37:52 UTC (rev 55956)
+++ trunk/blender/source/blender/makesrna/intern/rna_scene_api.c 2013-04-11 09:57:26 UTC (rev 55957)
@@ -52,8 +52,8 @@
#include "BKE_scene.h"
#include "BKE_writeavi.h"
+#include "ED_transform.h"
-
static void rna_Scene_frame_set(Scene *scene, int frame, float subframe)
{
float cfra = (float)frame + subframe;
@@ -91,6 +91,28 @@
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 @@
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");
More information about the Bf-blender-cvs
mailing list