2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-02-09 16:00:03 +11:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*
|
2022-08-17 11:57:21 -04:00
|
|
|
* MetaBalls are created from a single Object (with a name without number in it).
|
2011-10-10 09:38:02 +00:00
|
|
|
* All objects with the same name (but with a number in it) are added to this.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
#include <cctype>
|
|
|
|
|
#include <cfloat>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2015-03-25 22:36:43 +11:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2020-09-10 16:37:11 +02:00
|
|
|
/* Allow using deprecated functionality for .blend file I/O. */
|
|
|
|
|
#define DNA_DEPRECATED_ALLOW
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_defaults.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_material_types.h"
|
2022-08-17 10:20:25 -04:00
|
|
|
#include "DNA_mesh_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_meta_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2023-10-18 17:15:30 +02:00
|
|
|
#include "BLI_string_utils.hh"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-09-10 16:37:11 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_curve.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_displist.h"
|
2022-08-17 10:20:25 -04:00
|
|
|
#include "BKE_geometry_set.hh"
|
2024-01-20 19:17:36 +01:00
|
|
|
#include "BKE_idtype.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_lattice.hh"
|
2024-01-23 15:18:09 -05:00
|
|
|
#include "BKE_layer.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_material.h"
|
2024-01-24 11:33:47 -05:00
|
|
|
#include "BKE_mball.hh"
|
|
|
|
|
#include "BKE_mball_tessellate.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2023-11-15 18:46:07 +01:00
|
|
|
#include "BKE_object_types.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_scene.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
2019-03-06 13:16:48 +11:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-09-10 16:37:11 +02:00
|
|
|
|
2024-01-24 18:18:14 +01:00
|
|
|
using blender::Span;
|
|
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
static void metaball_init_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
MetaBall *metaball = (MetaBall *)id;
|
|
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(metaball, id));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
MEMCPY_STRUCT_AFTER(metaball, DNA_struct_default_get(MetaBall), id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static void metaball_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, const int /*flag*/)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2020-03-06 16:08:24 +01:00
|
|
|
MetaBall *metaball_dst = (MetaBall *)id_dst;
|
|
|
|
|
const MetaBall *metaball_src = (const MetaBall *)id_src;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
BLI_duplicatelist(&metaball_dst->elems, &metaball_src->elems);
|
2017-11-16 15:12:32 -02:00
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
metaball_dst->mat = static_cast<Material **>(MEM_dupallocN(metaball_src->mat));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
metaball_dst->editelems = nullptr;
|
|
|
|
|
metaball_dst->lastelem = nullptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
static void metaball_free_data(ID *id)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2020-03-06 16:08:24 +01:00
|
|
|
MetaBall *metaball = (MetaBall *)id;
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
MEM_SAFE_FREE(metaball->mat);
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(&metaball->elems);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:03:42 +02:00
|
|
|
static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
|
{
|
2023-08-22 15:42:19 +02:00
|
|
|
MetaBall *metaball = reinterpret_cast<MetaBall *>(id);
|
|
|
|
|
const int flag = BKE_lib_query_foreachid_process_flags_get(data);
|
|
|
|
|
|
2020-05-12 18:03:42 +02:00
|
|
|
for (int i = 0; i < metaball->totcol; i++) {
|
2021-10-26 10:40:36 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, metaball->mat[i], IDWALK_CB_USER);
|
2020-05-12 18:03:42 +02:00
|
|
|
}
|
2023-08-22 15:42:19 +02:00
|
|
|
|
|
|
|
|
if (flag & IDWALK_DO_DEPRECATED_POINTERS) {
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data, metaball->ipo, IDWALK_CB_USER);
|
|
|
|
|
}
|
2020-05-12 18:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 16:37:11 +02:00
|
|
|
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
|
|
|
|
{
|
|
|
|
|
MetaBall *mb = (MetaBall *)id;
|
2021-08-19 11:13:55 +02:00
|
|
|
|
|
|
|
|
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
2022-08-09 13:49:09 -05:00
|
|
|
mb->editelems = nullptr;
|
2021-08-19 11:13:55 +02:00
|
|
|
/* Must always be cleared (meta's don't have their own edit-data). */
|
|
|
|
|
mb->needs_flush_to_id = 0;
|
2022-08-09 13:49:09 -05:00
|
|
|
mb->lastelem = nullptr;
|
2021-08-19 11:13:55 +02:00
|
|
|
|
|
|
|
|
/* write LibData */
|
|
|
|
|
BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
|
|
|
|
|
BKE_id_blend_write(writer, &mb->id);
|
|
|
|
|
|
|
|
|
|
/* direct data */
|
|
|
|
|
BLO_write_pointer_array(writer, mb->totcol, mb->mat);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
|
|
|
|
|
BLO_write_struct(writer, MetaElem, ml);
|
2020-09-10 16:37:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
MetaBall *mb = (MetaBall *)id;
|
|
|
|
|
|
|
|
|
|
BLO_read_pointer_array(reader, (void **)&mb->mat);
|
|
|
|
|
|
|
|
|
|
BLO_read_list(reader, &(mb->elems));
|
|
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
mb->editelems = nullptr;
|
2020-09-10 16:37:11 +02:00
|
|
|
/* Must always be cleared (meta's don't have their own edit-data). */
|
|
|
|
|
mb->needs_flush_to_id = 0;
|
2022-08-09 13:49:09 -05:00
|
|
|
// mb->edit_elems.first = mb->edit_elems.last = nullptr;
|
|
|
|
|
mb->lastelem = nullptr;
|
2020-09-10 16:37:11 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
IDTypeInfo IDType_ID_MB = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*id_code*/ ID_MB,
|
|
|
|
|
/*id_filter*/ FILTER_ID_MB,
|
|
|
|
|
/*main_listbase_index*/ INDEX_ID_MB,
|
|
|
|
|
/*struct_size*/ sizeof(MetaBall),
|
|
|
|
|
/*name*/ "Metaball",
|
2023-10-04 02:53:31 +02:00
|
|
|
/*name_plural*/ N_("metaballs"),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*translation_context*/ BLT_I18NCONTEXT_ID_METABALL,
|
|
|
|
|
/*flags*/ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
|
|
|
|
|
/*asset_type_info*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ metaball_init_data,
|
|
|
|
|
/*copy_data*/ metaball_copy_data,
|
|
|
|
|
/*free_data*/ metaball_free_data,
|
|
|
|
|
/*make_local*/ nullptr,
|
|
|
|
|
/*foreach_id*/ metaball_foreach_id,
|
|
|
|
|
/*foreach_cache*/ nullptr,
|
|
|
|
|
/*foreach_path*/ nullptr,
|
|
|
|
|
/*owner_pointer_get*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*blend_write*/ metaball_blend_write,
|
|
|
|
|
/*blend_read_data*/ metaball_blend_read_data,
|
2023-03-11 18:07:59 +01:00
|
|
|
/*blend_read_after_liblink*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
|
|
|
|
|
/*blend_read_undo_preserve*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*lib_override_apply_post*/ nullptr,
|
2020-03-06 16:08:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
MetaBall *BKE_mball_add(Main *bmain, const char *name)
|
|
|
|
|
{
|
2022-08-09 13:49:09 -05:00
|
|
|
MetaBall *mb = static_cast<MetaBall *>(BKE_id_new(bmain, ID_MB, name));
|
2002-10-12 11:37:38 +00:00
|
|
|
return mb;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 06:38:41 +00:00
|
|
|
MetaElem *BKE_mball_element_add(MetaBall *mb, const int type)
|
2010-08-23 00:57:19 +00:00
|
|
|
{
|
2022-08-09 13:49:09 -05:00
|
|
|
MetaElem *ml = MEM_cnew<MetaElem>(__func__);
|
2010-08-23 00:57:19 +00:00
|
|
|
|
|
|
|
|
unit_qt(ml->quat);
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
ml->rad = 2.0;
|
|
|
|
|
ml->s = 2.0;
|
|
|
|
|
ml->flag = MB_SCALE_RAD;
|
2010-08-23 00:57:19 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (type) {
|
2012-05-06 15:15:33 +00:00
|
|
|
case MB_BALL:
|
|
|
|
|
ml->type = MB_BALL;
|
|
|
|
|
ml->expx = ml->expy = ml->expz = 1.0;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MB_TUBE:
|
|
|
|
|
ml->type = MB_TUBE;
|
|
|
|
|
ml->expx = ml->expy = ml->expz = 1.0;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MB_PLANE:
|
|
|
|
|
ml->type = MB_PLANE;
|
|
|
|
|
ml->expx = ml->expy = ml->expz = 1.0;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MB_ELIPSOID:
|
|
|
|
|
ml->type = MB_ELIPSOID;
|
|
|
|
|
ml->expx = 1.2f;
|
|
|
|
|
ml->expy = 0.8f;
|
|
|
|
|
ml->expz = 1.0;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MB_CUBE:
|
|
|
|
|
ml->type = MB_CUBE;
|
|
|
|
|
ml->expx = ml->expy = ml->expz = 1.0;
|
2010-08-23 00:57:19 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2010-08-23 00:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_addtail(&mb->elems, ml);
|
|
|
|
|
|
|
|
|
|
return ml;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2022-07-07 16:20:27 +02:00
|
|
|
bool BKE_mball_is_basis(const Object *ob)
|
2003-11-21 12:30:15 +00:00
|
|
|
{
|
2021-12-07 17:19:15 +11:00
|
|
|
/* Meta-Ball Basis Notes from Blender-2.5x
|
|
|
|
|
* =======================================
|
|
|
|
|
*
|
2023-02-09 11:30:25 +11:00
|
|
|
* NOTE(@ideasman42): This is a can of worms.
|
2021-12-07 17:19:15 +11:00
|
|
|
*
|
|
|
|
|
* This really needs a rewrite/refactor its totally broken in anything other than basic cases
|
|
|
|
|
* Multiple Scenes + Set Scenes & mixing meta-ball basis _should_ work but fails to update the
|
|
|
|
|
* depsgraph on rename and linking into scenes or removal of basis meta-ball.
|
|
|
|
|
* So take care when changing this code.
|
|
|
|
|
*
|
|
|
|
|
* Main idiot thing here is that the system returns #BKE_mball_basis_find()
|
|
|
|
|
* objects which fail a #BKE_mball_is_basis() test.
|
|
|
|
|
*
|
|
|
|
|
* Not only that but the depsgraph and their areas depend on this behavior,
|
|
|
|
|
* so making small fixes here isn't worth it. */
|
|
|
|
|
|
|
|
|
|
/* Just a quick test. */
|
2013-03-09 05:35:49 +00:00
|
|
|
const int len = strlen(ob->id.name);
|
2022-10-07 22:52:53 +11:00
|
|
|
return !isdigit(ob->id.name[len - 1]);
|
2003-11-21 12:30:15 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2022-07-07 16:20:27 +02:00
|
|
|
bool BKE_mball_is_same_group(const Object *ob1, const Object *ob2)
|
2010-06-27 12:45:09 +00:00
|
|
|
{
|
|
|
|
|
int basis1nr, basis2nr;
|
2012-01-11 08:51:06 +00:00
|
|
|
char basis1name[MAX_ID_NAME], basis2name[MAX_ID_NAME];
|
2010-06-27 12:45:09 +00:00
|
|
|
|
2018-10-21 17:17:34 +02:00
|
|
|
if (ob1->id.name[2] != ob2->id.name[2]) {
|
|
|
|
|
/* Quick return in case first char of both ID's names is not the same... */
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 10:40:38 +10:00
|
|
|
BLI_string_split_name_number(ob1->id.name + 2, '.', basis1name, &basis1nr);
|
|
|
|
|
BLI_string_split_name_number(ob2->id.name + 2, '.', basis2name, &basis2nr);
|
2010-06-27 12:45:09 +00:00
|
|
|
|
2022-07-07 16:20:27 +02:00
|
|
|
return STREQ(basis1name, basis2name);
|
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
2022-07-07 16:20:27 +02:00
|
|
|
bool BKE_mball_is_basis_for(const Object *ob1, const Object *ob2)
|
|
|
|
|
{
|
|
|
|
|
return BKE_mball_is_same_group(ob1, ob2) && BKE_mball_is_basis(ob1);
|
2010-06-27 12:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-12 22:16:09 +02:00
|
|
|
bool BKE_mball_is_any_selected(const MetaBall *mb)
|
|
|
|
|
{
|
2022-08-09 13:49:09 -05:00
|
|
|
LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) {
|
2018-05-20 08:52:10 +02:00
|
|
|
if (ml->flag & SELECT) {
|
2018-05-12 22:16:09 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 18:18:14 +01:00
|
|
|
bool BKE_mball_is_any_selected_multi(const Span<Base *> bases)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2024-01-24 18:18:14 +01:00
|
|
|
for (Base *base : bases) {
|
|
|
|
|
Object *obedit = base->object;
|
2018-11-06 23:30:30 -02:00
|
|
|
MetaBall *mb = (MetaBall *)obedit->data;
|
|
|
|
|
if (BKE_mball_is_any_selected(mb)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-12 22:16:09 +02:00
|
|
|
bool BKE_mball_is_any_unselected(const MetaBall *mb)
|
|
|
|
|
{
|
2022-08-09 13:49:09 -05:00
|
|
|
LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) {
|
2018-05-20 08:52:10 +02:00
|
|
|
if ((ml->flag & SELECT) == 0) {
|
2018-05-12 22:16:09 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 16:20:27 +02:00
|
|
|
static void mball_data_properties_copy(MetaBall *mb_dst, MetaBall *mb_src)
|
2009-08-03 14:40:10 +00:00
|
|
|
{
|
2022-07-07 16:20:27 +02:00
|
|
|
mb_dst->wiresize = mb_src->wiresize;
|
|
|
|
|
mb_dst->rendersize = mb_src->rendersize;
|
|
|
|
|
mb_dst->thresh = mb_src->thresh;
|
|
|
|
|
mb_dst->flag = mb_src->flag;
|
|
|
|
|
DEG_id_tag_update(&mb_dst->id, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mball_properties_copy(Main *bmain, MetaBall *metaball_src)
|
|
|
|
|
{
|
2022-07-08 09:10:30 +10:00
|
|
|
/**
|
|
|
|
|
* WARNING: This code does not cover all potential corner-cases. E.g. if:
|
|
|
|
|
* <pre>
|
|
|
|
|
* | Object | ObData |
|
|
|
|
|
* | ---------- | ---------- |
|
|
|
|
|
* | Meta_A | Meta_A |
|
|
|
|
|
* | Meta_A.001 | Meta_A.001 |
|
|
|
|
|
* | Meta_B | Meta_A |
|
|
|
|
|
* | Meta_B.001 | Meta_B.001 |
|
|
|
|
|
* </pre>
|
2022-07-07 16:20:27 +02:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2022-08-09 13:49:09 -05:00
|
|
|
for (Object *ob_src = static_cast<Object *>(bmain->objects.first);
|
|
|
|
|
ob_src != nullptr && !ID_IS_LINKED(ob_src);)
|
|
|
|
|
{
|
2022-07-07 16:20:27 +02:00
|
|
|
if (ob_src->data != metaball_src) {
|
2022-08-09 13:49:09 -05:00
|
|
|
ob_src = static_cast<Object *>(ob_src->id.next);
|
2022-07-07 16:20:27 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In this code we take advantage of two facts:
|
|
|
|
|
* - MetaBalls of the same family have the same basis name,
|
|
|
|
|
* - IDs are sorted by name in their Main listbase.
|
|
|
|
|
* So, all MetaBall objects of the same family are contiguous in bmain list (potentially mixed
|
|
|
|
|
* with non-meta-ball objects with same basis names).
|
|
|
|
|
*
|
|
|
|
|
* Using this, it is possible to process the whole set of meta-balls with a single loop on the
|
|
|
|
|
* whole list of Objects, though additionally going backward on part of the list in some cases.
|
|
|
|
|
*/
|
2022-08-09 13:49:09 -05:00
|
|
|
Object *ob_iter = nullptr;
|
2022-07-07 16:20:27 +02:00
|
|
|
int obactive_nr, ob_nr;
|
|
|
|
|
char obactive_name[MAX_ID_NAME], ob_name[MAX_ID_NAME];
|
2023-05-03 10:40:38 +10:00
|
|
|
BLI_string_split_name_number(ob_src->id.name + 2, '.', obactive_name, &obactive_nr);
|
2022-07-07 16:20:27 +02:00
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
for (ob_iter = static_cast<Object *>(ob_src->id.prev); ob_iter != nullptr;
|
|
|
|
|
ob_iter = static_cast<Object *>(ob_iter->id.prev))
|
|
|
|
|
{
|
2022-07-07 16:20:27 +02:00
|
|
|
if (ob_iter->id.name[2] != obactive_name[0]) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ob_iter->type != OB_MBALL || ob_iter->data == metaball_src) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-05-03 10:40:38 +10:00
|
|
|
BLI_string_split_name_number(ob_iter->id.name + 2, '.', ob_name, &ob_nr);
|
2022-07-07 16:20:27 +02:00
|
|
|
if (!STREQ(obactive_name, ob_name)) {
|
|
|
|
|
break;
|
2009-08-03 14:40:10 +00:00
|
|
|
}
|
2022-07-07 16:20:27 +02:00
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
mball_data_properties_copy(static_cast<MetaBall *>(ob_iter->data), metaball_src);
|
2009-08-03 14:40:10 +00:00
|
|
|
}
|
2022-07-07 16:20:27 +02:00
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
for (ob_iter = static_cast<Object *>(ob_src->id.next); ob_iter != nullptr;
|
|
|
|
|
ob_iter = static_cast<Object *>(ob_iter->id.next))
|
|
|
|
|
{
|
2022-07-07 16:20:27 +02:00
|
|
|
if (ob_iter->id.name[2] != obactive_name[0] || ID_IS_LINKED(ob_iter)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ob_iter->type != OB_MBALL || ob_iter->data == metaball_src) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-05-03 10:40:38 +10:00
|
|
|
BLI_string_split_name_number(ob_iter->id.name + 2, '.', ob_name, &ob_nr);
|
2022-07-07 16:20:27 +02:00
|
|
|
if (!STREQ(obactive_name, ob_name)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 13:49:09 -05:00
|
|
|
mball_data_properties_copy(static_cast<MetaBall *>(ob_iter->data), metaball_src);
|
2022-07-07 16:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ob_src = ob_iter;
|
2009-08-03 14:40:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
Object *BKE_mball_basis_find(Scene *scene, Object *object)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2020-09-04 20:59:13 +02:00
|
|
|
Object *bob = object;
|
2004-11-10 13:20:13 +00:00
|
|
|
int basisnr, obnr;
|
2012-01-11 08:51:06 +00:00
|
|
|
char basisname[MAX_ID_NAME], obname[MAX_ID_NAME];
|
2010-11-01 07:19:41 +00:00
|
|
|
|
2023-05-03 10:40:38 +10:00
|
|
|
BLI_string_split_name_number(object->id.name + 2, '.', basisname, &basisnr);
|
2004-11-10 13:20:13 +00:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
|
|
|
|
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
Object *ob = base->object;
|
2019-01-15 23:27:54 +11:00
|
|
|
if ((ob->type == OB_MBALL) && !(base->flag & BASE_FROM_DUPLI)) {
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
if (ob != bob) {
|
2023-05-03 10:40:38 +10:00
|
|
|
BLI_string_split_name_number(ob->id.name + 2, '.', obname, &obnr);
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Object ob has to be in same "group" ... it means,
|
|
|
|
|
* that it has to have same base of its name. */
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
if (STREQ(obname, basisname)) {
|
|
|
|
|
if (obnr < basisnr) {
|
2020-09-04 20:59:13 +02:00
|
|
|
object = ob;
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
basisnr = obnr;
|
|
|
|
|
}
|
2012-09-16 04:58:18 +00:00
|
|
|
}
|
2004-11-10 13:20:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
return object;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 08:02:02 +11:00
|
|
|
bool BKE_mball_minmax_ex(
|
|
|
|
|
const MetaBall *mb, float min[3], float max[3], const float obmat[4][4], const short flag)
|
2013-06-28 18:19:55 +00:00
|
|
|
{
|
|
|
|
|
const float scale = obmat ? mat4_to_scale(obmat) : 1.0f;
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
2013-06-28 18:19:55 +00:00
|
|
|
float centroid[3], vec[3];
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
|
2013-06-28 18:19:55 +00:00
|
|
|
if ((ml->flag & flag) == flag) {
|
|
|
|
|
const float scale_mb = (ml->rad * 0.5f) * scale;
|
|
|
|
|
|
|
|
|
|
if (obmat) {
|
|
|
|
|
mul_v3_m4v3(centroid, obmat, &ml->x);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3(centroid, &ml->x);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 11:30:25 +11:00
|
|
|
/* TODO(@ideasman42): non circle shapes cubes etc, probably nobody notices. */
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = -1; i != 3; i += 2) {
|
2013-06-28 18:19:55 +00:00
|
|
|
copy_v3_v3(vec, centroid);
|
|
|
|
|
add_v3_fl(vec, scale_mb * i);
|
|
|
|
|
minmax_v3v3_v3(min, max, vec);
|
|
|
|
|
}
|
2013-11-26 06:39:14 +11:00
|
|
|
changed = true;
|
2013-06-28 18:19:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2013-06-28 18:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 08:02:02 +11:00
|
|
|
bool BKE_mball_minmax(const MetaBall *mb, float min[3], float max[3])
|
2012-02-26 08:55:31 +00:00
|
|
|
{
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, &ml->x);
|
2012-02-26 08:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
return (BLI_listbase_is_empty(&mb->elems) == false);
|
2012-02-26 08:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 08:02:02 +11:00
|
|
|
bool BKE_mball_center_median(const MetaBall *mb, float r_cent[3])
|
2012-02-26 08:55:31 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
int total = 0;
|
2012-02-26 08:55:31 +00:00
|
|
|
|
2012-08-18 19:30:27 +00:00
|
|
|
zero_v3(r_cent);
|
2012-02-26 08:55:31 +00:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
|
2012-08-18 19:30:27 +00:00
|
|
|
add_v3_v3(r_cent, &ml->x);
|
2013-07-13 05:50:35 +00:00
|
|
|
total++;
|
2012-02-26 08:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-18 19:30:27 +00:00
|
|
|
if (total) {
|
2022-09-25 18:33:28 +10:00
|
|
|
mul_v3_fl(r_cent, 1.0f / float(total));
|
2012-08-18 19:30:27 +00:00
|
|
|
}
|
2012-02-26 08:55:31 +00:00
|
|
|
|
|
|
|
|
return (total != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 08:02:02 +11:00
|
|
|
bool BKE_mball_center_bounds(const MetaBall *mb, float r_cent[3])
|
2012-02-26 08:55:31 +00:00
|
|
|
{
|
|
|
|
|
float min[3], max[3];
|
|
|
|
|
|
2012-05-07 06:38:41 +00:00
|
|
|
if (BKE_mball_minmax(mb, min, max)) {
|
2012-08-18 19:30:27 +00:00
|
|
|
mid_v3_v3v3(r_cent, min, max);
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2012-02-26 08:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2012-02-26 08:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-23 09:03:57 +10:00
|
|
|
void BKE_mball_transform(MetaBall *mb, const float mat[4][4], const bool do_props)
|
2014-09-01 20:09:31 +10:00
|
|
|
{
|
|
|
|
|
float quat[4];
|
|
|
|
|
const float scale = mat4_to_scale(mat);
|
|
|
|
|
const float scale_sqrt = sqrtf(scale);
|
|
|
|
|
|
|
|
|
|
mat4_to_quat(quat, mat);
|
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
|
2018-11-08 08:02:02 +11:00
|
|
|
mul_m4_v3(mat, &ml->x);
|
|
|
|
|
mul_qt_qtqt(ml->quat, quat, ml->quat);
|
2017-08-11 22:16:44 +10:00
|
|
|
|
|
|
|
|
if (do_props) {
|
2018-11-08 08:02:02 +11:00
|
|
|
ml->rad *= scale;
|
2017-08-11 22:16:44 +10:00
|
|
|
/* hrmf, probably elems shouldn't be
|
|
|
|
|
* treating scale differently - campbell */
|
2018-11-08 08:02:02 +11:00
|
|
|
if (!MB_TYPE_SIZE_SQUARED(ml->type)) {
|
|
|
|
|
mul_v3_fl(&ml->expx, scale);
|
2017-08-11 22:16:44 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2018-11-08 08:02:02 +11:00
|
|
|
mul_v3_fl(&ml->expx, scale_sqrt);
|
2017-08-11 22:16:44 +10:00
|
|
|
}
|
2014-09-01 20:09:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-06 03:34:52 +00:00
|
|
|
void BKE_mball_translate(MetaBall *mb, const float offset[3])
|
2012-02-26 08:55:31 +00:00
|
|
|
{
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
|
2012-02-26 08:55:31 +00:00
|
|
|
add_v3_v3(&ml->x, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-06 03:02:14 +00:00
|
|
|
|
2018-11-08 08:02:02 +11:00
|
|
|
int BKE_mball_select_count(const MetaBall *mb)
|
|
|
|
|
{
|
2018-11-06 23:36:50 -02:00
|
|
|
int sel = 0;
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) {
|
2018-11-06 23:36:50 -02:00
|
|
|
if (ml->flag & SELECT) {
|
|
|
|
|
sel++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return sel;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 18:18:14 +01:00
|
|
|
int BKE_mball_select_count_multi(const Span<Base *> bases)
|
2018-11-08 08:02:02 +11:00
|
|
|
{
|
2018-11-06 23:36:50 -02:00
|
|
|
int sel = 0;
|
2024-01-24 18:18:14 +01:00
|
|
|
for (Base *base : bases) {
|
|
|
|
|
Object *obedit = base->object;
|
2018-11-08 08:02:02 +11:00
|
|
|
const MetaBall *mb = (MetaBall *)obedit->data;
|
2018-11-06 23:36:50 -02:00
|
|
|
sel += BKE_mball_select_count(mb);
|
|
|
|
|
}
|
|
|
|
|
return sel;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_select_all(MetaBall *mb)
|
2012-10-06 03:02:14 +00:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed = false;
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
|
2019-03-26 18:47:55 +11:00
|
|
|
if ((ml->flag & SELECT) == 0) {
|
|
|
|
|
ml->flag |= SELECT;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2012-10-06 03:02:14 +00:00
|
|
|
}
|
2019-03-26 18:47:55 +11:00
|
|
|
return changed;
|
2012-10-06 03:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 18:18:14 +01:00
|
|
|
bool BKE_mball_select_all_multi_ex(const Span<Base *> bases)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed_multi = false;
|
2024-01-24 18:18:14 +01:00
|
|
|
for (Base *base : bases) {
|
|
|
|
|
Object *obedit = base->object;
|
2022-08-09 13:49:09 -05:00
|
|
|
MetaBall *mb = static_cast<MetaBall *>(obedit->data);
|
2019-03-26 18:47:55 +11:00
|
|
|
changed_multi |= BKE_mball_select_all(mb);
|
2018-11-06 23:30:30 -02:00
|
|
|
}
|
2019-03-26 18:47:55 +11:00
|
|
|
return changed_multi;
|
2018-11-06 23:30:30 -02:00
|
|
|
}
|
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_deselect_all(MetaBall *mb)
|
2012-10-06 03:02:14 +00:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed = false;
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
|
2019-03-26 18:47:55 +11:00
|
|
|
if ((ml->flag & SELECT) != 0) {
|
|
|
|
|
ml->flag &= ~SELECT;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2012-10-06 03:02:14 +00:00
|
|
|
}
|
2019-03-26 18:47:55 +11:00
|
|
|
return changed;
|
2012-10-06 03:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 18:18:14 +01:00
|
|
|
bool BKE_mball_deselect_all_multi_ex(const Span<Base *> bases)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed_multi = false;
|
2024-01-24 18:18:14 +01:00
|
|
|
for (Base *base : bases) {
|
|
|
|
|
Object *obedit = base->object;
|
2022-08-09 13:49:09 -05:00
|
|
|
MetaBall *mb = static_cast<MetaBall *>(obedit->data);
|
2019-03-26 18:47:55 +11:00
|
|
|
changed_multi |= BKE_mball_deselect_all(mb);
|
|
|
|
|
DEG_id_tag_update(&mb->id, ID_RECALC_SELECT);
|
2018-11-06 23:30:30 -02:00
|
|
|
}
|
2019-03-26 18:47:55 +11:00
|
|
|
return changed_multi;
|
2018-11-06 23:30:30 -02:00
|
|
|
}
|
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_select_swap(MetaBall *mb)
|
2012-10-06 03:02:14 +00:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed = false;
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
|
2012-10-06 03:02:14 +00:00
|
|
|
ml->flag ^= SELECT;
|
2019-03-26 18:47:55 +11:00
|
|
|
changed = true;
|
2012-10-06 03:02:14 +00:00
|
|
|
}
|
2019-03-26 18:47:55 +11:00
|
|
|
return changed;
|
2012-10-06 03:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 18:18:14 +01:00
|
|
|
bool BKE_mball_select_swap_multi_ex(const Span<Base *> bases)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed_multi = false;
|
2024-01-24 18:18:14 +01:00
|
|
|
for (Base *base : bases) {
|
|
|
|
|
Object *obedit = base->object;
|
2018-11-06 23:30:30 -02:00
|
|
|
MetaBall *mb = (MetaBall *)obedit->data;
|
2019-03-26 18:47:55 +11:00
|
|
|
changed_multi |= BKE_mball_select_swap(mb);
|
2018-11-06 23:30:30 -02:00
|
|
|
}
|
2019-03-26 18:47:55 +11:00
|
|
|
return changed_multi;
|
2018-11-06 23:30:30 -02:00
|
|
|
}
|
|
|
|
|
|
2015-05-12 13:57:11 +05:00
|
|
|
/* **** Depsgraph evaluation **** */
|
|
|
|
|
|
2022-08-17 10:20:25 -04:00
|
|
|
void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
|
|
|
|
|
{
|
2023-06-15 22:18:28 +02:00
|
|
|
using namespace blender;
|
|
|
|
|
using namespace blender::bke;
|
2022-08-17 10:20:25 -04:00
|
|
|
BLI_assert(ob->type == OB_MBALL);
|
2017-11-16 15:12:32 -02:00
|
|
|
|
2022-08-17 10:20:25 -04:00
|
|
|
BKE_object_free_derived_caches(ob);
|
2017-11-16 15:12:32 -02:00
|
|
|
|
2022-08-17 10:20:25 -04:00
|
|
|
const Object *basis_object = BKE_mball_basis_find(scene, ob);
|
|
|
|
|
if (ob != basis_object) {
|
|
|
|
|
return;
|
2017-11-16 15:12:32 -02:00
|
|
|
}
|
2022-08-17 10:20:25 -04:00
|
|
|
|
|
|
|
|
Mesh *mesh = BKE_mball_polygonize(depsgraph, scene, ob);
|
2022-08-28 20:52:28 +10:00
|
|
|
if (mesh == nullptr) {
|
2022-08-17 10:20:25 -04:00
|
|
|
return;
|
2017-11-16 15:12:32 -02:00
|
|
|
}
|
2022-08-17 10:20:25 -04:00
|
|
|
|
|
|
|
|
const MetaBall *mball = static_cast<MetaBall *>(ob->data);
|
|
|
|
|
mesh->mat = static_cast<Material **>(MEM_dupallocN(mball->mat));
|
|
|
|
|
mesh->totcol = mball->totcol;
|
|
|
|
|
|
|
|
|
|
if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
|
2023-03-19 00:26:28 +01:00
|
|
|
BKE_lattice_deform_coords(
|
2023-06-14 11:59:32 -04:00
|
|
|
ob->parent,
|
|
|
|
|
ob,
|
|
|
|
|
reinterpret_cast<float(*)[3]>(mesh->vert_positions_for_write().data()),
|
2023-12-20 02:21:48 +01:00
|
|
|
mesh->verts_num,
|
2023-06-14 11:59:32 -04:00
|
|
|
0,
|
|
|
|
|
nullptr,
|
|
|
|
|
1.0f);
|
2023-12-12 15:38:42 -05:00
|
|
|
mesh->tag_positions_changed();
|
2022-08-17 10:20:25 -04:00
|
|
|
}
|
|
|
|
|
|
2023-11-15 18:46:07 +01:00
|
|
|
ob->runtime->geometry_set_eval = new GeometrySet(GeometrySet::from_mesh(mesh));
|
2022-08-17 10:20:25 -04:00
|
|
|
};
|