Blender  V3.3
transform_constraints.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_state.h"
#include "BLI_math.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "ED_view3d.h"
#include "BLT_translation.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "transform.h"
#include "transform_orientations.h"
#include "transform_snap.h"
#include "transform_constraints.h"

Go to the source code of this file.

Functions

Drawing Constraints
static void drawObjectConstraint (TransInfo *t)
 
void drawConstraint (TransInfo *t)
 
void drawPropCircle (const struct bContext *C, TransInfo *t)
 
Internal Setup Calls
void setConstraint (TransInfo *t, int mode, const char text[])
 
void setAxisMatrixConstraint (TransInfo *t, int mode, const char text[])
 
void setLocalConstraint (TransInfo *t, int mode, const char text[])
 
void setUserConstraint (TransInfo *t, int mode, const char ftext[])
 
Start / Stop Constraints
void startConstraint (TransInfo *t)
 
void stopConstraint (TransInfo *t)
 
Middle Mouse Button Select
void initSelectConstraint (TransInfo *t)
 
void selectConstraint (TransInfo *t)
 
void postSelectConstraint (TransInfo *t)
 
static void setNearestAxis2d (TransInfo *t)
 
static void setNearestAxis3d (TransInfo *t)
 
void setNearestAxis (TransInfo *t)
 
Helper Functions
int constraintModeToIndex (const TransInfo *t)
 
bool isLockConstraint (const TransInfo *t)
 
int getConstraintSpaceDimension (const TransInfo *t)
 

Internal Utilities

#define CONSTRAIN_EPSILON   0.0001f
 
static void projection_matrix_calc (const TransInfo *t, float r_pmtx[3][3])
 
static void view_vector_calc (const TransInfo *t, const float focus[3], float r_vec[3])
 
static void constraint_plane_calc (const TransInfo *t, float r_plane[4])
 
void constraintNumInput (TransInfo *t, float vec[3])
 
static void viewAxisCorrectCenter (const TransInfo *t, float t_con_center[3])
 
static void axisProjection (const TransInfo *t, const float axis[3], const float in[3], float out[3])
 
static void constraint_snap_plane_to_edge (const TransInfo *t, const float plane[4], float r_out[3])
 
static void UNUSED_FUNCTION (constraint_snap_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3]))
 
void transform_constraint_snap_axis_to_edge (const TransInfo *t, const float axis[3], float r_out[3])
 
void transform_constraint_snap_axis_to_face (const TransInfo *t, const float axis[3], float r_out[3])
 
static bool isPlaneProjectionViewAligned (const TransInfo *t, const float plane[4])
 
static void planeProjection (const TransInfo *t, const float plane[3], const float in[3], float out[3])
 
static short transform_orientation_or_default (const TransInfo *t)
 
static const float(* transform_object_axismtx_get (const TransInfo *t, const TransDataContainer *UNUSED(tc), const TransData *td))[3]
 
static void applyAxisConstraintVec (const TransInfo *t, const TransDataContainer *UNUSED(tc), const TransData *td, const float in[3], float out[3])
 
static void applyObjectConstraintVec (const TransInfo *t, const TransDataContainer *tc, const TransData *td, const float in[3], float out[3])
 
static void applyAxisConstraintSize (const TransInfo *t, const TransDataContainer *UNUSED(tc), const TransData *td, float r_smat[3][3])
 
static void applyObjectConstraintSize (const TransInfo *t, const TransDataContainer *tc, const TransData *td, float r_smat[3][3])
 
static void constraints_rotation_impl (const TransInfo *t, const float axismtx[3][3], float r_axis[3], float *r_angle)
 
static void applyAxisConstraintRot (const TransInfo *t, const TransDataContainer *UNUSED(tc), const TransData *td, float r_axis[3], float *r_angle)
 
static void applyObjectConstraintRot (const TransInfo *t, const TransDataContainer *tc, const TransData *td, float r_axis[3], float *r_angle)
 

Macro Definition Documentation

◆ CONSTRAIN_EPSILON

#define CONSTRAIN_EPSILON   0.0001f

Definition at line 83 of file transform_constraints.c.

Function Documentation

◆ applyAxisConstraintRot()

static void applyAxisConstraintRot ( const TransInfo t,
const TransDataContainer UNUSEDtc,
const TransData td,
float  r_axis[3],
float r_angle 
)
static

Generic callback for constant spatial constraints applied to rotations

The rotation axis is copied into vec.

In the case of single axis constraints, the rotation axis is directly the one constrained to. For planar constraints (2 axis), the rotation axis is the normal of the plane.

The following only applies when CON_NOFLIP is not set. The vector is then modified to always point away from the screen (in global space) This insures that the rotation is always logically following the mouse. (ie: not doing counterclockwise rotations when the mouse moves clockwise).

Definition at line 601 of file transform_constraints.c.

References CON_APPLY, constraints_rotation_impl(), and t.

Referenced by setConstraint().

◆ applyAxisConstraintSize()

static void applyAxisConstraintSize ( const TransInfo t,
const TransDataContainer UNUSEDtc,
const TransData td,
float  r_smat[3][3] 
)
static

