1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 */ 16 17 /** \file 18 * \ingroup editors 19 */ 20 21 #pragma once 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 struct BMEdge; 28 struct BMFace; 29 struct BMVert; 30 31 struct ARegion; 32 struct Depsgraph; 33 struct ListBase; 34 struct Main; 35 struct Object; 36 struct Scene; 37 struct View3D; 38 39 /* transform_snap_object.c */ 40 41 /* ED_transform_snap_object_*** API */ 42 43 typedef enum eSnapSelect { 44 SNAP_ALL = 0, 45 SNAP_NOT_SELECTED = 1, 46 SNAP_NOT_ACTIVE = 2, 47 } eSnapSelect; 48 49 /** used for storing multiple hits */ 50 struct SnapObjectHitDepth { 51 struct SnapObjectHitDepth *next, *prev; 52 53 float depth; 54 float co[3]; 55 float no[3]; 56 int index; 57 58 struct Object *ob; 59 float obmat[4][4]; 60 61 /* needed to tell which ray-cast this was part of, 62 * the same object may be part of many ray-casts when dupli's are used. */ 63 unsigned int ob_uuid; 64 }; 65 66 /** parameters that define which objects will be used to snap. */ 67 struct SnapObjectParams { 68 /* special context sensitive handling for the active or selected object */ 69 char snap_select; 70 /* use editmode cage */ 71 unsigned int use_object_edit_cage : 1; 72 /* snap to the closest element, use when using more than one snap type */ 73 unsigned int use_occlusion_test : 1; 74 /* exclude back facing geometry from snapping */ 75 unsigned int use_backface_culling : 1; 76 }; 77 78 typedef struct SnapObjectContext SnapObjectContext; 79 SnapObjectContext *ED_transform_snap_object_context_create(struct Scene *scene, int flag); 80 SnapObjectContext *ED_transform_snap_object_context_create_view3d(struct Scene *scene, 81 int flag, 82 /* extra args for view3d */ 83 const struct ARegion *region, 84 const struct View3D *v3d); 85 void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx); 86 87 /* callbacks to filter how snap works */ 88 void ED_transform_snap_object_context_set_editmesh_callbacks( 89 SnapObjectContext *sctx, 90 bool (*test_vert_fn)(struct BMVert *, void *user_data), 91 bool (*test_edge_fn)(struct BMEdge *, void *user_data), 92 bool (*test_face_fn)(struct BMFace *, void *user_data), 93 void *user_data); 94 95 bool ED_transform_snap_object_project_ray_ex(struct SnapObjectContext *sctx, 96 struct Depsgraph *depsgraph, 97 const struct SnapObjectParams *params, 98 const float ray_start[3], 99 const float ray_normal[3], 100 float *ray_depth, 101 /* return args */ 102 float r_loc[3], 103 float r_no[3], 104 int *r_index, 105 struct Object **r_ob, 106 float r_obmat[4][4]); 107 bool ED_transform_snap_object_project_ray(SnapObjectContext *sctx, 108 struct Depsgraph *depsgraph, 109 const struct SnapObjectParams *params, 110 const float ray_origin[3], 111 const float ray_direction[3], 112 float *ray_depth, 113 float r_co[3], 114 float r_no[3]); 115 116 bool ED_transform_snap_object_project_ray_all(SnapObjectContext *sctx, 117 struct Depsgraph *depsgraph, 118 const struct SnapObjectParams *params, 119 const float ray_start[3], 120 const float ray_normal[3], 121 float ray_depth, 122 bool sort, 123 struct ListBase *r_hit_list); 124 125 short ED_transform_snap_object_project_view3d_ex(struct SnapObjectContext *sctx, 126 struct Depsgraph *depsgraph, 127 const unsigned short snap_to, 128 const struct SnapObjectParams *params, 129 const float mval[2], 130 const float prev_co[3], 131 float *dist_px, 132 float r_loc[3], 133 float r_no[3], 134 int *r_index, 135 struct Object **r_ob, 136 float r_obmat[4][4]); 137 bool ED_transform_snap_object_project_view3d(struct SnapObjectContext *sctx, 138 struct Depsgraph *depsgraph, 139 const unsigned short snap_to, 140 const struct SnapObjectParams *params, 141 const float mval[2], 142 const float prev_co[3], 143 float *dist_px, 144 /* return args */ 145 float r_loc[3], 146 float r_no[3]); 147 148 bool ED_transform_snap_object_project_all_view3d_ex(SnapObjectContext *sctx, 149 struct Depsgraph *depsgraph, 150 const struct SnapObjectParams *params, 151 const float mval[2], 152 float ray_depth, 153 bool sort, 154 ListBase *r_hit_list); 155 156 #ifdef __cplusplus 157 } 158 #endif 159