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:
-rw-r--r--release/scripts/startup/bl_ui/properties_object_constraint.py4
-rw-r--r--source/blender/blenkernel/intern/constraint.c38
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c5
-rw-r--r--source/blender/makesdna/DNA_constraint_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_constraint.c36
5 files changed, 79 insertions, 5 deletions
diff --git a/release/scripts/startup/bl_ui/properties_object_constraint.py b/release/scripts/startup/bl_ui/properties_object_constraint.py
index cf66baa03c4..57adfa1fa20 100644
--- a/release/scripts/startup/bl_ui/properties_object_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_object_constraint.py
@@ -778,6 +778,10 @@ class ConstraintButtonsPanel():
layout.prop(con, "camera")
+ row = layout.row()
+ row.active = not con.use_3d_position
+ row.prop(con, "depth_object")
+
layout.operator("clip.constraint_to_fcurve")
def CAMERA_SOLVER(self, context, layout, con):
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 878db6b3ed1..77a4a6a429c 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -41,6 +41,7 @@
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_editVert.h"
+#include "BLI_kdopbvh.h"
#include "BLI_utildefines.h"
#include "DNA_armature_types.h"
@@ -64,6 +65,7 @@
#include "BKE_anim.h" /* for the curve calculation part */
#include "BKE_armature.h"
#include "BKE_blender.h"
+#include "BKE_bvhutils.h"
#include "BKE_camera.h"
#include "BKE_constraint.h"
#include "BKE_displist.h"
@@ -3950,6 +3952,7 @@ static void followtrack_id_looper (bConstraint *con, ConstraintIDFunc func, void
func(con, (ID**)&data->clip, userdata);
func(con, (ID**)&data->camera, userdata);
+ func(con, (ID**)&data->depth_ob, userdata);
}
static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
@@ -3985,7 +3988,6 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
if (data->flag & FOLLOWTRACK_USE_3D_POSITION) {
if (track->flag & TRACK_HAS_BUNDLE) {
- MovieTracking *tracking= &clip->tracking;
float obmat[4][4], mat[4][4];
copy_m4_m4(obmat, cob->matrix);
@@ -4008,9 +4010,8 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
}
}
- }
+ }
else {
- MovieClipUser user;
MovieTrackingMarker *marker;
float vec[3], disp[3], axis[3], mat[4][4];
float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
@@ -4035,8 +4036,7 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
CameraParams params;
float pos[2], rmat[4][4];
- user.framenr= scene->r.cfra;
- marker= BKE_tracking_get_marker(track, user.framenr);
+ marker= BKE_tracking_get_marker(track, scene->r.cfra);
add_v2_v2v2(pos, marker->pos, track->offset);
@@ -4078,6 +4078,34 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
copy_v3_v3(cob->matrix[3], disp);
}
+
+ if(data->depth_ob && data->depth_ob->derivedFinal) {
+ Object *depth_ob= data->depth_ob;
+ BVHTreeFromMesh treeData= NULL_BVHTreeFromMesh;
+ BVHTreeRayHit hit;
+ float ray_start[3], ray_end[3], ray_nor[3], imat[4][4];
+ int result;
+
+ invert_m4_m4(imat, depth_ob->obmat);
+
+ mul_v3_m4v3(ray_start, imat, camob->obmat[3]);
+ mul_v3_m4v3(ray_end, imat, cob->matrix[3]);
+
+ sub_v3_v3v3(ray_nor, ray_end, ray_start);
+
+ bvhtree_from_mesh_faces(&treeData, depth_ob->derivedFinal, 0.0f, 4, 6);
+
+ hit.dist= FLT_MAX;
+ hit.index= -1;
+
+ result= BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData);
+
+ if(result != -1) {
+ mul_v3_m4v3(cob->matrix[3], depth_ob->obmat, hit.co);
+ }
+
+ free_bvhtree_from_mesh(&treeData);
+ }
}
}
}
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 3cb2f8ce738..762aaf3efc1 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -657,6 +657,11 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
if((data->clip || data->flag&FOLLOWTRACK_ACTIVECLIP) && data->track[0])
depends_on_camera= 1;
+
+ if(data->depth_ob) {
+ node2 = dag_get_node(dag, data->depth_ob);
+ dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name);
+ }
}
else if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER)
depends_on_camera= 1;
diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h
index 8fdbde60bab..c829d5be294 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -417,6 +417,7 @@ typedef struct bFollowTrackConstraint {
int flag, pad;
char object[24];
struct Object *camera;
+ struct Object *depth_ob;
} bFollowTrackConstraint;
/* Camera Solver constraints */
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c
index 6439d22e808..3258b8c3dcb 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -358,6 +358,34 @@ static void rna_Constraint_followTrack_camera_set(PointerRNA *ptr, PointerRNA va
}
}
+static void rna_Constraint_followTrack_depthObject_set(PointerRNA *ptr, PointerRNA value)
+{
+ bConstraint *con= (bConstraint*)ptr->data;
+ bFollowTrackConstraint *data= (bFollowTrackConstraint*)con->data;
+ Object *ob= (Object*)value.data;
+
+ if (ob) {
+ if (ob->type == OB_MESH && ob != (Object*)ptr->id.data) {
+ data->depth_ob= ob;
+ }
+ } else {
+ data->depth_ob= NULL;
+ }
+}
+
+static int rna_Constraint_followTrack_depthObject_poll(PointerRNA *ptr, PointerRNA value)
+{
+ Object *ob= (Object*)value.data;
+
+ if(ob) {
+ if (ob->type == OB_MESH && ob != (Object*)ptr->id.data) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static void rna_Constraint_objectSolver_camera_set(PointerRNA *ptr, PointerRNA value)
{
bConstraint *con= (bConstraint*)ptr->data;
@@ -2126,6 +2154,14 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update");
RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_camera_set", NULL, "rna_Constraint_cameraObject_poll");
+
+ /* depth object */
+ prop= RNA_def_property(srna, "depth_object", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "depth_ob");
+ RNA_def_property_ui_text(prop, "Depth Object", "Object used to define depth in camera space by projecting onto surface of this object");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update");
+ RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_depthObject_set", NULL, "rna_Constraint_followTrack_depthObject_poll");
}
static void rna_def_constraint_camera_solver(BlenderRNA *brna)