Generic callback for constant spatial constraints applied to resize motion.

Definition at line 499 of file transform_constraints.c.

References CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, mul_m3_m3m3(), and t.

Referenced by setConstraint().

◆ applyAxisConstraintVec()

static void applyAxisConstraintVec ( const TransInfo t,
const TransDataContainer UNUSEDtc,
const TransData td,
const float  in[3],
float  out[3] 
)
static

Generic callback for constant spatial constraints applied to linear motion

The in vector in projected into the constrained space and then further projected along the view vector. (in perspective mode, the view vector is relative to the position on screen)

Definition at line 387 of file transform_constraints.c.

References activeSnap(), axisProjection(), BLI_assert, Freestyle::c, CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, constraint_plane_calc(), constraint_snap_plane_to_edge(), copy_v3_v3(), getConstraintSpaceDimension(), is_zero_v3(), isPlaneProjectionViewAligned(), mul_m3_v3(), usdtokens::out(), planeProjection(), SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_FACE_RAYCAST, SCE_SNAP_MODE_GRID, t, transform_constraint_snap_axis_to_edge(), transform_constraint_snap_axis_to_face(), and validSnap().

Referenced by applyObjectConstraintVec(), and setConstraint().

◆ applyObjectConstraintRot()

static void applyObjectConstraintRot ( const TransInfo t,
const TransDataContainer tc,
const TransData td,
float  r_axis[3],
float r_angle 
)
static

Callback for object based spatial constraints applied to rotations

The rotation axis is copied into vec.

In the case of single axis constraints, the rotation axis is directly the one constrained to. For planar constraints (2 axis), the rotation axis is the normal of the plane.

The following only applies when CON_NOFLIP is not set. The vector is then modified to always point away from the screen (in global space) This insures that the rotation is always logically following the mouse. (ie: not doing counterclockwise rotations when the mouse moves clockwise).

Definition at line 625 of file transform_constraints.c.

References TransData::axismtx, BLI_assert, CON_APPLY, constraints_rotation_impl(), TransDataContainer::data, float(), TransDataContainer::mat3_unit, mul_m3_m3m3(), NULL, t, T_EDIT, TRANS_DATA_CONTAINER_FIRST_OK, and transform_object_axismtx_get().

Referenced by setAxisMatrixConstraint().

◆ applyObjectConstraintSize()

static void applyObjectConstraintSize ( const TransInfo t,
const TransDataContainer tc,
const TransData td,
float  r_smat[3][3] 
)
static

Callback for object based spatial constraints applied to resize motion.

Definition at line 525 of file transform_constraints.c.

References CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, float(), invert_m3_m3(), TransDataContainer::mat3_unit, mul_m3_m3m3(), t, T_EDIT, and transform_object_axismtx_get().

Referenced by setAxisMatrixConstraint().

◆ applyObjectConstraintVec()

static void applyObjectConstraintVec ( const TransInfo t,
const TransDataContainer tc,
const TransData td,
const float  in[3],
float  out[3] 
)
static

Generic callback for object based spatial constraints applied to linear motion

At first, the following is applied without orientation The IN vector in projected into the constrained space and then further projected along the view vector. (in perspective mode, the view vector is relative to the position on screen).

Further down, that vector is mapped to each data's space.

Definition at line 473 of file transform_constraints.c.

References applyAxisConstraintVec(), CON_APPLY, copy_v3_v3(), float(), TransDataContainer::mat3_unit, mul_m3_v3(), usdtokens::out(), t, T_EDIT, and transform_object_axismtx_get().

Referenced by setAxisMatrixConstraint().

◆ axisProjection()

static void axisProjection ( const TransInfo t,
const float  axis[3],
const float  in[3],
float  out[3] 
)
static

◆ constraint_plane_calc()

static void constraint_plane_calc ( const TransInfo t,
float  r_plane[4] 
)
static

Definition at line 85 of file transform_constraints.c.

References BLI_assert, CON_AXIS0, cross_v3_v3v3(), dot_v3v3(), normalize_v3(), and t.

Referenced by applyAxisConstraintVec().

◆ constraint_snap_plane_to_edge()

static void constraint_snap_plane_to_edge ( const TransInfo t,
const float  plane[4],
float  r_out[3] 
)
static

Snap to the intersection between the edge direction and the constraint plane.

Definition at line 271 of file transform_constraints.c.

References CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_ray_plane_v3(), madd_v3_v3v3fl(), sub_v3_v3(), and t.

Referenced by applyAxisConstraintVec().

◆ constraintModeToIndex()

int constraintModeToIndex ( const TransInfo t)

Definition at line 1117 of file transform_constraints.c.

References CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, and t.

Referenced by saveTransform().

◆ constraintNumInput()

void constraintNumInput ( TransInfo t,
float  vec[3] 
)

◆ constraints_rotation_impl()

static void constraints_rotation_impl ( const TransInfo t,
const float  axismtx[3][3],
float  r_axis[3],
float r_angle 
)
static

◆ drawConstraint()

void drawConstraint ( TransInfo t)

