Blender  V3.3
Macros | Functions | Variables
mball.c File Reference
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_defaults.h"
#include "DNA_material_types.h"
#include "DNA_meta_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "BKE_main.h"
#include "BKE_anim_data.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_material.h"
#include "BKE_mball.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "DEG_depsgraph.h"
#include "BLO_read_write.h"

Go to the source code of this file.

Macros

#define DNA_DEPRECATED_ALLOW
 

Functions

static void metaball_init_data (ID *id)
 
static void metaball_copy_data (Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int UNUSED(flag))
 
static void metaball_free_data (ID *id)
 
static void metaball_foreach_id (ID *id, LibraryForeachIDData *data)
 
static void metaball_blend_write (BlendWriter *writer, ID *id, const void *id_address)
 
static void metaball_blend_read_data (BlendDataReader *reader, ID *id)
 
static void metaball_blend_read_lib (BlendLibReader *reader, ID *id)
 
static void metaball_blend_read_expand (BlendExpander *expander, ID *id)
 
MetaBallBKE_mball_add (Main *bmain, const char *name)
 
MetaElemBKE_mball_element_add (MetaBall *mb, const int type)
 
void BKE_mball_texspace_calc (Object *ob)
 
BoundBoxBKE_mball_boundbox_get (Object *ob)
 
floatBKE_mball_make_orco (Object *ob, ListBase *dispbase)
 
bool BKE_mball_is_basis (const Object *ob)
 
bool BKE_mball_is_same_group (const Object *ob1, const Object *ob2)
 
bool BKE_mball_is_basis_for (const Object *ob1, const Object *ob2)
 
bool BKE_mball_is_any_selected (const MetaBall *mb)
 
bool BKE_mball_is_any_selected_multi (Base **bases, int bases_len)
 
bool BKE_mball_is_any_unselected (const MetaBall *mb)
 
static void mball_data_properties_copy (MetaBall *mb_dst, MetaBall *mb_src)
 
void BKE_mball_properties_copy (Main *bmain, MetaBall *metaball_src)
 
ObjectBKE_mball_basis_find (Scene *scene, Object *object)
 
bool BKE_mball_minmax_ex (const MetaBall *mb, float min[3], float max[3], const float obmat[4][4], const short flag)
 
bool BKE_mball_minmax (const MetaBall *mb, float min[3], float max[3])
 
bool BKE_mball_center_median (const MetaBall *mb, float r_cent[3])
 
bool BKE_mball_center_bounds (const MetaBall *mb, float r_cent[3])
 
void BKE_mball_transform (MetaBall *mb, const float mat[4][4], const bool do_props)
 
void BKE_mball_translate (MetaBall *mb, const float offset[3])
 
int BKE_mball_select_count (const MetaBall *mb)
 
int BKE_mball_select_count_multi (Base **bases, int bases_len)
 
bool BKE_mball_select_all (MetaBall *mb)
 
bool BKE_mball_select_all_multi_ex (Base **bases, int bases_len)
 
bool BKE_mball_deselect_all (MetaBall *mb)
 
bool BKE_mball_deselect_all_multi_ex (Base **bases, int bases_len)
 
bool BKE_mball_select_swap (MetaBall *mb)
 
bool BKE_mball_select_swap_multi_ex (Base **bases, int bases_len)
 
void BKE_mball_batch_cache_dirty_tag (MetaBall *mb, int mode)
 
void BKE_mball_batch_cache_free (MetaBall *mb)
 

Variables

IDTypeInfo IDType_ID_MB
 
void(* BKE_mball_batch_cache_dirty_tag_cb )(MetaBall *mb, int mode) = NULL
 
void(* BKE_mball_batch_cache_free_cb )(MetaBall *mb) = NULL
 

Detailed Description

MetaBalls are created from a single Object (with a name without number in it), here the DispList and BoundBox also is located. All objects with the same name (but with a number in it) are added to this.

texture coordinates are patched within the displist

Definition in file mball.c.

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 24 of file mball.c.

Function Documentation

◆ BKE_mball_add()

MetaBall* BKE_mball_add ( Main bmain,
const char *  name 
)

Definition at line 200 of file mball.c.

References BKE_id_new(), and ID_MB.

Referenced by BKE_object_obdata_add_from_type().

◆ BKE_mball_basis_find()

Object* BKE_mball_basis_find ( struct Scene scene,
struct Object ob 
)

This function finds the basis meta-ball.

