2006-08-28 01:12:36 +00:00
|
|
|
/*
|
2011-10-10 09:38:02 +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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
2020-05-09 17:14:35 +10:00
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2011-10-10 09:38:02 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
* Modifier stack implementation.
|
|
|
|
*
|
|
|
|
* BKE_modifier.h contains the function prototypes for this file.
|
|
|
|
*/
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdarg.h>
|
2010-08-13 15:26:37 +00:00
|
|
|
#include <stddef.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdlib.h>
|
2010-08-13 15:26:37 +00:00
|
|
|
#include <string.h>
|
2005-07-19 20:14:17 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2005-10-20 16:31:46 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2018-04-18 15:45:54 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_object_types.h"
|
2019-04-30 16:43:44 -03:00
|
|
|
#include "DNA_scene_types.h"
|
2005-07-19 20:14:17 +00:00
|
|
|
|
2011-10-22 01:53:35 +00:00
|
|
|
#include "BLI_linklist.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_listbase.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_path_util.h"
|
2011-10-20 13:50:24 +00:00
|
|
|
#include "BLI_string.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_string_utils.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2010-08-16 05:46:10 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-10-27 11:12:09 +00:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2014-11-23 14:37:13 +01:00
|
|
|
#include "BKE_appdir.h"
|
2018-05-30 11:34:08 +02:00
|
|
|
#include "BKE_editmesh.h"
|
2020-05-25 20:16:42 +10:00
|
|
|
#include "BKE_editmesh_cache.h"
|
2018-05-31 15:24:30 +02:00
|
|
|
#include "BKE_global.h"
|
2020-03-19 19:37:00 +01:00
|
|
|
#include "BKE_idtype.h"
|
2009-10-22 16:35:51 +00:00
|
|
|
#include "BKE_key.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
#include "BKE_lib_query.h"
|
2018-04-18 15:45:54 +02:00
|
|
|
#include "BKE_mesh.h"
|
2020-06-10 22:32:06 +10:00
|
|
|
#include "BKE_mesh_wrapper.h"
|
2010-09-09 00:14:51 +00:00
|
|
|
#include "BKE_multires.h"
|
2018-05-25 12:27:54 +02:00
|
|
|
#include "BKE_object.h"
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
/* may move these, only for BKE_modifier_path_relbase */
|
2011-11-20 14:38:11 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
/* end */
|
|
|
|
|
2018-02-06 19:34:36 +11:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-05-24 16:40:08 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-02-06 19:34:36 +11:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "MOD_modifiertypes.h"
|
2009-06-09 13:03:00 +00:00
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
|
|
|
static CLG_LogRef LOG = {"bke.modifier"};
|
2013-08-19 09:05:34 +00:00
|
|
|
static ModifierTypeInfo *modifier_types[NUM_MODIFIER_TYPES] = {NULL};
|
|
|
|
static VirtualModifierData virtualModifierCommonData;
|
|
|
|
|
|
|
|
void BKE_modifier_init(void)
|
2009-06-09 13:03:00 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md;
|
2009-06-09 13:03:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Initialize modifier types */
|
|
|
|
modifier_type_init(modifier_types); /* MOD_utils.c */
|
2013-08-19 09:05:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Initialize global cmmon storage used for virtual modifier list */
|
2020-05-08 10:14:02 +02:00
|
|
|
md = BKE_modifier_new(eModifierType_Armature);
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierCommonData.amd = *((ArmatureModifierData *)md);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free(md);
|
2013-08-19 09:05:34 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
md = BKE_modifier_new(eModifierType_Curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierCommonData.cmd = *((CurveModifierData *)md);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free(md);
|
2009-06-09 13:03:00 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
md = BKE_modifier_new(eModifierType_Lattice);
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierCommonData.lmd = *((LatticeModifierData *)md);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free(md);
|
2013-08-19 09:05:34 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
md = BKE_modifier_new(eModifierType_ShapeKey);
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierCommonData.smd = *((ShapeKeyModifierData *)md);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free(md);
|
2013-08-19 09:05:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierCommonData.amd.modifier.mode |= eModifierMode_Virtual;
|
|
|
|
virtualModifierCommonData.cmd.modifier.mode |= eModifierMode_Virtual;
|
|
|
|
virtualModifierCommonData.lmd.modifier.mode |= eModifierMode_Virtual;
|
|
|
|
virtualModifierCommonData.smd.modifier.mode |= eModifierMode_Virtual;
|
2013-08-19 09:05:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *BKE_modifier_get_info(ModifierType type)
|
2013-08-19 09:05:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* type unsigned, no need to check < 0 */
|
2019-12-17 08:58:43 +11:00
|
|
|
if (type < NUM_MODIFIER_TYPES && modifier_types[type] && modifier_types[type]->name[0] != '\0') {
|
2019-04-17 06:17:24 +02:00
|
|
|
return modifier_types[type];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-19 20:14:17 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
/**
|
|
|
|
* Get the idname of the modifier type's panel, which was defined in the #panelRegister callback.
|
|
|
|
*/
|
|
|
|
void BKE_modifier_type_panel_id(ModifierType type, char *r_idname)
|
|
|
|
{
|
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(type);
|
|
|
|
|
|
|
|
strcpy(r_idname, MODIFIER_TYPE_PANEL_PREFIX);
|
|
|
|
strcat(r_idname, mti->name);
|
|
|
|
}
|
|
|
|
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-10 22:05:52 +00:00
|
|
|
/***/
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *BKE_modifier_new(int type)
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(type);
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md = MEM_callocN(mti->structSize, mti->structName);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* note, this name must be made unique later */
|
|
|
|
BLI_strncpy(md->name, DATA_(mti->name), sizeof(md->name));
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-10 22:05:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
md->type = type;
|
2020-06-05 10:41:03 -04:00
|
|
|
md->mode = eModifierMode_Realtime | eModifierMode_Render;
|
2019-06-14 23:16:04 +02:00
|
|
|
md->flag = eModifierFlag_OverrideLibrary_Local;
|
2020-06-05 10:41:03 -04:00
|
|
|
md->ui_expand_flag = 1; /* Only open the main panel at the beginning, not the subpanels. */
|
2005-07-23 19:15:08 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->flags & eModifierTypeFlag_EnableInEditmode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
md->mode |= eModifierMode_Editmode;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->initData) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mti->initData(md);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return md;
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void modifier_free_data_id_us_cb(void *UNUSED(userData),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
ID **idpoin,
|
|
|
|
int cb_flag)
|
2018-04-04 14:56:32 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ID *id = *idpoin;
|
|
|
|
if (id != NULL && (cb_flag & IDWALK_CB_USER) != 0) {
|
|
|
|
id_us_min(id);
|
|
|
|
}
|
2018-04-04 14:56:32 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_free_ex(ModifierData *md, const int flag)
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
if (mti->foreachIDLink) {
|
|
|
|
mti->foreachIDLink(md, NULL, modifier_free_data_id_us_cb, NULL);
|
|
|
|
}
|
|
|
|
else if (mti->foreachObjectLink) {
|
|
|
|
mti->foreachObjectLink(md, NULL, (ObjectWalkFunc)modifier_free_data_id_us_cb, NULL);
|
|
|
|
}
|
|
|
|
}
|
2018-04-04 14:56:32 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->freeData) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mti->freeData(md);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (md->error) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(md->error);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(md);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_free(ModifierData *md)
|
2018-04-04 14:56:32 +02:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free_ex(md, 0);
|
2018-04-04 14:56:32 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_unique_name(ListBase *modifiers, ModifierData *md)
|
2009-10-09 09:48:04 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (modifiers && md) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2013-03-25 08:29:06 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_uniquename(
|
|
|
|
modifiers, md, DATA_(mti->name), '.', offsetof(ModifierData, name), sizeof(md->name));
|
|
|
|
}
|
|
|
|
return false;
|
2009-10-09 09:48:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_depends_ontime(ModifierData *md)
|
2005-07-20 04:14:21 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2005-07-20 04:14:21 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return mti->dependsOnTime && mti->dependsOnTime(md);
|
2005-07-20 04:14:21 +00:00
|
|
|
}
|
2005-07-27 20:16:41 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_supports_mapping(ModifierData *md)
|
2005-08-03 04:04:05 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2005-08-03 04:04:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (mti->type == eModifierTypeType_OnlyDeform ||
|
|
|
|
(mti->flags & eModifierTypeFlag_SupportsMapping));
|
2005-08-03 04:04:05 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_is_preview(ModifierData *md)
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Constructive modifiers are highly likely to also modify data like vgroups or vcol! */
|
|
|
|
if (!((mti->flags & eModifierTypeFlag_UsesPreview) ||
|
|
|
|
(mti->type == eModifierTypeType_Constructive))) {
|
|
|
|
return false;
|
|
|
|
}
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (md->mode & eModifierMode_Realtime) {
|
|
|
|
return true;
|
|
|
|
}
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *BKE_modifiers_findby_type(Object *ob, ModifierType type)
|
2005-07-27 20:16:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md = ob->modifiers.first;
|
2005-07-27 20:16:41 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == type) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2005-07-27 20:16:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return md;
|
2005-07-27 20:16:41 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 11:39:52 +02:00
|
|
|
ModifierData *BKE_modifiers_findby_name(Object *ob, const char *name)
|
2010-04-22 01:55:10 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_findstring(&(ob->modifiers), name, offsetof(ModifierData, name));
|
2010-04-22 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifiers_clear_errors(Object *ob)
|
2005-08-04 07:25:43 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md = ob->modifiers.first;
|
|
|
|
/* int qRedraw = 0; */
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->error) {
|
|
|
|
MEM_freeN(md->error);
|
|
|
|
md->error = NULL;
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* qRedraw = 1; */
|
|
|
|
}
|
|
|
|
}
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-10 22:05:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifiers_foreach_object_link(Object *ob, ObjectWalkFunc walk, void *userData)
|
2006-08-28 01:12:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md = ob->modifiers.first;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->foreachObjectLink) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mti->foreachObjectLink(md, ob, walk, userData);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifiers_foreach_ID_link(Object *ob, IDWalkFunc walk, void *userData)
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-10 22:05:52 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md = ob->modifiers.first;
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-10 22:05:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-10 22:05:52 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->foreachIDLink) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mti->foreachIDLink(md, ob, walk, userData);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else if (mti->foreachObjectLink) {
|
|
|
|
/* each Object can masquerade as an ID, so this should be OK */
|
|
|
|
ObjectWalkFunc fp = (ObjectWalkFunc)walk;
|
|
|
|
mti->foreachObjectLink(md, ob, fp, userData);
|
|
|
|
}
|
|
|
|
}
|
2005-08-04 07:25:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifiers_foreach_tex_link(Object *ob, TexWalkFunc walk, void *userData)
|
2011-08-12 18:11:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md = ob->modifiers.first;
|
2011-08-12 18:11:22 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2011-08-12 18:11:22 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->foreachTexLink) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mti->foreachTexLink(md, ob, walk, userData);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-08-12 18:11:22 +00:00
|
|
|
}
|
|
|
|
|
2013-12-22 04:35:52 +11:00
|
|
|
/* callback's can use this
|
|
|
|
* to avoid copying every member.
|
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_copydata_generic(const ModifierData *md_src,
|
2020-05-08 19:02:03 +10:00
|
|
|
ModifierData *md_dst,
|
|
|
|
const int UNUSED(flag))
|
2013-12-22 04:35:52 +11:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md_src->type);
|
2018-05-07 17:58:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* md_dst may have already be fully initialized with some extra allocated data,
|
|
|
|
* we need to free it now to avoid memleak. */
|
|
|
|
if (mti->freeData) {
|
|
|
|
mti->freeData(md_dst);
|
|
|
|
}
|
2018-05-07 17:58:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
const size_t data_size = sizeof(ModifierData);
|
|
|
|
const char *md_src_data = ((const char *)md_src) + data_size;
|
|
|
|
char *md_dst_data = ((char *)md_dst) + data_size;
|
|
|
|
BLI_assert(data_size <= (size_t)mti->structSize);
|
|
|
|
memcpy(md_dst_data, md_src_data, (size_t)mti->structSize - data_size);
|
2019-03-20 14:45:01 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Runtime fields are never to be preserved. */
|
|
|
|
md_dst->runtime = NULL;
|
2013-12-22 04:35:52 +11:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void modifier_copy_data_id_us_cb(void *UNUSED(userData),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
ID **idpoin,
|
|
|
|
int cb_flag)
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ID *id = *idpoin;
|
|
|
|
if (id != NULL && (cb_flag & IDWALK_CB_USER) != 0) {
|
|
|
|
id_us_plus(id);
|
|
|
|
}
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_copydata_ex(ModifierData *md, ModifierData *target, const int flag)
|
2005-07-27 20:16:41 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2005-07-27 20:16:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
target->mode = md->mode;
|
|
|
|
target->flag = md->flag;
|
2020-06-05 10:41:03 -04:00
|
|
|
target->ui_expand_flag = md->ui_expand_flag;
|
2005-07-27 20:16:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (mti->copyData) {
|
|
|
|
mti->copyData(md, target, flag);
|
|
|
|
}
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
if (mti->foreachIDLink) {
|
|
|
|
mti->foreachIDLink(target, NULL, modifier_copy_data_id_us_cb, NULL);
|
|
|
|
}
|
|
|
|
else if (mti->foreachObjectLink) {
|
|
|
|
mti->foreachObjectLink(target, NULL, (ObjectWalkFunc)modifier_copy_data_id_us_cb, NULL);
|
|
|
|
}
|
|
|
|
}
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_copydata(ModifierData *md, ModifierData *target)
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_copydata_ex(md, target, 0);
|
2005-07-27 20:16:41 +00:00
|
|
|
}
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_supports_cage(struct Scene *scene, ModifierData *md)
|
2013-12-13 20:57:36 +01:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2013-12-13 20:57:36 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((!mti->isDisabled || !mti->isDisabled(scene, md, 0)) &&
|
2020-05-08 10:14:02 +02:00
|
|
|
(mti->flags & eModifierTypeFlag_SupportsEditmode) && BKE_modifier_supports_mapping(md));
|
2013-12-13 20:57:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_couldbe_cage(struct Scene *scene, ModifierData *md)
|
2005-08-04 07:25:43 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((md->mode & eModifierMode_Realtime) && (md->mode & eModifierMode_Editmode) &&
|
2020-05-08 19:02:03 +10:00
|
|
|
(!mti->isDisabled || !mti->isDisabled(scene, md, 0)) &&
|
|
|
|
BKE_modifier_supports_mapping(md));
|
2005-08-04 07:25:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_is_same_topology(ModifierData *md)
|
2009-11-22 13:44:09 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
return ELEM(mti->type, eModifierTypeType_OnlyDeform, eModifierTypeType_NonGeometrical);
|
2011-12-20 14:15:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_is_non_geometrical(ModifierData *md)
|
2011-12-20 14:15:59 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
return (mti->type == eModifierTypeType_NonGeometrical);
|
2009-11-22 13:44:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_set_error(ModifierData *md, const char *_format, ...)
|
2005-08-04 07:25:43 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char buffer[512];
|
|
|
|
va_list ap;
|
|
|
|
const char *format = TIP_(_format);
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
va_start(ap, _format);
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (md->error) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(md->error);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
md->error = BLI_strdup(buffer);
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
CLOG_STR_ERROR(&LOG, md->error);
|
2005-08-04 07:25:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 01:12:36 +00:00
|
|
|
/* used for buttons, to find out if the 'draw deformed in editmode' option is
|
|
|
|
* there
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2006-08-28 01:12:36 +00:00
|
|
|
* also used in transform_conversion.c, to detect CrazySpace [tm] (2nd arg
|
2018-06-01 18:19:39 +02:00
|
|
|
* then is NULL)
|
2010-12-21 15:10:09 +00:00
|
|
|
* also used for some mesh tools to give warnings
|
2006-08-28 01:12:36 +00:00
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
int BKE_modifiers_get_cage_index(struct Scene *scene,
|
2020-05-08 19:02:03 +10:00
|
|
|
Object *ob,
|
|
|
|
int *r_lastPossibleCageIndex,
|
|
|
|
bool is_virtual)
|
2005-08-04 07:25:43 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 19:02:03 +10:00
|
|
|
ModifierData *md = (is_virtual) ?
|
|
|
|
BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData) :
|
|
|
|
ob->modifiers.first;
|
2019-04-17 06:17:24 +02:00
|
|
|
int i, cageIndex = -1;
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_lastPossibleCageIndex) {
|
|
|
|
/* ensure the value is initialized */
|
|
|
|
*r_lastPossibleCageIndex = -1;
|
|
|
|
}
|
2011-02-22 12:19:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Find the last modifier acting on the cage. */
|
|
|
|
for (i = 0; md; i++, md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
bool supports_mapping;
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->isDisabled && mti->isDisabled(scene, md, 0)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (!(mti->flags & eModifierTypeFlag_SupportsEditmode)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (md->mode & eModifierMode_DisableTemporary) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
supports_mapping = BKE_modifier_supports_mapping(md);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_lastPossibleCageIndex && supports_mapping) {
|
|
|
|
*r_lastPossibleCageIndex = i;
|
|
|
|
}
|
2014-08-17 09:35:57 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!(md->mode & eModifierMode_Realtime)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (!(md->mode & eModifierMode_Editmode)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-05-30 20:22:23 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!supports_mapping) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (md->mode & eModifierMode_OnCage) {
|
2019-04-17 06:17:24 +02:00
|
|
|
cageIndex = i;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2005-08-04 07:25:43 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return cageIndex;
|
2005-08-04 07:25:43 +00:00
|
|
|
}
|
2005-08-11 02:23:52 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_is_softbody_enabled(Object *ob)
|
2005-08-11 02:23:52 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Softbody);
|
2005-08-11 02:23:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
|
2005-08-11 02:23:52 +00:00
|
|
|
}
|
2005-08-11 03:31:33 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_is_cloth_enabled(Object *ob)
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Cloth);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_is_modifier_enabled(Object *ob, int modifierType)
|
2012-07-04 16:55:17 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_findby_type(ob, modifierType);
|
2012-07-04 16:55:17 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
|
2012-07-04 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_is_particle_enabled(Object *ob)
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_ParticleSystem);
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 11:12:01 +01:00
|
|
|
/**
|
|
|
|
* Check whether is enabled.
|
|
|
|
*
|
2019-04-27 12:07:07 +10:00
|
|
|
* \param scene: Current scene, may be NULL,
|
|
|
|
* in which case isDisabled callback of the modifier is never called.
|
2018-01-24 11:12:01 +01:00
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_is_enabled(const struct Scene *scene, ModifierData *md, int required_mode)
|
2009-06-15 11:48:42 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((md->mode & required_mode) != required_mode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scene != NULL && mti->isDisabled &&
|
2019-04-22 09:39:35 +10:00
|
|
|
mti->isDisabled(scene, md, required_mode == eModifierMode_Render)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (md->mode & eModifierMode_DisableTemporary) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((required_mode & eModifierMode_Editmode) &&
|
2019-04-22 09:39:35 +10:00
|
|
|
!(mti->flags & eModifierTypeFlag_SupportsEditmode)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
CDMaskLink *BKE_modifier_calc_data_masks(struct Scene *scene,
|
2020-05-08 19:02:03 +10:00
|
|
|
Object *ob,
|
|
|
|
ModifierData *md,
|
|
|
|
CustomData_MeshMasks *final_datamask,
|
|
|
|
int required_mode,
|
|
|
|
ModifierData *previewmd,
|
|
|
|
const CustomData_MeshMasks *previewmask)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
CDMaskLink *dataMasks = NULL;
|
|
|
|
CDMaskLink *curr, *prev;
|
2019-06-10 15:42:15 +02:00
|
|
|
bool have_deform_modifier = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* build a list of modifier data requirements in reverse order */
|
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
curr = MEM_callocN(sizeof(CDMaskLink), "CDMaskLink");
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
if (BKE_modifier_is_enabled(scene, md, required_mode)) {
|
2019-06-10 15:42:15 +02:00
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform) {
|
|
|
|
have_deform_modifier = true;
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mti->requiredDataMask) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mti->requiredDataMask(ob, md, &curr->mask);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (previewmd == md && previewmask != NULL) {
|
|
|
|
CustomData_MeshMasks_update(&curr->mask, previewmask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 15:42:15 +02:00
|
|
|
if (!have_deform_modifier) {
|
|
|
|
/* Don't create orco layer when there is no deformation, we fall
|
|
|
|
* back to regular vertex coordinates */
|
|
|
|
curr->mask.vmask &= ~CD_MASK_ORCO;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* prepend new datamask */
|
|
|
|
curr->next = dataMasks;
|
|
|
|
dataMasks = curr;
|
|
|
|
}
|
|
|
|
|
2019-06-10 15:42:15 +02:00
|
|
|
if (!have_deform_modifier) {
|
|
|
|
final_datamask->vmask &= ~CD_MASK_ORCO;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* build the list of required data masks - each mask in the list must
|
|
|
|
* include all elements of the masks that follow it
|
|
|
|
*
|
|
|
|
* note the list is currently in reverse order, so "masks that follow it"
|
|
|
|
* actually means "masks that precede it" at the moment
|
|
|
|
*/
|
|
|
|
for (curr = dataMasks, prev = NULL; curr; prev = curr, curr = curr->next) {
|
|
|
|
if (prev) {
|
|
|
|
CustomData_MeshMasks_update(&curr->mask, &prev->mask);
|
|
|
|
}
|
|
|
|
else {
|
2019-06-10 15:42:15 +02:00
|
|
|
CustomData_MeshMasks_update(&curr->mask, final_datamask);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reverse the list so it's in the correct order */
|
|
|
|
BLI_linklist_reverse((LinkNode **)&dataMasks);
|
|
|
|
|
|
|
|
return dataMasks;
|
2006-12-05 17:42:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 19:02:03 +10:00
|
|
|
ModifierData *BKE_modifier_get_last_preview(struct Scene *scene,
|
|
|
|
ModifierData *md,
|
|
|
|
int required_mode)
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *tmp_md = NULL;
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((required_mode & ~eModifierMode_Editmode) != eModifierMode_Realtime) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return tmp_md;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Find the latest modifier in stack generating preview. */
|
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
if (BKE_modifier_is_enabled(scene, md, required_mode) && BKE_modifier_is_preview(md)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tmp_md = md;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return tmp_md;
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 14:52:58 +01:00
|
|
|
/* This is to include things that are not modifiers in the evaluation of the modifier stack, for
|
|
|
|
* example parenting to an armature. */
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *BKE_modifiers_get_virtual_modifierlist(const Object *ob,
|
2020-05-08 19:02:03 +10:00
|
|
|
VirtualModifierData *virtualModifierData)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
ModifierData *md;
|
|
|
|
|
|
|
|
md = ob->modifiers.first;
|
|
|
|
|
|
|
|
*virtualModifierData = virtualModifierCommonData;
|
|
|
|
|
|
|
|
if (ob->parent) {
|
|
|
|
if (ob->parent->type == OB_ARMATURE && ob->partype == PARSKEL) {
|
|
|
|
virtualModifierData->amd.object = ob->parent;
|
|
|
|
virtualModifierData->amd.modifier.next = md;
|
|
|
|
virtualModifierData->amd.deformflag = ((bArmature *)(ob->parent->data))->deformflag;
|
|
|
|
md = &virtualModifierData->amd.modifier;
|
|
|
|
}
|
|
|
|
else if (ob->parent->type == OB_CURVE && ob->partype == PARSKEL) {
|
|
|
|
virtualModifierData->cmd.object = ob->parent;
|
|
|
|
virtualModifierData->cmd.defaxis = ob->trackflag + 1;
|
|
|
|
virtualModifierData->cmd.modifier.next = md;
|
|
|
|
md = &virtualModifierData->cmd.modifier;
|
|
|
|
}
|
|
|
|
else if (ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
|
|
|
|
virtualModifierData->lmd.object = ob->parent;
|
|
|
|
virtualModifierData->lmd.modifier.next = md;
|
|
|
|
md = &virtualModifierData->lmd.modifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shape key modifier, not yet for curves */
|
|
|
|
if (ELEM(ob->type, OB_MESH, OB_LATTICE) && BKE_key_from_object(ob)) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->type == OB_MESH && (ob->shapeflag & OB_SHAPE_EDIT_MODE)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierData->smd.modifier.mode |= eModifierMode_Editmode | eModifierMode_OnCage;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
virtualModifierData->smd.modifier.mode &= ~eModifierMode_Editmode | eModifierMode_OnCage;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
virtualModifierData->smd.modifier.next = md;
|
|
|
|
md = &virtualModifierData->smd.modifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
return md;
|
2005-08-11 03:31:33 +00:00
|
|
|
}
|
2012-10-15 03:16:38 +00:00
|
|
|
|
|
|
|
/* Takes an object and returns its first selected armature, else just its armature
|
2006-08-28 01:12:36 +00:00
|
|
|
* This should work for multiple armatures per object
|
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
Object *BKE_modifiers_is_deformed_by_armature(Object *ob)
|
2005-08-22 20:24:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
ArmatureModifierData *amd = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return the first selected armature, this lets us use multiple armatures */
|
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Armature) {
|
|
|
|
amd = (ArmatureModifierData *)md;
|
2019-04-30 16:43:44 -03:00
|
|
|
if (amd->object && (amd->object->base_flag & BASE_SELECTED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return amd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-03-19 20:33:23 +01:00
|
|
|
if (amd) { /* if we're still here then return the last armature */
|
2019-04-17 06:17:24 +02:00
|
|
|
return amd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
New: CrazySpace [tm] correction
When Modifiers are used in Edit Mode to show the deformed result for
editing, all actual coordinates Blender works with are still the ones from
the original Cage. You can notice that with the Transform Widget or
helper lines while transforming.
Even worse, the actual transformations still happened on the original Cage
as well, making it very hard to edit. That caused the feature to be named
"CrazySpace" (baptized by Andy, afaik?).
This commit calculates the deformation transformation per vertex, and
inverse corrects it, so it's more intuitive editing this way.
Unfortunately all the deformation features of Blender don't use matrices
for defining deform, so the existing code cannot be re-used to retrieve
the correct deformation matrix per vertex. The solution I found is based
on calculating per face the transformation based on its first 3 vertices,
and store this transformation averaged in the face's vertices.
The solution can also only work on entire faces, because the full deform
can only be retrieved using 3 vertices. (using 2 vertices will miss edge-
aligned rotation, using 1 vertex can only retrieve translation).
By deriving the deformations per face, small errors will still happen,
especially on very low-poly Meshes with extreme deformations.
The only alternative I know now, is providing each vertex in
a mesh with 2 extreme small tangent vectors, which get deformed using the
existing code as well. That will mess up the existing deformation code too
much though, this solution has the benefit it works with each deform we can
up with later too.
Last note about CrazySpace: it can only be used to tweak Meshes. Do not
even try to add vertices, extrude, or duplicate. Probably we should disable
this... but preventing user errors isn't always power-user-friendly, eh. :)
2005-10-26 09:56:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
Object *BKE_modifiers_is_deformed_by_meshdeform(Object *ob)
|
2018-05-11 08:16:41 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
MeshDeformModifierData *mdmd = NULL;
|
2018-05-11 08:16:41 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return the first selected armature, this lets us use multiple armatures */
|
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_MeshDeform) {
|
|
|
|
mdmd = (MeshDeformModifierData *)md;
|
2019-04-30 16:43:44 -03:00
|
|
|
if (mdmd->object && (mdmd->object->base_flag & BASE_SELECTED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return mdmd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-11 08:16:41 +02:00
|
|
|
|
2020-03-19 20:33:23 +01:00
|
|
|
if (mdmd) { /* if we're still here then return the last armature */
|
2019-04-17 06:17:24 +02:00
|
|
|
return mdmd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-05-11 08:16:41 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2018-05-11 08:16:41 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 03:16:38 +00:00
|
|
|
/* Takes an object and returns its first selected lattice, else just its lattice
|
|
|
|
* This should work for multiple lattices per object
|
2012-03-03 20:19:11 +00:00
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
Object *BKE_modifiers_is_deformed_by_lattice(Object *ob)
|
2006-12-23 11:56:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
LatticeModifierData *lmd = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return the first selected lattice, this lets us use multiple lattices */
|
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Lattice) {
|
|
|
|
lmd = (LatticeModifierData *)md;
|
2019-04-30 16:43:44 -03:00
|
|
|
if (lmd->object && (lmd->object->base_flag & BASE_SELECTED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return lmd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-03-19 20:33:23 +01:00
|
|
|
if (lmd) { /* if we're still here then return the last lattice */
|
2019-04-17 06:17:24 +02:00
|
|
|
return lmd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2006-12-23 11:56:22 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 03:16:38 +00:00
|
|
|
/* Takes an object and returns its first selected curve, else just its curve
|
|
|
|
* This should work for multiple curves per object
|
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
Object *BKE_modifiers_is_deformed_by_curve(Object *ob)
|
2012-10-15 03:16:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
CurveModifierData *cmd = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return the first selected curve, this lets us use multiple curves */
|
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Curve) {
|
|
|
|
cmd = (CurveModifierData *)md;
|
2019-04-30 16:43:44 -03:00
|
|
|
if (cmd->object && (cmd->object->base_flag & BASE_SELECTED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return cmd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-03-19 20:33:23 +01:00
|
|
|
if (cmd) { /* if we're still here then return the last curve */
|
2019-04-17 06:17:24 +02:00
|
|
|
return cmd->object;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2012-10-15 03:16:38 +00:00
|
|
|
}
|
2006-12-23 11:56:22 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_uses_multires(Object *ob)
|
2019-10-01 22:30:14 +02:00
|
|
|
{
|
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-10-01 22:30:14 +02:00
|
|
|
MultiresModifierData *mmd = NULL;
|
|
|
|
|
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Multires) {
|
|
|
|
mmd = (MultiresModifierData *)md;
|
|
|
|
if (mmd->totlvl != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_uses_armature(Object *ob, bArmature *arm)
|
2006-05-04 00:59:02 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2006-05-04 00:59:02 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Armature) {
|
|
|
|
ArmatureModifierData *amd = (ArmatureModifierData *)md;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (amd->object && amd->object->data == arm) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2006-05-04 00:59:02 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2006-05-04 00:59:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_uses_subsurf_facedots(struct Scene *scene, Object *ob)
|
2019-07-07 18:58:11 +02:00
|
|
|
{
|
|
|
|
/* Search (backward) in the modifier stack to find if we have a subsurf modifier (enabled) before
|
|
|
|
* the last modifier displayed on cage (or if the subsurf is the last). */
|
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
|
|
|
int cage_index = BKE_modifiers_get_cage_index(scene, ob, NULL, 1);
|
2019-07-10 12:12:50 +02:00
|
|
|
if (cage_index == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-07 18:58:11 +02:00
|
|
|
/* Find first modifier enabled on cage. */
|
2019-07-09 14:55:27 +02:00
|
|
|
for (int i = 0; md && i < cage_index; i++) {
|
2019-07-07 18:58:11 +02:00
|
|
|
md = md->next;
|
|
|
|
}
|
|
|
|
/* Now from this point, search for subsurf modifier. */
|
|
|
|
for (; md; md = md->prev) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-07-07 18:58:11 +02:00
|
|
|
if (md->type == eModifierType_Subsurf) {
|
|
|
|
ModifierMode mode = eModifierMode_Realtime | eModifierMode_Editmode;
|
2020-05-08 10:14:02 +02:00
|
|
|
if (BKE_modifier_is_enabled(scene, md, mode)) {
|
2019-07-07 18:58:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mti->type == eModifierTypeType_OnlyDeform) {
|
2019-08-01 13:53:25 +10:00
|
|
|
/* These modifiers do not reset the subdiv flag nor change the topology.
|
2019-07-07 18:58:11 +02:00
|
|
|
* We can still search for a subsurf modifier. */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Other modifiers may reset the subdiv facedot flag or create. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifier_is_correctable_deformed(ModifierData *md)
|
2007-07-28 21:04:30 +00:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
return mti->deformMatricesEM != NULL;
|
2007-07-28 21:04:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
bool BKE_modifiers_is_correctable_deformed(struct Scene *scene, Object *ob)
|
New: CrazySpace [tm] correction
When Modifiers are used in Edit Mode to show the deformed result for
editing, all actual coordinates Blender works with are still the ones from
the original Cage. You can notice that with the Transform Widget or
helper lines while transforming.
Even worse, the actual transformations still happened on the original Cage
as well, making it very hard to edit. That caused the feature to be named
"CrazySpace" (baptized by Andy, afaik?).
This commit calculates the deformation transformation per vertex, and
inverse corrects it, so it's more intuitive editing this way.
Unfortunately all the deformation features of Blender don't use matrices
for defining deform, so the existing code cannot be re-used to retrieve
the correct deformation matrix per vertex. The solution I found is based
on calculating per face the transformation based on its first 3 vertices,
and store this transformation averaged in the face's vertices.
The solution can also only work on entire faces, because the full deform
can only be retrieved using 3 vertices. (using 2 vertices will miss edge-
aligned rotation, using 1 vertex can only retrieve translation).
By deriving the deformations per face, small errors will still happen,
especially on very low-poly Meshes with extreme deformations.
The only alternative I know now, is providing each vertex in
a mesh with 2 extreme small tangent vectors, which get deformed using the
existing code as well. That will mess up the existing deformation code too
much though, this solution has the benefit it works with each deform we can
up with later too.
Last note about CrazySpace: it can only be used to tweak Meshes. Do not
even try to add vertices, extrude, or duplicate. Probably we should disable
this... but preventing user errors isn't always power-user-friendly, eh. :)
2005-10-26 09:56:52 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
int required_mode = eModifierMode_Realtime;
|
2013-09-24 00:56:47 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->mode == OB_MODE_EDIT) {
|
|
|
|
required_mode |= eModifierMode_Editmode;
|
|
|
|
}
|
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* pass */
|
|
|
|
}
|
2020-05-08 10:14:02 +02:00
|
|
|
else if (BKE_modifier_is_correctable_deformed(md)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
New: CrazySpace [tm] correction
When Modifiers are used in Edit Mode to show the deformed result for
editing, all actual coordinates Blender works with are still the ones from
the original Cage. You can notice that with the Transform Widget or
helper lines while transforming.
Even worse, the actual transformations still happened on the original Cage
as well, making it very hard to edit. That caused the feature to be named
"CrazySpace" (baptized by Andy, afaik?).
This commit calculates the deformation transformation per vertex, and
inverse corrects it, so it's more intuitive editing this way.
Unfortunately all the deformation features of Blender don't use matrices
for defining deform, so the existing code cannot be re-used to retrieve
the correct deformation matrix per vertex. The solution I found is based
on calculating per face the transformation based on its first 3 vertices,
and store this transformation averaged in the face's vertices.
The solution can also only work on entire faces, because the full deform
can only be retrieved using 3 vertices. (using 2 vertices will miss edge-
aligned rotation, using 1 vertex can only retrieve translation).
By deriving the deformations per face, small errors will still happen,
especially on very low-poly Meshes with extreme deformations.
The only alternative I know now, is providing each vertex in
a mesh with 2 extreme small tangent vectors, which get deformed using the
existing code as well. That will mess up the existing deformation code too
much though, this solution has the benefit it works with each deform we can
up with later too.
Last note about CrazySpace: it can only be used to tweak Meshes. Do not
even try to add vertices, extrude, or duplicate. Probably we should disable
this... but preventing user errors isn't always power-user-friendly, eh. :)
2005-10-26 09:56:52 +00:00
|
|
|
}
|
2007-11-04 22:00:24 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_free_temporary_data(ModifierData *md)
|
2007-12-17 11:47:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (md->type == eModifierType_Armature) {
|
|
|
|
ArmatureModifierData *amd = (ArmatureModifierData *)md;
|
2007-12-17 11:47:24 +00:00
|
|
|
|
2020-06-12 14:29:59 +10:00
|
|
|
MEM_SAFE_FREE(amd->vert_coords_prev);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2007-12-17 11:47:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 00:14:51 +00:00
|
|
|
/* ensure modifier correctness when changing ob->data */
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifiers_test_object(Object *ob)
|
2010-09-09 00:14:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md;
|
2010-09-09 00:14:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* just multires checked for now, since only multires
|
|
|
|
* modifies mesh data */
|
2010-09-09 00:14:51 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->type != OB_MESH) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2007-12-17 11:47:24 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (md = ob->modifiers.first; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Multires) {
|
|
|
|
MultiresModifierData *mmd = (MultiresModifierData *)md;
|
2008-09-24 11:52:31 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
multiresModifier_set_levels_from_disps(mmd, ob);
|
|
|
|
}
|
|
|
|
}
|
2010-09-09 00:14:51 +00:00
|
|
|
}
|
2011-11-20 14:38:11 +00:00
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* where should this go?, it doesn't fit well anywhere :S - campbell */
|
2011-11-20 14:38:11 +00:00
|
|
|
|
|
|
|
/* elubie: changed this to default to the same dir as the render output
|
|
|
|
* to prevent saving to C:\ on Windows */
|
|
|
|
|
|
|
|
/* campbell: logic behind this...
|
|
|
|
*
|
|
|
|
* - if the ID is from a library, return library path
|
|
|
|
* - else if the file has been saved return the blend file path.
|
2012-03-18 07:38:51 +00:00
|
|
|
* - else if the file isn't saved and the ID isn't from a library, return the temp dir.
|
2011-11-20 14:38:11 +00:00
|
|
|
*/
|
2020-05-08 10:14:02 +02:00
|
|
|
const char *BKE_modifier_path_relbase(Main *bmain, Object *ob)
|
2011-11-20 14:38:11 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (G.relbase_valid || ID_IS_LINKED(ob)) {
|
|
|
|
return ID_BLEND_PATH(bmain, &ob->id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* last resort, better then using "" which resolves to the current
|
|
|
|
* working directory */
|
|
|
|
return BKE_tempdir_session();
|
|
|
|
}
|
2011-11-20 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
const char *BKE_modifier_path_relbase_from_global(Object *ob)
|
2018-06-09 15:16:44 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (G.relbase_valid || ID_IS_LINKED(ob)) {
|
|
|
|
return ID_BLEND_PATH_FROM_GLOBAL(&ob->id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* last resort, better then using "" which resolves to the current
|
|
|
|
* working directory */
|
|
|
|
return BKE_tempdir_session();
|
|
|
|
}
|
2018-06-09 15:16:44 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 14:38:11 +00:00
|
|
|
/* initializes the path with either */
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_path_init(char *path, int path_maxlen, const char *name)
|
2011-11-20 14:38:11 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* elubie: changed this to default to the same dir as the render output
|
|
|
|
* to prevent saving to C:\ on Windows */
|
|
|
|
BLI_join_dirfile(path, path_maxlen, G.relbase_valid ? "//" : BKE_tempdir_session(), name);
|
2011-11-20 14:38:11 +00:00
|
|
|
}
|
2013-06-19 08:00:20 +00:00
|
|
|
|
2020-05-25 20:16:42 +10:00
|
|
|
/**
|
|
|
|
* Call when #ModifierTypeInfo.dependsOnNormals callback requests normals.
|
|
|
|
*/
|
|
|
|
static void modwrap_dependsOnNormals(Mesh *me)
|
|
|
|
{
|
|
|
|
switch ((eMeshWrapperType)me->runtime.wrapper_type) {
|
|
|
|
case ME_WRAPPER_TYPE_BMESH: {
|
|
|
|
EditMeshData *edit_data = me->runtime.edit_data;
|
|
|
|
if (edit_data->vertexCos) {
|
|
|
|
/* Note that 'ensure' is acceptable here since these values aren't modified in-place.
|
|
|
|
* If that changes we'll need to recalculate. */
|
|
|
|
BKE_editmesh_cache_ensure_vert_normals(me->edit_mesh, edit_data);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BM_mesh_normals_update(me->edit_mesh->bm);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ME_WRAPPER_TYPE_MDATA:
|
|
|
|
BKE_mesh_calc_normals(me);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
/* wrapper around ModifierTypeInfo.modifyMesh that ensures valid normals */
|
2013-06-19 08:00:20 +00:00
|
|
|
|
2020-05-08 19:02:03 +10:00
|
|
|
struct Mesh *BKE_modifier_modify_mesh(ModifierData *md,
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
struct Mesh *me)
|
2018-10-09 13:19:21 +11:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(CustomData_has_layer(&me->pdata, CD_NORMAL) == false);
|
2018-10-09 13:19:21 +11:00
|
|
|
|
2020-05-25 20:16:42 +10:00
|
|
|
if (me->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH) {
|
|
|
|
if ((mti->flags & eModifierTypeFlag_AcceptsBMesh) == 0) {
|
|
|
|
BKE_mesh_wrapper_ensure_mdata(me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
|
2020-05-25 20:16:42 +10:00
|
|
|
modwrap_dependsOnNormals(me);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-04-21 13:09:41 +02:00
|
|
|
return mti->modifyMesh(md, ctx, me);
|
2018-10-09 13:19:21 +11:00
|
|
|
}
|
2013-06-19 08:00:20 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_deform_verts(ModifierData *md,
|
2020-05-08 19:02:03 +10:00
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
Mesh *me,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2018-10-09 13:19:21 +11:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(!me || CustomData_has_layer(&me->pdata, CD_NORMAL) == false);
|
2018-10-09 13:19:21 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (me && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
|
2020-05-25 20:16:42 +10:00
|
|
|
modwrap_dependsOnNormals(me);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
mti->deformVerts(md, ctx, me, vertexCos, numVerts);
|
2018-10-09 13:19:21 +11:00
|
|
|
}
|
2013-06-19 08:00:20 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_deform_vertsEM(ModifierData *md,
|
2020-05-08 19:02:03 +10:00
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
struct BMEditMesh *em,
|
|
|
|
Mesh *me,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2018-04-24 04:08:16 -04:00
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(!me || CustomData_has_layer(&me->pdata, CD_NORMAL) == false);
|
2018-04-24 04:08:16 -04:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (me && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
|
|
|
|
BKE_mesh_calc_normals(me);
|
|
|
|
}
|
|
|
|
mti->deformVertsEM(md, ctx, em, me, vertexCos, numVerts);
|
2018-04-18 15:45:54 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 13:19:21 +11:00
|
|
|
/* end modifier callback wrappers */
|
2018-04-24 04:08:16 -04:00
|
|
|
|
2018-05-30 11:34:08 +02:00
|
|
|
/**
|
|
|
|
* Get evaluated mesh for other evaluated object, which is used as an operand for the modifier,
|
|
|
|
* e.g. second operand for boolean modifier.
|
2019-04-27 12:07:07 +10:00
|
|
|
* Note that modifiers in stack always get fully evaluated COW ID pointers,
|
|
|
|
* never original ones. Makes things simpler.
|
2019-02-11 20:20:12 +01:00
|
|
|
*
|
2019-05-19 19:21:45 +10:00
|
|
|
* \param get_cage_mesh: Return evaluated mesh with only deforming modifiers applied
|
|
|
|
* (i.e. mesh topology remains the same as original one, a.k.a. 'cage' mesh).
|
2018-05-09 12:44:22 +02:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object(Object *ob_eval,
|
|
|
|
const bool get_cage_mesh)
|
2018-05-09 12:44:22 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *me = NULL;
|
2018-05-30 11:34:08 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((ob_eval->type == OB_MESH) && (ob_eval->mode & OB_MODE_EDIT)) {
|
|
|
|
/* In EditMode, evaluated mesh is stored in BMEditMesh, not the object... */
|
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
|
2019-04-27 12:07:07 +10:00
|
|
|
/* 'em' might not exist yet in some cases, just after loading a .blend file, see T57878. */
|
|
|
|
if (em != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
me = (get_cage_mesh && em->mesh_eval_cage != NULL) ? em->mesh_eval_cage :
|
|
|
|
em->mesh_eval_final;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (me == NULL) {
|
|
|
|
me = (get_cage_mesh && ob_eval->runtime.mesh_deform_eval != NULL) ?
|
|
|
|
ob_eval->runtime.mesh_deform_eval :
|
2020-02-27 11:23:15 +01:00
|
|
|
BKE_object_get_evaluated_mesh(ob_eval);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-30 11:34:08 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return me;
|
2018-05-09 12:44:22 +02:00
|
|
|
}
|
2019-04-04 14:42:33 +02:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *BKE_modifier_get_original(ModifierData *md)
|
2019-04-04 14:42:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (md->orig_modifier_data == NULL) {
|
|
|
|
return md;
|
|
|
|
}
|
|
|
|
return md->orig_modifier_data;
|
2019-04-04 14:42:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 19:02:03 +10:00
|
|
|
struct ModifierData *BKE_modifier_get_evaluated(Depsgraph *depsgraph,
|
|
|
|
Object *object,
|
|
|
|
ModifierData *md)
|
2019-04-04 14:42:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
|
|
|
|
if (object_eval == object) {
|
|
|
|
return md;
|
|
|
|
}
|
2020-05-25 11:39:52 +02:00
|
|
|
return BKE_modifiers_findby_name(object_eval, md->name);
|
2019-04-04 14:42:33 +02:00
|
|
|
}
|