Blender V4.3
overlay_metaball.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "DRW_render.hh"
10
11#include "DNA_meta_types.h"
12
13#include "BKE_object.hh"
14#include "BKE_object_types.hh"
15
17
18#include "ED_mball.hh"
19
20#include "overlay_private.hh"
21
23{
24 OVERLAY_PassList *psl = vedata->psl;
25 OVERLAY_PrivateData *pd = vedata->stl->pd;
26
28
29#define BUF_INSTANCE DRW_shgroup_call_buffer_instance
30
31 for (int i = 0; i < 2; i++) {
32 DRWState infront_state = (DRW_state_is_select() && (i == 1)) ? DRW_STATE_IN_FRONT_SELECT :
33 DRWState(0);
35 DRW_PASS_CREATE(psl->metaball_ps[i], state | pd->clipping_state | infront_state);
36
37 /* Reuse armature shader as it's perfect to outline ellipsoids. */
41 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
43 }
44}
45
47 BoneInstanceData *data, Object *ob, const float *pos, const float radius, const float color[4])
48{
49 /* Bone point radius is 0.05. Compensate for that. */
50 mul_v3_v3fl(data->mat[0], ob->object_to_world().ptr()[0], radius / 0.05f);
51 mul_v3_v3fl(data->mat[1], ob->object_to_world().ptr()[1], radius / 0.05f);
52 mul_v3_v3fl(data->mat[2], ob->object_to_world().ptr()[2], radius / 0.05f);
53 mul_v3_m4v3(data->mat[3], ob->object_to_world().ptr(), pos);
54 /* WATCH: Reminder, alpha is wire-size. */
56}
57
59{
60 const bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
61 const bool is_select = DRW_state_is_select();
62 OVERLAY_PrivateData *pd = vedata->stl->pd;
63 MetaBall *mb = static_cast<MetaBall *>(ob->data);
64
65 const float *color;
66 const float *col_radius = G_draw.block.color_mball_radius;
67 const float *col_radius_select = G_draw.block.color_mball_radius_select;
68 const float *col_stiffness = G_draw.block.color_mball_stiffness;
69 const float *col_stiffness_select = G_draw.block.color_mball_stiffness_select;
70
71 int select_id = 0;
72 if (is_select) {
73 select_id = ob->runtime->select_id;
74 }
75
77 const bool is_selected = (ml->flag & SELECT) != 0;
78 const bool is_scale_radius = (ml->flag & MB_SCALE_RAD) != 0;
79 float stiffness_radius = ml->rad * atanf(ml->s) / float(M_PI_2);
80 BoneInstanceData instdata;
81
82 if (is_select) {
84 }
85 color = (is_selected && is_scale_radius) ? col_radius_select : col_radius;
86 metaball_instance_data_set(&instdata, ob, &ml->x, ml->rad, color);
87 DRW_buffer_add_entry_struct(pd->mball.handle[do_in_front], &instdata);
88
89 if (is_select) {
91 }
92 color = (is_selected && !is_scale_radius) ? col_stiffness_select : col_stiffness;
93 metaball_instance_data_set(&instdata, ob, &ml->x, stiffness_radius, color);
94 DRW_buffer_add_entry_struct(pd->mball.handle[do_in_front], &instdata);
95
96 select_id += 0x10000;
97 }
98
99 /* Needed so object centers and geometry are not detected as meta-elements. */
100 if (is_select) {
102 }
103}
104
106{
107 const bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
108 OVERLAY_PrivateData *pd = vedata->stl->pd;
109 MetaBall *mb = static_cast<MetaBall *>(ob->data);
110 const DRWContextState *draw_ctx = DRW_context_state_get();
111
112 float *color;
113 DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color);
114
115 LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
116 /* Draw radius only. */
117 BoneInstanceData instdata;
118 metaball_instance_data_set(&instdata, ob, &ml->x, ml->rad, color);
119 DRW_buffer_add_entry_struct(pd->mball.handle[do_in_front], &instdata);
120 }
121}
122
124{
125 OVERLAY_PassList *psl = vedata->psl;
126
127 DRW_draw_pass(psl->metaball_ps[0]);
128}
129
131{
132 OVERLAY_PassList *psl = vedata->psl;
133
134 DRW_draw_pass(psl->metaball_ps[1]);
135}
General operations, lookup, etc. for blender objects.
#define LISTBASE_FOREACH(type, var, list)
#define M_PI_2
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
@ MB_SCALE_RAD
@ OB_DRAW_IN_FRONT
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
#define MBALLSEL_STIFF
Definition ED_mball.hh:62
#define MBALLSEL_RADIUS
Definition ED_mball.hh:63
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
struct GPUShader GPUShader
#define SELECT
#define atanf(x)
blender::gpu::Batch * DRW_cache_bone_point_wire_outline_get()
int DRW_object_wire_theme_get(Object *ob, ViewLayer *view_layer, float **r_color)
DRW_Global G_draw
const DRWContextState * DRW_context_state_get()
bool DRW_state_is_select()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_buffer_add_entry_struct(DRWCallBuffer *callbuf, const void *data)
void DRW_draw_pass(DRWPass *pass)
void DRW_select_load_id(uint id)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_IN_FRONT_SELECT
Definition draw_state.hh:67
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
draw_view in_light_buf[] float
format
static ulong state[N]
void OVERLAY_bone_instance_data_set_color(BoneInstanceData *data, const float bone_color[4])
void OVERLAY_metaball_cache_populate(OVERLAY_Data *vedata, Object *ob)
#define BUF_INSTANCE
void OVERLAY_metaball_in_front_draw(OVERLAY_Data *vedata)
void OVERLAY_edit_metaball_cache_populate(OVERLAY_Data *vedata, Object *ob)
static void metaball_instance_data_set(BoneInstanceData *data, Object *ob, const float *pos, const float radius, const float color[4])
void OVERLAY_metaball_draw(OVERLAY_Data *vedata)
void OVERLAY_metaball_cache_init(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_armature_sphere(bool use_outline)
OVERLAY_InstanceFormats * OVERLAY_shader_instance_formats_get()
ViewLayer * view_layer
GlobalsUboStorage block
GPUUniformBuf * block_ubo
ListBase elems
ListBase * editelems
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
GPUVertFormat * instance_bone
DRWPass * metaball_ps[2]
struct OVERLAY_PrivateData::@236 mball
DRWCallBuffer * handle[2]
OVERLAY_PrivateData * pd
ObjectRuntimeHandle * runtime