Basis meta-ball doesn't include any number at the end of its name. All meta-balls with same base of name can be blended. meta-balls with different basic name can't be blended.

Warning
BKE_mball_is_basis() can fail on returned object, see function docs for details.

Definition at line 508 of file mball.c.

References BASE_FROM_DUPLI, BLI_split_name_num(), Object::id, LISTBASE_FOREACH, MAX_ID_NAME, ID::name, OB_MBALL, scene, STREQ, Object::type, and Scene::view_layers.

Referenced by BKE_displist_make_mball(), blender::deg::DepsgraphRelationBuilder::build_object_data_geometry(), and object_convert_exec().

◆ BKE_mball_batch_cache_dirty_tag()

void BKE_mball_batch_cache_dirty_tag ( MetaBall mb,
int  mode 
)

◆ BKE_mball_batch_cache_free()

void BKE_mball_batch_cache_free ( MetaBall mb)

Definition at line 749 of file mball.c.

References MetaBall::batch_cache, and BKE_mball_batch_cache_free_cb.

Referenced by metaball_free_data().

◆ BKE_mball_boundbox_get()

BoundBox* BKE_mball_boundbox_get ( struct Object ob)

Return or compute bounding-box for given meta-ball object.

Definition at line 298 of file mball.c.

References Object_Runtime::bb, BKE_mball_texspace_calc(), BLI_assert, BOUNDBOX_DIRTY, Object_Runtime::curve_cache, BoundBox::flag, NULL, OB_MBALL, Object::runtime, and Object::type.

Referenced by BKE_object_boundbox_get().

◆ BKE_mball_center_bounds()

bool BKE_mball_center_bounds ( const MetaBall mb,
float  r_cent[3] 
)

Definition at line 601 of file mball.c.

References BKE_mball_minmax(), max, mid_v3_v3v3(), and min.

◆ BKE_mball_center_median()

bool BKE_mball_center_median ( const MetaBall mb,
float  r_cent[3] 
)

Definition at line 583 of file mball.c.

References add_v3_v3(), MetaBall::elems, LISTBASE_FOREACH, mul_v3_fl(), and zero_v3().

◆ BKE_mball_deselect_all()

bool BKE_mball_deselect_all ( MetaBall mb)

◆ BKE_mball_deselect_all_multi_ex()

bool BKE_mball_deselect_all_multi_ex ( Base **  bases,
int  bases_len 
)

◆ BKE_mball_element_add()

MetaElem* BKE_mball_element_add ( struct MetaBall mb,
int  type 
)

Most simple meta-element adding function.

Note
don't do context manipulation here (rna uses).

Definition at line 209 of file mball.c.

References BLI_addtail(), MetaBall::elems, MetaElem::expx, MetaElem::expy, MetaElem::expz, MetaElem::flag, MB_BALL, MB_CUBE, MB_ELIPSOID, MB_PLANE, MB_SCALE_RAD, MB_TUBE, MEM_callocN, MetaElem::quat, MetaElem::rad, MetaElem::s, type, MetaElem::type, and unit_qt().

Referenced by ED_mball_add_primitive().

◆ BKE_mball_is_any_selected()

bool BKE_mball_is_any_selected ( const MetaBall mb)

Definition at line 394 of file mball.c.

References MetaBall::editelems, ListBase::first, NULL, and SELECT.

Referenced by BKE_mball_is_any_selected_multi().

◆ BKE_mball_is_any_selected_multi()

bool BKE_mball_is_any_selected_multi ( Base **  bases,
int  bases_len 
)

Definition at line 404 of file mball.c.

References BKE_mball_is_any_selected(), Object::data, if(), and Base::object.

Referenced by mball_select_all_exec().

◆ BKE_mball_is_any_unselected()

bool BKE_mball_is_any_unselected ( const MetaBall mb)

Definition at line 416 of file mball.c.

References MetaBall::editelems, ListBase::first, NULL, and SELECT.

◆ BKE_mball_is_basis()

bool BKE_mball_is_basis ( const Object ob)

Definition at line 350 of file mball.c.

References Object::id, len, and ID::name.

Referenced by BKE_mball_is_basis_for().

◆ BKE_mball_is_basis_for()

bool BKE_mball_is_basis_for ( const Object ob1,
const Object ob2 
)

Definition at line 389 of file mball.c.

References BKE_mball_is_basis(), and BKE_mball_is_same_group().

◆ BKE_mball_is_same_group()

