2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
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.
|
|
|
|
*
|
2003-12-08 13:30:04 +00:00
|
|
|
* Contributor(s): Jiri Hnidek <jiri.hnidek@vslib.cz>.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
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
|
|
|
*/
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/mball.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
2003-12-08 13:48:20 +00:00
|
|
|
#include <ctype.h>
|
2007-04-20 12:56:51 +00:00
|
|
|
#include <float.h>
|
2015-03-25 22:36:43 +11:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_meta_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
2009-08-03 13:09:23 +00:00
|
|
|
#include "BKE_animsys.h"
|
2013-08-19 09:25:24 +00:00
|
|
|
#include "BKE_curve.h"
|
2013-12-26 17:24:42 +06:00
|
|
|
#include "BKE_depsgraph.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_scene.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_displist.h"
|
|
|
|
#include "BKE_mball.h"
|
2005-07-18 19:59:51 +00:00
|
|
|
#include "BKE_object.h"
|
2011-04-26 07:17:21 +00:00
|
|
|
#include "BKE_material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
2012-05-07 06:38:41 +00:00
|
|
|
void BKE_mball_unlink(MetaBall *mb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
int a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < mb->totcol; a++) {
|
2012-02-23 02:17:50 +00:00
|
|
|
if (mb->mat[a]) mb->mat[a]->id.us--;
|
2012-05-06 15:15:33 +00:00
|
|
|
mb->mat[a] = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* do not free mball itself */
|
2012-05-07 06:38:41 +00:00
|
|
|
void BKE_mball_free(MetaBall *mb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-09-16 04:58:18 +00:00
|
|
|
BKE_mball_unlink(mb);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (mb->adt) {
|
2015-04-04 15:13:56 +11:00
|
|
|
BKE_animdata_free((ID *)mb);
|
2010-12-13 06:31:49 +00:00
|
|
|
mb->adt = NULL;
|
|
|
|
}
|
2012-02-23 02:17:50 +00:00
|
|
|
if (mb->mat) MEM_freeN(mb->mat);
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_freelistN(&mb->elems);
|
2012-05-07 06:58:03 +00:00
|
|
|
if (mb->disp.first) BKE_displist_free(&mb->disp);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-05 12:46:15 +00:00
|
|
|
MetaBall *BKE_mball_add(Main *bmain, const char *name)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
MetaBall *mb;
|
|
|
|
|
2014-01-15 16:37:03 +01:00
|
|
|
mb = BKE_libblock_alloc(bmain, ID_MB, name);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
mb->size[0] = mb->size[1] = mb->size[2] = 1.0;
|
|
|
|
mb->texflag = MB_AUTOSPACE;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
mb->wiresize = 0.4f;
|
|
|
|
mb->rendersize = 0.2f;
|
|
|
|
mb->thresh = 0.6f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return mb;
|
|
|
|
}
|
|
|
|
|
2012-05-07 06:38:41 +00:00
|
|
|
MetaBall *BKE_mball_copy(MetaBall *mb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
MetaBall *mbn;
|
|
|
|
int a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
mbn = BKE_libblock_copy(&mb->id);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-01-01 18:29:19 +00:00
|
|
|
BLI_duplicatelist(&mbn->elems, &mb->elems);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
mbn->mat = MEM_dupallocN(mb->mat);
|
|
|
|
for (a = 0; a < mbn->totcol; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
id_us_plus((ID *)mbn->mat[a]);
|
|
|
|
}
|
2011-04-21 09:38:09 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
mbn->editelems = NULL;
|
|
|
|
mbn->lastelem = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-01-09 09:52:51 +01:00
|
|
|
if (mb->id.lib) {
|
|
|
|
BKE_id_lib_local_paths(G.main, mb->id.lib, &mbn->id);
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return mbn;
|
|
|
|
}
|
|
|
|
|
2011-04-26 07:17:21 +00:00
|
|
|
static void extern_local_mball(MetaBall *mb)
|
|
|
|
{
|
2012-02-23 02:17:50 +00:00
|
|
|
if (mb->mat) {
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_matarar(mb->mat, mb->totcol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-07 06:38:41 +00:00
|
|
|
void BKE_mball_make_local(MetaBall *mb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Main *bmain = G.main;
|
2002-10-12 11:37:38 +00:00
|
|
|
Object *ob;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool is_local = false, is_lib = false;
|
2003-04-26 13:07:59 +00:00
|
|
|
|
|
|
|
/* - only lib users: do nothing
|
|
|
|
* - only local users: set flag
|
|
|
|
* - mixed: make copy
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (mb->id.lib == NULL) return;
|
|
|
|
if (mb->id.us == 1) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &mb->id);
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_mball(mb);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-26 07:17:21 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (ob = G.main->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) {
|
2012-02-23 02:17:50 +00:00
|
|
|
if (ob->data == mb) {
|
2014-04-01 11:34:00 +11:00
|
|
|
if (ob->id.lib) is_lib = true;
|
|
|
|
else is_local = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
if (is_local && is_lib == false) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &mb->id);
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_mball(mb);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-02-23 02:17:50 +00:00
|
|
|
else if (is_local && is_lib) {
|
2012-05-07 06:38:41 +00:00
|
|
|
MetaBall *mb_new = BKE_mball_copy(mb);
|
2012-05-06 15:15:33 +00:00
|
|
|
mb_new->id.us = 0;
|
2011-04-26 07:17:21 +00:00
|
|
|
|
2011-10-27 05:34:39 +00:00
|
|
|
/* Remap paths of new ID using old library as base. */
|
2011-11-30 00:32:13 +00:00
|
|
|
BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id);
|
2011-10-27 05:34:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (ob = G.main->object.first; ob; ob = ob->id.next) {
|
2012-02-23 02:17:50 +00:00
|
|
|
if (ob->data == mb) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->id.lib == NULL) {
|
|
|
|
ob->data = mb_new;
|
2011-11-30 00:32:13 +00:00
|
|
|
mb_new->id.us++;
|
2002-10-12 11:37:38 +00:00
|
|
|
mb->id.us--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
2003-12-08 13:30:04 +00:00
|
|
|
/** Compute bounding box of all MetaElems/MetaBalls.
|
|
|
|
*
|
|
|
|
* Bounding box is computed from polygonized surface. Object *ob is
|
2011-04-21 05:49:47 +00:00
|
|
|
* basic MetaBall (usually with name Meta). All other MetaBalls (with
|
2003-12-08 13:30:04 +00:00
|
|
|
* names Meta.001, Meta.002, etc) are included in this Bounding Box.
|
|
|
|
*/
|
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;
|
2003-09-05 13:54:22 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->bb == NULL) ob->bb = MEM_callocN(sizeof(BoundBox), "mb boundbox");
|
|
|
|
bb = ob->bb;
|
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;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-08-19 09:25:24 +00:00
|
|
|
dl = ob->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;
|
2014-04-01 11:34:00 +11:00
|
|
|
if (tot) do_it = true;
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2012-03-03 20:19:11 +00:00
|
|
|
#if 0
|
2012-05-06 15:15:33 +00:00
|
|
|
loc[0] = (min[0] + max[0]) / 2.0f;
|
|
|
|
loc[1] = (min[1] + max[1]) / 2.0f;
|
|
|
|
loc[2] = (min[2] + max[2]) / 2.0f;
|
|
|
|
|
|
|
|
size[0] = (max[0] - min[0]) / 2.0f;
|
|
|
|
size[1] = (max[1] - min[1]) / 2.0f;
|
|
|
|
size[2] = (max[2] - min[2]) / 2.0f;
|
2012-03-03 20:19:11 +00:00
|
|
|
#endif
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2002-10-12 11:37:38 +00: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 */
|
2012-05-06 15:15:33 +00:00
|
|
|
bb = ob->bb;
|
|
|
|
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;
|
|
|
|
orcodata = MEM_mallocN(sizeof(float) * 3 * dl->nr, "MballOrco");
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* Note on mball basis stuff 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 then basic cases
|
2010-11-18 04:26:50 +00:00
|
|
|
* Multiple Scenes + Set Scenes & mixing mball basis SHOULD work but fails to update the depsgraph on rename
|
|
|
|
* and linking into scenes or removal of basis mball. so take care when changing this code.
|
|
|
|
*
|
|
|
|
* Main idiot thing here is that the system returns find_basis_mball() objects which fail a is_basis_mball() test.
|
|
|
|
*
|
2011-04-21 05:49:47 +00:00
|
|
|
* Not only that but the depsgraph and their areas depend on this behavior!, so making small fixes here isn't worth it.
|
|
|
|
* - Campbell
|
2010-11-18 04:26:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-12-08 13:30:04 +00:00
|
|
|
/** \brief Test, if Object *ob is basic MetaBall.
|
|
|
|
*
|
|
|
|
* It test last character of Object ID name. If last character
|
|
|
|
* is digit it return 0, else it return 1.
|
|
|
|
*/
|
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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-27 12:45:09 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 14:40:10 +00:00
|
|
|
/* \brief copy some properties from object to other metaball object with same base name
|
|
|
|
*
|
|
|
|
* When some properties (wiresize, threshold, update flags) of metaball are changed, then this properties
|
|
|
|
* are copied to all metaballs in same "group" (metaballs with same base name: MBall,
|
|
|
|
* MBall.001, MBall.002, etc). The most important is to copy properties to the base metaball,
|
|
|
|
* because this metaball influence polygonisation of metaballs. */
|
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;
|
2009-08-03 14:40:10 +00:00
|
|
|
Base *base;
|
|
|
|
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;
|
2013-12-26 17:24:42 +06:00
|
|
|
EvaluationContext *eval_ctx = G.main->eval_ctx;
|
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
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
BLI_split_name_num(basisname, &basisnr, active_object->id.name + 2, '.');
|
2009-08-03 14:40:10 +00:00
|
|
|
|
2014-07-18 21:35:50 +02:00
|
|
|
BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL);
|
2013-12-26 17:24:42 +06:00
|
|
|
while (BKE_scene_base_iter_next(eval_ctx, &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, '.');
|
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;
|
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;
|
2009-08-03 14:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-08 13:30:04 +00:00
|
|
|
/** \brief This function finds basic MetaBall.
|
|
|
|
*
|
|
|
|
* Basic MetaBall doesn't include any number at the end of
|
|
|
|
* its name. All MetaBalls with same base of name can be
|
|
|
|
* blended. MetaBalls with different basic name can't be
|
|
|
|
* blended.
|
2010-11-18 04:26:50 +00:00
|
|
|
*
|
|
|
|
* warning!, is_basis_mball() can fail on returned object, see long note above.
|
2003-12-08 13:30:04 +00:00
|
|
|
*/
|
2012-05-07 06:38:41 +00:00
|
|
|
Object *BKE_mball_basis_find(Scene *scene, Object *basis)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Scene *sce_iter = scene;
|
2002-10-12 11:37:38 +00:00
|
|
|
Base *base;
|
2012-05-06 15:15:33 +00:00
|
|
|
Object *ob, *bob = basis;
|
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];
|
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;
|
2013-12-26 17:24:42 +06:00
|
|
|
EvaluationContext *eval_ctx = G.main->eval_ctx;
|
2010-11-01 07:19:41 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.');
|
2004-11-10 13:20:13 +00:00
|
|
|
|
2014-07-18 21:35:50 +02:00
|
|
|
BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL);
|
2013-12-26 17:24:42 +06:00
|
|
|
while (BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 1, &base, &ob)) {
|
2014-07-18 21:35:50 +02:00
|
|
|
if ((ob->type == OB_MBALL) && !(base->flag & OB_FROMDUPLI)) {
|
2013-06-17 11:18:29 +00:00
|
|
|
if (ob != bob) {
|
2012-05-06 15:15:33 +00:00
|
|
|
BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
|
2004-11-10 13:20:13 +00:00
|
|
|
|
2014-07-18 21:35:50 +02: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-02-23 02:17:50 +00:00
|
|
|
if (obnr < basisnr) {
|
2014-07-18 21:35:50 +02:00
|
|
|
basis = ob;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return basis;
|
|
|
|
}
|
|
|
|
|
2013-06-28 18:19:55 +00:00
|
|
|
bool BKE_mball_minmax_ex(MetaBall *mb, float min[3], float max[3],
|
|
|
|
float obmat[4][4], const short flag)
|
|
|
|
{
|
|
|
|
const float scale = obmat ? mat4_to_scale(obmat) : 1.0f;
|
|
|
|
MetaElem *ml;
|
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);
|
|
|
|
|
|
|
|
for (ml = mb->elems.first; ml; ml = ml->next) {
|
|
|
|
if ((ml->flag & flag) == flag) {
|
|
|
|
const float scale_mb = (ml->rad * 0.5f) * scale;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
for (i = -1; i != 3; i += 2) {
|
|
|
|
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 */
|
2013-06-28 18:19:55 +00:00
|
|
|
bool BKE_mball_minmax(MetaBall *mb, float min[3], float max[3])
|
2012-02-26 08:55:31 +00:00
|
|
|
{
|
|
|
|
MetaElem *ml;
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
for (ml = mb->elems.first; ml; ml = ml->next) {
|
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
|
|
|
}
|
|
|
|
|
2013-06-28 18:19:55 +00:00
|
|
|
bool BKE_mball_center_median(MetaBall *mb, float r_cent[3])
|
2012-02-26 08:55:31 +00:00
|
|
|
{
|
|
|
|
MetaElem *ml;
|
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
|
|
|
|
|
|
|
for (ml = mb->elems.first; ml; ml = ml->next) {
|
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);
|
|
|
|
}
|
|
|
|
|
2013-06-28 18:19:55 +00:00
|
|
|
bool BKE_mball_center_bounds(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
|
|
|
}
|
|
|
|
|
2014-09-01 20:09:31 +10:00
|
|
|
void BKE_mball_transform(MetaBall *mb, float mat[4][4])
|
|
|
|
{
|
|
|
|
MetaElem *me;
|
|
|
|
float quat[4];
|
|
|
|
const float scale = mat4_to_scale(mat);
|
|
|
|
const float scale_sqrt = sqrtf(scale);
|
|
|
|
|
|
|
|
mat4_to_quat(quat, mat);
|
|
|
|
|
|
|
|
for (me = mb->elems.first; me; me = me->next) {
|
|
|
|
mul_m4_v3(mat, &me->x);
|
|
|
|
mul_qt_qtqt(me->quat, quat, me->quat);
|
|
|
|
me->rad *= scale;
|
|
|
|
/* hrmf, probably elems shouldn't be
|
|
|
|
* treating scale differently - campbell */
|
|
|
|
if (!MB_TYPE_SIZE_SQUARED(me->type)) {
|
|
|
|
mul_v3_fl(&me->expx, scale);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mul_v3_fl(&me->expx, scale_sqrt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
MetaElem *ml;
|
|
|
|
|
|
|
|
for (ml = mb->elems.first; ml; ml = ml->next) {
|
|
|
|
add_v3_v3(&ml->x, offset);
|
|
|
|
}
|
|
|
|
}
|
2012-10-06 03:02:14 +00:00
|
|
|
|
|
|
|
/* *** select funcs *** */
|
|
|
|
void BKE_mball_select_all(struct MetaBall *mb)
|
|
|
|
{
|
|
|
|
MetaElem *ml;
|
|
|
|
|
|
|
|
for (ml = mb->editelems->first; ml; ml = ml->next) {
|
|
|
|
ml->flag |= SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_mball_deselect_all(MetaBall *mb)
|
|
|
|
{
|
|
|
|
MetaElem *ml;
|
|
|
|
|
|
|
|
for (ml = mb->editelems->first; ml; ml = ml->next) {
|
|
|
|
ml->flag &= ~SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_mball_select_swap(struct MetaBall *mb)
|
|
|
|
{
|
|
|
|
MetaElem *ml;
|
|
|
|
|
|
|
|
for (ml = mb->editelems->first; ml; ml = ml->next) {
|
|
|
|
ml->flag ^= SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|