Enable vertex snapping to bundle positions
This means it's possible now to snap stuff to reconstructed tracks positions.
This commit is contained in:
@@ -170,7 +170,7 @@ int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob);
|
||||
|
||||
void BKE_object_relink(struct Object *ob);
|
||||
|
||||
struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, int use_default);
|
||||
struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, bool use_default);
|
||||
|
||||
/* this function returns a superset of the scenes selection based on relationships */
|
||||
|
||||
|
||||
@@ -2275,7 +2275,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
|
||||
* so it should happen tracking-related constraints recalculation
|
||||
* when camera is changing (sergey) */
|
||||
if (sce->camera && &sce->camera->id == id) {
|
||||
MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, 1);
|
||||
MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, true);
|
||||
|
||||
if (clip)
|
||||
dag_id_flush_update(bmain, sce, &clip->id);
|
||||
|
||||
@@ -3261,7 +3261,7 @@ void BKE_object_relink(Object *ob)
|
||||
ID_NEW(ob->proxy_group);
|
||||
}
|
||||
|
||||
MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, int use_default)
|
||||
MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default)
|
||||
{
|
||||
MovieClip *clip = use_default ? scene->clip : NULL;
|
||||
bConstraint *con = ob->constraints.first, *scon = NULL;
|
||||
|
||||
@@ -551,7 +551,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
|
||||
}
|
||||
}
|
||||
else if (ob->type == OB_CAMERA) {
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, ob, FALSE);
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
|
||||
|
||||
/* applying scale on camera actually scales clip's reconstruction.
|
||||
* of there's clip assigned to camera nothing to do actually.
|
||||
|
||||
@@ -1874,13 +1874,13 @@ static Object *get_camera_with_movieclip(Scene *scene, MovieClip *clip)
|
||||
Object *camera = scene->camera;
|
||||
Base *base;
|
||||
|
||||
if (camera && BKE_object_movieclip_get(scene, camera, 0) == clip)
|
||||
if (camera && BKE_object_movieclip_get(scene, camera, false) == clip)
|
||||
return camera;
|
||||
|
||||
base = scene->base.first;
|
||||
while (base) {
|
||||
if (base->object->type == OB_CAMERA) {
|
||||
if (BKE_object_movieclip_get(scene, base->object, 0) == clip) {
|
||||
if (BKE_object_movieclip_get(scene, base->object, false) == clip) {
|
||||
camera = base->object;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1672,7 +1672,7 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
|
||||
int i;
|
||||
float drawsize;
|
||||
const bool is_view = (rv3d->persp == RV3D_CAMOB && ob == v3d->camera);
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, base->object, 0);
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, base->object, false);
|
||||
|
||||
/* draw data for movie clip set as active for scene */
|
||||
if (clip) {
|
||||
|
||||
@@ -1662,7 +1662,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
|
||||
|
||||
if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
|
||||
if (scene->camera)
|
||||
clip = BKE_object_movieclip_get(scene, scene->camera, 1);
|
||||
clip = BKE_object_movieclip_get(scene, scene->camera, true);
|
||||
}
|
||||
else {
|
||||
clip = bgpic->clip;
|
||||
|
||||
@@ -1462,7 +1462,7 @@ static bool mouse_select(bContext *C, const int mval[2], bool extend, bool desel
|
||||
/* index of bundle is 1<<16-based. if there's no "bone" index
|
||||
* in height word, this buffer value belongs to camera. not to bundle */
|
||||
if (buffer[4 * i + 3] & 0xFFFF0000) {
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, 0);
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, false);
|
||||
MovieTracking *tracking = &clip->tracking;
|
||||
ListBase *tracksbase;
|
||||
MovieTrackingTrack *track;
|
||||
|
||||
@@ -882,7 +882,7 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
|
||||
|
||||
static void bundle_midpoint(Scene *scene, Object *ob, float vec[3])
|
||||
{
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, ob, 0);
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
|
||||
MovieTracking *tracking;
|
||||
MovieTrackingObject *object;
|
||||
int ok = 0;
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_editmesh.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_tracking.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
|
||||
@@ -1557,6 +1558,90 @@ static bool snapEmpty(short snap_mode, ARegion *ar, Object *ob, float obmat[4][4
|
||||
return retval;
|
||||
}
|
||||
|
||||
static bool snapCamera(short snap_mode, ARegion *ar, Scene *scene, Object *object, float obmat[4][4],
|
||||
const float ray_start[3], const float ray_normal[3], const float mval[2],
|
||||
float r_loc[3], float *UNUSED(r_no), float *r_dist_px, float *r_depth)
|
||||
{
|
||||
float orig_camera_mat[4][4], orig_camera_imat[4][4], imat[4][4];
|
||||
bool retval = false;
|
||||
MovieClip *clip = BKE_object_movieclip_get(scene, object, false);
|
||||
MovieTracking *tracking;
|
||||
float ray_start_local[3], ray_normal_local[3];
|
||||
|
||||
if (clip == NULL) {
|
||||
return retval;
|
||||
}
|
||||
if (object->transflag & OB_DUPLI) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
tracking = &clip->tracking;
|
||||
|
||||
BKE_tracking_get_camera_object_matrix(scene, object, orig_camera_mat);
|
||||
|
||||
invert_m4_m4(orig_camera_imat, orig_camera_mat);
|
||||
invert_m4_m4(imat, obmat);
|
||||
|
||||
switch (snap_mode) {
|
||||
case SCE_SNAP_MODE_VERTEX:
|
||||
{
|
||||
MovieTrackingObject *tracking_object;
|
||||
|
||||
for (tracking_object = tracking->objects.first;
|
||||
tracking_object;
|
||||
tracking_object = tracking_object->next)
|
||||
{
|
||||
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
|
||||
MovieTrackingTrack *track;
|
||||
float reconstructed_camera_mat[4][4],
|
||||
reconstructed_camera_imat[4][4];
|
||||
float (*vertex_obmat)[4];
|
||||
|
||||
copy_v3_v3(ray_start_local, ray_start);
|
||||
copy_v3_v3(ray_normal_local, ray_normal);
|
||||
|
||||
if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
|
||||
BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object,
|
||||
CFRA, reconstructed_camera_mat);
|
||||
|
||||
invert_m4_m4(reconstructed_camera_imat, reconstructed_camera_mat);
|
||||
}
|
||||
|
||||
for (track = tracksbase->first; track; track = track->next) {
|
||||
float bundle_pos[3];
|
||||
|
||||
if ((track->flag & TRACK_HAS_BUNDLE) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
copy_v3_v3(bundle_pos, track->bundle_pos);
|
||||
if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
|
||||
mul_m4_v3(orig_camera_imat, ray_start_local);
|
||||
mul_mat3_m4_v3(orig_camera_imat, ray_normal_local);
|
||||
vertex_obmat = orig_camera_mat;
|
||||
}
|
||||
else {
|
||||
mul_m4_v3(reconstructed_camera_imat, bundle_pos);
|
||||
mul_m4_v3(imat, ray_start_local);
|
||||
mul_mat3_m4_v3(imat, ray_normal_local);
|
||||
vertex_obmat = obmat;
|
||||
}
|
||||
|
||||
retval |= snapVertex(ar, bundle_pos, NULL, vertex_obmat, NULL,
|
||||
ray_start, ray_start_local, ray_normal_local, mval,
|
||||
r_loc, NULL, r_dist_px, r_depth);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
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],
|
||||
@@ -1586,6 +1671,8 @@ static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, f
|
||||
}
|
||||
else if (ob->type == OB_EMPTY) {
|
||||
retval = snapEmpty(snap_mode, ar, ob, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth);
|
||||
} else if (ob->type == OB_CAMERA) {
|
||||
retval = snapCamera(snap_mode, ar, scene, ob, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth);
|
||||
}
|
||||
|
||||
if (retval) {
|
||||
|
||||
Reference in New Issue
Block a user