◆ drawObjectConstraint()

static void drawObjectConstraint ( TransInfo t)
static

◆ drawPropCircle()

void drawPropCircle ( const struct bContext C,
TransInfo t 
)

◆ getConstraintSpaceDimension()

int getConstraintSpaceDimension ( const TransInfo t)

Returns the dimension of the constraint space.

For that reason, the flags always needs to be set to properly evaluate here, even if they aren't actually used in the callback function. (Which could happen for weird constraints not yet designed. Along a path for example.)

Definition at line 1156 of file transform_constraints.c.

References CON_AXIS0, CON_AXIS1, CON_AXIS2, and t.

Referenced by applyAxisConstraintVec(), constraintNumInput(), and startConstraint().

◆ initSelectConstraint()

void initSelectConstraint ( TransInfo t)

◆ isLockConstraint()

bool isLockConstraint ( const TransInfo t)

Definition at line 1137 of file transform_constraints.c.

References CON_AXIS0, CON_AXIS1, CON_AXIS2, and t.

Referenced by applyPushPull().

◆ isPlaneProjectionViewAligned()

static bool isPlaneProjectionViewAligned ( const TransInfo t,
const float  plane[4] 
)
static

Return true if the 2x axis are both aligned when projected into the view. In this case, we can't usefully project the cursor onto the plane.

Definition at line 331 of file transform_constraints.c.

References dot_v3v3(), eps, fabsf, t, and view_vector_calc().

Referenced by applyAxisConstraintVec().

◆ planeProjection()

static void planeProjection ( const TransInfo t,
const float  plane[3],
const float  in[3],
float  out[3] 
)
static

◆ postSelectConstraint()

void postSelectConstraint ( TransInfo t)

Definition at line 994 of file transform_constraints.c.

References CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, CON_SELECT, and t.

Referenced by transformEvent().

◆ projection_matrix_calc()

static void projection_matrix_calc ( const TransInfo t,
float  r_pmtx[3][3] 
)
static

◆ selectConstraint()

void selectConstraint ( TransInfo t)

Definition at line 986 of file transform_constraints.c.

References CON_SELECT, setNearestAxis(), startConstraint(), and t.

Referenced by transformApply().

◆ setAxisMatrixConstraint()

void setAxisMatrixConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

◆ setConstraint()

void setConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

◆ setLocalConstraint()

void setLocalConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

Definition at line 690 of file transform_constraints.c.

References setAxisMatrixConstraint(), setConstraint(), t, and T_EDIT.

Referenced by setUserConstraint(), and transformEvent().

◆ setNearestAxis()

void setNearestAxis ( TransInfo t)

◆ setNearestAxis2d()

static void setNearestAxis2d ( TransInfo t)
static

Definition at line 1002 of file transform_constraints.c.

References blender::math::abs(), BLI_strncpy(), CON_AXIS0, CON_AXIS1, t, and TIP_.

Referenced by setNearestAxis().

◆ setNearestAxis3d()

static void setNearestAxis3d ( TransInfo t)
static

◆ setUserConstraint()

void setUserConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

◆ startConstraint()

void startConstraint ( TransInfo t)

◆ stopConstraint()

void stopConstraint ( TransInfo t)

◆ transform_constraint_snap_axis_to_edge()

void transform_constraint_snap_axis_to_edge ( const TransInfo t,
const float  axis[3],
float  r_out[3] 
)

Snap to the nearest point on the axis to the edge/line element.

Definition at line 298 of file transform_constraints.c.

References CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_ray_ray_v3(), mul_v3_v3fl(), NULL, and t.

Referenced by applyAxisConstraintVec(), edge_slide_snap_apply(), and vert_slide_snap_apply().

◆ transform_constraint_snap_axis_to_face()

void transform_constraint_snap_axis_to_face ( const TransInfo t,
const float  axis[3],
float  r_out[3] 
)

Snap to the intersection of the axis and the plane defined by the face.

Definition at line 312 of file transform_constraints.c.

References CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_ray_plane_v3(), mul_v3_v3fl(), plane_from_point_normal_v3(), and t.

Referenced by applyAxisConstraintVec(), edge_slide_snap_apply(), and vert_slide_snap_apply().

◆ transform_object_axismtx_get()

static const float(* transform_object_axismtx_get ( const TransInfo t,
const TransDataContainer UNUSEDtc,
const TransData td 
) )[3]
static

◆ transform_orientation_or_default()

static short transform_orientation_or_default ( const TransInfo t)
static

Definition at line 357 of file transform_constraints.c.

References t, and V3D_ORIENT_CUSTOM_MATRIX.

Referenced by setUserConstraint(), and transform_object_axismtx_get().

◆ UNUSED_FUNCTION()

static void UNUSED_FUNCTION ( constraint_snap_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3])  )
static

◆ view_vector_calc()

static void view_vector_calc ( const TransInfo t,
const float  focus[3],
float  r_vec[3] 
)
static

◆ viewAxisCorrectCenter()

static void viewAxisCorrectCenter ( const TransInfo t,
float  t_con_center[3] 
)
static