27
27
* \ingroup spview3d
34
30
#include "MEM_guardedalloc.h"
36
32
#include "DNA_camera_types.h"
37
33
#include "DNA_curve_types.h"
38
#include "DNA_constraint_types.h" // for drawing constraint
34
#include "DNA_constraint_types.h" /* for drawing constraint */
39
35
#include "DNA_lamp_types.h"
40
36
#include "DNA_lattice_types.h"
41
37
#include "DNA_material_types.h"
42
38
#include "DNA_mesh_types.h"
43
#include "DNA_meshdata_types.h"
44
39
#include "DNA_meta_types.h"
45
40
#include "DNA_scene_types.h"
46
41
#include "DNA_smoke_types.h"
47
#include "DNA_speaker_types.h"
48
42
#include "DNA_world_types.h"
49
#include "DNA_armature_types.h"
43
#include "DNA_object_types.h"
51
#include "BLI_utildefines.h"
52
45
#include "BLI_blenlib.h"
53
46
#include "BLI_math.h"
54
#include "BLI_edgehash.h"
56
#include "BLI_utildefines.h"
58
#include "BKE_anim.h" //for the where_on_path function
48
#include "BKE_anim.h" /* for the where_on_path function */
59
49
#include "BKE_armature.h"
60
50
#include "BKE_camera.h"
61
#include "BKE_constraint.h" // for the get_constraint_target function
51
#include "BKE_constraint.h" /* for the get_constraint_target function */
62
52
#include "BKE_curve.h"
63
53
#include "BKE_DerivedMesh.h"
64
54
#include "BKE_deform.h"
115
101
OBDRAW_WIRE_ON_DEPTH = 2
118
/* user data structures for derived mesh callbacks */
119
typedef struct foreachScreenVert_userData {
120
void (*func)(void *userData, BMVert *eve, int x, int y, int index);
123
eV3DClipTest clipVerts;
124
} foreachScreenVert_userData;
126
typedef struct foreachScreenEdge_userData {
127
void (*func)(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index);
130
rcti win_rect; /* copy of: vc.ar->winx/winy, use for faster tests, minx/y will always be 0 */
131
eV3DClipTest clipVerts;
132
} foreachScreenEdge_userData;
134
typedef struct foreachScreenFace_userData {
135
void (*func)(void *userData, BMFace *efa, int x, int y, int index);
138
} foreachScreenFace_userData;
140
104
typedef struct drawDMVerts_userData {
141
BMEditMesh *em; /* BMESH BRANCH ONLY */
110
/* cached theme values */
111
unsigned char th_editmesh_active[4];
112
unsigned char th_vertex_select[4];
113
unsigned char th_vertex[4];
114
unsigned char th_skin_root[4];
115
float th_vertex_size;
117
/* for skin node drawing */
145
120
} drawDMVerts_userData;
147
122
typedef struct drawDMEdgesSel_userData {
148
BMEditMesh *em; /* BMESH BRANCH ONLY */
150
125
unsigned char *baseCol, *selCol, *actCol;
181
157
static void draw_empty_sphere(float size);
182
158
static void draw_empty_cone(float size);
160
static void ob_wire_color_blend_theme_id(const unsigned char ob_wire_col[4], const int theme_id, float fac)
162
float col_wire[3], col_bg[3], col[3];
164
rgb_uchar_to_float(col_wire, ob_wire_col);
166
UI_GetThemeColor3fv(theme_id, col_bg);
167
interp_v3_v3v3(col, col_bg, col_wire, fac);
184
171
/* this condition has been made more complex since editmode can draw textures */
185
static int check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
172
static bool check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
187
174
/* texture and material draw modes */
188
if (ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID)
175
if (ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID) {
191
179
/* textured solid */
192
if (v3d->drawtype == OB_SOLID && (v3d->flag2 & V3D_SOLID_TEX) && !scene_use_new_shading_nodes(scene))
180
if ((v3d->drawtype == OB_SOLID) &&
181
(v3d->flag2 & V3D_SOLID_TEX) &&
182
(BKE_scene_use_new_shading_nodes(scene) == false))
187
if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) {
198
194
static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
219
/* ************* only use while object drawing **************
220
* or after running ED_view3d_init_mats_rv3d
222
static void view3d_project_short_clip(ARegion *ar, const float vec[3], short adr[2], int is_local)
224
RegionView3D *rv3d = ar->regiondata;
225
float fx, fy, vec4[4];
229
/* clipplanes in eye space */
230
if (rv3d->rflag & RV3D_CLIPPING) {
231
if (ED_view3d_clipping_test(rv3d, vec, is_local))
235
copy_v3_v3(vec4, vec);
238
mul_m4_v4(rv3d->persmatob, vec4);
240
/* clipplanes in window space */
241
if (vec4[3] > (float)BL_NEAR_CLIP) { /* is the NEAR clipping cutoff for picking */
242
fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
244
if (fx > 0 && fx < ar->winx) {
246
fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
248
if (fy > 0.0f && fy < (float)ar->winy) {
249
adr[0] = (short)floorf(fx);
250
adr[1] = (short)floorf(fy);
256
/* BMESH NOTE: this function is unused in bmesh only */
258
/* only use while object drawing */
259
static void UNUSED_FUNCTION(view3d_project_short_noclip) (ARegion * ar, const float vec[3], short adr[2])
261
RegionView3D *rv3d = ar->regiondata;
262
float fx, fy, vec4[4];
266
copy_v3_v3(vec4, vec);
269
mul_m4_v4(rv3d->persmatob, vec4);
271
if (vec4[3] > (float)BL_NEAR_CLIP) { /* is the NEAR clipping cutoff for picking */
272
fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
274
if (fx > -32700 && fx < 32700) {
276
fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
278
if (fy > -32700.0f && fy < 32700.0f) {
279
adr[0] = (short)floorf(fx);
280
adr[1] = (short)floorf(fy);
286
/* same as view3d_project_short_clip but use persmat instead of persmatob for projection */
287
static void view3d_project_short_clip_persmat(ARegion *ar, const float vec[3], short adr[2], int is_local)
289
RegionView3D *rv3d = ar->regiondata;
290
float fx, fy, vec4[4];
294
/* clipplanes in eye space */
295
if (rv3d->rflag & RV3D_CLIPPING) {
296
if (ED_view3d_clipping_test(rv3d, vec, is_local))
300
copy_v3_v3(vec4, vec);
303
mul_m4_v4(rv3d->persmat, vec4);
305
/* clipplanes in window space */
306
if (vec4[3] > (float)BL_NEAR_CLIP) { /* is the NEAR clipping cutoff for picking */
307
fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
309
if (fx > 0 && fx < ar->winx) {
311
fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
313
if (fy > 0.0f && fy < (float)ar->winy) {
314
adr[0] = (short)floorf(fx);
315
adr[1] = (short)floorf(fy);
320
215
/* ************************ */
322
217
/* check for glsl drawing */
324
int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt)
219
int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, const char dt)
326
221
if (!GPU_glsl_support())
714
617
glDisable(GL_BLEND);
717
UI_ThemeColor((ob->flag & SELECT) ? TH_SELECT : TH_WIRE);
620
if ((dflag & DRAW_CONSTCOLOR) == 0) {
621
glColor3ubv(ob_wire_col);
719
/* Calculate the outline vertex positions */
720
glBegin(GL_LINE_LOOP);
721
glVertex2f(ofs_x, ofs_y);
722
glVertex2f(ofs_x + ima_x, ofs_y);
723
glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
724
glVertex2f(ofs_x, ofs_y + ima_y);
623
/* Calculate the outline vertex positions */
624
glBegin(GL_LINE_LOOP);
625
glVertex2f(ofs_x, ofs_y);
626
glVertex2f(ofs_x + ima_x, ofs_y);
627
glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
628
glVertex2f(ofs_x, ofs_y + ima_y);
727
632
/* Reset GL settings */
728
633
glMatrixMode(GL_MODELVIEW);
636
BKE_image_release_ibuf(ima, ibuf, NULL);
732
static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3], float rad, float tmat[][4])
639
static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3], float rad, float tmat[4][4])
734
641
float vx[3], vy[3];
735
642
float *viter = (float *)verts;
1536
1470
static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D *v3d,
1537
MovieClip *clip, MovieTrackingObject *tracking_object, int flag,
1471
MovieClip *clip, MovieTrackingObject *tracking_object,
1472
const short dflag, const unsigned char ob_wire_col[4],
1538
1473
int *global_track_index, int draw_selected)
1540
1475
MovieTracking *tracking = &clip->tracking;
1541
1476
MovieTrackingTrack *track;
1542
1477
float mat[4][4], imat[4][4];
1543
unsigned char col[4], scol[4];
1478
unsigned char col_unsel[4], col_sel[4];
1544
1479
int tracknr = *global_track_index;
1545
ListBase *tracksbase = BKE_tracking_object_tracks(tracking, tracking_object);
1547
UI_GetThemeColor4ubv(TH_TEXT, col);
1548
UI_GetThemeColor4ubv(TH_SELECT, scol);
1550
BKE_get_tracking_mat(scene, base->object, mat);
1480
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
1482
UI_GetThemeColor4ubv(TH_TEXT, col_unsel);
1483
UI_GetThemeColor4ubv(TH_SELECT, col_sel);
1485
BKE_tracking_get_camera_object_matrix(scene, base->object, mat);
1552
1487
glPushMatrix();
1740
1676
float drawsize;
1741
1677
const short is_view = (rv3d->persp == RV3D_CAMOB && ob == v3d->camera);
1742
MovieClip *clip = object_get_movieclip(scene, base->object, 0);
1678
MovieClip *clip = BKE_object_movieclip_get(scene, base->object, 0);
1744
1680
/* draw data for movie clip set as active for scene */
1746
draw_viewport_reconstruction(scene, base, v3d, clip, flag, FALSE);
1747
draw_viewport_reconstruction(scene, base, v3d, clip, flag, TRUE);
1682
draw_viewport_reconstruction(scene, base, v3d, clip, dflag, ob_wire_col, FALSE);
1683
draw_viewport_reconstruction(scene, base, v3d, clip, dflag, ob_wire_col, TRUE);
1750
1686
#ifdef VIEW3D_CAMERA_BORDER_HACK
1751
1687
if (is_view && !(G.f & G_PICKSEL)) {
1752
glGetFloatv(GL_CURRENT_COLOR, view3d_camera_border_hack_col);
1688
if ((dflag & DRAW_CONSTCOLOR) == 0) {
1689
view3d_camera_border_hack_col[0] = ob_wire_col[0];
1690
view3d_camera_border_hack_col[1] = ob_wire_col[1];
1691
view3d_camera_border_hack_col[2] = ob_wire_col[2];
1695
glGetFloatv(GL_CURRENT_COLOR, col);
1696
rgb_float_to_uchar(view3d_camera_border_hack_col, col);
1753
1698
view3d_camera_border_hack_test = TRUE;
1921
void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPoint *bp, int x, int y), void *userData)
1923
Object *obedit = vc->obedit;
1924
Lattice *lt = obedit->data;
1925
BPoint *bp = lt->editlatt->latt->def;
1926
DispList *dl = find_displist(&obedit->disp, DL_VERTS);
1927
float *co = dl ? dl->verts : NULL;
1928
int i, N = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
1929
short s[2] = {IS_CLIPPED, 0};
1931
ED_view3d_clipping_local(vc->rv3d, obedit->obmat); /* for local clipping lookups */
1933
for (i = 0; i < N; i++, bp++, co += 3) {
1934
if (bp->hide == 0) {
1935
view3d_project_short_clip(vc->ar, dl ? co : bp->vec, s, TRUE);
1936
if (s[0] != IS_CLIPPED)
1937
func(userData, bp, s[0], s[1]);
1942
1866
static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, int use_wcol)
1944
1868
int index = ((w * lt->pntsv + v) * lt->pntsu) + u;
2026
1950
/* ***************** ******************** */
2028
/* Note! - foreach funcs should be called while drawing or directly after
2029
* if not, ED_view3d_init_mats_rv3d() can be used for selection tools
2030
* but would not give correct results with dupli's for eg. which don't
2031
* use the object matrix in the usual way */
2032
static void mesh_foreachScreenVert__mapFunc(void *userData, int index, const float co[3],
2033
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
2035
foreachScreenVert_userData *data = userData;
2036
BMVert *eve = EDBM_vert_at_index(data->vc.em, index);
2038
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
2039
short s[2] = {IS_CLIPPED, 0};
2041
if (data->clipVerts != V3D_CLIP_TEST_OFF) {
2042
view3d_project_short_clip(data->vc.ar, co, s, TRUE);
2046
mul_v3_m4v3(co2, data->vc.obedit->obmat, co);
2047
project_short_noclip(data->vc.ar, co2, s);
2050
if (s[0] != IS_CLIPPED)
2051
data->func(data->userData, eve, s[0], s[1], index);
2055
void mesh_foreachScreenVert(
2057
void (*func)(void *userData, BMVert *eve, int x, int y, int index),
2058
void *userData, eV3DClipTest clipVerts)
2060
foreachScreenVert_userData data;
2061
DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
2065
data.userData = userData;
2066
data.clipVerts = clipVerts;
2068
if (clipVerts != V3D_CLIP_TEST_OFF)
2069
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
2071
EDBM_index_arrays_init(vc->em, 1, 0, 0);
2072
dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
2073
EDBM_index_arrays_free(vc->em);
2078
1952
/* draw callback */
2079
1953
static void drawSelectedVertices__mapFunc(void *userData, int index, const float co[3],
2080
1954
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
2106
static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, const float v0co[3], const float v1co[3])
2108
foreachScreenEdge_userData *data = userData;
2109
BMEdge *eed = EDBM_edge_at_index(data->vc.em, index);
2111
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
2114
if (data->clipVerts == V3D_CLIP_TEST_RV3D_CLIPPING) {
2115
view3d_project_short_clip(data->vc.ar, v0co, s[0], TRUE);
2116
view3d_project_short_clip(data->vc.ar, v1co, s[1], TRUE);
2119
float v1_co[3], v2_co[3];
2121
mul_v3_m4v3(v1_co, data->vc.obedit->obmat, v0co);
2122
mul_v3_m4v3(v2_co, data->vc.obedit->obmat, v1co);
2124
project_short_noclip(data->vc.ar, v1_co, s[0]);
2125
project_short_noclip(data->vc.ar, v2_co, s[1]);
2127
if (data->clipVerts == V3D_CLIP_TEST_REGION) {
2128
/* make an int copy */
2129
int s_int[2][2] = {{s[0][0], s[0][1]},
2130
{s[1][0], s[1][1]}};
2131
if (!BLI_segment_in_rcti(&data->win_rect, s_int[0], s_int[1])) {
2137
data->func(data->userData, eed, s[0][0], s[0][1], s[1][0], s[1][1], index);
2141
void mesh_foreachScreenEdge(
2143
void (*func)(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index),
2144
void *userData, eV3DClipTest clipVerts)
2146
foreachScreenEdge_userData data;
2147
DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
2151
data.win_rect.xmin = 0;
2152
data.win_rect.ymin = 0;
2153
data.win_rect.xmax = vc->ar->winx;
2154
data.win_rect.ymax = vc->ar->winy;
2157
data.userData = userData;
2158
data.clipVerts = clipVerts;
2160
if (clipVerts != V3D_CLIP_TEST_OFF)
2161
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
2163
EDBM_index_arrays_init(vc->em, 0, 1, 0);
2164
dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
2165
EDBM_index_arrays_free(vc->em);
2170
static void mesh_foreachScreenFace__mapFunc(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
2172
foreachScreenFace_userData *data = userData;
2173
BMFace *efa = EDBM_face_at_index(data->vc.em, index);
2175
if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
2179
mul_v3_m4v3(cent2, data->vc.obedit->obmat, cent);
2180
project_short(data->vc.ar, cent2, s);
2182
if (s[0] != IS_CLIPPED) {
2183
data->func(data->userData, efa, s[0], s[1], index);
2188
void mesh_foreachScreenFace(
2190
void (*func)(void *userData, BMFace *efa, int x, int y, int index),
2193
foreachScreenFace_userData data;
2194
DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
2198
data.userData = userData;
2201
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
2203
EDBM_index_arrays_init(vc->em, 0, 0, 1);
2204
dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
2205
EDBM_index_arrays_free(vc->em);
2210
void nurbs_foreachScreenVert(
2212
void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y),
2215
Curve *cu = vc->obedit->data;
2216
short s[2] = {IS_CLIPPED, 0};
2219
ListBase *nurbs = curve_editnurbs(cu);
2221
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
2223
for (nu = nurbs->first; nu; nu = nu->next) {
2224
if (nu->type == CU_BEZIER) {
2225
for (i = 0; i < nu->pntsu; i++) {
2226
BezTriple *bezt = &nu->bezt[i];
2228
if (bezt->hide == 0) {
2230
if (cu->drawflag & CU_HIDE_HANDLES) {
2231
view3d_project_short_clip(vc->ar, bezt->vec[1], s, TRUE);
2232
if (s[0] != IS_CLIPPED)
2233
func(userData, nu, NULL, bezt, 1, s[0], s[1]);
2236
view3d_project_short_clip(vc->ar, bezt->vec[0], s, TRUE);
2237
if (s[0] != IS_CLIPPED)
2238
func(userData, nu, NULL, bezt, 0, s[0], s[1]);
2239
view3d_project_short_clip(vc->ar, bezt->vec[1], s, TRUE);
2240
if (s[0] != IS_CLIPPED)
2241
func(userData, nu, NULL, bezt, 1, s[0], s[1]);
2242
view3d_project_short_clip(vc->ar, bezt->vec[2], s, TRUE);
2243
if (s[0] != IS_CLIPPED)
2244
func(userData, nu, NULL, bezt, 2, s[0], s[1]);
2250
for (i = 0; i < nu->pntsu * nu->pntsv; i++) {
2251
BPoint *bp = &nu->bp[i];
2253
if (bp->hide == 0) {
2254
view3d_project_short_clip(vc->ar, bp->vec, s, TRUE);
2255
if (s[0] != IS_CLIPPED)
2256
func(userData, nu, bp, NULL, -1, s[0], s[1]);
2263
1980
/* ************** DRAW MESH ****************** */
2265
/* First section is all the "simple" draw routines,
1982
/* First section is all the "simple" draw routines,
2266
1983
* ones that just pass some sort of primitive to GL,
2267
1984
* with perhaps various options to control lighting,
2902
#define DRAW_EM_MEASURE_STATS_FACEAREA() \
2903
if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { \
2904
mul_v3_fl(vmid, 1.0f / (float)n); \
2906
bUnit_AsString(numstr, sizeof(numstr), \
2907
(double)(area * unit->scale_length), \
2908
3, unit->system, B_UNIT_LENGTH, do_split, FALSE); \
2910
BLI_snprintf(numstr, sizeof(numstr), conv_float, area); \
2911
view3d_cached_text_draw_add(vmid, numstr, 0, txt_flag, col); \
2656
#define DRAW_EM_MEASURE_STATS_FACEAREA() \
2657
if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { \
2658
mul_v3_fl(vmid, 1.0f / (float)n); \
2659
if (unit->system) { \
2660
bUnit_AsString(numstr, sizeof(numstr), \
2661
(double)(area * unit->scale_length * unit->scale_length), \
2662
3, unit->system, B_UNIT_AREA, do_split, FALSE); \
2663
view3d_cached_text_draw_add(vmid, numstr, 0, \
2664
/* Metric system uses unicode "squared" sign! */ \
2665
txt_flag ^ V3D_CACHE_TEXT_ASCII, col); \
2668
BLI_snprintf(numstr, sizeof(numstr), conv_float, area); \
2669
view3d_cached_text_draw_add(vmid, numstr, 0, txt_flag, col); \
2914
2673
UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
2951
2710
if (me->drawflag & ME_DRAWEXTRA_FACEANG) {
2712
int is_rad = unit->system_rotation == USER_UNIT_ROT_RADIANS;
2954
2714
UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
2957
for (efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL);
2958
efa; efa = BM_iter_step(&iter))
2963
BM_face_calc_center_bounds(efa, vmid);
2965
for (loop = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa);
2966
loop; loop = BM_iter_step(&liter))
2968
float v1[3], v2[3], v3[3];
2970
copy_v3_v3(v1, loop->prev->v->co);
2971
copy_v3_v3(v2, loop->v->co);
2972
copy_v3_v3(v3, loop->next->v->co);
2975
mul_mat3_m4_v3(ob->obmat, v1);
2976
mul_mat3_m4_v3(ob->obmat, v2);
2977
mul_mat3_m4_v3(ob->obmat, v3);
2980
if ( (BM_elem_flag_test(efa, BM_ELEM_SELECT)) ||
2981
(do_moving && BM_elem_flag_test(loop->v, BM_ELEM_SELECT)))
2983
BLI_snprintf(numstr, sizeof(numstr), "%.3g", RAD2DEGF(angle_v3v3v3(v1, v2, v3)));
2984
interp_v3_v3v3(fvec, vmid, v2, 0.8f);
2985
view3d_cached_text_draw_add(fvec, numstr, 0, txt_flag, col);
2717
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
2718
const int is_face_sel = BM_elem_flag_test(efa, BM_ELEM_SELECT);
2720
if (is_face_sel || do_moving) {
2723
int is_first = TRUE;
2725
BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) {
2726
if (is_face_sel || (do_moving && BM_elem_flag_test(loop->v, BM_ELEM_SELECT))) {
2729
/* lazy init center calc */
2731
BM_face_calc_center_bounds(efa, vmid);
2732
/* Avoid triple matrix multiply every vertex for 'global' */
2734
copy_v3_v3(v1, loop->prev->v->co);
2735
copy_v3_v3(v2, loop->v->co);
2736
mul_mat3_m4_v3(ob->obmat, v1);
2737
mul_mat3_m4_v3(ob->obmat, v2);
2743
copy_v3_v3(v3, loop->next->v->co);
2745
mul_mat3_m4_v3(ob->obmat, v3);
2747
angle = angle_v3v3v3(v1, v2, v3);
2752
angle = angle_v3v3v3(loop->prev->v->co, loop->v->co, loop->next->v->co);
2755
BLI_snprintf(numstr, sizeof(numstr), "%.3f", is_rad ? angle : RAD2DEGF(angle));
2756
interp_v3_v3v3(fvec, vmid, loop->v->co, 0.8f);
2757
view3d_cached_text_draw_add(fvec, numstr, 0, txt_flag, col);
3348
3121
if (!(draw_flags & DRAW_FACE_SELECT)) {
3349
if (base->flag & SELECT)
3350
UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
3352
UI_ThemeColor(TH_WIRE);
3354
if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
3122
if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
3123
if ((dflag & DRAW_CONSTCOLOR) == 0) {
3124
glColor3ubv(ob_wire_col);
3355
3126
dm->drawLooseEdges(dm);
3358
3130
else if (dt == OB_SOLID) {
3359
if (is_obact && ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
3360
/* weight paint in solid mode, special case. focus on making the weights clear
3361
* rather than the shading, this is also forced in wire view */
3362
GPU_enable_material(0, NULL);
3363
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, me->mpoly,
3364
DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
3366
bglPolygonOffset(rv3d->dist, 1.0);
3367
glDepthMask(0); // disable write in zbuffer, selected edge wires show better
3370
glColor4ub(255, 255, 255, 96);
3371
glEnable(GL_LINE_STIPPLE);
3372
glLineStipple(1, 0xAAAA);
3374
dm->drawEdges(dm, 1, 1);
3376
bglPolygonOffset(rv3d->dist, 0.0);
3378
glDisable(GL_LINE_STIPPLE);
3379
glDisable(GL_BLEND);
3381
GPU_disable_material();
3383
/* since we already draw wire as wp guide, don't draw over the top */
3384
draw_wire = OBDRAW_WIRE_OFF;
3386
else if (draw_flags & DRAW_MODIFIERS_PREVIEW) {
3131
if (draw_flags & DRAW_MODIFIERS_PREVIEW) {
3387
3132
/* for object selection draws no shade */
3388
if (flag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
3133
if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
3389
3134
dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
3137
const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f};
3392
3139
/* draw outline */
3393
if ( (v3d->flag & V3D_SELECT_OUTLINE) &&
3394
((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
3395
(base->flag & SELECT) &&
3396
(draw_wire == OBDRAW_WIRE_OFF) &&
3397
(ob->sculpt == NULL))
3140
if ((v3d->flag & V3D_SELECT_OUTLINE) &&
3141
((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
3142
(base->flag & SELECT) &&
3143
(draw_wire == OBDRAW_WIRE_OFF) &&
3144
(ob->sculpt == NULL))
3399
3146
draw_mesh_object_outline(v3d, ob, dm);
3464
3209
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
3466
if (base->flag & SELECT) {
3467
UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
3470
UI_ThemeColor(TH_WIRE);
3472
if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
3211
if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
3212
if ((dflag & DRAW_CONSTCOLOR) == 0) {
3213
glColor3ubv(ob_wire_col);
3473
3215
dm->drawLooseEdges(dm);
3476
3219
else if (dt == OB_PAINT) {
3477
draw_mesh_paint(rv3d, ob, dm, draw_flags);
3480
/* set default draw color back for wire or for draw-extra later on */
3481
if (dt != OB_WIRE) {
3482
if (base->flag & SELECT) {
3483
if (is_obact && ob->flag & OB_FROMGROUP)
3484
UI_ThemeColor(TH_GROUP_ACTIVE);
3485
else if (ob->flag & OB_FROMGROUP)
3486
UI_ThemeColorShade(TH_GROUP_ACTIVE, -16);
3487
else if (flag != DRAW_CONSTCOLOR)
3488
UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
3490
glColor3ub(80, 80, 80);
3493
if (ob->flag & OB_FROMGROUP)
3494
UI_ThemeColor(TH_GROUP);
3496
if (ob->dtx & OB_DRAWWIRE && flag == DRAW_CONSTCOLOR)
3497
glColor3ub(80, 80, 80);
3499
UI_ThemeColor(TH_WIRE);
3503
if (draw_wire != OBDRAW_WIRE_OFF) {
3220
draw_mesh_paint(v3d, rv3d, ob, dm, draw_flags);
3222
/* since we already draw wire as wp guide, don't draw over the top */
3223
draw_wire = OBDRAW_WIRE_OFF;
3226
if ((draw_wire != OBDRAW_WIRE_OFF) && /* draw extra wire */
3227
/* when overriding with render only, don't bother */
3228
(((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0))
3505
3230
/* When using wireframe object draw in particle edit mode
3506
3231
* the mesh gets in the way of seeing the particles, fade the wire color
3507
3232
* with the background. */
3508
if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
3509
float col_wire[4], col_bg[4], col[3];
3511
UI_GetThemeColor3fv(TH_BACK, col_bg);
3512
glGetFloatv(GL_CURRENT_COLOR, col_wire);
3513
interp_v3_v3v3(col, col_bg, col_wire, 0.15);
3234
if ((dflag & DRAW_CONSTCOLOR) == 0) {
3235
if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
3236
ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.15f);
3239
glColor3ubv(ob_wire_col);
3517
3243
/* If drawing wire and drawtype is not OB_WIRE then we are
3619
/* GPU_begin_object_materials checked if this is needed */
3620
if (do_alpha_after) {
3621
if (ob->dtx & OB_DRAWXRAY) {
3622
add_view3d_after(&v3d->afterdraw_xraytransp, base, flag);
3625
add_view3d_after(&v3d->afterdraw_transp, base, flag);
3628
else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) {
3629
/* special case xray+transp when alpha is 1.0, without this the object vanishes */
3630
if (v3d->xray == 0 && v3d->transp == 0) {
3631
add_view3d_after(&v3d->afterdraw_xray, base, flag);
3355
if ((dflag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0 && (v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
3356
/* GPU_begin_object_materials checked if this is needed */
3357
if (do_alpha_after) {
3358
if (ob->dtx & OB_DRAWXRAY) {
3359
ED_view3d_after_add(&v3d->afterdraw_xraytransp, base, dflag);
3362
ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
3365
else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) {
3366
/* special case xray+transp when alpha is 1.0, without this the object vanishes */
3367
if (v3d->xray == 0 && v3d->transp == 0) {
3368
ED_view3d_after_add(&v3d->afterdraw_xray, base, dflag);
3373
if (v3d->flag2 & V3D_BACKFACE_CULLING)
3374
glDisable(GL_CULL_FACE);
3962
3712
dl = lb->first;
3963
if (dl == NULL) return 1;
3965
if (dl->nors == NULL) addnormalsDispList(lb);
3717
if (dl->nors == NULL) BKE_displist_normals_add(lb);
3967
3719
if (draw_glsl_material(scene, ob, v3d, dt)) {
3968
3720
GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
3969
drawDispListsolid(lb, ob, 1);
3721
drawDispListsolid(lb, ob, dflag, ob_wire_col, TRUE);
3970
3722
GPU_end_object_materials();
3973
3725
GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
3974
drawDispListsolid(lb, ob, 0);
3726
drawDispListsolid(lb, ob, dflag, ob_wire_col, FALSE);
3975
3727
GPU_end_object_materials();
3979
retval = drawDispListwire(lb);
3731
return drawDispListwire(lb);
3984
if (is_basis_mball(ob)) {
3736
if (BKE_mball_is_basis(ob)) {
3985
3737
lb = &ob->disp;
3986
if (lb->first == NULL) makeDispListMBall(scene, ob);
3987
if (lb->first == NULL) return 1;
3738
if (lb->first == NULL) BKE_displist_make_mball(scene, ob);
3739
if (lb->first == NULL) {
3991
3745
if (draw_glsl_material(scene, ob, v3d, dt)) {
3992
3746
GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
3993
drawDispListsolid(lb, ob, 1);
3747
drawDispListsolid(lb, ob, dflag, ob_wire_col, TRUE);
3994
3748
GPU_end_object_materials();
3997
3751
GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
3998
drawDispListsolid(lb, ob, 0);
3752
drawDispListsolid(lb, ob, dflag, ob_wire_col, FALSE);
3999
3753
GPU_end_object_materials();
4003
3757
/* MetaBalls use DL_INDEX4 type of DispList */
4004
retval = drawDispListwire(lb);
3758
return drawDispListwire(lb);
3766
static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
3767
const char dt, const short dflag, const unsigned char ob_wire_col[4])
3771
/* backface culling */
3772
if (v3d->flag2 & V3D_BACKFACE_CULLING) {
3773
/* not all displists use same in/out normal direction convention */
3774
glEnable(GL_CULL_FACE);
3775
glCullFace((base->object->type == OB_MBALL) ? GL_BACK : GL_FRONT);
3778
retval = drawDispList_nobackface(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
3780
if (v3d->flag2 & V3D_BACKFACE_CULLING) {
3781
glDisable(GL_CULL_FACE);
5841
5592
if (mb->editelems) {
5842
UI_ThemeColor(TH_WIRE);
5843
if ((G.f & G_PICKSEL) == 0) drawDispList(scene, v3d, rv3d, base, dt);
5593
if ((G.f & G_PICKSEL) == 0) {
5594
unsigned char wire_col[4];
5595
UI_GetThemeColor4ubv(TH_WIRE, wire_col);
5596
glColor3ubv(wire_col);
5598
drawDispList(scene, v3d, rv3d, base, dt, dflag, wire_col);
5844
5600
ml = mb->editelems->first;
5847
if ((base->flag & OB_FROMDUPLI) == 0)
5848
drawDispList(scene, v3d, rv3d, base, dt);
5603
if ((base->flag & OB_FROMDUPLI) == 0) {
5604
drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
5849
5606
ml = mb->elems.first;
5852
if (ml == NULL) return 1;
5854
if (v3d->flag2 & V3D_RENDER_OVERRIDE) return 0;
5856
/* in case solid draw, reset wire colors */
5857
if (ob->flag & SELECT) {
5858
if (ob == OBACT) UI_ThemeColor(TH_ACTIVE);
5859
else UI_ThemeColor(TH_SELECT);
5613
if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
5861
else UI_ThemeColor(TH_WIRE);
5863
5617
invert_m4_m4(imat, rv3d->viewmatob);
5864
5618
normalize_v3(imat[0]);
5865
5619
normalize_v3(imat[1]);
5621
if (mb->editelems == NULL) {
5622
if ((dflag & DRAW_CONSTCOLOR) == 0) {
5623
glColor3ubv(ob_wire_col);
5869
5628
/* draw radius */
5870
5629
if (mb->editelems) {
5871
if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
5872
else cpack(0x3030A0);
5630
if ((dflag & DRAW_CONSTCOLOR) == 0) {
5631
if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
5632
else cpack(0x3030A0);
5874
5635
if (G.f & G_PICKSEL) {
5875
5636
ml->selcol1 = code;
6251
6019
else if (ob->type == OB_MBALL) {
6252
if (is_basis_mball(ob)) {
6020
if (BKE_mball_is_basis(ob)) {
6253
6021
if ((base->flag & OB_FROMDUPLI) == 0)
6254
6022
drawDispListwire(&ob->disp);
6257
6025
else if (ob->type == OB_ARMATURE) {
6258
6026
if (!(ob->mode & OB_MODE_POSE && base == scene->basact))
6259
draw_armature(scene, v3d, ar, base, OB_WIRE, FALSE, TRUE);
6027
draw_armature(scene, v3d, ar, base, OB_WIRE, FALSE, ob_wire_col, TRUE);
6262
6030
glLineWidth(1.0);
6263
6031
glDepthMask(1);
6266
static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob)
6034
static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsigned char ob_wire_col[4])
6268
if (ob != scene->obedit && (ob->flag & SELECT)) {
6270
if (ob->flag & OB_FROMGROUP) UI_ThemeColor(TH_GROUP_ACTIVE);
6271
else UI_ThemeColor(TH_ACTIVE);
6036
if (ELEM4(ob->type, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL)) {
6038
if (scene->obedit == ob) {
6039
UI_ThemeColor(TH_WIRE);
6273
else if (ob->flag & OB_FROMGROUP)
6274
UI_ThemeColorShade(TH_GROUP_ACTIVE, -16);
6276
UI_ThemeColor(TH_SELECT);
6279
if (ob->flag & OB_FROMGROUP)
6280
UI_ThemeColor(TH_GROUP);
6282
if (ob->dtx & OB_DRAWWIRE) {
6283
glColor3ub(80, 80, 80);
6286
UI_ThemeColor(TH_WIRE);
6291
bglPolygonOffset(rv3d->dist, 1.0);
6292
glDepthMask(0); // disable write in zbuffer, selected edge wires show better
6294
if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
6295
Curve *cu = ob->data;
6296
if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
6297
if (ob->type == OB_CURVE)
6298
draw_index_wire = 0;
6300
if (ob->derivedFinal) {
6301
drawCurveDMWired(ob);
6042
glColor3ubv(ob_wire_col);
6045
bglPolygonOffset(rv3d->dist, 1.0);
6046
glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */
6048
if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
6049
Curve *cu = ob->data;
6050
if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
6051
if (ob->type == OB_CURVE)
6052
draw_index_wire = 0;
6054
if (ob->derivedFinal) {
6055
drawCurveDMWired(ob);
6058
drawDispListwire(&ob->disp);
6061
if (ob->type == OB_CURVE)
6062
draw_index_wire = 1;
6065
else if (ob->type == OB_MBALL) {
6066
if (BKE_mball_is_basis(ob)) {
6304
6067
drawDispListwire(&ob->disp);
6307
if (ob->type == OB_CURVE)
6308
draw_index_wire = 1;
6311
else if (ob->type == OB_MBALL) {
6312
if (is_basis_mball(ob)) {
6313
drawDispListwire(&ob->disp);
6318
bglPolygonOffset(rv3d->dist, 0.0);
6072
bglPolygonOffset(rv3d->dist, 0.0);
6321
6076
/* should be called in view space */
6379
6126
glVertex3fv(v);
6382
view3d_cached_text_draw_add(v, axis_str[axis], 0, V3D_CACHE_TEXT_ASCII, tcol);
6129
/* when const color is set wirecolor is NULL - we could get the current color but
6130
* with selection and group instancing its not needed to draw the text */
6131
if ((dflag & DRAW_CONSTCOLOR) == 0) {
6132
view3d_cached_text_draw_add(v, axis_str[axis], 0, V3D_CACHE_TEXT_ASCII, ob_wire_col);
6384
6135
glLineWidth(1.0f);
6385
6136
setlinestyle(0);
6388
/* flag can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET */
6389
void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
6139
static void draw_object_wire_color(Scene *scene, Base *base, unsigned char r_ob_wire_col[4],
6140
const int warning_recursive)
6142
Object *ob = base->object;
6145
/* confusing logic here, there are 2 methods of setting the color
6146
* 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
6148
* note: no theme yet for 'colindex' */
6149
int theme_id = TH_WIRE;
6150
int theme_shade = 0;
6152
if ((scene->obedit == NULL) &&
6153
(G.moving & G_TRANSFORM_OBJ) &&
6154
(base->flag & (SELECT + BA_WAS_SEL)))
6156
theme_id = TH_TRANSFORM;
6159
/* Sets the 'colindex' */
6161
colindex = (base->flag & (SELECT + BA_WAS_SEL)) ? 4 : 3;
6163
else if (warning_recursive == 1) {
6164
if (base->flag & (SELECT + BA_WAS_SEL)) {
6165
colindex = (scene->basact == base) ? 8 : 7;
6171
/* Sets the 'theme_id' or fallback to wire */
6173
if (ob->flag & OB_FROMGROUP) {
6174
if (base->flag & (SELECT + BA_WAS_SEL)) {
6175
/* uses darker active color for non-active + selected*/
6176
theme_id = TH_GROUP_ACTIVE;
6178
if (scene->basact != base) {
6183
theme_id = TH_GROUP;
6187
if (base->flag & (SELECT + BA_WAS_SEL)) {
6188
theme_id = scene->basact == base ? TH_ACTIVE : TH_SELECT;
6191
if (ob->type == OB_LAMP) theme_id = TH_LAMP;
6192
else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
6193
else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
6194
else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
6195
/* fallback to TH_WIRE */
6201
/* finally set the color */
6202
if (colindex == 0) {
6203
if (theme_shade == 0) UI_GetThemeColor3ubv(theme_id, r_ob_wire_col);
6204
else UI_GetThemeColorShade3ubv(theme_id, theme_shade, r_ob_wire_col);
6207
cpack_cpy_3ub(r_ob_wire_col, colortab[colindex]);
6210
/* no reason to use this but some functions take col[4] */
6211
r_ob_wire_col[3] = 255;
6214
static void draw_object_matcap_check(Scene *scene, View3D *v3d, Object *ob)
6216
/* fixed rule, active object draws as matcap */
6218
if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))
6221
if (v3d->defmaterial == NULL) {
6222
extern Material defmaterial;
6224
v3d->defmaterial = MEM_mallocN(sizeof(Material), "matcap material");
6225
*(v3d->defmaterial) = defmaterial;
6226
v3d->defmaterial->gpumaterial.first = v3d->defmaterial->gpumaterial.last = NULL;
6227
v3d->defmaterial->preview = NULL;
6229
/* first time users */
6230
if (v3d->matcap_icon == 0)
6231
v3d->matcap_icon = ICON_MATCAP_01;
6233
if (v3d->defmaterial->preview == NULL)
6234
v3d->defmaterial->preview = UI_icon_to_preview(v3d->matcap_icon);
6236
/* signal to all material checks, gets cleared below */
6237
v3d->flag2 |= V3D_SHOW_SOLID_MATCAP;
6243
* main object drawing function, draws in selection
6244
* \param dflag (draw flag) can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET
6246
void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short dflag)
6391
6248
static int warning_recursive = 0;
6392
6249
ModifierData *md = NULL;
6455
6312
ED_view3d_init_mats_rv3d_gl(ob, rv3d);
6457
6314
/* which wire color */
6458
if ((flag & DRAW_CONSTCOLOR) == 0) {
6459
/* confusing logic here, there are 2 methods of setting the color
6460
* 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
6462
* note: no theme yet for 'colindex' */
6463
int theme_id = TH_WIRE;
6464
int theme_shade = 0;
6466
project_short(ar, ob->obmat[3], &base->sx);
6468
if ((scene->obedit == NULL) &&
6469
(G.moving & G_TRANSFORM_OBJ) &&
6470
(base->flag & (SELECT + BA_WAS_SEL)))
6472
theme_id = TH_TRANSFORM;
6475
/* Sets the 'colindex' */
6477
colindex = (base->flag & (SELECT + BA_WAS_SEL)) ? 4 : 3;
6479
else if (warning_recursive == 1) {
6480
if (base->flag & (SELECT + BA_WAS_SEL)) {
6481
colindex = (scene->basact == base) ? 8 : 7;
6487
/* Sets the 'theme_id' or fallback to wire */
6489
if (ob->flag & OB_FROMGROUP) {
6490
if (base->flag & (SELECT + BA_WAS_SEL)) {
6491
/* uses darker active color for non-active + selected*/
6492
theme_id = TH_GROUP_ACTIVE;
6494
if (scene->basact != base) {
6499
theme_id = TH_GROUP;
6503
if (base->flag & (SELECT + BA_WAS_SEL)) {
6504
theme_id = scene->basact == base ? TH_ACTIVE : TH_SELECT;
6507
if (ob->type == OB_LAMP) theme_id = TH_LAMP;
6508
else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
6509
else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
6510
else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
6511
/* fallback to TH_WIRE */
6517
/* finally set the color */
6518
if (colindex == 0) {
6519
if (theme_shade == 0) UI_ThemeColor(theme_id);
6520
else UI_ThemeColorShade(theme_id, theme_shade);
6523
col = colortab[colindex];
6315
if ((dflag & DRAW_CONSTCOLOR) == 0) {
6317
ED_view3d_project_base(ar, base);
6319
draw_object_wire_color(scene, base, _ob_wire_col, warning_recursive);
6320
ob_wire_col = _ob_wire_col;
6322
glColor3ubv(ob_wire_col);
6528
6325
/* maximum drawtype */
6575
6376
/* bad exception, solve this! otherwise outline shows too late */
6576
6377
if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
6577
6378
/* still needed for curves hidden in other layers. depgraph doesnt handle that yet */
6578
if (ob->disp.first == NULL) makeDispListCurveTypes(scene, ob, 0);
6379
if (ob->disp.first == NULL) BKE_displist_make_curveTypes(scene, ob, 0);
6581
6382
/* draw outline for selected objects, mesh does itself */
6582
6383
if ((v3d->flag & V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && ob->type != OB_MESH) {
6583
if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (flag & DRAW_SCENESET) == 0) {
6584
if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(flag & DRAW_PICKING)) {
6586
drawObjectSelect(scene, v3d, ar, base);
6384
if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (dflag & DRAW_SCENESET) == 0) {
6385
if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(dflag & (DRAW_PICKING | DRAW_CONSTCOLOR))) {
6386
drawObjectSelect(scene, v3d, ar, base, ob_wire_col);
6591
6391
switch (ob->type) {
6593
empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, flag);
6594
if (flag != DRAW_CONSTCOLOR) dtx &= ~OB_DRAWWIRE; // mesh draws wire itself
6393
empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
6394
if (dflag != DRAW_CONSTCOLOR) dtx &= ~OB_DRAWWIRE; // mesh draws wire itself
6599
6399
if (cu->editfont) {
6600
draw_textcurs(cu->editfont->textcurs);
6400
draw_textcurs(rv3d, cu->editfont->textcurs);
6602
6402
if (cu->flag & CU_FAST) {
6603
6403
cpack(0xFFFFFF);
6604
6404
set_inverted_drawing(1);
6605
drawDispList(scene, v3d, rv3d, base, OB_WIRE);
6405
drawDispList(scene, v3d, rv3d, base, OB_WIRE, dflag, ob_wire_col);
6606
6406
set_inverted_drawing(0);
6609
drawDispList(scene, v3d, rv3d, base, dt);
6409
drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6612
6412
if (cu->linewidth != 0.0f) {
6892
// only draw domains
6893
if (smd->domain && smd->domain->fluid) {
6894
if (CFRA < smd->domain->point_cache[0]->startframe) {
6895
/* don't show smoke before simulation starts, this could be made an option in the future */
6897
else if (!smd->domain->wt || !(smd->domain->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
6899
smd->domain->tex = NULL;
6900
GPU_create_smoke(smd, 0);
6901
draw_volume(ar, smd->domain->tex,
6902
smd->domain->p0, smd->domain->p1,
6903
smd->domain->res, smd->domain->dx,
6904
smd->domain->tex_shadow);
6905
GPU_free_smoke(smd);
6691
/* only draw domains */
6693
SmokeDomainSettings *sds = smd->domain;
6694
float p0[3], p1[3], viewnormal[3];
6697
glLoadMatrixf(rv3d->viewmat);
6698
glMultMatrixf(ob->obmat);
6700
/* draw adaptive domain bounds */
6701
if (sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN) {
6702
/* draw domain max bounds */
6703
VECSUBFAC(p0, sds->p0, sds->cell_size, sds->adapt_res);
6704
VECADDFAC(p1, sds->p1, sds->cell_size, sds->adapt_res);
6705
BKE_boundbox_init_from_minmax(&bb, p0, p1);
6708
/* draw base resolution bounds */
6909
float *density = smoke_get_density(smd->domain->fluid);
6911
glLoadMatrixf(rv3d->viewmat);
6912
// glMultMatrixf(ob->obmat);
6914
if (col || (ob->flag & SELECT)) cpack(0xFFFFFF);
6915
glDepthMask(GL_FALSE);
6919
// glPointSize(3.0);
6920
bglBegin(GL_POINTS);
6922
for (x = 0; x < smd->domain->res[0]; x++) {
6923
for (y = 0; y < smd->domain->res[1]; y++) {
6924
for (z = 0; z < smd->domain->res[2]; z++) {
6926
int index = smoke_get_index(x, smd->domain->res[0], y, smd->domain->res[1], z);
6928
if (density[index] > FLT_EPSILON) {
6930
copy_v3_v3(tmp, smd->domain->p0);
6931
tmp[0] += smd->domain->dx * x + smd->domain->dx * 0.5;
6932
tmp[1] += smd->domain->dx * y + smd->domain->dx * 0.5;
6933
tmp[2] += smd->domain->dx * z + smd->domain->dx * 0.5;
6934
color[0] = color[1] = color[2] = density[index];
6945
glMultMatrixf(ob->obmat);
6946
glDisable(GL_BLEND);
6947
glDepthMask(GL_TRUE);
6948
if (col) cpack(col);
6710
BKE_boundbox_init_from_minmax(&bb, sds->p0, sds->p1);
6951
else if (smd->domain->wt && (smd->domain->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
6952
smd->domain->tex = NULL;
6953
GPU_create_smoke(smd, 1);
6954
draw_volume(ar, smd->domain->tex,
6955
smd->domain->p0, smd->domain->p1,
6956
smd->domain->res_wt, smd->domain->dx_wt,
6957
smd->domain->tex_shadow);
6958
GPU_free_smoke(smd);
6715
/* don't show smoke before simulation starts, this could be made an option in the future */
6716
if (smd->domain->fluid && CFRA >= smd->domain->point_cache[0]->startframe) {
6719
copy_v3_v3(viewnormal, rv3d->viewinv[2]);
6720
mul_mat3_m4_v3(ob->imat, viewnormal);
6721
normalize_v3(viewnormal);
6723
/* set dynamic boundaries to draw the volume */
6724
p0[0] = sds->p0[0] + sds->cell_size[0] * sds->res_min[0] + sds->obj_shift_f[0];
6725
p0[1] = sds->p0[1] + sds->cell_size[1] * sds->res_min[1] + sds->obj_shift_f[1];
6726
p0[2] = sds->p0[2] + sds->cell_size[2] * sds->res_min[2] + sds->obj_shift_f[2];
6727
p1[0] = sds->p0[0] + sds->cell_size[0] * sds->res_max[0] + sds->obj_shift_f[0];
6728
p1[1] = sds->p0[1] + sds->cell_size[1] * sds->res_max[1] + sds->obj_shift_f[1];
6729
p1[2] = sds->p0[2] + sds->cell_size[2] * sds->res_max[2] + sds->obj_shift_f[2];
6731
/* scale cube to global space to equalize volume slicing on all axises
6732
* (its scaled back before drawing) */
6733
mul_v3_v3(p0, ob->size);
6734
mul_v3_v3(p1, ob->size);
6736
if (!sds->wt || !(sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
6737
smd->domain->tex = NULL;
6738
GPU_create_smoke(smd, 0);
6739
draw_smoke_volume(sds, ob, sds->tex,
6741
sds->res, sds->dx, sds->scale * sds->maxres,
6742
viewnormal, sds->tex_shadow, sds->tex_flame);
6743
GPU_free_smoke(smd);
6745
else if (sds->wt && (sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
6747
GPU_create_smoke(smd, 1);
6748
draw_smoke_volume(sds, ob, sds->tex,
6750
sds->res_wt, sds->dx, sds->scale * sds->maxres,
6751
viewnormal, sds->tex_shadow, sds->tex_flame);
6752
GPU_free_smoke(smd);
6755
/* smoke debug render */
6756
#ifdef SMOKE_DEBUG_VELOCITY
6757
draw_smoke_velocity(smd->domain, ob);
6759
#ifdef SMOKE_DEBUG_HEAT
6760
draw_smoke_heat(smd->domain, ob);
6985
6789
if (dtx & OB_AXIS) {
6986
6790
drawaxes(1.0f, OB_ARROWS);
6988
if (dtx & OB_BOUNDBOX) {
6792
if (dtx & OB_DRAWBOUNDOX) {
6989
6793
draw_bounding_volume(scene, ob, ob->boundtype);
6991
6795
if (dtx & OB_TEXSPACE) {
6992
6796
drawtexspace(ob);
6994
6798
if (dtx & OB_DRAWNAME) {
6995
/* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
6799
/* patch for several 3d cards (IBM mostly) that crash on GL_SELECT with text drawing */
6996
6800
/* but, we also don't draw names for sets or duplicators */
6998
float zero[3] = {0, 0, 0};
7000
unsigned char tcol[4];
7001
glGetFloatv(GL_CURRENT_COLOR, curcol);
7002
rgb_float_to_uchar(tcol, curcol);
7004
view3d_cached_text_draw_add(zero, ob->id.name + 2, 10, 0, tcol);
6802
const float zero[3] = {0, 0, 0};
6803
view3d_cached_text_draw_add(zero, ob->id.name + 2, 10, 0, ob_wire_col);
7007
6806
/*if (dtx & OB_DRAWIMAGE) drawDispListwire(&ob->disp);*/
7008
6807
if ((dtx & OB_DRAWWIRE) && dt >= OB_SOLID) {
7009
drawWireExtra(scene, rv3d, ob);
6808
if ((dflag & DRAW_CONSTCOLOR) == 0) {
6809
draw_wire_extra(scene, rv3d, ob, ob_wire_col);
7014
6815
if (dt <= OB_SOLID && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
7015
if ((ob->gameflag & OB_DYNAMIC) ||
7016
((ob->gameflag & OB_BOUNDS) && (ob->boundtype == OB_BOUND_SPHERE)))
6816
if (((ob->gameflag & OB_DYNAMIC) &&
6817
!ELEM(ob->collision_boundtype, OB_BOUND_TRIANGLE_MESH, OB_BOUND_CONVEX_HULL)) ||
6819
((ob->gameflag & OB_BOUNDS) &&
6820
(ob->boundtype == OB_BOUND_SPHERE)))
7018
6822
float imat[4][4], vec[3] = {0.0f, 0.0f, 0.0f};
7320
7126
return DM_DRAW_OPTION_SKIP;
7323
static void bbs_mesh_solid(Scene *scene, Object *ob)
7130
static void bbs_mesh_solid_verts(Scene *scene, Object *ob)
7132
Mesh *me = ob->data;
7133
DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
7134
glColor3ub(0, 0, 0);
7136
dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, GPU_enable_material, NULL, me, 0);
7138
bbs_obmode_mesh_verts(ob, dm, 1);
7139
bm_vertoffs = me->totvert + 1;
7143
static void bbs_mesh_solid_faces(Scene *scene, Object *ob)
7325
7145
DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
7326
7146
Mesh *me = (Mesh *)ob->data;
7328
7148
glColor3ub(0, 0, 0);
7330
if ((me->editflag & ME_EDIT_PAINT_MASK))
7150
if ((me->editflag & ME_EDIT_PAINT_FACE_SEL))
7331
7151
dm->drawMappedFaces(dm, bbs_mesh_solid_hide__setDrawOpts, GPU_enable_material, NULL, me, 0);
7333
7153
dm->drawMappedFaces(dm, bbs_mesh_solid__setDrawOpts, GPU_enable_material, NULL, me, 0);