bool BKE_mball_is_same_group ( const Object ob1,
const Object ob2 
)

Definition at line 373 of file mball.c.

References BLI_split_name_num(), Object::id, MAX_ID_NAME, ID::name, and STREQ.

Referenced by BKE_mball_is_basis_for().

◆ BKE_mball_make_orco()

float* BKE_mball_make_orco ( Object ob,
ListBase dispbase 
)

◆ BKE_mball_minmax()

bool BKE_mball_minmax ( const MetaBall mb,
float  min[3],
float  max[3] 
)

◆ BKE_mball_minmax_ex()

bool BKE_mball_minmax_ex ( const MetaBall mb,
float  min[3],
float  max[3],
const float  obmat[4][4],
const short  flag 
)

◆ BKE_mball_properties_copy()

void BKE_mball_properties_copy ( struct Main bmain,
struct MetaBall active_metaball 
)

Copy some properties from a meta-ball obdata to all other meta-ball obdata belonging to the same family (i.e. object sharing the same name basis).

When some properties (wire-size, threshold, update flags) of meta-ball are changed, then this properties are copied to all meta-balls in same "group" (meta-balls with same base name: MBall, MBall.001, MBall.002, etc). The most important is to copy properties to the base meta-ball, because this meta-ball influences polygonization of meta-balls.

WARNING: This code does not cover all potential corner-cases. E.g. if:

|   Object   |   ObData   |
| ---------- | ---------- |
| Meta_A     | Meta_A     |
| Meta_A.001 | Meta_A.001 |
| Meta_B     | Meta_A     |
| Meta_B.001 | Meta_B.001 |

Calling this function with metaball_src being Meta_A.001 will update Meta_A, but NOT Meta_B.001. So in the 'Meta_B' family, the two metaballs will have unmatching settings now.

Solving this case would drastically increase the complexity of this code though, so don't think it would be worth it.

Definition at line 435 of file mball.c.

References BLI_split_name_num(), Object::data, ListBase::first, Object::id, ID_IS_LINKED, MAX_ID_NAME, mball_data_properties_copy(), ID::name, ID::next, NULL, OB_MBALL, Main::objects, ID::prev, STREQ, and Object::type.

◆ BKE_mball_select_all()

bool BKE_mball_select_all ( MetaBall mb)

Definition at line 668 of file mball.c.

References MetaBall::editelems, LISTBASE_FOREACH, and SELECT.

Referenced by BKE_mball_select_all_multi_ex().

◆ BKE_mball_select_all_multi_ex()

bool BKE_mball_select_all_multi_ex ( Base **  bases,
int  bases_len 
)

Definition at line 680 of file mball.c.

References BKE_mball_select_all(), Object::data, and Base::object.

Referenced by mball_select_all_exec().

◆ BKE_mball_select_count()

int BKE_mball_select_count ( const MetaBall mb)

Definition at line 646 of file mball.c.

References MetaBall::editelems, LISTBASE_FOREACH, and SELECT.

Referenced by BKE_mball_select_count_multi().

◆ BKE_mball_select_count_multi()

int BKE_mball_select_count_multi ( Base **  bases,
int  bases_len 
)

Definition at line 657 of file mball.c.

References BKE_mball_select_count(), Object::data, and Base::object.

Referenced by mball_select_similar_exec().

◆ BKE_mball_select_swap()

bool BKE_mball_select_swap ( MetaBall mb)

Definition at line 715 of file mball.c.

References MetaBall::editelems, LISTBASE_FOREACH, and SELECT.

Referenced by BKE_mball_select_swap_multi_ex().

◆ BKE_mball_select_swap_multi_ex()

bool BKE_mball_select_swap_multi_ex ( Base **  bases,
int  bases_len 
)

Definition at line 725 of file mball.c.

References BKE_mball_select_swap(), Object::data, and Base::object.

Referenced by mball_select_all_exec().

◆ BKE_mball_texspace_calc()

void BKE_mball_texspace_calc ( struct Object ob)

Compute bounding box of all meta-elements / meta-ball.

Bounding box is computed from polygonized surface. ob is basic meta-balls (with name Meta for example). All other meta-ball objects (with names Meta.001, Meta.002, etc) are included in this bounding-box.

Definition at line 255 of file mball.c.

References Object_Runtime::bb, BKE_boundbox_init_from_minmax(), BOUNDBOX_DIRTY, Object_Runtime::curve_cache, data, CurveCache::disp, ListBase::first, BoundBox::flag, max, MEM_callocN, min, minmax_v3v3_v3(), DispList::next, DispList::nr, NULL, Object::runtime, and DispList::verts.

