Blender V4.3
mball.cc File Reference
#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <optional>
#include "MEM_guardedalloc.h"
#include "DNA_defaults.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_main.hh"
#include "BKE_geometry_set.hh"
#include "BKE_idtype.hh"
#include "BKE_lattice.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_mball.hh"
#include "BKE_mball_tessellate.hh"
#include "BKE_object.hh"
#include "BKE_object_types.hh"
#include "DEG_depsgraph.hh"
#include "BLO_read_write.hh"

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 *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
 
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)
 
MetaBallBKE_mball_add (Main *bmain, const char *name)
 
MetaElemBKE_mball_element_add (MetaBall *mb, const int type)
 
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 (const Span< Base * > bases)
 
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 (const Span< Base * > bases)
 
bool BKE_mball_select_all (MetaBall *mb)
 
bool BKE_mball_select_all_multi_ex (const Span< Base * > bases)
 
bool BKE_mball_deselect_all (MetaBall *mb)
 
bool BKE_mball_deselect_all_multi_ex (const Span< Base * > bases)
 
bool BKE_mball_select_swap (MetaBall *mb)
 
bool BKE_mball_select_swap_multi_ex (const Span< Base * > bases)
 
void BKE_mball_data_update (Depsgraph *depsgraph, Scene *scene, Object *ob)
 

Variables

IDTypeInfo IDType_ID_MB
 

Detailed Description

MetaBalls are created from a single Object (with a name without number in it). All objects with the same name (but with a number in it) are added to this.

Definition in file mball.cc.

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 23 of file mball.cc.

Function Documentation

◆ BKE_mball_add()

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

Definition at line 177 of file mball.cc.

References BKE_id_new(), and ID_MB.

Referenced by BKE_object_obdata_add_from_type().

◆ BKE_mball_basis_find()

Object * BKE_mball_basis_find ( Scene * scene,
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 394 of file mball.cc.

References BASE_FROM_DUPLI, BKE_view_layer_object_bases_get(), BKE_view_layer_synced_ensure(), BLI_string_split_name_number(), Object::id, LISTBASE_FOREACH, MAX_ID_NAME, ID::name, OB_MBALL, STREQ, and Object::type.

Referenced by BKE_mball_data_update(), blender::deg::DepsgraphRelationBuilder::build_object_data_geometry(), and blender::ed::object::object_convert_exec().

◆ BKE_mball_center_bounds()

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

Definition at line 488 of file mball.cc.

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

Referenced by blender::ed::object::object_origin_set_exec().

◆ BKE_mball_center_median()

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

◆ BKE_mball_data_update()

◆ BKE_mball_deselect_all()

bool BKE_mball_deselect_all ( MetaBall * mb)

◆ BKE_mball_deselect_all_multi_ex()

bool BKE_mball_deselect_all_multi_ex ( const Span< Base * > bases)

◆ BKE_mball_element_add()

MetaElem * BKE_mball_element_add ( MetaBall * mb,
int type )

Most simple meta-element adding function.

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

Definition at line 183 of file mball.cc.

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, MetaElem::quat, MetaElem::rad, MetaElem::s, 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)

◆ BKE_mball_is_any_selected_multi()

bool BKE_mball_is_any_selected_multi ( const Span< Base * > bases)

Definition at line 284 of file mball.cc.

References BKE_mball_is_any_selected(), and Object::data.

◆ BKE_mball_is_any_unselected()

bool BKE_mball_is_any_unselected ( const MetaBall * mb)

Definition at line 296 of file mball.cc.

References MetaBall::editelems, LISTBASE_FOREACH, and SELECT.

Referenced by select_random_metaelems_exec().

◆ BKE_mball_is_basis()

bool BKE_mball_is_basis ( const Object * ob)

Test, if ob is a basis meta-ball.

It test last character of Object ID name. If last character is digit it return 0, else it return 1.

Definition at line 230 of file mball.cc.

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

Referenced by BKE_mball_is_basis_for(), libblock_remap_data_postprocess_object_update(), blender::ed::object::object_convert_exec(), blender::draw::overlay::Bounds::object_sync(), and OVERLAY_bounds().

◆ BKE_mball_is_basis_for()

bool BKE_mball_is_basis_for ( const Object * ob1,
const Object * ob2 )

Return true if ob1 and ob2 are part of the same metaBall group, and ob1 is its basis.

Definition at line 269 of file mball.cc.

References BKE_mball_is_basis(), and BKE_mball_is_same_group().

Referenced by libblock_remap_data_postprocess_object_update().

◆ BKE_mball_is_same_group()

bool BKE_mball_is_same_group ( const Object * ob1,
const Object * ob2 )

Return true if ob1 and ob2 are part of the same metaBall group.

Note
Currently checks whether their two base names (without numerical suffix) is the same.

Definition at line 253 of file mball.cc.

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

Referenced by BKE_mball_is_basis_for().

◆ 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 ( Main * bmain,
MetaBall * metaball_src )

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 315 of file mball.cc.

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

◆ BKE_mball_select_all()

bool BKE_mball_select_all ( MetaBall * mb)

Definition at line 555 of file mball.cc.

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 ( const Span< Base * > bases)

Definition at line 567 of file mball.cc.

References BKE_mball_select_all(), and Object::data.

◆ BKE_mball_select_count()

int BKE_mball_select_count ( const MetaBall * mb)

Definition at line 533 of file mball.cc.

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 ( const Span< Base * > bases)

Definition at line 544 of file mball.cc.

References BKE_mball_select_count(), and Object::data.

◆ BKE_mball_select_swap()

bool BKE_mball_select_swap ( MetaBall * mb)

Definition at line 602 of file mball.cc.

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 ( const Span< Base * > bases)

Definition at line 612 of file mball.cc.

References BKE_mball_select_swap(), and Object::data.

◆ BKE_mball_transform()

◆ BKE_mball_translate()

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

Definition at line 526 of file mball.cc.

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

Referenced by blender::ed::object::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_write()

◆ metaball_copy_data()

static void metaball_copy_data ( Main * ,
std::optional< Library * > ,
ID * id_dst,
const ID * id_src,
const int  )
static

◆ metaball_foreach_id()

◆ metaball_free_data()

static void metaball_free_data ( ID * id)
static

Definition at line 85 of file mball.cc.

References BLI_freelistN(), MEM_SAFE_FREE, and metaball().

◆ metaball_init_data()

static void metaball_init_data ( ID * id)
static

Variable Documentation

◆ IDType_ID_MB

IDTypeInfo IDType_ID_MB
Initial value:
= {
sizeof(MetaBall),
"Metaball",
N_("metaballs"),
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
}
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:39
#define BLT_I18NCONTEXT_ID_METABALL
#define FILTER_ID_MA
Definition DNA_ID.h:1175
#define FILTER_ID_MB
Definition DNA_ID.h:1176
@ INDEX_ID_MB
Definition DNA_ID.h:1295
@ ID_MB
struct MetaBall MetaBall
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition mball.cc:108
static void metaball_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
Definition mball.cc:68
static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
Definition mball.cc:130
static void metaball_init_data(ID *id)
Definition mball.cc:59
static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
Definition mball.cc:94
static void metaball_free_data(ID *id)
Definition mball.cc:85
#define N_(msgid)

Definition at line 145 of file mball.cc.