2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
2011-10-10 09:38:02 +00:00
|
|
|
* 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
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
2003-12-08 13:48:20 +00:00
|
|
|
#include <ctype.h>
|
2007-04-20 12:56:51 +00:00
|
|
|
#include <float.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
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"
|
|
|
|
#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"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_string_utils.h"
|
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"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
2020-09-10 16:37:11 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2013-08-19 09:25:24 +00:00
|
|
|
#include "BKE_curve.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_displist.h"
|
2020-03-06 16:08:24 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-12 18:03:42 +02:00
|
|
|
#include "BKE_lib_query.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_mball.h"
|
2005-07-18 19:59:51 +00:00
|
|
|
#include "BKE_object.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_scene.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-03-06 13:16:48 +11:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2020-09-10 16:37:11 +02:00
|
|
|
#include "BLO_read_write.h"
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void metaball_copy_data(Main *UNUSED(bmain),
|
|
|
|
ID *id_dst,
|
|
|
|
const ID *id_src,
|
|
|
|
const int UNUSED(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
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
metaball_dst->mat = MEM_dupallocN(metaball_src->mat);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
metaball_dst->editelems = NULL;
|
|
|
|
metaball_dst->lastelem = NULL;
|
|
|
|
metaball_dst->batch_cache = NULL;
|
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
|
|
|
BKE_mball_batch_cache_free(metaball);
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(metaball->mat);
|
|
|
|
|
|
|
|
BLI_freelistN(&metaball->elems);
|
|
|
|
if (metaball->disp.first) {
|
|
|
|
BKE_displist_free(&metaball->disp);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
MetaBall *metaball = (MetaBall *)id;
|
|
|
|
for (int i = 0; i < metaball->totcol; i++) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, metaball->mat[i], IDWALK_CB_USER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (mb->id.us > 0 || BLO_write_is_undo(writer)) {
|
|
|
|
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
|
|
|
BLI_listbase_clear(&mb->disp);
|
|
|
|
mb->editelems = NULL;
|
|
|
|
/* Must always be cleared (meta's don't have their own edit-data). */
|
|
|
|
mb->needs_flush_to_id = 0;
|
|
|
|
mb->lastelem = NULL;
|
|
|
|
mb->batch_cache = NULL;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
if (mb->adt) {
|
|
|
|
BKE_animdata_blend_write(writer, mb->adt);
|
|
|
|
}
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
|
|
|
|
BLO_write_struct(writer, MetaElem, ml);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
{
|
|
|
|
MetaBall *mb = (MetaBall *)id;
|
|
|
|
BLO_read_data_address(reader, &mb->adt);
|
|
|
|
BKE_animdata_blend_read_data(reader, mb->adt);
|
|
|
|
|
|
|
|
BLO_read_pointer_array(reader, (void **)&mb->mat);
|
|
|
|
|
|
|
|
BLO_read_list(reader, &(mb->elems));
|
|
|
|
|
|
|
|
BLI_listbase_clear(&mb->disp);
|
|
|
|
mb->editelems = NULL;
|
|
|
|
/* Must always be cleared (meta's don't have their own edit-data). */
|
|
|
|
mb->needs_flush_to_id = 0;
|
|
|
|
/* mb->edit_elems.first= mb->edit_elems.last= NULL;*/
|
|
|
|
mb->lastelem = NULL;
|
|
|
|
mb->batch_cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void metaball_blend_read_lib(BlendLibReader *reader, ID *id)
|
|
|
|
{
|
|
|
|
MetaBall *mb = (MetaBall *)id;
|
|
|
|
for (int a = 0; a < mb->totcol; a++) {
|
|
|
|
BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system
|
|
|
|
}
|
|
|
|
|
|
|
|
static void metaball_blend_read_expand(BlendExpander *expander, ID *id)
|
|
|
|
{
|
|
|
|
MetaBall *mb = (MetaBall *)id;
|
|
|
|
for (int a = 0; a < mb->totcol; a++) {
|
|
|
|
BLO_expand(expander, mb->mat[a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:08:24 +01:00
|
|
|
IDTypeInfo IDType_ID_MB = {
|
|
|
|
.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,
|
|
|
|
.flags = 0,
|
|
|
|
|
|
|
|
.init_data = metaball_init_data,
|
|
|
|
.copy_data = metaball_copy_data,
|
|
|
|
.free_data = metaball_free_data,
|
|
|
|
.make_local = NULL,
|
2020-05-12 18:03:42 +02:00
|
|
|
.foreach_id = metaball_foreach_id,
|
2020-08-28 13:05:48 +02:00
|
|
|
.foreach_cache = NULL,
|
2021-02-25 10:17:31 +01:00
|
|
|
.owner_get = NULL,
|
2020-08-28 13:05:48 +02:00
|
|
|
|
2020-09-10 16:37:11 +02:00
|
|
|
.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,
|
2020-11-03 11:39:36 +01:00
|
|
|
|
|
|
|
.blend_read_undo_preserve = NULL,
|
2021-01-22 14:52:50 +01:00
|
|
|
|
|
|
|
.lib_override_apply_post = NULL,
|
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)
|
|
|
|
{
|
|
|
|
MetaBall *mb;
|
|
|
|
|
2020-10-08 12:50:04 +02:00
|
|
|
mb = BKE_id_new(bmain, ID_MB, name);
|
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
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return mb;
|
|
|
|
}
|
|
|
|
|
2010-08-23 00:57:19 +00:00
|
|
|
/* most simple meta-element adding function
|
2011-04-21 05:49:47 +00:00
|
|
|
* don't do context manipulation here (rna uses) */
|
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
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
MetaElem *ml = MEM_callocN(sizeof(MetaElem), "metaelem");
|
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;
|
|
|
|
}
|
2019-11-25 01:14:39 +11:00
|
|
|
/**
|
2020-08-19 14:15:10 +10:00
|
|
|
* Compute bounding box of all #MetaElem / #MetaBall
|
2003-12-08 13:30:04 +00:00
|
|
|
*
|
2020-08-19 14:15:10 +10:00
|
|
|
* Bounding box is computed from polygonized surface. \a 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.
|
2003-12-08 13:30:04 +00:00
|
|
|
*/
|
2012-05-07 06:38:41 +00:00
|
|
|
void BKE_mball_texspace_calc(Object *ob)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
DispList *dl;
|
|
|
|
BoundBox *bb;
|
2011-04-21 05:49:47 +00:00
|
|
|
float *data, min[3], max[3] /*, loc[3], size[3] */;
|
2014-04-11 11:25:41 +10:00
|
|
|
int tot;
|
|
|
|
bool do_it = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-17 12:24:08 +11:00
|
|
|
if (ob->runtime.bb == NULL) {
|
|
|
|
ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "mb boundbox");
|
|
|
|
}
|
|
|
|
bb = ob->runtime.bb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* Weird one, this. */
|
2012-05-06 15:15:33 +00:00
|
|
|
/* INIT_MINMAX(min, max); */
|
|
|
|
(min)[0] = (min)[1] = (min)[2] = 1.0e30f;
|
|
|
|
(max)[0] = (max)[1] = (max)[2] = -1.0e30f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-30 16:54:40 +02:00
|
|
|
dl = ob->runtime.curve_cache->disp.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (dl) {
|
2012-05-06 15:15:33 +00:00
|
|
|
tot = dl->nr;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot) {
|
2014-04-01 11:34:00 +11:00
|
|
|
do_it = true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
data = dl->verts;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (tot--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
/* Also weird... but longer. From utildefines. */
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, data);
|
2012-05-06 15:15:33 +00:00
|
|
|
data += 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = dl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
if (!do_it) {
|
2005-07-18 17:33:51 +00:00
|
|
|
min[0] = min[1] = min[2] = -1.0f;
|
|
|
|
max[0] = max[1] = max[2] = 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-03-04 21:50:54 +11:00
|
|
|
bb->flag &= ~BOUNDBOX_DIRTY;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 21:26:44 +02:00
|
|
|
/** Return or compute bbox for given metaball object. */
|
|
|
|
BoundBox *BKE_mball_boundbox_get(Object *ob)
|
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MBALL);
|
|
|
|
|
2019-02-17 12:24:08 +11:00
|
|
|
if (ob->runtime.bb != NULL && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
|
|
|
|
return ob->runtime.bb;
|
2018-08-23 21:26:44 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* This should always only be called with evaluated objects,
|
|
|
|
* but currently RNA is a problem here... */
|
2018-08-23 21:26:44 +02:00
|
|
|
if (ob->runtime.curve_cache != NULL) {
|
|
|
|
BKE_mball_texspace_calc(ob);
|
|
|
|
}
|
|
|
|
|
2019-02-17 12:24:08 +11:00
|
|
|
return ob->runtime.bb;
|
2018-08-23 21:26:44 +02:00
|
|
|
}
|
|
|
|
|
2012-05-07 06:38:41 +00:00
|
|
|
float *BKE_mball_make_orco(Object *ob, ListBase *dispbase)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BoundBox *bb;
|
|
|
|
DispList *dl;
|
2008-02-26 16:20:36 +00:00
|
|
|
float *data, *orco, *orcodata;
|
2002-10-12 11:37:38 +00:00
|
|
|
float loc[3], size[3];
|
|
|
|
int a;
|
2008-02-26 16:20:36 +00:00
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* restore size and loc */
|
2019-02-17 12:24:08 +11:00
|
|
|
bb = ob->runtime.bb;
|
2012-05-06 15:15:33 +00:00
|
|
|
loc[0] = (bb->vec[0][0] + bb->vec[4][0]) / 2.0f;
|
|
|
|
size[0] = bb->vec[4][0] - loc[0];
|
|
|
|
loc[1] = (bb->vec[0][1] + bb->vec[2][1]) / 2.0f;
|
|
|
|
size[1] = bb->vec[2][1] - loc[1];
|
|
|
|
loc[2] = (bb->vec[0][2] + bb->vec[1][2]) / 2.0f;
|
|
|
|
size[2] = bb->vec[1][2] - loc[2];
|
|
|
|
|
|
|
|
dl = dispbase->first;
|
2020-08-08 13:29:21 +10:00
|
|
|
orcodata = MEM_mallocN(sizeof(float[3]) * dl->nr, "MballOrco");
|
2012-05-06 15:15:33 +00:00
|
|
|
|
|
|
|
data = dl->verts;
|
|
|
|
orco = orcodata;
|
|
|
|
a = dl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
orco[0] = (data[0] - loc[0]) / size[0];
|
|
|
|
orco[1] = (data[1] - loc[1]) / size[1];
|
|
|
|
orco[2] = (data[2] - loc[2]) / size[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
data += 3;
|
|
|
|
orco += 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-02-26 16:20:36 +00:00
|
|
|
|
|
|
|
return orcodata;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-11-18 04:26:50 +00:00
|
|
|
|
2020-08-19 14:15:10 +10:00
|
|
|
/**
|
|
|
|
* \brief Test, if \a 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Meta-Ball Basis Notes from Blender-2.5x
|
|
|
|
* =======================================
|
|
|
|
*
|
|
|
|
* This is a can of worms.
|
|
|
|
*
|
2011-04-21 05:49:47 +00:00
|
|
|
* This really needs a rewrite/refactor its totally broken in anything other than basic cases
|
2020-08-19 14:15:10 +10:00
|
|
|
* 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.
|
2019-04-27 12:07:07 +10:00
|
|
|
* So take care when changing this code.
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2020-08-19 14:15:10 +10:00
|
|
|
* Main idiot thing here is that the system returns #BKE_mball_basis_find()
|
|
|
|
* objects which fail a #BKE_mball_is_basis() test.
|
2010-11-18 04:26:50 +00:00
|
|
|
*
|
2020-08-19 14:15:10 +10:00
|
|
|
* Not only that but the depsgraph and their areas depend on this behavior,
|
2019-04-27 12:07:07 +10:00
|
|
|
* so making small fixes here isn't worth it.
|
2011-04-21 05:49:47 +00:00
|
|
|
* - Campbell
|
2010-11-18 04:26:50 +00:00
|
|
|
*/
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_mball_is_basis(Object *ob)
|
2003-11-21 12:30:15 +00:00
|
|
|
{
|
|
|
|
/* just a quick test */
|
2013-03-09 05:35:49 +00:00
|
|
|
const int len = strlen(ob->id.name);
|
|
|
|
return (!isdigit(ob->id.name[len - 1]));
|
2003-11-21 12:30:15 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-06-27 12:45:09 +00:00
|
|
|
/* return nonzero if ob1 is a basis mball for ob */
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_mball_is_basis_for(Object *ob1, 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;
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
BLI_split_name_num(basis1name, &basis1nr, ob1->id.name + 2, '.');
|
|
|
|
BLI_split_name_num(basis2name, &basis2nr, ob2->id.name + 2, '.');
|
2010-06-27 12:45:09 +00:00
|
|
|
|
2015-01-26 16:03:11 +01:00
|
|
|
if (STREQ(basis1name, basis2name)) {
|
2013-03-09 05:35:49 +00:00
|
|
|
return BKE_mball_is_basis(ob1);
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
return false;
|
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)
|
|
|
|
{
|
|
|
|
for (const MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) {
|
2018-05-20 08:52:10 +02:00
|
|
|
if (ml->flag & SELECT) {
|
2018-05-12 22:16:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_is_any_selected_multi(Base **bases, int bases_len)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
for (uint base_index = 0; base_index < bases_len; base_index++) {
|
|
|
|
Object *obedit = bases[base_index]->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)
|
|
|
|
{
|
|
|
|
for (const MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-17 00:54:22 +10:00
|
|
|
/**
|
2020-08-19 14:15:10 +10:00
|
|
|
* \brief copy some properties from object to other meta-ball object with same base name
|
2009-08-03 14:40:10 +00:00
|
|
|
*
|
2020-08-19 14:15:10 +10:00
|
|
|
* 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 influence polygonization of meta-balls. */
|
2012-05-07 06:38:41 +00:00
|
|
|
void BKE_mball_properties_copy(Scene *scene, Object *active_object)
|
2009-08-03 14:40:10 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Scene *sce_iter = scene;
|
2017-11-09 15:44:56 -02:00
|
|
|
Base *base;
|
2009-08-03 14:40:10 +00:00
|
|
|
Object *ob;
|
2012-05-06 15:15:33 +00:00
|
|
|
MetaBall *active_mball = (MetaBall *)active_object->data;
|
2009-08-03 14:40:10 +00:00
|
|
|
int basisnr, obnr;
|
2012-01-11 08:51:06 +00:00
|
|
|
char basisname[MAX_ID_NAME], obname[MAX_ID_NAME];
|
Fixed more threading issues with metaballs
This time issue was caused by static variables used in
BKE_scene_base_iter_next function.
Change is not so much ultimate actually, but didn't
find more clear solution for now. So the changes are:
- Wrap almost all the static variables into own context-
like structure, which is owned by the callee function
and getting passed to the iteration function.
- Recursion detection wasn't possible with such approach,
so recursion detection still uses static in_next_object
variable, but which is now stored in thread local
storage (TLS, or thread variable if this names are more
clear for you).
This makes code thread-safe, but for sure final solution
shall be completely different. Ideally, dependency graph
shall be possible to answer on question "which object is
a motherball for this metaball". This will avoid iterating
via all the bases, objects and duplis just to get needed
motherball.
Further, metaball evaluation ideally will use the same
kind of depsgraph filtering, which will get result for
question like "which objects belongs to this group of
metaballs".
But this ideal things are to be solved in Joshua's and
mind GSoC projects.
Tested on linux (gcc and clang) and windows (msvc2008),
hopefully no compilation error will happen.
Thanks to Brecht for reviewing the change and getting
feedback for other possible ways we've dicussed!
2013-07-09 08:23:01 +00:00
|
|
|
SceneBaseIter iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
BLI_split_name_num(basisname, &basisnr, active_object->id.name + 2, '.');
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
/* Pass depsgraph as NULL, which means we will not expand into
|
2020-08-19 14:15:10 +10:00
|
|
|
* duplis unlike when we generate the meta-ball. Expanding duplis
|
2018-04-06 12:07:27 +02:00
|
|
|
* would not be compatible when editing multiple view layers. */
|
|
|
|
BKE_scene_base_iter_next(NULL, &iter, &sce_iter, 0, NULL, NULL);
|
|
|
|
while (BKE_scene_base_iter_next(NULL, &iter, &sce_iter, 1, &base, &ob)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->type == OB_MBALL) {
|
2012-02-23 02:17:50 +00:00
|
|
|
if (ob != active_object) {
|
2012-05-06 15:15:33 +00:00
|
|
|
BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-08-03 14:40:10 +00:00
|
|
|
/* Object ob has to be in same "group" ... it means, that it has to have
|
|
|
|
* same base of its name */
|
2015-01-26 16:03:11 +01:00
|
|
|
if (STREQ(obname, basisname)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
MetaBall *mb = ob->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-08-03 14:40:10 +00:00
|
|
|
/* Copy properties from selected/edited metaball */
|
2012-05-06 15:15:33 +00:00
|
|
|
mb->wiresize = active_mball->wiresize;
|
|
|
|
mb->rendersize = active_mball->rendersize;
|
|
|
|
mb->thresh = active_mball->thresh;
|
|
|
|
mb->flag = active_mball->flag;
|
2019-03-06 13:16:48 +11:00
|
|
|
DEG_id_tag_update(&mb->id, 0);
|
2009-08-03 14:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
/** \brief This function finds the basis MetaBall.
|
2003-12-08 13:30:04 +00:00
|
|
|
*
|
2020-09-04 20:59:13 +02:00
|
|
|
* Basis meta-ball doesn't include any number at the end of
|
2020-08-19 14:15:10 +10:00
|
|
|
* its name. All meta-balls with same base of name can be
|
|
|
|
* blended. meta-balls with different basic name can't be blended.
|
2010-11-18 04:26:50 +00:00
|
|
|
*
|
2020-08-19 14:15:10 +10:00
|
|
|
* \warning #BKE_mball_is_basis() can fail on returned object, see function docs for details.
|
2003-12-08 13:30:04 +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
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
BLI_split_name_num(basisname, &basisnr, object->id.name + 2, '.');
|
2004-11-10 13:20:13 +00:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
|
|
|
|
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
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) {
|
|
|
|
BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO, non circle shapes cubes etc, probably nobody notices - campbell */
|
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
|
|
|
}
|
|
|
|
|
2012-02-26 08:55:31 +00:00
|
|
|
/* basic vertex data functions */
|
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) {
|
|
|
|
mul_v3_fl(r_cent, 1.0f / (float)total);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
/* *** select funcs *** */
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
int BKE_mball_select_count_multi(Base **bases, int bases_len)
|
2018-11-08 08:02:02 +11:00
|
|
|
{
|
2018-11-06 23:36:50 -02:00
|
|
|
int sel = 0;
|
2019-03-26 18:47:55 +11:00
|
|
|
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
|
|
|
|
const Object *obedit = bases[ob_index]->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
|
|
|
}
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_select_all_multi_ex(Base **bases, int bases_len)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed_multi = false;
|
|
|
|
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
|
|
|
|
Object *obedit = bases[ob_index]->object;
|
2018-11-08 08:02:02 +11:00
|
|
|
MetaBall *mb = 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
|
|
|
}
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_deselect_all_multi_ex(Base **bases, int bases_len)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed_multi = false;
|
|
|
|
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
|
|
|
|
Object *obedit = bases[ob_index]->object;
|
2018-11-08 08:02:02 +11:00
|
|
|
MetaBall *mb = 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
|
|
|
}
|
|
|
|
|
2019-03-26 18:47:55 +11:00
|
|
|
bool BKE_mball_select_swap_multi_ex(Base **bases, int bases_len)
|
2018-11-06 23:30:30 -02:00
|
|
|
{
|
2019-03-26 18:47:55 +11:00
|
|
|
bool changed_multi = false;
|
|
|
|
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
|
|
|
|
Object *obedit = bases[ob_index]->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 **** */
|
|
|
|
|
2017-11-16 15:12:32 -02:00
|
|
|
/* Draw Engine */
|
|
|
|
|
2020-10-09 07:25:43 +02:00
|
|
|
void (*BKE_mball_batch_cache_dirty_tag_cb)(MetaBall *mb, int mode) = NULL;
|
2017-11-16 15:12:32 -02:00
|
|
|
void (*BKE_mball_batch_cache_free_cb)(MetaBall *mb) = NULL;
|
|
|
|
|
2020-10-09 07:25:43 +02:00
|
|
|
void BKE_mball_batch_cache_dirty_tag(MetaBall *mb, int mode)
|
2017-11-16 15:12:32 -02:00
|
|
|
{
|
|
|
|
if (mb->batch_cache) {
|
2018-08-23 10:14:29 -03:00
|
|
|
BKE_mball_batch_cache_dirty_tag_cb(mb, mode);
|
2017-11-16 15:12:32 -02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void BKE_mball_batch_cache_free(MetaBall *mb)
|
|
|
|
{
|
|
|
|
if (mb->batch_cache) {
|
|
|
|
BKE_mball_batch_cache_free_cb(mb);
|
|
|
|
}
|
|
|
|
}
|