From 4b2b8fe9bdb4b47a414c9315e515706bdb30194a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 29 Sep 2011 08:23:52 +0000 Subject: rna function: vecs = Camera.view_frame(scene) returns 4 points for the camera frame, without this its very hard to know if a point is in the camera view or not, without rewriting blenders internal logic in python. --- source/blender/makesrna/intern/CMakeLists.txt | 1 + source/blender/makesrna/intern/makesrna.c | 2 +- source/blender/makesrna/intern/rna_camera.c | 3 + source/blender/makesrna/intern/rna_camera_api.c | 88 +++++++++++++++++++++++++ source/blender/makesrna/intern/rna_internal.h | 1 + 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 source/blender/makesrna/intern/rna_camera_api.c (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 99c7a0e2476..5a0a3388c85 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -95,6 +95,7 @@ set(APISRC rna_actuator_api.c rna_animation_api.c rna_armature_api.c + rna_camera_api.c rna_controller_api.c rna_fcurve_api.c rna_image_api.c diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 80352d3f03e..bc45ea4deed 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -2432,7 +2432,7 @@ static RNAProcessItem PROCESS_ITEMS[]= { {"rna_armature.c", "rna_armature_api.c", RNA_def_armature}, {"rna_boid.c", NULL, RNA_def_boid}, {"rna_brush.c", NULL, RNA_def_brush}, - {"rna_camera.c", NULL, RNA_def_camera}, + {"rna_camera.c", "rna_camera_api.c", RNA_def_camera}, {"rna_cloth.c", NULL, RNA_def_cloth}, {"rna_color.c", NULL, RNA_def_color}, {"rna_constraint.c", NULL, RNA_def_constraint}, diff --git a/source/blender/makesrna/intern/rna_camera.c b/source/blender/makesrna/intern/rna_camera.c index 37912f810fc..9954fdfd88d 100644 --- a/source/blender/makesrna/intern/rna_camera.c +++ b/source/blender/makesrna/intern/rna_camera.c @@ -209,6 +209,9 @@ void RNA_def_camera(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "DOF Object", "Use this object to define the depth of field focal point"); RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); + + /* Camera API */ + RNA_api_camera(srna); } #endif diff --git a/source/blender/makesrna/intern/rna_camera_api.c b/source/blender/makesrna/intern/rna_camera_api.c new file mode 100644 index 00000000000..9e92527aef7 --- /dev/null +++ b/source/blender/makesrna/intern/rna_camera_api.c @@ -0,0 +1,88 @@ +/* + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/makesrna/intern/rna_camera_api.c + * \ingroup RNA + */ + + +#include +#include +#include + + +#include "RNA_define.h" +#include "BKE_utildefines.h" + +#ifdef RNA_RUNTIME + +#include "DNA_scene_types.h" +#include "BKE_context.h" +#include "BKE_object.h" + +void rna_camera_view_frame(struct Camera *camera, struct Scene *scene, + float vec1_r[3], float vec2_r[3], float vec3_r[3], float vec4_r[3]) +{ + float vec[4][3]; + + camera_view_frame(scene, camera, vec); + + copy_v3_v3(vec1_r, vec[0]); + copy_v3_v3(vec2_r, vec[1]); + copy_v3_v3(vec3_r, vec[2]); + copy_v3_v3(vec4_r, vec[3]); +} + +#else + +void RNA_api_camera(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + func= RNA_def_function(srna, "view_frame", "rna_camera_view_frame"); + RNA_def_function_ui_description(func, "Return 4 points for the cameras frame (before object transformation)"); + + RNA_def_pointer(func, "scene", "Scene", "", "Scene to use for aspect calculation, when omitted 1:1 aspect is used"); + + /* return location and normal */ + parm= RNA_def_float_vector(func, "result_1", 3, NULL, -FLT_MAX, FLT_MAX, "Result", NULL, -1e4, 1e4); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); + + parm= RNA_def_float_vector(func, "result_2", 3, NULL, -FLT_MAX, FLT_MAX, "Result", NULL, -1e4, 1e4); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); + + parm= RNA_def_float_vector(func, "result_3", 3, NULL, -FLT_MAX, FLT_MAX, "Result", NULL, -1e4, 1e4); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); + + parm= RNA_def_float_vector(func, "result_4", 3, NULL, -FLT_MAX, FLT_MAX, "Result", NULL, -1e4, 1e4); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); +} + +#endif + diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 78b8c67d92c..cf1be39124e 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -234,6 +234,7 @@ char *rna_TextureSlot_path(struct PointerRNA *ptr); void RNA_api_action(StructRNA *srna); void RNA_api_armature_edit_bone(StructRNA *srna); void RNA_api_bone(StructRNA *srna); +void RNA_api_camera(StructRNA *srna); void RNA_api_drivers(StructRNA *srna); void RNA_api_image(struct StructRNA *srna); void RNA_api_operator(struct StructRNA *srna); -- cgit v1.2.3