Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <j.bakker@atmind.nl>2019-04-18 09:00:59 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2019-04-25 12:25:22 +0300
commit38a0896f154162cb07cd20b6189c080046a050f5 (patch)
treedb94e40c16bd81e3b397809c63753b3470bf67b5 /source/blender/draw/intern/draw_cache_impl_mesh.c
parent486d9356bab3498c528812baaee3d515e4fa873c (diff)
Overlay: Mesh Analysis
Enabling the drawing of the mesh analysis overlay. Currently the settings are part of the scene toolsettings. What makes sense, for 3d printing, but does not fit well with the per viewport blender 2.80 overlays. Reviewers: brecht, fclem Differential Revision: https://developer.blender.org/D4707
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_mesh.c')
-rw-r--r--source/blender/draw/intern/draw_cache_impl_mesh.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index dcc249e90cf..b2e960f461f 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -1911,6 +1911,7 @@ typedef struct MeshBatchCache {
GPUVertBuf *loop_data;
GPUVertBuf *loop_lnor;
GPUVertBuf *facedots_pos_nor_data;
+ GPUVertBuf *loop_mesh_analysis;
/* UV data without modifier applied.
* Vertex count is always the one of the cage. */
GPUVertBuf *loop_uv;
@@ -1958,6 +1959,7 @@ typedef struct MeshBatchCache {
GPUBatch *edit_edges;
GPUBatch *edit_lnor;
GPUBatch *edit_facedots;
+ GPUBatch *edit_mesh_analysis;
/* Edit UVs */
GPUBatch *edituv_faces_strech_area;
GPUBatch *edituv_faces_strech_angle;
@@ -2169,6 +2171,7 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
GPU_BATCH_DISCARD_SAFE(cache->batch.edit_vertices);
GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges);
GPU_BATCH_DISCARD_SAFE(cache->batch.edit_facedots);
+ GPU_BATCH_DISCARD_SAFE(cache->batch.edit_mesh_analysis);
/* Paint mode selection */
/* TODO only do that in paint mode. */
GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_pos_nor);
@@ -3383,6 +3386,72 @@ static void mesh_create_edit_facedots(MeshRenderData *rdata, GPUVertBuf *vbo_fac
}
}
+static void mesh_create_edit_mesh_analysis(MeshRenderData *rdata,
+ GPUVertBuf *vbo_mesh_analysis)
+{
+ const MeshStatVis *mesh_stat_vis = &rdata->toolsettings->statvis;
+
+ int mesh_analysis_len_used = 0;
+
+ const uint loops_len = mesh_render_data_loops_len_get(rdata);
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter_efa, iter_loop;
+ BMFace *efa;
+ BMLoop *loop;
+
+ static struct {
+ uint weight;
+ } attr_id;
+ static GPUVertFormat mesh_analysis_format = {0};
+ if (mesh_analysis_format.attr_len == 0) {
+ attr_id.weight = GPU_vertformat_attr_add(
+ &mesh_analysis_format, "weight_color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ /* TODO(jbakker): Maybe move data generation to mesh_render_data_create() */
+ BKE_editmesh_statvis_calc(rdata->edit_bmesh, rdata->edit_data, mesh_stat_vis);
+
+ if (DRW_TEST_ASSIGN_VBO(vbo_mesh_analysis)) {
+ GPU_vertbuf_init_with_format(vbo_mesh_analysis, &mesh_analysis_format);
+ GPU_vertbuf_data_alloc(vbo_mesh_analysis, loops_len);
+ }
+
+ const bool is_vertex_data = mesh_stat_vis->type == SCE_STATVIS_SHARP;
+ if (is_vertex_data) {
+ BM_ITER_MESH (efa, &iter_efa, bm, BM_FACES_OF_MESH) {
+ BM_ITER_ELEM (loop, &iter_loop, efa, BM_LOOPS_OF_FACE) {
+ uint vertex_index = BM_elem_index_get(loop->v);
+ GPU_vertbuf_attr_set(vbo_mesh_analysis,
+ attr_id.weight,
+ mesh_analysis_len_used,
+ &rdata->edit_bmesh->derivedVertColor[vertex_index]);
+ mesh_analysis_len_used += 1;
+ }
+ }
+ }
+ else {
+ uint face_index;
+ BM_ITER_MESH_INDEX (efa, &iter_efa, bm, BM_FACES_OF_MESH, face_index) {
+ BM_ITER_ELEM (loop, &iter_loop, efa, BM_LOOPS_OF_FACE) {
+ GPU_vertbuf_attr_set(vbo_mesh_analysis,
+ attr_id.weight,
+ mesh_analysis_len_used,
+ &rdata->edit_bmesh->derivedFaceColor[face_index]);
+ mesh_analysis_len_used += 1;
+ }
+ }
+ }
+
+ // Free temp data in edit bmesh
+ BKE_editmesh_color_free(rdata->edit_bmesh);
+
+ /* Resize & Finish */
+ if (mesh_analysis_len_used != loops_len) {
+ if (vbo_mesh_analysis != NULL) {
+ GPU_vertbuf_data_resize(vbo_mesh_analysis, mesh_analysis_len_used);
+ }
+ }
+}
/* Indices */
#define NO_EDGE INT_MAX
@@ -4195,6 +4264,12 @@ GPUBatch *DRW_mesh_batch_cache_get_wireframes_face(Mesh *me)
return DRW_batch_request(&cache->batch.wire_edges);
}
+GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+ return DRW_batch_request(&cache->batch.edit_mesh_analysis);
+}
+
GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me,
struct GPUMaterial **gpumat_array,
uint gpumat_array_len,
@@ -4898,6 +4973,13 @@ void DRW_mesh_batch_cache_create_requested(
DRW_vbo_request(cache->batch.edit_facedots, &cache->edit.facedots_pos_nor_data);
}
+ /* Mesh Analysis */
+ if (DRW_batch_requested(cache->batch.edit_mesh_analysis, GPU_PRIM_TRIS)) {
+ DRW_ibo_request(cache->batch.edit_mesh_analysis, &cache->ibo.edit_loops_tris);
+ DRW_vbo_request(cache->batch.edit_mesh_analysis, &cache->edit.loop_pos_nor);
+ DRW_vbo_request(cache->batch.edit_mesh_analysis, &cache->edit.loop_mesh_analysis);
+ }
+
/* Edit UV */
if (DRW_batch_requested(cache->batch.edituv_faces, GPU_PRIM_TRI_FAN)) {
DRW_ibo_request(cache->batch.edituv_faces, &cache->ibo.edituv_loops_tri_fans);
@@ -5050,6 +5132,9 @@ void DRW_mesh_batch_cache_create_requested(
cache->edit.facedots_pos_nor_data,
MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY |
MR_DATATYPE_OVERLAY);
+ DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag,
+ cache->edit.loop_mesh_analysis,
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY);
DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.loop_stretch_angle, combined_edit_flag);
DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.loop_stretch_area, combined_edit_flag);
DRW_ADD_FLAG_FROM_VBO_REQUEST(
@@ -5177,6 +5262,9 @@ void DRW_mesh_batch_cache_create_requested(
if (DRW_ibo_requested(cache->ibo.edit_loops_tris)) {
mesh_create_edit_loops_tris(rdata, cache->ibo.edit_loops_tris);
}
+ if (DRW_vbo_requested(cache->edit.loop_mesh_analysis)) {
+ mesh_create_edit_mesh_analysis(rdata, cache->edit.loop_mesh_analysis);
+ }
/* UV editor */
/**