Edit Mesh overlay: pack normals with face centers.

Needed for face normals.
This commit is contained in:
2017-03-02 15:03:40 +01:00
parent 0b6fa1a0fb
commit 561d11c5e6
2 changed files with 25 additions and 8 deletions

View File

@@ -334,13 +334,14 @@ static void mesh_render_data_edge_verts_indices_get(const MeshRenderData *mrdata
}
}
static void mesh_render_data_poly_center_select_get(MeshRenderData *mrdata, const int poly, float center[3], bool *selected)
static void mesh_render_data_pnors_pcenter_select_get(MeshRenderData *mrdata, const int poly, float pnors[3], float center[3], bool *selected)
{
BLI_assert(mrdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
if (mrdata->edit_bmesh) {
const BMFace *bf = BM_face_at_index(mrdata->edit_bmesh->bm, poly);
BM_face_calc_center_mean(bf, center);
BM_face_calc_normal(bf, pnors);
*selected = (BM_elem_flag_test(bf, BM_ELEM_SELECT) != 0) ? true : false;
}
else {
@@ -349,6 +350,7 @@ static void mesh_render_data_poly_center_select_get(MeshRenderData *mrdata, cons
const MLoop *mloop = mrdata->mloop + mpoly->loopstart;
BKE_mesh_calc_poly_center(mpoly, mloop, mvert, center);
BKE_mesh_calc_poly_normal(mpoly, mloop, mvert, pnors);
*selected = false; /* No selection if not in edit mode */
}
@@ -1197,7 +1199,11 @@ Batch *BKE_mesh_batch_cache_get_overlay_facedots(Mesh *me)
if (format.attrib_ct == 0) {
/* initialize vertex format */
pos_id = add_attrib(&format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
data_id = add_attrib(&format, "data", GL_INT, 1, KEEP_INT);
#if USE_10_10_10
data_id = add_attrib(&format, "norAndFlag", COMP_I10, 4, NORMALIZE_INT_TO_FLOAT);
#else
data_id = add_attrib(&format, "norAndFlag", GL_FLOAT, 4, KEEP_FLOAT);
#endif
}
const int poly_ct = mesh_render_data_polys_num_get(mrdata);
@@ -1206,11 +1212,22 @@ Batch *BKE_mesh_batch_cache_get_overlay_facedots(Mesh *me)
VertexBuffer_allocate_data(vbo, poly_ct);
for (int i = 0; i < poly_ct; ++i) {
float poly_center[3];
float pcenter[3], pnor[3];
int selected = 0;
mesh_render_data_poly_center_select_get(mrdata, i, poly_center, (bool *)&selected);
setAttrib(vbo, pos_id, i, poly_center);
setAttrib(vbo, data_id, i, &selected);
mesh_render_data_pnors_pcenter_select_get(mrdata, i, pnor, pcenter, (bool *)&selected);
#if USE_10_10_10
PackedNormal nor = { .x = 0, .y = 0, .z = -511 };
nor = convert_i10_v3(pnor);
nor.w = selected;
setAttrib(vbo, data_id, i, &nor);
#else
float nor[4] = {pnor[0], pnor[1], pnor[2], (float)selected};
setAttrib(vbo, data_id, i, nor);
#endif
setAttrib(vbo, pos_id, i, pcenter);
}
cache->overlay_facedots = Batch_create(GL_POINTS, vbo, NULL);

View File

@@ -45,7 +45,7 @@ layout(std140) uniform globalsBlock {
uniform mat4 ModelViewProjectionMatrix;
in vec3 pos;
in int data;
in vec4 norAndFlag;
flat out int isSelected;
@@ -53,5 +53,5 @@ void main()
{
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
gl_PointSize = sizeFaceDot;
isSelected = data;
isSelected = int(norAndFlag.w);
}