diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-04-24 21:49:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-04-24 21:49:13 +0400 |
commit | 00d04e1924e0247d79b1ef1913e8ae384583b515 (patch) | |
tree | 79ea4ee9f65081cfcba45aee19e6965394b92284 | |
parent | dbeec2be86db5b4ba440175e59c52ff84eb98462 (diff) |
rna api function scene.ray_cast now returns the object and its matrix (incase its a dupli).
-rw-r--r-- | source/blender/editors/include/ED_transform.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ruler.c | 1 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 46 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene_api.c | 17 |
4 files changed, 48 insertions, 17 deletions
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index f674f70ebee..dc4eb298998 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -188,6 +188,7 @@ bool snapObjectsContext(struct bContext *C, const float mval[2], float *r_dist_p bool snapObjectsEx(struct Scene *scene, struct Base *base_act, struct View3D *v3d, struct ARegion *ar, struct Object *obedit, short snap_mode, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode); bool snapObjectsRayEx(struct Scene *scene, struct Base *base_act, struct View3D *v3d, struct ARegion *ar, struct Object *obedit, short snap_mode, + struct Object **r_ob, float r_obmat[4][4], const float ray_start[3], const float ray_normal[3], float *r_ray_dist, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode); diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c index e6ec1afb02b..b38f4974f66 100644 --- a/source/blender/editors/space_view3d/view3d_ruler.c +++ b/source/blender/editors/space_view3d/view3d_ruler.c @@ -105,6 +105,7 @@ static bool ED_view3d_snap_ray(bContext *C, float r_co[3], /* try snap edge, then face if it fails */ ret = snapObjectsRayEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_FACE, + NULL, NULL, ray_start, ray_normal, &ray_dist, NULL, &dist_px, r_co, r_no_dummy, SNAP_ALL); diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index d21f65554b3..bb2ba2b6e3b 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1517,7 +1517,8 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes return retval; } -static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, int editobject, float obmat[4][4], +static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, float obmat[4][4], bool use_obedit, + Object **r_ob, float r_obmat[4][4], const float ray_start[3], const float ray_normal[3], const float mval[2], float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth) { @@ -1527,7 +1528,7 @@ static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, i BMEditMesh *em; DerivedMesh *dm; - if (editobject) { + if (use_obedit) { em = BKE_editmesh_from_object(ob); dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH); } @@ -1544,10 +1545,18 @@ static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, i retval = snapArmature(snap_mode, ar, ob, ob->data, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth); } + if (retval) { + if (r_ob) { + *r_ob = ob; + copy_m4_m4(r_obmat, obmat); + } + } + return retval; } static bool snapObjectsRay(Scene *scene, short snap_mode, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, + Object **r_ob, float r_obmat[4][4], const float ray_start[3], const float ray_normal[3], float *r_ray_dist, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode) { @@ -1557,7 +1566,9 @@ static bool snapObjectsRay(Scene *scene, short snap_mode, Base *base_act, View3D if (mode == SNAP_ALL && obedit) { Object *ob = obedit; - retval |= snapObject(scene, snap_mode, ar, ob, 1, ob->obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); + retval |= snapObject(scene, snap_mode, ar, ob, ob->obmat, true, + r_ob, r_obmat, + ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); } /* Need an exception for particle edit because the base is flagged with BA_HAS_RECALC_DATA @@ -1568,7 +1579,9 @@ static bool snapObjectsRay(Scene *scene, short snap_mode, Base *base_act, View3D base = base_act; if (base && base->object && base->object->mode & OB_MODE_PARTICLE_EDIT) { Object *ob = base->object; - retval |= snapObject(scene, snap_mode, ar, ob, 0, ob->obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); + retval |= snapObject(scene, snap_mode, ar, ob, ob->obmat, false, + r_ob, r_obmat, + ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); } for (base = FIRSTBASE; base != NULL; base = base->next) { @@ -1585,15 +1598,17 @@ static bool snapObjectsRay(Scene *scene, short snap_mode, Base *base_act, View3D ListBase *lb = object_duplilist(scene, ob, FALSE); for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) { - Object *dob = dupli_ob->ob; - - retval |= snapObject(scene, snap_mode, ar, dob, 0, dupli_ob->mat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); + retval |= snapObject(scene, snap_mode, ar, dupli_ob->ob, dupli_ob->mat, false, + r_ob, r_obmat, + ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); } free_object_duplilist(lb); } - retval |= snapObject(scene, snap_mode, ar, ob, 0, ob->obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); + retval |= snapObject(scene, snap_mode, ar, ob, ob->obmat, false, + r_ob, r_obmat, + ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist); } } @@ -1610,6 +1625,7 @@ static bool snapObjects(Scene *scene, short snap_mode, Base *base_act, View3D *v } return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit, + NULL, NULL, ray_start, ray_normal, &ray_dist, mval, r_dist_px, r_loc, r_no, mode); } @@ -1625,8 +1641,10 @@ bool snapObjectsContext(bContext *C, const float mval[2], float *r_dist_px, floa ScrArea *sa = CTX_wm_area(C); View3D *v3d = sa->spacedata.first; Scene *scene = CTX_data_scene(C); + ARegion *ar = CTX_wm_region(C); + Object *obedit = CTX_data_edit_object(C); - return snapObjects(scene, scene->toolsettings->snap_mode, scene->basact, v3d, CTX_wm_region(C), CTX_data_edit_object(C), mval, r_dist_px, r_loc, r_no, mode); + return snapObjects(scene, scene->toolsettings->snap_mode, scene->basact, v3d, ar, obedit, mval, r_dist_px, r_loc, r_no, mode); } bool snapObjectsEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, short snap_mode, @@ -1636,10 +1654,12 @@ bool snapObjectsEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Objec mval, r_dist_px, r_loc, r_no, mode); } bool snapObjectsRayEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, short snap_mode, + Object **r_ob, float r_obmat[4][4], const float ray_start[3], const float ray_normal[3], float *r_ray_dist, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode) { return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit, + r_ob, r_obmat, ray_start, ray_normal, r_ray_dist, mval, r_dist_px, r_loc, r_no, mode); } @@ -1889,10 +1909,13 @@ bool peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, const float mval[ bool peelObjectsContext(bContext *C, ListBase *depth_peels, const float mval[2], SnapMode mode) { + Scene *scene = CTX_data_scene(C); ScrArea *sa = CTX_wm_area(C); View3D *v3d = sa->spacedata.first; + ARegion *ar = CTX_wm_region(C); + Object *obedit = CTX_data_edit_object(C); - return peelObjects(CTX_data_scene(C), v3d, CTX_wm_region(C), CTX_data_edit_object(C), depth_peels, mval, mode); + return peelObjects(scene, v3d, ar, obedit, depth_peels, mval, mode); } /******************** NODES ***********************************/ @@ -1999,7 +2022,8 @@ bool snapNodesTransform(TransInfo *t, const int mval[2], float *r_dist_px, float bool snapNodesContext(bContext *C, const int mval[2], float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode) { Scene *scene = CTX_data_scene(C); - return snapNodes(scene->toolsettings, CTX_wm_space_node(C), CTX_wm_region(C), mval, r_dist_px, r_loc, r_node_border, mode); + ARegion *ar = CTX_wm_region(C); + return snapNodes(scene->toolsettings, CTX_wm_space_node(C), ar, mval, r_dist_px, r_loc, r_node_border, mode); } /*================================================================*/ diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 9d920ff2519..1f4622ff7f4 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -91,8 +91,9 @@ 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) +static void rna_Scene_ray_cast(Scene *scene, float ray_start[3], float ray_end[3], + int *r_success, Object **r_ob, float r_obmat[16], + float r_location[3], float r_normal[3]) { float dummy_dist_px = 0; float ray_nor[3]; @@ -102,12 +103,14 @@ static void rna_Scene_ray_cast(Scene *scene, ReportList *reports, float ray_star ray_dist = normalize_v3(ray_nor); if (snapObjectsRayEx(scene, NULL, NULL, NULL, NULL, SCE_SNAP_MODE_FACE, + r_ob, (float(*)[4])r_obmat, ray_start, ray_nor, &ray_dist, NULL, &dummy_dist_px, r_location, r_normal, SNAP_ALL)) { *r_success = true; } else { + unit_m4((float(*)[4])r_obmat); zero_v3(r_location); zero_v3(r_normal); @@ -170,7 +173,6 @@ void RNA_api_scene(StructRNA *srna) /* 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); @@ -179,6 +181,12 @@ void RNA_api_scene(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED); /* return location and normal */ + parm = RNA_def_boolean(func, "result", 0, "", ""); + RNA_def_function_output(func, parm); + parm = RNA_def_pointer(func, "object", "Object", "", "Ray cast object"); + RNA_def_function_output(func, parm); + parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f); + RNA_def_function_output(func, parm); 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); @@ -188,9 +196,6 @@ void RNA_api_scene(StructRNA *srna) 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"); |