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)
This commit is contained in:
@@ -1573,7 +1573,7 @@ static bool snapObjectsRay(Scene *scene, short snap_mode, Base *base_act, View3D
|
||||
}
|
||||
|
||||
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) ||
|
||||
|
||||
@@ -1394,6 +1394,9 @@ typedef struct Scene {
|
||||
#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
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user