Referenced by BKE_displist_make_mball(), and BKE_mball_boundbox_get().

◆ BKE_mball_transform()

void BKE_mball_transform ( MetaBall mb,
const float  mat[4][4],
const bool  do_props 
)

◆ BKE_mball_translate()

void BKE_mball_translate ( MetaBall mb,
const float  offset[3] 
)

Definition at line 639 of file mball.c.

References add_v3_v3(), MetaBall::elems, LISTBASE_FOREACH, and offset.

Referenced by object_origin_set_exec().

◆ mball_data_properties_copy()

static void mball_data_properties_copy ( MetaBall mb_dst,
MetaBall mb_src 
)
static

◆ metaball_blend_read_data()

static void metaball_blend_read_data ( BlendDataReader reader,
ID id 
)
static

◆ metaball_blend_read_expand()

static void metaball_blend_read_expand ( BlendExpander expander,
ID id 
)
static

Definition at line 160 of file mball.c.

References Freestyle::a, BLO_expand, MetaBall::mat, and MetaBall::totcol.

◆ metaball_blend_read_lib()

static void metaball_blend_read_lib ( BlendLibReader reader,
ID id 
)
static

◆ metaball_blend_write()

static void metaball_blend_write ( BlendWriter writer,
ID id,
const void id_address 
)
static

◆ metaball_copy_data()

static void metaball_copy_data ( Main UNUSEDbmain,
ID id_dst,
const ID id_src,
const int   UNUSEDflag 
)
static

◆ metaball_foreach_id()

static void metaball_foreach_id ( ID id,
LibraryForeachIDData data 
)
static

Definition at line 96 of file mball.c.

References BKE_LIB_FOREACHID_PROCESS_IDSUPER, data, IDWALK_CB_USER, and metaball().

◆ metaball_free_data()

static void metaball_free_data ( ID id)
static

◆ metaball_init_data()

static void metaball_init_data ( ID id)
static

Variable Documentation

◆ BKE_mball_batch_cache_dirty_tag_cb

void(* BKE_mball_batch_cache_dirty_tag_cb) (MetaBall *mb, int mode) ( MetaBall mb,
int  mode 
) = NULL

Definition at line 740 of file mball.c.

Referenced by BKE_mball_batch_cache_dirty_tag(), and DRW_engines_register().

◆ BKE_mball_batch_cache_free_cb

void(* BKE_mball_batch_cache_free_cb) (MetaBall *mb) ( MetaBall mb) = NULL

Definition at line 741 of file mball.c.

Referenced by BKE_mball_batch_cache_free(), and DRW_engines_register().

◆ IDType_ID_MB

IDTypeInfo IDType_ID_MB
Initial value:
= {
.id_code = ID_MB,
.id_filter = FILTER_ID_MB,
.main_listbase_index = INDEX_ID_MB,
.struct_size = sizeof(MetaBall),
.name = "Metaball",
.name_plural = "metaballs",
.translation_context = BLT_I18NCONTEXT_ID_METABALL,
.asset_type_info = NULL,
.copy_data = metaball_copy_data,
.free_data = metaball_free_data,
.make_local = NULL,
.foreach_id = metaball_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.blend_write = metaball_blend_write,
.blend_read_data = metaball_blend_read_data,
.blend_read_lib = metaball_blend_read_lib,
.blend_read_expand = metaball_blend_read_expand,
.blend_read_undo_preserve = NULL,
.lib_override_apply_post = NULL,
}
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition: BKE_idtype.h:39
#define BLT_I18NCONTEXT_ID_METABALL
@ INDEX_ID_MB
Definition: DNA_ID.h:1028
#define FILTER_ID_MB
Definition: DNA_ID.h:911
@ ID_MB
Definition: DNA_ID_enums.h:50
struct MetaBall MetaBall
static void init_data(ModifierData *md)
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: mball.c:104
static void metaball_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int UNUSED(flag))
Definition: mball.c:65
static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
Definition: mball.c:131
static void metaball_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: mball.c:150
static void metaball_init_data(ID *id)
Definition: mball.c:56
static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: mball.c:96
static void metaball_free_data(ID *id)
Definition: mball.c:82
static void metaball_blend_read_expand(BlendExpander *expander, ID *id)
Definition: mball.c:160

Definition at line 168 of file mball.c.