Blender  V3.3
overlay_metaball.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. */
3 
8 #include "DRW_render.h"
9 
10 #include "DNA_meta_types.h"
11 
12 #include "BKE_object.h"
13 
14 #include "DEG_depsgraph_query.h"
15 
16 #include "ED_mball.h"
17 
18 #include "overlay_private.h"
19 
21 {
22  OVERLAY_PassList *psl = vedata->psl;
23  OVERLAY_PrivateData *pd = vedata->stl->pd;
24 
26 
27 #define BUF_INSTANCE DRW_shgroup_call_buffer_instance
28 
29  for (int i = 0; i < 2; i++) {
30  DRWState infront_state = (DRW_state_is_select() && (i == 1)) ? DRW_STATE_IN_FRONT_SELECT : 0;
32  DRW_PASS_CREATE(psl->metaball_ps[i], state | pd->clipping_state | infront_state);
33 
34  /* Reuse armature shader as it's perfect to outline ellipsoids. */
35  struct GPUVertFormat *format = formats->instance_bone;
38  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
40  }
41 }
42 
44  BoneInstanceData *data, Object *ob, const float *pos, const float radius, const float color[4])
45 {
46  /* Bone point radius is 0.05. Compensate for that. */
47  mul_v3_v3fl(data->mat[0], ob->obmat[0], radius / 0.05f);
48  mul_v3_v3fl(data->mat[1], ob->obmat[1], radius / 0.05f);
49  mul_v3_v3fl(data->mat[2], ob->obmat[2], radius / 0.05f);
50  mul_v3_m4v3(data->mat[3], ob->obmat, pos);
51  /* WATCH: Reminder, alpha is wire-size. */
53 }
54 
56 {
57  const bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
58  const bool is_select = DRW_state_is_select();
59  OVERLAY_PrivateData *pd = vedata->stl->pd;
60  MetaBall *mb = ob->data;
61 
62  const float *color;
63  const float *col_radius = G_draw.block.color_mball_radius;
64  const float *col_radius_select = G_draw.block.color_mball_radius_select;
65  const float *col_stiffness = G_draw.block.color_mball_stiffness;
66  const float *col_stiffness_select = G_draw.block.color_mball_stiffness_select;
67 
68  int select_id = 0;
69  if (is_select) {
70  select_id = ob->runtime.select_id;
71  }
72 
73  LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
74  const bool is_selected = (ml->flag & SELECT) != 0;
75  const bool is_scale_radius = (ml->flag & MB_SCALE_RAD) != 0;
76  float stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
77  BoneInstanceData instdata;
78 
79  if (is_select) {
81  }
82  color = (is_selected && is_scale_radius) ? col_radius_select : col_radius;
83  metaball_instance_data_set(&instdata, ob, &ml->x, ml->rad, color);
84  DRW_buffer_add_entry_struct(pd->mball.handle[do_in_front], &instdata);
85 
86  if (is_select) {
88  }
89  color = (is_selected && !is_scale_radius) ? col_stiffness_select : col_stiffness;
90  metaball_instance_data_set(&instdata, ob, &ml->x, stiffness_radius, color);
91  DRW_buffer_add_entry_struct(pd->mball.handle[do_in_front], &instdata);
92 
93  select_id += 0x10000;
94  }
95 
96  /* Needed so object centers and geometry are not detected as meta-elements. */
97  if (is_select) {
99  }
100 }
101 
103 {
104  const bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
105  OVERLAY_PrivateData *pd = vedata->stl->pd;
106  MetaBall *mb = ob->data;
107  const DRWContextState *draw_ctx = DRW_context_state_get();
108 
109  float *color;
110  DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color);
111 
112  LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
113  /* Draw radius only. */
114  BoneInstanceData instdata;
115  metaball_instance_data_set(&instdata, ob, &ml->x, ml->rad, color);
116  DRW_buffer_add_entry_struct(pd->mball.handle[do_in_front], &instdata);
117  }
118 }
119 
121 {
122  OVERLAY_PassList *psl = vedata->psl;
123 
124  DRW_draw_pass(psl->metaball_ps[0]);
125 }
126 
128 {
129  OVERLAY_PassList *psl = vedata->psl;
130 
131  DRW_draw_pass(psl->metaball_ps[1]);
132 }
typedef float(TangentPoint)[2]
General operations, lookup, etc. for blender objects.
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define M_PI_2
Definition: BLI_math_base.h:23
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
#define MB_SCALE_RAD
@ OB_DRAW_IN_FRONT
DRWState
Definition: DRW_render.h:298
@ DRW_STATE_IN_FRONT_SELECT
Definition: DRW_render.h:340
@ DRW_STATE_WRITE_DEPTH
Definition: DRW_render.h:302
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition: DRW_render.h:311
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:690
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
Definition: DRW_render.h:651
#define MBALLSEL_STIFF
Definition: ED_mball.h:72
#define MBALLSEL_RADIUS
Definition: ED_mball.h:73
struct GPUShader GPUShader
Definition: GPU_shader.h:20
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 a color
#define SELECT
GPUBatch * DRW_cache_bone_point_wire_outline_get(void)
Definition: draw_cache.c:2327
int DRW_object_wire_theme_get(Object *ob, ViewLayer *view_layer, float **r_color)
Definition: draw_common.c:279
struct DRW_Global G_draw
Definition: draw_common.c:32
bool DRW_state_is_select(void)
const DRWContextState * DRW_context_state_get(void)
void DRW_buffer_add_entry_struct(DRWCallBuffer *callbuf, const void *data)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
void DRW_draw_pass(DRWPass *pass)
void DRW_select_load_id(uint id)
uint pos
const int state
ccl_gpu_kernel_postfix ccl_global float int int int int sh
format
Definition: logImageCore.h:38
#define atanf(x)
Definition: metal/compat.h:223
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(void)
struct ViewLayer * view_layer
Definition: DRW_render.h:980
GlobalsUboStorage block
Definition: draw_common.h:127
struct GPUUniformBuf * block_ubo
Definition: draw_common.h:129
ListBase elems
ListBase * editelems
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
struct GPUVertFormat * instance_bone
DRWPass * metaball_ps[2]
DRWCallBuffer * handle[2]
struct OVERLAY_PrivateData::@258 mball
struct OVERLAY_PrivateData * pd
Object_Runtime runtime
float obmat[4][4]
void * data