Metaball: pointers used in DRW_shgroup_call_dynamic_add don't need to hold the reference.
This commit is contained in:
@@ -78,10 +78,6 @@ void BKE_mball_eval_geometry(struct Depsgraph *depsgraph,
|
||||
struct MetaBall *mball);
|
||||
/* Draw Cache */
|
||||
|
||||
void BKE_mball_element_calc_scale_xform(float r_scale_xform[3][4],
|
||||
const float obmat[4][4],
|
||||
const float local_pos[3]);
|
||||
|
||||
enum {
|
||||
BKE_MBALL_BATCH_DIRTY_ALL = 0,
|
||||
};
|
||||
|
||||
@@ -550,32 +550,6 @@ void BKE_mball_eval_geometry(struct Depsgraph *UNUSED(depsgraph),
|
||||
|
||||
/* Draw Engine */
|
||||
|
||||
/* use for draw-manager only. */
|
||||
void BKE_mball_element_calc_scale_xform(float r_scale_xform[3][4],
|
||||
const float obmat[4][4],
|
||||
const float local_pos[3])
|
||||
{
|
||||
float world_pos[3], scamat[3][3];
|
||||
mul_v3_m4v3(world_pos, obmat, local_pos);
|
||||
copy_m3_m4(scamat, obmat);
|
||||
{
|
||||
/* Get the normalized inverse matrix to extract only
|
||||
* the scale of Scamat */
|
||||
float iscamat[3][3];
|
||||
invert_m3_m3(iscamat, scamat);
|
||||
normalize_m3(iscamat);
|
||||
mul_m3_m3_post(scamat, iscamat);
|
||||
}
|
||||
|
||||
copy_v3_v3(r_scale_xform[0], scamat[0]);
|
||||
copy_v3_v3(r_scale_xform[1], scamat[1]);
|
||||
copy_v3_v3(r_scale_xform[2], scamat[2]);
|
||||
|
||||
r_scale_xform[0][3] = world_pos[0];
|
||||
r_scale_xform[1][3] = world_pos[1];
|
||||
r_scale_xform[2][3] = world_pos[2];
|
||||
}
|
||||
|
||||
void (*BKE_mball_batch_cache_dirty_cb)(MetaBall *mb, int mode) = NULL;
|
||||
void (*BKE_mball_batch_cache_free_cb)(MetaBall *mb) = NULL;
|
||||
|
||||
|
||||
@@ -493,7 +493,7 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass)
|
||||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass, struct Gwn_Batch *geom)
|
||||
DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
|
||||
{
|
||||
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_MBALL_HANDLES);
|
||||
|
||||
@@ -503,7 +503,8 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass, struct Gwn_Batch
|
||||
{"color" , DRW_ATTRIB_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_mball_handles);
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, DRW_cache_screenspace_circle_get(),
|
||||
g_formats.instance_mball_handles);
|
||||
DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
|
||||
|
||||
return grp;
|
||||
|
||||
@@ -121,7 +121,7 @@ struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct Gwn_B
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
|
||||
|
||||
@@ -120,48 +120,10 @@ static void EDIT_METABALL_cache_init(void *vedata)
|
||||
psl->pass = DRW_pass_create("My Pass", state);
|
||||
|
||||
/* Create a shadingGroup using a function in draw_common.c or custom one */
|
||||
stl->g_data->group = shgroup_instance_mball_handles(psl->pass, DRW_cache_screenspace_circle_get());
|
||||
stl->g_data->group = shgroup_instance_mball_handles(psl->pass);
|
||||
}
|
||||
}
|
||||
|
||||
static void EDIT_METABALL_cache_populate_radius(
|
||||
DRWShadingGroup *group, MetaElem *ml, const float scale_xform[3][4],
|
||||
const float *radius, const int selection_id)
|
||||
{
|
||||
const float *color;
|
||||
static const float col_radius[3] = {0.63, 0.19, 0.19}; /* 0x3030A0 */
|
||||
static const float col_radius_select[3] = {0.94, 0.63, 0.63}; /* 0xA0A0F0 */
|
||||
|
||||
if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) color = col_radius_select;
|
||||
else color = col_radius;
|
||||
|
||||
if (selection_id != -1) {
|
||||
ml->selcol1 = selection_id;
|
||||
DRW_select_load_id(selection_id);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(group, scale_xform, radius, color);
|
||||
}
|
||||
|
||||
static void EDIT_METABALL_cache_populate_stiffness(
|
||||
DRWShadingGroup *group, MetaElem *ml, const float scale_xform[3][4],
|
||||
const float *radius, const int selection_id)
|
||||
{
|
||||
const float *color;
|
||||
static const float col_stiffness[3] = {0.19, 0.63, 0.19}; /* 0x30A030 */
|
||||
static const float col_stiffness_select[3] = {0.63, 0.94, 0.63}; /* 0xA0F0A0 */
|
||||
|
||||
if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) color = col_stiffness_select;
|
||||
else color = col_stiffness;
|
||||
|
||||
if (selection_id != -1) {
|
||||
ml->selcol2 = selection_id;
|
||||
DRW_select_load_id(selection_id);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(group, scale_xform, radius, color);
|
||||
}
|
||||
|
||||
/* Add geometry to shadingGroups. Execute for each objects */
|
||||
static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
|
||||
{
|
||||
@@ -175,19 +137,60 @@ static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
|
||||
if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) {
|
||||
MetaBall *mb = ob->data;
|
||||
|
||||
const float *color;
|
||||
const float col_radius[3] = {0.63, 0.19, 0.19}; /* 0x3030A0 */
|
||||
const float col_radius_select[3] = {0.94, 0.63, 0.63}; /* 0xA0A0F0 */
|
||||
const float col_stiffness[3] = {0.19, 0.63, 0.19}; /* 0x30A030 */
|
||||
const float col_stiffness_select[3] = {0.63, 0.94, 0.63}; /* 0xA0F0A0 */
|
||||
|
||||
const bool is_select = DRW_state_is_select();
|
||||
|
||||
int selection_id = 0;
|
||||
|
||||
float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
|
||||
{
|
||||
float scamat[3][3];
|
||||
copy_m3_m4(scamat, ob->obmat);
|
||||
/* Get the normalized inverse matrix to extract only
|
||||
* the scale of Scamat */
|
||||
float iscamat[3][3];
|
||||
invert_m3_m3(iscamat, scamat);
|
||||
normalize_m3(iscamat);
|
||||
mul_m3_m3_post(scamat, iscamat);
|
||||
|
||||
copy_v3_v3(draw_scale_xform[0], scamat[0]);
|
||||
copy_v3_v3(draw_scale_xform[1], scamat[1]);
|
||||
copy_v3_v3(draw_scale_xform[2], scamat[2]);
|
||||
}
|
||||
|
||||
for (MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) {
|
||||
BKE_mball_element_calc_scale_xform(ml->draw_scale_xform, ob->obmat, &ml->x);
|
||||
ml->draw_stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
|
||||
float world_pos[3];
|
||||
mul_v3_m4v3(world_pos, ob->obmat, &ml->x);
|
||||
draw_scale_xform[0][3] = world_pos[0];
|
||||
draw_scale_xform[1][3] = world_pos[1];
|
||||
draw_scale_xform[2][3] = world_pos[2];
|
||||
|
||||
EDIT_METABALL_cache_populate_radius(
|
||||
group, ml, ml->draw_scale_xform, &ml->rad, is_select ? ++selection_id : -1);
|
||||
float draw_stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
|
||||
|
||||
EDIT_METABALL_cache_populate_stiffness(
|
||||
group, ml, ml->draw_scale_xform, &ml->draw_stiffness_radius, is_select ? ++selection_id : -1);
|
||||
if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) color = col_radius_select;
|
||||
else color = col_radius;
|
||||
|
||||
if (is_select) {
|
||||
ml->selcol1 = ++selection_id;
|
||||
DRW_select_load_id(selection_id);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(group, draw_scale_xform, &ml->rad, color);
|
||||
|
||||
if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) color = col_stiffness_select;
|
||||
else color = col_stiffness;
|
||||
|
||||
if (is_select) {
|
||||
ml->selcol2 = ++selection_id;
|
||||
DRW_select_load_id(selection_id);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(group, draw_scale_xform, &draw_stiffness_radius, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1188,9 +1188,7 @@ static void OBJECT_cache_init(void *vedata)
|
||||
|
||||
{
|
||||
/* Metaballs Handles */
|
||||
struct Gwn_Batch *geom;
|
||||
geom = DRW_cache_screenspace_circle_get();
|
||||
stl->g_data->mball_handle = shgroup_instance_mball_handles(psl->non_meshes, geom);
|
||||
stl->g_data->mball_handle = shgroup_instance_mball_handles(psl->non_meshes);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1329,10 +1327,31 @@ static void DRW_shgroup_mball_handles(OBJECT_StorageList *stl, Object *ob, ViewL
|
||||
float *color;
|
||||
DRW_object_wire_theme_get(ob, view_layer, &color);
|
||||
|
||||
float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
|
||||
{
|
||||
float scamat[3][3];
|
||||
copy_m3_m4(scamat, ob->obmat);
|
||||
/* Get the normalized inverse matrix to extract only
|
||||
* the scale of Scamat */
|
||||
float iscamat[3][3];
|
||||
invert_m3_m3(iscamat, scamat);
|
||||
normalize_m3(iscamat);
|
||||
mul_m3_m3_post(scamat, iscamat);
|
||||
|
||||
copy_v3_v3(draw_scale_xform[0], scamat[0]);
|
||||
copy_v3_v3(draw_scale_xform[1], scamat[1]);
|
||||
copy_v3_v3(draw_scale_xform[2], scamat[2]);
|
||||
}
|
||||
|
||||
for (MetaElem *ml = mb->elems.first; ml != NULL; ml = ml->next) {
|
||||
/* draw radius */
|
||||
BKE_mball_element_calc_scale_xform(ml->draw_scale_xform, ob->obmat, &ml->x);
|
||||
DRW_shgroup_call_dynamic_add(stl->g_data->mball_handle, ml->draw_scale_xform, &ml->rad, color);
|
||||
float world_pos[3];
|
||||
mul_v3_m4v3(world_pos, ob->obmat, &ml->x);
|
||||
draw_scale_xform[0][3] = world_pos[0];
|
||||
draw_scale_xform[1][3] = world_pos[1];
|
||||
draw_scale_xform[2][3] = world_pos[2];
|
||||
|
||||
DRW_shgroup_call_dynamic_add(stl->g_data->mball_handle, draw_scale_xform, &ml->rad, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,11 +59,6 @@ typedef struct MetaElem {
|
||||
float len; /* old, only used for backwards compat. use dimensions now */
|
||||
|
||||
float *mat, *imat; /* matrix and inverted matrix */
|
||||
|
||||
/* Draw_Data: stores pointers used for shader attributes */
|
||||
float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
|
||||
float draw_stiffness_radius; /* radius of the stiffness circle (only in edit mode) */
|
||||
float pad;
|
||||
} MetaElem;
|
||||
|
||||
typedef struct MetaBall {
|
||||
|
||||
Reference in New Issue
Block a user