Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/modes/edit_mesh_mode.c
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| extern char datatoc_edit_mesh_overlay_common_lib_glsl[]; | extern char datatoc_edit_mesh_overlay_common_lib_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_frag_glsl[]; | extern char datatoc_edit_mesh_overlay_frag_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_vert_glsl[]; | extern char datatoc_edit_mesh_overlay_vert_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_geom_glsl[]; | extern char datatoc_edit_mesh_overlay_geom_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_mix_frag_glsl[]; | extern char datatoc_edit_mesh_overlay_mix_frag_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_facefill_vert_glsl[]; | extern char datatoc_edit_mesh_overlay_facefill_vert_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_facefill_frag_glsl[]; | extern char datatoc_edit_mesh_overlay_facefill_frag_glsl[]; | ||||
| extern char datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl[]; | |||||
| extern char datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl[]; | |||||
| extern char datatoc_edit_normals_vert_glsl[]; | extern char datatoc_edit_normals_vert_glsl[]; | ||||
| extern char datatoc_edit_normals_geom_glsl[]; | extern char datatoc_edit_normals_geom_glsl[]; | ||||
| extern char datatoc_common_globals_lib_glsl[]; | extern char datatoc_common_globals_lib_glsl[]; | ||||
| extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; | extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; | ||||
| extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[]; | extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[]; | ||||
| extern char datatoc_gpu_shader_flat_color_frag_glsl[]; | extern char datatoc_gpu_shader_flat_color_frag_glsl[]; | ||||
| extern char datatoc_gpu_shader_point_varying_color_frag_glsl[]; | extern char datatoc_gpu_shader_point_varying_color_frag_glsl[]; | ||||
| /* *********** LISTS *********** */ | /* *********** LISTS *********** */ | ||||
| typedef struct EDIT_MESH_PassList { | typedef struct EDIT_MESH_PassList { | ||||
| struct DRWPass *weight_faces; | struct DRWPass *weight_faces; | ||||
| struct DRWPass *depth_hidden_wire; | struct DRWPass *depth_hidden_wire; | ||||
| struct DRWPass *depth_hidden_wire_in_front; | struct DRWPass *depth_hidden_wire_in_front; | ||||
| struct DRWPass *edit_face_overlay; | struct DRWPass *edit_face_overlay; | ||||
| struct DRWPass *edit_face_overlay_in_front; | struct DRWPass *edit_face_overlay_in_front; | ||||
| struct DRWPass *edit_face_in_front; | struct DRWPass *edit_face_in_front; | ||||
| struct DRWPass *edit_face_occluded; | struct DRWPass *edit_face_occluded; | ||||
| struct DRWPass *mix_occlude; | struct DRWPass *mix_occlude; | ||||
| struct DRWPass *facefill_occlude; | struct DRWPass *facefill_occlude; | ||||
| struct DRWPass *mesh_analysis_pass; | |||||
| struct DRWPass *normals; | struct DRWPass *normals; | ||||
| } EDIT_MESH_PassList; | } EDIT_MESH_PassList; | ||||
| typedef struct EDIT_MESH_FramebufferList { | typedef struct EDIT_MESH_FramebufferList { | ||||
| struct GPUFrameBuffer *occlude_wire_fb; | struct GPUFrameBuffer *occlude_wire_fb; | ||||
| struct GPUFrameBuffer *ghost_wire_fb; | struct GPUFrameBuffer *ghost_wire_fb; | ||||
| } EDIT_MESH_FramebufferList; | } EDIT_MESH_FramebufferList; | ||||
| Show All 24 Lines | typedef struct EDIT_MESH_Shaders { | ||||
| GPUShader *overlay_facedot; | GPUShader *overlay_facedot; | ||||
| GPUShader *overlay_mix; | GPUShader *overlay_mix; | ||||
| GPUShader *overlay_facefill; | GPUShader *overlay_facefill; | ||||
| GPUShader *normals_face; | GPUShader *normals_face; | ||||
| GPUShader *normals_loop; | GPUShader *normals_loop; | ||||
| GPUShader *normals; | GPUShader *normals; | ||||
| GPUShader *depth; | GPUShader *depth; | ||||
| /* Mesh analysis shader */ | |||||
| GPUShader *mesh_analysis_face; | |||||
| GPUShader *mesh_analysis_vertex; | |||||
| } EDIT_MESH_Shaders; | } EDIT_MESH_Shaders; | ||||
| /* *********** STATIC *********** */ | /* *********** STATIC *********** */ | ||||
| static struct { | static struct { | ||||
| EDIT_MESH_Shaders sh_data[GPU_SHADER_CFG_LEN]; | EDIT_MESH_Shaders sh_data[GPU_SHADER_CFG_LEN]; | ||||
| /* temp buffer texture */ | /* temp buffer texture */ | ||||
| struct GPUTexture *occlude_wire_depth_tx; | struct GPUTexture *occlude_wire_depth_tx; | ||||
| Show All 18 Lines | typedef struct EDIT_MESH_PrivateData { | ||||
| DRWShadingGroup *vert_shgrp_in_front; | DRWShadingGroup *vert_shgrp_in_front; | ||||
| DRWShadingGroup *edge_shgrp_in_front; | DRWShadingGroup *edge_shgrp_in_front; | ||||
| DRWShadingGroup *face_shgrp_in_front; | DRWShadingGroup *face_shgrp_in_front; | ||||
| DRWShadingGroup *face_cage_shgrp_in_front; | DRWShadingGroup *face_cage_shgrp_in_front; | ||||
| DRWShadingGroup *facedot_shgrp_in_front; | DRWShadingGroup *facedot_shgrp_in_front; | ||||
| DRWShadingGroup *facefill_occluded_shgrp; | DRWShadingGroup *facefill_occluded_shgrp; | ||||
| DRWShadingGroup *mesh_analysis_shgrp; | |||||
| int data_mask[4]; | int data_mask[4]; | ||||
| int ghost_ob; | int ghost_ob; | ||||
| int edit_ob; | int edit_ob; | ||||
| bool do_zbufclip; | bool do_zbufclip; | ||||
| bool do_faces; | bool do_faces; | ||||
| bool do_edges; | bool do_edges; | ||||
| } EDIT_MESH_PrivateData; /* Transient data */ | } EDIT_MESH_PrivateData; /* Transient data */ | ||||
| ▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | if (!sh_data->weight_face) { | ||||
| sh_data->normals = GPU_shader_create_from_arrays({ | sh_data->normals = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_vert_glsl, NULL}, | .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_vert_glsl, NULL}, | ||||
| .geom = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_geom_glsl, NULL}, | .geom = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_geom_glsl, NULL}, | ||||
| .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL}, | .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL}, | ||||
| .defs = (const char *[]){sh_cfg_data->def, NULL}, | .defs = (const char *[]){sh_cfg_data->def, NULL}, | ||||
| }); | }); | ||||
| /* Mesh Analysis */ | |||||
| sh_data->mesh_analysis_face = GPU_shader_create_from_arrays({ | |||||
| .vert = (const char *[]){sh_cfg_data->lib, | |||||
| datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl, | |||||
| NULL}, | |||||
| .frag = (const char *[]){datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl, NULL}, | |||||
| .defs = (const char *[]){sh_cfg_data->def, "#define FACE_COLOR\n", NULL}, | |||||
| }); | |||||
| sh_data->mesh_analysis_vertex = GPU_shader_create_from_arrays({ | |||||
| .vert = (const char *[]){sh_cfg_data->lib, | |||||
| datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl, | |||||
| NULL}, | |||||
| .frag = (const char *[]){datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl, NULL}, | |||||
| .defs = (const char *[]){sh_cfg_data->def, "#define VERTEX_COLOR\n", NULL}, | |||||
| }); | |||||
| sh_data->depth = DRW_shader_create_3d_depth_only(draw_ctx->sh_cfg); | sh_data->depth = DRW_shader_create_3d_depth_only(draw_ctx->sh_cfg); | ||||
| } | } | ||||
| } | } | ||||
| static DRWPass *edit_mesh_create_overlay_pass(float *face_alpha, | static DRWPass *edit_mesh_create_overlay_pass(float *face_alpha, | ||||
| int *data_mask, | int *data_mask, | ||||
| bool do_edges, | bool do_edges, | ||||
| DRWState statemod, | DRWState statemod, | ||||
| ▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | if (draw_ctx->object_edit->type == OB_MESH) { | ||||
| stl->g_data->lnormals_shgrp = DRW_shgroup_create(sh_data->normals_loop, psl->normals); | stl->g_data->lnormals_shgrp = DRW_shgroup_create(sh_data->normals_loop, psl->normals); | ||||
| DRW_shgroup_uniform_float(stl->g_data->lnormals_shgrp, "normalSize", &size_normal, 1); | DRW_shgroup_uniform_float(stl->g_data->lnormals_shgrp, "normalSize", &size_normal, 1); | ||||
| DRW_shgroup_uniform_vec4(stl->g_data->lnormals_shgrp, "color", G_draw.block.colorLNormal, 1); | DRW_shgroup_uniform_vec4(stl->g_data->lnormals_shgrp, "color", G_draw.block.colorLNormal, 1); | ||||
| if (rv3d->rflag & RV3D_CLIPPING) { | if (rv3d->rflag & RV3D_CLIPPING) { | ||||
| DRW_shgroup_world_clip_planes_from_rv3d(stl->g_data->lnormals_shgrp, rv3d); | DRW_shgroup_world_clip_planes_from_rv3d(stl->g_data->lnormals_shgrp, rv3d); | ||||
| } | } | ||||
| } | } | ||||
| { | |||||
| /* Mesh Analysis Pass */ | |||||
| DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND; | |||||
| psl->mesh_analysis_pass = DRW_pass_create("Mesh Analysis", state); | |||||
| const bool is_vertex_color = scene->toolsettings->statvis.type == SCE_STATVIS_SHARP; | |||||
| stl->g_data->mesh_analysis_shgrp = DRW_shgroup_create( | |||||
jbakker: Remove comment | |||||
| is_vertex_color ? sh_data->mesh_analysis_vertex : sh_data->mesh_analysis_face, | |||||
| psl->mesh_analysis_pass); | |||||
| if (rv3d->rflag & RV3D_CLIPPING) { | |||||
| DRW_shgroup_world_clip_planes_from_rv3d(stl->g_data->mesh_analysis_shgrp, rv3d); | |||||
| } | |||||
| } | |||||
| /* For in front option */ | /* For in front option */ | ||||
| psl->edit_face_overlay_in_front = edit_mesh_create_overlay_pass( | psl->edit_face_overlay_in_front = edit_mesh_create_overlay_pass( | ||||
| &face_mod, | &face_mod, | ||||
| stl->g_data->data_mask, | stl->g_data->data_mask, | ||||
| stl->g_data->do_edges, | stl->g_data->do_edges, | ||||
| DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND, | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND, | ||||
| &stl->g_data->face_shgrp_in_front, | &stl->g_data->face_shgrp_in_front, | ||||
| &stl->g_data->face_cage_shgrp_in_front, | &stl->g_data->face_cage_shgrp_in_front, | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | static void EDIT_MESH_cache_populate(void *vedata, Object *ob) | ||||
| ToolSettings *tsettings = scene->toolsettings; | ToolSettings *tsettings = scene->toolsettings; | ||||
| struct GPUBatch *geom; | struct GPUBatch *geom; | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode(ob)) { | if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode(ob)) { | ||||
| bool do_in_front = (ob->dtx & OB_DRAWXRAY) != 0; | bool do_in_front = (ob->dtx & OB_DRAWXRAY) != 0; | ||||
| bool do_occlude_wire = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0; | bool do_occlude_wire = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0; | ||||
| bool do_show_weight = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_WEIGHT) != 0; | bool do_show_weight = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_WEIGHT) != 0; | ||||
| bool do_show_mesh_analysis = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_STATVIS) != 0; | |||||
| bool fnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_NORMALS) != 0; | bool fnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_NORMALS) != 0; | ||||
| bool vnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_VERT_NORMALS) != 0; | bool vnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_VERT_NORMALS) != 0; | ||||
| bool lnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_LOOP_NORMALS) != 0; | bool lnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_LOOP_NORMALS) != 0; | ||||
| bool show_face_dots = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) != 0; | bool show_face_dots = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) != 0; | ||||
| if (g_data->do_faces == false && g_data->do_edges == false && | if (g_data->do_faces == false && g_data->do_edges == false && | ||||
| (tsettings->selectmode & SCE_SELECT_FACE)) { | (tsettings->selectmode & SCE_SELECT_FACE)) { | ||||
| Show All 12 Lines | if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode(ob)) { | ||||
| face_mod = 0.0f; | face_mod = 0.0f; | ||||
| } | } | ||||
| if (do_show_weight) { | if (do_show_weight) { | ||||
| geom = DRW_cache_mesh_surface_weights_get(ob); | geom = DRW_cache_mesh_surface_weights_get(ob); | ||||
| DRW_shgroup_call_add(g_data->fweights_shgrp, geom, ob->obmat); | DRW_shgroup_call_add(g_data->fweights_shgrp, geom, ob->obmat); | ||||
| } | } | ||||
| if (do_show_mesh_analysis) { | |||||
| Mesh *me = (Mesh *)ob->data; | |||||
Done Inline Actionsremove comment jbakker: remove comment | |||||
| BMEditMesh *embm = me->edit_mesh; | |||||
| const bool is_original = embm->mesh_eval_final && \ | |||||
| (embm->mesh_eval_final->runtime.is_original == true); | |||||
| if (is_original) { | |||||
| geom = DRW_cache_mesh_surface_mesh_analysis_get(ob); | |||||
| if (geom) { | |||||
| DRW_shgroup_call_add(g_data->mesh_analysis_shgrp, geom, ob->obmat); | |||||
| } | |||||
| } | |||||
| } | |||||
| if (do_occlude_wire || do_in_front) { | if (do_occlude_wire || do_in_front) { | ||||
| geom = DRW_cache_mesh_surface_get(ob); | geom = DRW_cache_mesh_surface_get(ob); | ||||
| DRW_shgroup_call_add(do_in_front ? g_data->depth_shgrp_hidden_wire_in_front : | DRW_shgroup_call_add(do_in_front ? g_data->depth_shgrp_hidden_wire_in_front : | ||||
| g_data->depth_shgrp_hidden_wire, | g_data->depth_shgrp_hidden_wire, | ||||
| geom, | geom, | ||||
| ob->obmat); | ob->obmat); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| static void EDIT_MESH_draw_scene(void *vedata) | static void EDIT_MESH_draw_scene(void *vedata) | ||||
| { | { | ||||
| EDIT_MESH_PassList *psl = ((EDIT_MESH_Data *)vedata)->psl; | EDIT_MESH_PassList *psl = ((EDIT_MESH_Data *)vedata)->psl; | ||||
| EDIT_MESH_StorageList *stl = ((EDIT_MESH_Data *)vedata)->stl; | EDIT_MESH_StorageList *stl = ((EDIT_MESH_Data *)vedata)->stl; | ||||
| EDIT_MESH_FramebufferList *fbl = ((EDIT_MESH_Data *)vedata)->fbl; | EDIT_MESH_FramebufferList *fbl = ((EDIT_MESH_Data *)vedata)->fbl; | ||||
| DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | ||||
| DRW_draw_pass(psl->weight_faces); | DRW_draw_pass(psl->weight_faces); | ||||
| DRW_draw_pass(psl->mesh_analysis_pass); | |||||
| DRW_draw_pass(psl->depth_hidden_wire); | DRW_draw_pass(psl->depth_hidden_wire); | ||||
| if (stl->g_data->do_zbufclip) { | if (stl->g_data->do_zbufclip) { | ||||
| float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | ||||
| DRW_draw_pass(psl->depth_hidden_wire_in_front); | DRW_draw_pass(psl->depth_hidden_wire_in_front); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||
Remove comment