Files
test/source/blender/blenkernel/intern/modifier.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1539 lines
48 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2005 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bke
* Modifier stack implementation.
2023-11-14 09:30:40 +01:00
* BKE_modifier.hh contains the function prototypes for this file.
2011-02-27 20:40:57 +00:00
*/
/* Allow using deprecated functionality for .blend file I/O. */
#define DNA_DEPRECATED_ALLOW
2022-09-29 16:43:09 -05:00
#include <cfloat>
Modifiers: measure execution time and provide Python access The goal is to give technical artists the ability to optimize modifier usage and/or geometry node groups for performance. In the long term, it would be useful if Blender could provide its own UI to display profiling information to users. However, right now, there are too many open design questions making it infeasible to tackle this in the short term. This commit uses a simpler approach: Instead of adding new ui for profiling data, it exposes the execution-time of modifiers in the Python API. This allows technical artists to access the information and to build their own UI to display the relevant information. In the long term this will hopefully also help us to integrate a native ui for this in Blender by observing how users use this information. Note: The execution time of a modifier highly depends on what other things the CPU is doing at the same time. For example, in many more complex files, many objects and therefore modifiers are evaluated at the same time by multiple threads which makes the measurement much less reliable. For best results, make sure that only one object is evaluated at a time (e.g. by changing it in isolation) and that no other process on the system keeps the CPU busy. As shown below, the execution time has to be accessed on the evaluated object, not the original object. ```lang=python import bpy depsgraph = bpy.context.view_layer.depsgraph ob = bpy.context.active_object ob_eval = ob.evaluated_get(depsgraph) modifier_eval = ob_eval.modifiers[0] print(modifier_eval.execution_time, "s") ``` Differential Revision: https://developer.blender.org/D17185
2023-02-06 15:39:59 +01:00
#include <chrono>
2022-09-29 16:43:09 -05:00
#include <cmath>
#include <cstdarg>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
#include "DNA_cloth_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_fluid_types.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_fluidsim_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
2011-10-22 01:53:35 +00:00
#include "BLI_linklist.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_session_uuid.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "BKE_DerivedMesh.hh"
#include "BKE_appdir.h"
#include "BKE_editmesh.hh"
#include "BKE_editmesh_cache.hh"
#include "BKE_effect.h"
#include "BKE_fluid.h"
#include "BKE_global.h"
#include "BKE_gpencil_modifier_legacy.h"
#include "BKE_idtype.h"
#include "BKE_key.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_mesh.hh"
#include "BKE_mesh_wrapper.hh"
#include "BKE_multires.hh"
#include "BKE_object.hh"
#include "BKE_pointcache.h"
#include "BKE_screen.hh"
/* may move these, only for BKE_modifier_path_relbase */
#include "BKE_main.h"
/* end */
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "MOD_modifiertypes.hh"
#include "BLO_read_write.hh"
#include "CLG_log.h"
static CLG_LogRef LOG = {"bke.modifier"};
2022-09-29 16:43:09 -05:00
static ModifierTypeInfo *modifier_types[NUM_MODIFIER_TYPES] = {nullptr};
static VirtualModifierData virtualModifierCommonData;
void BKE_modifier_init()
{
ModifierData *md;
/* Initialize modifier types */
modifier_type_init(modifier_types); /* MOD_utils.c */
2021-09-23 22:06:49 +10:00
/* Initialize global common storage used for virtual modifier list. */
md = BKE_modifier_new(eModifierType_Armature);
virtualModifierCommonData.amd = *((ArmatureModifierData *)md);
BKE_modifier_free(md);
md = BKE_modifier_new(eModifierType_Curve);
virtualModifierCommonData.cmd = *((CurveModifierData *)md);
BKE_modifier_free(md);
md = BKE_modifier_new(eModifierType_Lattice);
virtualModifierCommonData.lmd = *((LatticeModifierData *)md);
BKE_modifier_free(md);
md = BKE_modifier_new(eModifierType_ShapeKey);
virtualModifierCommonData.smd = *((ShapeKeyModifierData *)md);
BKE_modifier_free(md);
virtualModifierCommonData.amd.modifier.mode |= eModifierMode_Virtual;
virtualModifierCommonData.cmd.modifier.mode |= eModifierMode_Virtual;
virtualModifierCommonData.lmd.modifier.mode |= eModifierMode_Virtual;
virtualModifierCommonData.smd.modifier.mode |= eModifierMode_Virtual;
}
const ModifierTypeInfo *BKE_modifier_get_info(ModifierType type)
{
/* 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') {
return modifier_types[type];
}
2022-09-29 16:43:09 -05:00
return nullptr;
}
void BKE_modifier_type_panel_id(ModifierType type, char *r_idname)
{
const ModifierTypeInfo *mti = BKE_modifier_get_info(type);
BLI_string_join(r_idname, sizeof(PanelType::idname), MODIFIER_TYPE_PANEL_PREFIX, mti->idname);
}
void BKE_modifier_panel_expand(ModifierData *md)
{
md->ui_expand_flag |= UI_PANEL_DATA_EXPAND_ROOT;
}
/***/
2022-09-29 16:43:09 -05:00
static ModifierData *modifier_allocate_and_init(ModifierType 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
{
const ModifierTypeInfo *mti = BKE_modifier_get_info(type);
ModifierData *md = static_cast<ModifierData *>(MEM_callocN(mti->struct_size, mti->struct_name));
2018-06-17 17:05:51 +02:00
/* NOTE: this name must be made unique later. */
STRNCPY_UTF8(md->name, DATA_(mti->name));
- 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
md->type = type;
md->mode = eModifierMode_Realtime | eModifierMode_Render;
md->flag = eModifierFlag_OverrideLibrary_Local;
/* Only open the main panel at the beginning, not the sub-panels. */
md->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT;
if (mti->flags & eModifierTypeFlag_EnableInEditmode) {
md->mode |= eModifierMode_Editmode;
}
- 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
if (mti->init_data) {
mti->init_data(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
return md;
}
ModifierData *BKE_modifier_new(int type)
{
2022-09-29 16:43:09 -05:00
ModifierData *md = modifier_allocate_and_init(ModifierType(type));
BKE_modifier_session_uuid_generate(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
return md;
}
static void modifier_free_data_id_us_cb(void * /*user_data*/,
Object * /*ob*/,
ID **idpoin,
int cb_flag)
{
ID *id = *idpoin;
2022-09-29 16:43:09 -05:00
if (id != nullptr && (cb_flag & IDWALK_CB_USER) != 0) {
id_us_min(id);
}
}
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
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(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
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
if (mti->foreach_ID_link) {
mti->foreach_ID_link(md, nullptr, modifier_free_data_id_us_cb, nullptr);
}
}
if (mti->free_data) {
mti->free_data(md);
}
if (md->error) {
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
MEM_freeN(md->error);
}
- 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
MEM_freeN(md);
}
void BKE_modifier_free(ModifierData *md)
{
BKE_modifier_free_ex(md, 0);
}
void BKE_modifier_remove_from_list(Object *ob, ModifierData *md)
{
BLI_assert(BLI_findindex(&ob->modifiers, md) != -1);
if (md->flag & eModifierFlag_Active) {
/* Prefer the previous modifier but use the next if this modifier is the first in the list. */
2022-09-29 16:43:09 -05:00
if (md->next != nullptr) {
BKE_object_modifier_set_active(ob, md->next);
}
2022-09-29 16:43:09 -05:00
else if (md->prev != nullptr) {
BKE_object_modifier_set_active(ob, md->prev);
}
}
BLI_remlink(&ob->modifiers, md);
}
void BKE_modifier_session_uuid_generate(ModifierData *md)
{
md->session_uuid = BLI_session_uuid_generate();
}
void BKE_modifier_unique_name(ListBase *modifiers, ModifierData *md)
{
if (modifiers && md) {
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
BLI_uniquename(
modifiers, md, DATA_(mti->name), '.', offsetof(ModifierData, name), sizeof(md->name));
}
}
bool BKE_modifier_depends_ontime(Scene *scene, ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
return mti->depends_on_time && mti->depends_on_time(scene, md);
}
bool BKE_modifier_supports_mapping(ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
return (mti->type == ModifierTypeType::OnlyDeform ||
2012-05-06 17:22:54 +00:00
(mti->flags & eModifierTypeFlag_SupportsMapping));
}
bool BKE_modifier_is_preview(ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
/* Constructive modifiers are highly likely to also modify data like vgroups or vertex-colors! */
if (!((mti->flags & eModifierTypeFlag_UsesPreview) ||
(mti->type == ModifierTypeType::Constructive)))
{
2014-03-20 22:56:28 +11:00
return false;
}
if (md->mode & eModifierMode_Realtime) {
2014-03-20 22:56:28 +11:00
return true;
}
2014-03-20 22:56:28 +11:00
return false;
}
ModifierData *BKE_modifiers_findby_type(const Object *ob, ModifierType type)
{
2020-10-09 13:51:13 -05:00
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (md->type == type) {
2020-10-09 13:51:13 -05:00
return md;
}
}
2022-09-29 16:43:09 -05:00
return nullptr;
}
ModifierData *BKE_modifiers_findby_name(const Object *ob, const char *name)
{
2022-09-29 16:43:09 -05:00
return static_cast<ModifierData *>(
BLI_findstring(&(ob->modifiers), name, offsetof(ModifierData, name)));
}
ModifierData *BKE_modifiers_findby_session_uuid(const Object *ob, const SessionUUID *session_uuid)
{
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (BLI_session_uuid_is_equal(&md->session_uuid, session_uuid)) {
return md;
}
}
2022-09-29 16:43:09 -05:00
return nullptr;
}
void BKE_modifiers_clear_errors(Object *ob)
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
{
2020-10-09 13:51:13 -05:00
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
if (md->error) {
MEM_freeN(md->error);
2022-09-29 16:43:09 -05:00
md->error = nullptr;
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
}
}
}
void BKE_modifiers_foreach_ID_link(Object *ob, IDWalkFunc walk, void *user_data)
{
2020-10-09 13:51:13 -05:00
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (mti->foreach_ID_link) {
mti->foreach_ID_link(md, ob, walk, user_data);
}
}
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
}
void BKE_modifiers_foreach_tex_link(Object *ob, TexWalkFunc walk, void *user_data)
{
2020-10-09 13:51:13 -05:00
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (mti->foreach_tex_link) {
mti->foreach_tex_link(md, ob, walk, user_data);
}
}
}
ModifierData *BKE_modifier_copy_ex(const ModifierData *md, int flag)
{
2022-09-29 16:43:09 -05:00
ModifierData *md_dst = modifier_allocate_and_init(ModifierType(md->type));
2023-05-09 12:50:37 +10:00
STRNCPY(md_dst->name, md->name);
BKE_modifier_copydata_ex(md, md_dst, flag);
return md_dst;
}
void BKE_modifier_copydata_generic(const ModifierData *md_src,
2020-05-08 19:02:03 +10:00
ModifierData *md_dst,
const int /*flag*/)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md_src->type));
/* `md_dst` may have already be fully initialized with some extra allocated data,
* we need to free it now to avoid a memory leak. */
if (mti->free_data) {
mti->free_data(md_dst);
}
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->struct_size));
memcpy(md_dst_data, md_src_data, size_t(mti->struct_size) - data_size);
/* Runtime fields are never to be preserved. */
2022-09-29 16:43:09 -05:00
md_dst->runtime = nullptr;
}
static void modifier_copy_data_id_us_cb(void * /*user_data*/,
Object * /*ob*/,
ID **idpoin,
int cb_flag)
{
ID *id = *idpoin;
2022-09-29 16:43:09 -05:00
if (id != nullptr && (cb_flag & IDWALK_CB_USER) != 0) {
id_us_plus(id);
}
}
void BKE_modifier_copydata_ex(const ModifierData *md, ModifierData *target, const int flag)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
target->mode = md->mode;
target->flag = md->flag;
target->ui_expand_flag = md->ui_expand_flag;
if (mti->copy_data) {
mti->copy_data(md, target, flag);
}
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
if (mti->foreach_ID_link) {
mti->foreach_ID_link(target, nullptr, modifier_copy_data_id_us_cb, nullptr);
}
}
if (flag & LIB_ID_CREATE_NO_MAIN) {
/* Make sure UUID is the same between the source and the target.
* This is needed in the cases when UUID is to be preserved and when there is no copy_data
* callback, or the copy_data does not do full byte copy of the modifier data. */
target->session_uuid = md->session_uuid;
}
else {
/* In the case copy_data made full byte copy force UUID to be re-generated. */
BKE_modifier_session_uuid_generate(target);
}
}
void BKE_modifier_copydata(const ModifierData *md, ModifierData *target)
{
BKE_modifier_copydata_ex(md, target, 0);
}
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
bool BKE_modifier_supports_cage(Scene *scene, ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
return ((!mti->is_disabled || !mti->is_disabled(scene, md, false)) &&
(mti->flags & eModifierTypeFlag_SupportsEditmode) && BKE_modifier_supports_mapping(md));
}
bool BKE_modifier_couldbe_cage(Scene *scene, ModifierData *md)
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
2012-05-06 17:22:54 +00:00
return ((md->mode & eModifierMode_Realtime) && (md->mode & eModifierMode_Editmode) &&
(!mti->is_disabled || !mti->is_disabled(scene, md, false)) &&
2020-05-08 19:02:03 +10:00
BKE_modifier_supports_mapping(md));
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
}
bool BKE_modifier_is_same_topology(ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
return ELEM(mti->type, ModifierTypeType::OnlyDeform, ModifierTypeType::NonGeometrical);
}
bool BKE_modifier_is_non_geometrical(ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
return (mti->type == ModifierTypeType::NonGeometrical);
}
void BKE_modifier_set_error(const Object *ob, ModifierData *md, const char *_format, ...)
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
{
char buffer[512];
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
va_list ap;
const char *format = TIP_(_format);
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
va_start(ap, _format);
vsnprintf(buffer, sizeof(buffer), format, ap);
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
va_end(ap);
2012-05-06 17:22:54 +00:00
buffer[sizeof(buffer) - 1] = '\0';
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
if (md->error) {
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
MEM_freeN(md->error);
}
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
md->error = BLI_strdup(buffer);
#ifndef NDEBUG
if ((md->mode & eModifierMode_Virtual) == 0) {
/* Ensure correct object is passed in. */
2022-09-29 16:43:09 -05:00
BLI_assert(BKE_modifier_get_original(ob, md) != nullptr);
}
#endif
Nodes: Fix versioning 2.6 groups, causing dangling link pointers In 2.6 the old method of using bNodeSocket lists in bNodeTree directly as group sockets was replaced with new group input/output nodes. This required versioning to create those input/output nodes and then redirect links to the new node sockets. Because creating nodes relies heavily on node typeinfo this versioning was done in the `_after_linking` section of the 2.6 versioning code, running after _all other versioning_ (including for much newer versions!) has already happended. While typinfo is available at that point, doing such late versioning causes severe problems when the data structure changes, as is the case with the recent node panels patch (#111348). The new node group interface also has versioning code for 4.0, but this runs _before_ the `_after_linking` code for 2.6! Versioning for node panels expects sockets in bNodeTree to not have any links pointing at them, but this is not true for old 2.6 files which have not yet been fully versioned at that point, because of the late versioning stage. Subsequently 2.6 `_after_linking` code crashes when trying to modify node links with dangling pointers. The solution here is to move the old versioning code out of the `after_linking` stage to restore the expected versioning chain. This requires creating nodes and node sockets without any typeinfo, but luckily we only need to create simple known group input/output nodes which don't have much complicated behavior. Pull Request: https://projects.blender.org/blender/blender/pulls/111704
2023-09-05 12:37:05 +02:00
CLOG_WARN(&LOG, "Object: \"%s\", Modifier: \"%s\", %s", ob->id.name + 2, md->name, md->error);
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
}
void BKE_modifier_set_warning(const Object *ob, ModifierData *md, const char *_format, ...)
{
char buffer[512];
va_list ap;
const char *format = TIP_(_format);
va_start(ap, _format);
vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);
buffer[sizeof(buffer) - 1] = '\0';
/* Store the warning in the same field as the error.
* It is not expected to have both error and warning and having a single place to store the
* message simplifies interface code. */
if (md->error) {
MEM_freeN(md->error);
}
md->error = BLI_strdup(buffer);
#ifndef NDEBUG
if ((md->mode & eModifierMode_Virtual) == 0) {
/* Ensure correct object is passed in. */
2022-09-29 16:43:09 -05:00
BLI_assert(BKE_modifier_get_original(ob, md) != nullptr);
}
#endif
UNUSED_VARS_NDEBUG(ob);
}
2021-02-17 10:27:50 +11:00
int BKE_modifiers_get_cage_index(const Scene *scene,
2020-05-08 19:02:03 +10:00
Object *ob,
int *r_lastPossibleCageIndex,
bool is_virtual)
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
{
VirtualModifierData virtual_modifier_data;
2020-05-08 19:02:03 +10:00
ModifierData *md = (is_virtual) ?
BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data) :
2022-09-29 16:43:09 -05:00
static_cast<ModifierData *>(ob->modifiers.first);
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
if (r_lastPossibleCageIndex) {
/* ensure the value is initialized */
*r_lastPossibleCageIndex = -1;
}
/* Find the last modifier acting on the cage. */
2020-10-09 13:51:13 -05:00
int cageIndex = -1;
for (int i = 0; md; i++, md = md->next) {
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
bool supports_mapping;
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
if (mti->is_disabled && mti->is_disabled(scene, md, false)) {
continue;
}
if (!(mti->flags & eModifierTypeFlag_SupportsEditmode)) {
continue;
}
if (md->mode & eModifierMode_DisableTemporary) {
continue;
}
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
supports_mapping = BKE_modifier_supports_mapping(md);
if (r_lastPossibleCageIndex && supports_mapping) {
*r_lastPossibleCageIndex = i;
}
if (!(md->mode & eModifierMode_Realtime)) {
continue;
}
if (!(md->mode & eModifierMode_Editmode)) {
continue;
}
if (!supports_mapping) {
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
break;
}
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
if (md->mode & eModifierMode_OnCage) {
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
cageIndex = i;
}
- modifier UI update (aka, find the modifier buttons!!) - moved back to editing buttons, where life is now cramped... switched to constraint style foldout panes, still a WIP. In particular not sure what buttons should be in header (and if current toggles stay in header if they should also be in an expanded pane). Also need new icons for move up/move down (and drag and drop would of course be nice). Finally current plane is to make it so modifiers will expand out in modifier pane for horizontal orientations instead of just going down down down to goblin town. - added error field to modifiers that is displayed in UI, need to have some way for modifiers to return errors back to interface (esp. important for python) - tweaked cage determination and handling, currently the editmode cage is determined by last modifier with OnCage set that is preceeded completely by modifiers that support mapping or are disabled in editmode. it is kinda confusing, but the interface only lets you toggle OnCage for modifiers that support it - it just might not be clear all the time why you can't toggle a certain modifier OnCage. - update displistmesh_copy to only copy edges if non-NULL There is a display bug that already existed but is more obvious with new modifiers where parts of the pane get drawn in a different area after toggling editmode. It has to do with drawing parts of the interface using GL instead of 100% buttons. I try to keep my grubby little toes out of the interface code so this can wait for Ton to return.
2005-08-04 07:25:43 +00:00
}
return cageIndex;
}
bool BKE_modifiers_is_softbody_enabled(Object *ob)
{
ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Softbody);
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
}
bool BKE_modifiers_is_cloth_enabled(Object *ob)
{
ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Cloth);
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
}
bool BKE_modifiers_is_modifier_enabled(Object *ob, int modifierType)
{
2022-09-29 16:43:09 -05:00
ModifierData *md = BKE_modifiers_findby_type(ob, ModifierType(modifierType));
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
}
bool BKE_modifiers_is_particle_enabled(Object *ob)
{
ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_ParticleSystem);
return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
}
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if ((md->mode & required_mode) != required_mode) {
2014-08-20 20:41:30 +02:00
return false;
}
if (scene != nullptr && mti->is_disabled &&
mti->is_disabled(scene, md, required_mode == eModifierMode_Render))
{
2014-08-20 20:41:30 +02:00
return false;
}
if (md->mode & eModifierMode_DisableTemporary) {
2014-08-20 20:41:30 +02:00
return false;
}
2014-08-20 20:41:30 +02:00
if ((required_mode & eModifierMode_Editmode) &&
!(mti->flags & eModifierTypeFlag_SupportsEditmode)) {
return false;
}
2014-08-20 20:41:30 +02:00
return true;
}
bool BKE_modifier_is_nonlocal_in_liboverride(const Object *ob, const ModifierData *md)
{
return (ID_IS_OVERRIDE_LIBRARY(ob) &&
2022-09-29 16:43:09 -05:00
(md == nullptr || (md->flag & eModifierFlag_OverrideLibrary_Local) == 0));
}
CDMaskLink *BKE_modifier_calc_data_masks(const Scene *scene,
2020-05-08 19:02:03 +10:00
ModifierData *md,
CustomData_MeshMasks *final_datamask,
int required_mode,
ModifierData *previewmd,
const CustomData_MeshMasks *previewmask)
{
2022-09-29 16:43:09 -05:00
CDMaskLink *dataMasks = nullptr;
CDMaskLink *curr, *prev;
bool have_deform_modifier = false;
/* build a list of modifier data requirements in reverse order */
for (; md; md = md->next) {
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
2022-09-29 16:43:09 -05:00
curr = MEM_cnew<CDMaskLink>(__func__);
if (BKE_modifier_is_enabled(scene, md, required_mode)) {
if (mti->type == ModifierTypeType::OnlyDeform) {
have_deform_modifier = true;
}
if (mti->required_data_mask) {
mti->required_data_mask(md, &curr->mask);
}
2022-09-29 16:43:09 -05:00
if (previewmd == md && previewmask != nullptr) {
CustomData_MeshMasks_update(&curr->mask, previewmask);
}
}
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;
}
/* prepend new datamask */
curr->next = dataMasks;
dataMasks = curr;
}
if (!have_deform_modifier) {
final_datamask->vmask &= ~CD_MASK_ORCO;
}
/* 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
*/
2022-09-29 16:43:09 -05:00
for (curr = dataMasks, prev = nullptr; curr; prev = curr, curr = curr->next) {
if (prev) {
CustomData_MeshMasks_update(&curr->mask, &prev->mask);
}
else {
CustomData_MeshMasks_update(&curr->mask, final_datamask);
}
}
/* reverse the list so it's in the correct order */
2012-05-06 17:22:54 +00:00
BLI_linklist_reverse((LinkNode **)&dataMasks);
return dataMasks;
}
ModifierData *BKE_modifier_get_last_preview(const Scene *scene,
2020-05-08 19:02:03 +10:00
ModifierData *md,
int required_mode)
{
2022-09-29 16:43:09 -05:00
ModifierData *tmp_md = nullptr;
if ((required_mode & ~eModifierMode_Editmode) != eModifierMode_Realtime) {
return tmp_md;
}
/* Find the latest modifier in stack generating preview. */
for (; md; md = md->next) {
if (BKE_modifier_is_enabled(scene, md, required_mode) && BKE_modifier_is_preview(md)) {
tmp_md = md;
}
}
return tmp_md;
}
ModifierData *BKE_modifiers_get_virtual_modifierlist(const Object *ob,
VirtualModifierData *virtual_modifier_data)
{
2022-09-29 16:43:09 -05:00
ModifierData *md = static_cast<ModifierData *>(ob->modifiers.first);
*virtual_modifier_data = virtualModifierCommonData;
if (ob->parent) {
2012-05-06 17:22:54 +00:00
if (ob->parent->type == OB_ARMATURE && ob->partype == PARSKEL) {
virtual_modifier_data->amd.object = ob->parent;
virtual_modifier_data->amd.modifier.next = md;
virtual_modifier_data->amd.deformflag = ((bArmature *)(ob->parent->data))->deformflag;
md = &virtual_modifier_data->amd.modifier;
}
else if (ob->parent->type == OB_CURVES_LEGACY && ob->partype == PARSKEL) {
virtual_modifier_data->cmd.object = ob->parent;
virtual_modifier_data->cmd.defaxis = ob->trackflag + 1;
virtual_modifier_data->cmd.modifier.next = md;
md = &virtual_modifier_data->cmd.modifier;
}
2012-05-06 17:22:54 +00:00
else if (ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
virtual_modifier_data->lmd.object = ob->parent;
virtual_modifier_data->lmd.modifier.next = md;
md = &virtual_modifier_data->lmd.modifier;
}
}
/* shape key modifier, not yet for curves */
2022-04-28 10:53:50 -05:00
if (ELEM(ob->type, OB_MESH, OB_LATTICE) && BKE_key_from_object((Object *)ob)) {
if (ob->type == OB_MESH && (ob->shapeflag & OB_SHAPE_EDIT_MODE)) {
virtual_modifier_data->smd.modifier.mode |= eModifierMode_Editmode | eModifierMode_OnCage;
}
else {
virtual_modifier_data->smd.modifier.mode &= ~eModifierMode_Editmode | eModifierMode_OnCage;
}
virtual_modifier_data->smd.modifier.next = md;
md = &virtual_modifier_data->smd.modifier;
}
return md;
}
Object *BKE_modifiers_is_deformed_by_armature(Object *ob)
{
if (ob->type == OB_GPENCIL_LEGACY) {
GpencilVirtualModifierData gpencilvirtualModifierData;
2022-09-29 16:43:09 -05:00
ArmatureGpencilModifierData *agmd = nullptr;
GpencilModifierData *gmd = BKE_gpencil_modifiers_get_virtual_modifierlist(
ob, &gpencilvirtualModifierData);
/* return the first selected armature, this lets us use multiple armatures */
for (; gmd; gmd = gmd->next) {
if (gmd->type == eGpencilModifierType_Armature) {
agmd = (ArmatureGpencilModifierData *)gmd;
if (agmd->object && (agmd->object->base_flag & BASE_SELECTED)) {
return agmd->object;
}
}
}
/* If we're still here then return the last armature. */
if (agmd) {
return agmd->object;
}
}
else {
VirtualModifierData virtual_modifier_data;
2022-09-29 16:43:09 -05:00
ArmatureModifierData *amd = nullptr;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
/* return the first selected armature, this lets us use multiple armatures */
for (; md; md = md->next) {
if (md->type == eModifierType_Armature) {
amd = (ArmatureModifierData *)md;
if (amd->object && (amd->object->base_flag & BASE_SELECTED)) {
return amd->object;
}
}
}
/* If we're still here then return the last armature. */
if (amd) {
return amd->object;
}
}
2018-06-17 17:05:51 +02:00
2022-09-29 16:43:09 -05:00
return nullptr;
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
}
Object *BKE_modifiers_is_deformed_by_meshdeform(Object *ob)
{
VirtualModifierData virtual_modifier_data;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
2022-09-29 16:43:09 -05:00
MeshDeformModifierData *mdmd = nullptr;
/* return the first selected armature, this lets us use multiple armatures */
for (; md; md = md->next) {
if (md->type == eModifierType_MeshDeform) {
mdmd = (MeshDeformModifierData *)md;
if (mdmd->object && (mdmd->object->base_flag & BASE_SELECTED)) {
return mdmd->object;
}
}
}
if (mdmd) { /* if we're still here then return the last armature */
return mdmd->object;
}
2022-09-29 16:43:09 -05:00
return nullptr;
}
Object *BKE_modifiers_is_deformed_by_lattice(Object *ob)
{
VirtualModifierData virtual_modifier_data;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
2022-09-29 16:43:09 -05:00
LatticeModifierData *lmd = nullptr;
2018-06-17 17:05:51 +02:00
/* return the first selected lattice, this lets us use multiple lattices */
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
if (md->type == eModifierType_Lattice) {
lmd = (LatticeModifierData *)md;
if (lmd->object && (lmd->object->base_flag & BASE_SELECTED)) {
return lmd->object;
}
}
}
2018-06-17 17:05:51 +02:00
if (lmd) { /* if we're still here then return the last lattice */
return lmd->object;
}
2018-06-17 17:05:51 +02:00
2022-09-29 16:43:09 -05:00
return nullptr;
}
Object *BKE_modifiers_is_deformed_by_curve(Object *ob)
{
VirtualModifierData virtual_modifier_data;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
2022-09-29 16:43:09 -05:00
CurveModifierData *cmd = nullptr;
2018-06-17 17:05:51 +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;
if (cmd->object && (cmd->object->base_flag & BASE_SELECTED)) {
return cmd->object;
}
}
}
2018-06-17 17:05:51 +02:00
if (cmd) { /* if we're still here then return the last curve */
return cmd->object;
}
2018-06-17 17:05:51 +02:00
2022-09-29 16:43:09 -05:00
return nullptr;
}
bool BKE_modifiers_uses_multires(Object *ob)
{
VirtualModifierData virtual_modifier_data;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
2022-09-29 16:43:09 -05:00
MultiresModifierData *mmd = nullptr;
for (; md; md = md->next) {
if (md->type == eModifierType_Multires) {
mmd = (MultiresModifierData *)md;
if (mmd->totlvl != 0) {
return true;
}
}
}
return false;
}
bool BKE_modifiers_uses_armature(Object *ob, bArmature *arm)
{
VirtualModifierData virtual_modifier_data;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
if (md->type == eModifierType_Armature) {
ArmatureModifierData *amd = (ArmatureModifierData *)md;
if (amd->object && amd->object->data == arm) {
return true;
}
}
}
return false;
}
bool BKE_modifier_is_correctable_deformed(ModifierData *md)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
return mti->deform_matrices_EM != nullptr;
}
bool BKE_modifiers_is_correctable_deformed(const 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
{
VirtualModifierData virtual_modifier_data;
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
int required_mode = eModifierMode_Realtime;
if (ob->mode == OB_MODE_EDIT) {
required_mode |= eModifierMode_Editmode;
}
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
2012-10-07 09:48:59 +00:00
/* pass */
}
else if (BKE_modifier_is_correctable_deformed(md)) {
return true;
2012-10-07 09:48:59 +00:00
}
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
}
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
}
void BKE_modifier_free_temporary_data(ModifierData *md)
{
if (md->type == eModifierType_Armature) {
2012-05-06 17:22:54 +00:00
ArmatureModifierData *amd = (ArmatureModifierData *)md;
MEM_SAFE_FREE(amd->vert_coords_prev);
}
}
void BKE_modifiers_test_object(Object *ob)
{
/* just multires checked for now, since only multires
* modifies mesh data */
if (ob->type != OB_MESH) {
return;
}
2022-09-29 16:43:09 -05:00
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (md->type == eModifierType_Multires) {
2012-05-06 17:22:54 +00:00
MultiresModifierData *mmd = (MultiresModifierData *)md;
multiresModifier_set_levels_from_disps(mmd, ob);
}
}
}
const char *BKE_modifier_path_relbase(Main *bmain, Object *ob)
{
/* - If the ID is from a library, return library path.
* - Else if the file has been saved return the blend file path.
* - Else if the file isn't saved and the ID isn't from a library, return the temp dir.
*/
if ((bmain->filepath[0] != '\0') || ID_IS_LINKED(ob)) {
return ID_BLEND_PATH(bmain, &ob->id);
}
/* Last resort, better than using "" which resolves to the current working directory. */
return BKE_tempdir_session();
}
const char *BKE_modifier_path_relbase_from_global(Object *ob)
2018-06-09 15:16:44 +02:00
{
return BKE_modifier_path_relbase(G_MAIN, ob);
2018-06-09 15:16:44 +02:00
}
void BKE_modifier_path_init(char *path, int path_maxncpy, const char *name)
{
const char *blendfile_path = BKE_main_blendfile_path_from_global();
BLI_path_join(path, path_maxncpy, blendfile_path[0] ? "//" : BKE_tempdir_session(), name);
}
/**
* Call when #ModifierTypeInfo.depends_on_normals callback requests normals.
*/
static void modwrap_dependsOnNormals(Mesh *me)
{
switch (me->runtime->wrapper_type) {
case ME_WRAPPER_TYPE_BMESH: {
blender::bke::EditMeshData *edit_data = me->runtime->edit_data;
if (!edit_data->vertexCos.is_empty()) {
/* 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;
}
OpenSubDiv: add support for an OpenGL evaluator This evaluator is used in order to evaluate subdivision at render time, allowing for faster renders of meshes with a subdivision surface modifier placed at the last position in the modifier list. When evaluating the subsurf modifier, we detect whether we can delegate evaluation to the draw code. If so, the subdivision is first evaluated on the GPU using our own custom evaluator (only the coarse data needs to be initially sent to the GPU), then, buffers for the final `MeshBufferCache` are filled on the GPU using a set of compute shaders. However, some buffers are still filled on the CPU side, if doing so on the GPU is impractical (e.g. the line adjacency buffer used for x-ray, whose logic is hardly GPU compatible). This is done at the mesh buffer extraction level so that the result can be readily used in the various OpenGL engines, without having to write custom geometry or tesselation shaders. We use our own subdivision evaluation shaders, instead of OpenSubDiv's vanilla one, in order to control the data layout, and interpolation. For example, we store vertex colors as compressed 16-bit integers, while OpenSubDiv's default evaluator only work for float types. In order to still access the modified geometry on the CPU side, for use in modifiers or transform operators, a dedicated wrapper type is added `MESH_WRAPPER_TYPE_SUBD`. Subdivision will be lazily evaluated via `BKE_object_get_evaluated_mesh` which will create such a wrapper if possible. If the final subdivision surface is not needed on the CPU side, `BKE_object_get_evaluated_mesh_no_subsurf` should be used. Enabling or disabling GPU subdivision can be done through the user preferences (under Viewport -> Subdivision). See patch description for benchmarks. Reviewed By: campbellbarton, jbakker, fclem, brecht, #eevee_viewport Differential Revision: https://developer.blender.org/D12406
2021-12-27 16:34:47 +01:00
case ME_WRAPPER_TYPE_SUBD:
/* Not an expected case. */
break;
case ME_WRAPPER_TYPE_MDATA:
/* Normals are calculated lazily. */
break;
}
}
/* wrapper around ModifierTypeInfo.modify_mesh that ensures valid normals */
Mesh *BKE_modifier_modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *me)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (me->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH) {
if ((mti->flags & eModifierTypeFlag_AcceptsBMesh) == 0) {
BKE_mesh_wrapper_ensure_mdata(me);
}
}
if (mti->depends_on_normals && mti->depends_on_normals(md)) {
modwrap_dependsOnNormals(me);
}
return mti->modify_mesh(md, ctx, me);
}
void BKE_modifier_deform_verts(ModifierData *md,
2020-05-08 19:02:03 +10:00
const ModifierEvalContext *ctx,
Mesh *me,
blender::MutableSpan<blender::float3> positions)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (me && mti->depends_on_normals && mti->depends_on_normals(md)) {
modwrap_dependsOnNormals(me);
}
mti->deform_verts(md, ctx, me, positions);
if (me) {
BKE_mesh_tag_positions_changed(me);
}
}
void BKE_modifier_deform_vertsEM(ModifierData *md,
2020-05-08 19:02:03 +10:00
const ModifierEvalContext *ctx,
BMEditMesh *em,
2020-05-08 19:02:03 +10:00
Mesh *me,
blender::MutableSpan<blender::float3> positions)
{
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (me && mti->depends_on_normals && mti->depends_on_normals(md)) {
modwrap_dependsOnNormals(me);
}
mti->deform_verts_EM(md, ctx, em, me, positions);
}
/* end modifier callback wrappers */
Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object(Object *ob_eval)
{
2022-09-29 16:43:09 -05:00
Mesh *me = nullptr;
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);
/* 'em' might not exist yet in some cases, just after loading a .blend file, see #57878. */
2022-09-29 16:43:09 -05:00
if (em != nullptr) {
me = BKE_object_get_editmesh_eval_final(ob_eval);
}
}
2022-09-29 16:43:09 -05:00
if (me == nullptr) {
me = BKE_object_get_evaluated_mesh(ob_eval);
}
return me;
}
ModifierData *BKE_modifier_get_original(const Object *object, ModifierData *md)
{
const Object *object_orig = DEG_get_original_object((Object *)object);
return BKE_modifiers_findby_session_uuid(object_orig, &md->session_uuid);
}
ModifierData *BKE_modifier_get_evaluated(Depsgraph *depsgraph, Object *object, ModifierData *md)
{
Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
if (object_eval == object) {
return md;
}
return BKE_modifiers_findby_session_uuid(object_eval, &md->session_uuid);
}
void BKE_modifier_check_uuids_unique_and_report(const Object *object)
{
GSet *used_uuids = BLI_gset_new(
BLI_session_uuid_ghash_hash, BLI_session_uuid_ghash_compare, "modifier used uuids");
LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
const SessionUUID *session_uuid = &md->session_uuid;
if (!BLI_session_uuid_is_generated(session_uuid)) {
printf("Modifier %s -> %s does not have UUID generated.\n", object->id.name + 2, md->name);
continue;
}
2022-09-29 16:43:09 -05:00
if (BLI_gset_lookup(used_uuids, session_uuid) != nullptr) {
printf("Modifier %s -> %s has duplicate UUID generated.\n", object->id.name + 2, md->name);
continue;
}
BLI_gset_insert(used_uuids, (void *)session_uuid);
}
2022-09-29 16:43:09 -05:00
BLI_gset_free(used_uuids, nullptr);
}
void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBase *modbase)
{
2022-09-29 16:43:09 -05:00
if (modbase == nullptr) {
return;
}
LISTBASE_FOREACH (ModifierData *, md, modbase) {
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (mti == nullptr) {
continue;
}
/* If the blend_write callback is defined, it should handle the whole writing process. */
if (mti->blend_write != nullptr) {
mti->blend_write(writer, id_owner, md);
continue;
}
BLO_write_struct_by_name(writer, mti->struct_name, md);
if (md->type == eModifierType_Cloth) {
ClothModifierData *clmd = (ClothModifierData *)md;
BLO_write_struct(writer, ClothSimSettings, clmd->sim_parms);
BLO_write_struct(writer, ClothCollSettings, clmd->coll_parms);
BLO_write_struct(writer, EffectorWeights, clmd->sim_parms->effector_weights);
BKE_ptcache_blend_write(writer, &clmd->ptcaches);
}
else if (md->type == eModifierType_Fluid) {
FluidModifierData *fmd = (FluidModifierData *)md;
if (fmd->type & MOD_FLUID_TYPE_DOMAIN) {
BLO_write_struct(writer, FluidDomainSettings, fmd->domain);
if (fmd->domain) {
BKE_ptcache_blend_write(writer, &(fmd->domain->ptcaches[0]));
/* create fake pointcache so that old blender versions can read it */
fmd->domain->point_cache[1] = BKE_ptcache_add(&fmd->domain->ptcaches[1]);
fmd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE | PTCACHE_FAKE_SMOKE;
fmd->domain->point_cache[1]->step = 1;
BKE_ptcache_blend_write(writer, &(fmd->domain->ptcaches[1]));
if (fmd->domain->coba) {
BLO_write_struct(writer, ColorBand, fmd->domain->coba);
}
/* cleanup the fake pointcache */
BKE_ptcache_free_list(&fmd->domain->ptcaches[1]);
2022-09-29 16:43:09 -05:00
fmd->domain->point_cache[1] = nullptr;
BLO_write_struct(writer, EffectorWeights, fmd->domain->effector_weights);
}
}
else if (fmd->type & MOD_FLUID_TYPE_FLOW) {
BLO_write_struct(writer, FluidFlowSettings, fmd->flow);
}
else if (fmd->type & MOD_FLUID_TYPE_EFFEC) {
BLO_write_struct(writer, FluidEffectorSettings, fmd->effector);
}
}
else if (md->type == eModifierType_Fluidsim) {
FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
BLO_write_struct(writer, FluidsimSettings, fluidmd->fss);
}
else if (md->type == eModifierType_DynamicPaint) {
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
if (pmd->canvas) {
BLO_write_struct(writer, DynamicPaintCanvasSettings, pmd->canvas);
/* write surfaces */
LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) {
BLO_write_struct(writer, DynamicPaintSurface, surface);
}
/* write caches and effector weights */
LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) {
BKE_ptcache_blend_write(writer, &(surface->ptcaches));
BLO_write_struct(writer, EffectorWeights, surface->effector_weights);
}
}
if (pmd->brush) {
BLO_write_struct(writer, DynamicPaintBrushSettings, pmd->brush);
BLO_write_struct(writer, ColorBand, pmd->brush->paint_ramp);
BLO_write_struct(writer, ColorBand, pmd->brush->vel_ramp);
}
}
else if (md->type == eModifierType_Collision) {
#if 0
CollisionModifierData *collmd = (CollisionModifierData *)md;
2022-02-02 13:15:43 +11:00
/* TODO: CollisionModifier should use pointcache
* + have proper reset events before enabling this. */
Mesh: Move positions to a generic attribute **Changes** As described in T93602, this patch removes all use of the `MVert` struct, replacing it with a generic named attribute with the name `"position"`, consistent with other geometry types. Variable names have been changed from `verts` to `positions`, to align with the attribute name and the more generic design (positions are not vertices, they are just an attribute stored on the point domain). This change is made possible by previous commits that moved all other data out of `MVert` to runtime data or other generic attributes. What remains is mostly a simple type change. Though, the type still shows up 859 times, so the patch is quite large. One compromise is that now `CD_MASK_BAREMESH` now contains `CD_PROP_FLOAT3`. With the general move towards generic attributes over custom data types, we are removing use of these type masks anyway. **Benefits** The most obvious benefit is reduced memory usage and the benefits that brings in memory-bound situations. `float3` is only 3 bytes, in comparison to `MVert` which was 4. When there are millions of vertices this starts to matter more. The other benefits come from using a more generic type. Instead of writing algorithms specifically for `MVert`, code can just use arrays of vectors. This will allow eliminating many temporary arrays or wrappers used to extract positions. Many possible improvements aren't implemented in this patch, though I did switch simplify or remove the process of creating temporary position arrays in a few places. The design clarity that "positions are just another attribute" brings allows removing explicit copying of vertices in some procedural operations-- they are just processed like most other attributes. **Performance** This touches so many areas that it's hard to benchmark exhaustively, but I observed some areas as examples. * The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster. * The Spring splash screen went from ~4.3 to ~4.5 fps. * The subdivision surface modifier/node was slightly faster RNA access through Python may be slightly slower, since now we need a name lookup instead of just a custom data type lookup for each index. **Future Improvements** * Remove uses of "vert_coords" functions: * `BKE_mesh_vert_coords_alloc` * `BKE_mesh_vert_coords_get` * `BKE_mesh_vert_coords_apply{_with_mat4}` * Remove more hidden copying of positions * General simplification now possible in many areas * Convert more code to C++ to use `float3` instead of `float[3]` * Currently `reinterpret_cast` is used for those C-API functions Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
writestruct(wd, DATA, float[3], collmd->numverts, collmd->x);
writestruct(wd, DATA, float[3], collmd->numverts, collmd->xnew);
writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces);
#endif
}
}
}
/* TODO(sergey): Find a better place for this.
*
* Unfortunately, this can not be done as a regular do_versions() since the modifier type is
* set to NONE, so the do_versions code wouldn't know where the modifier came from.
*
* The best approach seems to have the functionality in `versioning_280.cc` but still call the
* function from #BKE_modifier_blend_read_data().
*/
/* Domain, inflow, ... */
static void modifier_ensure_type(FluidModifierData *fluid_modifier_data, int type)
{
fluid_modifier_data->type = type;
BKE_fluid_modifier_free(fluid_modifier_data);
BKE_fluid_modifier_create_type_data(fluid_modifier_data);
}
/**
* \note The old_modifier_data is NOT linked.
* This means that in order to access sub-data pointers #BLO_read_get_new_data_address is to be
* used.
*/
static ModifierData *modifier_replace_with_fluid(BlendDataReader *reader,
Object *object,
ListBase *modifiers,
ModifierData *old_modifier_data)
{
ModifierData *new_modifier_data = BKE_modifier_new(eModifierType_Fluid);
FluidModifierData *fluid_modifier_data = (FluidModifierData *)new_modifier_data;
if (old_modifier_data->type == eModifierType_Fluidsim) {
FluidsimModifierData *old_fluidsim_modifier_data = (FluidsimModifierData *)old_modifier_data;
2022-09-29 16:43:09 -05:00
FluidsimSettings *old_fluidsim_settings = static_cast<FluidsimSettings *>(
BLO_read_get_new_data_address(reader, old_fluidsim_modifier_data->fss));
switch (old_fluidsim_settings->type) {
case OB_FLUIDSIM_ENABLE:
modifier_ensure_type(fluid_modifier_data, 0);
break;
case OB_FLUIDSIM_DOMAIN:
modifier_ensure_type(fluid_modifier_data, MOD_FLUID_TYPE_DOMAIN);
BKE_fluid_domain_type_set(object, fluid_modifier_data->domain, FLUID_DOMAIN_TYPE_LIQUID);
break;
case OB_FLUIDSIM_FLUID:
modifier_ensure_type(fluid_modifier_data, MOD_FLUID_TYPE_FLOW);
BKE_fluid_flow_type_set(object, fluid_modifier_data->flow, FLUID_FLOW_TYPE_LIQUID);
/* No need to emit liquid far away from surface. */
fluid_modifier_data->flow->surface_distance = 0.0f;
break;
case OB_FLUIDSIM_OBSTACLE:
modifier_ensure_type(fluid_modifier_data, MOD_FLUID_TYPE_EFFEC);
BKE_fluid_effector_type_set(
object, fluid_modifier_data->effector, FLUID_EFFECTOR_TYPE_COLLISION);
break;
case OB_FLUIDSIM_INFLOW:
modifier_ensure_type(fluid_modifier_data, MOD_FLUID_TYPE_FLOW);
BKE_fluid_flow_type_set(object, fluid_modifier_data->flow, FLUID_FLOW_TYPE_LIQUID);
BKE_fluid_flow_behavior_set(object, fluid_modifier_data->flow, FLUID_FLOW_BEHAVIOR_INFLOW);
/* No need to emit liquid far away from surface. */
fluid_modifier_data->flow->surface_distance = 0.0f;
break;
case OB_FLUIDSIM_OUTFLOW:
modifier_ensure_type(fluid_modifier_data, MOD_FLUID_TYPE_FLOW);
BKE_fluid_flow_type_set(object, fluid_modifier_data->flow, FLUID_FLOW_TYPE_LIQUID);
BKE_fluid_flow_behavior_set(
object, fluid_modifier_data->flow, FLUID_FLOW_BEHAVIOR_OUTFLOW);
break;
case OB_FLUIDSIM_PARTICLE:
/* "Particle" type objects not being used by Mantaflow fluid simulations.
* Skip this object, secondary particles can only be enabled through the domain object. */
break;
case OB_FLUIDSIM_CONTROL:
/* "Control" type objects not being used by Mantaflow fluid simulations.
* Use guiding type instead which is similar. */
modifier_ensure_type(fluid_modifier_data, MOD_FLUID_TYPE_EFFEC);
BKE_fluid_effector_type_set(
object, fluid_modifier_data->effector, FLUID_EFFECTOR_TYPE_GUIDE);
break;
}
}
else if (old_modifier_data->type == eModifierType_Smoke) {
SmokeModifierData *old_smoke_modifier_data = (SmokeModifierData *)old_modifier_data;
modifier_ensure_type(fluid_modifier_data, old_smoke_modifier_data->type);
if (fluid_modifier_data->type == MOD_FLUID_TYPE_DOMAIN) {
BKE_fluid_domain_type_set(object, fluid_modifier_data->domain, FLUID_DOMAIN_TYPE_GAS);
}
else if (fluid_modifier_data->type == MOD_FLUID_TYPE_FLOW) {
BKE_fluid_flow_type_set(object, fluid_modifier_data->flow, FLUID_FLOW_TYPE_SMOKE);
}
else if (fluid_modifier_data->type == MOD_FLUID_TYPE_EFFEC) {
BKE_fluid_effector_type_set(
object, fluid_modifier_data->effector, FLUID_EFFECTOR_TYPE_COLLISION);
}
}
/* Replace modifier data in the stack. */
new_modifier_data->next = old_modifier_data->next;
new_modifier_data->prev = old_modifier_data->prev;
2022-09-29 16:43:09 -05:00
if (new_modifier_data->prev != nullptr) {
new_modifier_data->prev->next = new_modifier_data;
}
2022-09-29 16:43:09 -05:00
if (new_modifier_data->next != nullptr) {
new_modifier_data->next->prev = new_modifier_data;
}
if (modifiers->first == old_modifier_data) {
modifiers->first = new_modifier_data;
}
if (modifiers->last == old_modifier_data) {
modifiers->last = new_modifier_data;
}
/* Free old modifier data. */
MEM_freeN(old_modifier_data);
return new_modifier_data;
}
void BKE_modifier_blend_read_data(BlendDataReader *reader, ListBase *lb, Object *ob)
{
BLO_read_list(reader, lb);
LISTBASE_FOREACH (ModifierData *, md, lb) {
BKE_modifier_session_uuid_generate(md);
2022-09-29 16:43:09 -05:00
md->error = nullptr;
md->runtime = nullptr;
/* If linking from a library, clear 'local' library override flag. */
if (ID_IS_LINKED(ob)) {
md->flag &= ~eModifierFlag_OverrideLibrary_Local;
}
/* Modifier data has been allocated as a part of data migration process and
* no reading of nested fields from file is needed. */
bool is_allocated = false;
if (md->type == eModifierType_Fluidsim) {
BLO_reportf_wrap(
BLO_read_data_reports(reader),
RPT_WARNING,
TIP_("Possible data loss when saving this file! %s modifier is deprecated (Object: %s)"),
md->name,
ob->id.name + 2);
md = modifier_replace_with_fluid(reader, ob, lb, md);
is_allocated = true;
}
else if (md->type == eModifierType_Smoke) {
BLO_reportf_wrap(
BLO_read_data_reports(reader),
RPT_WARNING,
TIP_("Possible data loss when saving this file! %s modifier is deprecated (Object: %s)"),
md->name,
ob->id.name + 2);
md = modifier_replace_with_fluid(reader, ob, lb, md);
is_allocated = true;
}
2022-09-29 16:43:09 -05:00
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
/* if modifiers disappear, or for upward compatibility */
2022-09-29 16:43:09 -05:00
if (mti == nullptr) {
md->type = eModifierType_None;
}
if (is_allocated) {
/* All the fields has been properly allocated. */
}
else if (md->type == eModifierType_Cloth) {
ClothModifierData *clmd = (ClothModifierData *)md;
2022-09-29 16:43:09 -05:00
clmd->clothObject = nullptr;
clmd->hairdata = nullptr;
BLO_read_data_address(reader, &clmd->sim_parms);
BLO_read_data_address(reader, &clmd->coll_parms);
BKE_ptcache_blend_read_data(reader, &clmd->ptcaches, &clmd->point_cache, 0);
if (clmd->sim_parms) {
if (clmd->sim_parms->presets > 10) {
clmd->sim_parms->presets = 0;
}
clmd->sim_parms->reset = 0;
BLO_read_data_address(reader, &clmd->sim_parms->effector_weights);
if (!clmd->sim_parms->effector_weights) {
2022-09-29 16:43:09 -05:00
clmd->sim_parms->effector_weights = BKE_effector_add_weights(nullptr);
}
}
2022-09-29 16:43:09 -05:00
clmd->solver_result = nullptr;
}
else if (md->type == eModifierType_Fluid) {
FluidModifierData *fmd = (FluidModifierData *)md;
if (fmd->type == MOD_FLUID_TYPE_DOMAIN) {
2022-09-29 16:43:09 -05:00
fmd->flow = nullptr;
fmd->effector = nullptr;
BLO_read_data_address(reader, &fmd->domain);
fmd->domain->fmd = fmd;
2022-09-29 16:43:09 -05:00
fmd->domain->fluid = nullptr;
fmd->domain->fluid_mutex = BLI_rw_mutex_alloc();
2022-09-29 16:43:09 -05:00
fmd->domain->tex_density = nullptr;
fmd->domain->tex_color = nullptr;
fmd->domain->tex_shadow = nullptr;
fmd->domain->tex_flame = nullptr;
fmd->domain->tex_flame_coba = nullptr;
fmd->domain->tex_coba = nullptr;
fmd->domain->tex_field = nullptr;
fmd->domain->tex_velocity_x = nullptr;
fmd->domain->tex_velocity_y = nullptr;
fmd->domain->tex_velocity_z = nullptr;
fmd->domain->tex_wt = nullptr;
BLO_read_data_address(reader, &fmd->domain->coba);
BLO_read_data_address(reader, &fmd->domain->effector_weights);
if (!fmd->domain->effector_weights) {
2022-09-29 16:43:09 -05:00
fmd->domain->effector_weights = BKE_effector_add_weights(nullptr);
}
BKE_ptcache_blend_read_data(
reader, &(fmd->domain->ptcaches[0]), &(fmd->domain->point_cache[0]), 1);
/* Manta sim uses only one cache from now on, so store pointer convert */
if (fmd->domain->ptcaches[1].first || fmd->domain->point_cache[1]) {
if (fmd->domain->point_cache[1]) {
2022-09-29 16:43:09 -05:00
PointCache *cache = static_cast<PointCache *>(
BLO_read_get_new_data_address(reader, fmd->domain->point_cache[1]));
if (cache->flag & PTCACHE_FAKE_SMOKE) {
/* Manta-sim/smoke was already saved in "new format" and this cache is a fake one. */
}
else {
printf(
"High resolution manta cache not available due to pointcache update. Please "
"reset the simulation.\n");
}
BKE_ptcache_free(cache);
}
BLI_listbase_clear(&fmd->domain->ptcaches[1]);
2022-09-29 16:43:09 -05:00
fmd->domain->point_cache[1] = nullptr;
}
/* Flag for refreshing the simulation after loading */
fmd->domain->flags |= FLUID_DOMAIN_FILE_LOAD;
}
else if (fmd->type == MOD_FLUID_TYPE_FLOW) {
2022-09-29 16:43:09 -05:00
fmd->domain = nullptr;
fmd->effector = nullptr;
BLO_read_data_address(reader, &fmd->flow);
fmd->flow->fmd = fmd;
2022-09-29 16:43:09 -05:00
fmd->flow->mesh = nullptr;
fmd->flow->verts_old = nullptr;
fmd->flow->numverts = 0;
BLO_read_data_address(reader, &fmd->flow->psys);
fmd->flow->flags &= ~FLUID_FLOW_NEEDS_UPDATE;
}
else if (fmd->type == MOD_FLUID_TYPE_EFFEC) {
2022-09-29 16:43:09 -05:00
fmd->flow = nullptr;
fmd->domain = nullptr;
BLO_read_data_address(reader, &fmd->effector);
if (fmd->effector) {
fmd->effector->fmd = fmd;
2022-09-29 16:43:09 -05:00
fmd->effector->verts_old = nullptr;
fmd->effector->numverts = 0;
2022-09-29 16:43:09 -05:00
fmd->effector->mesh = nullptr;
fmd->effector->flags &= ~FLUID_EFFECTOR_NEEDS_UPDATE;
}
else {
fmd->type = 0;
2022-09-29 16:43:09 -05:00
fmd->flow = nullptr;
fmd->domain = nullptr;
fmd->effector = nullptr;
}
}
}
else if (md->type == eModifierType_DynamicPaint) {
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
if (pmd->canvas) {
BLO_read_data_address(reader, &pmd->canvas);
pmd->canvas->pmd = pmd;
pmd->canvas->flags &= ~MOD_DPAINT_BAKING; /* just in case */
if (pmd->canvas->surfaces.first) {
BLO_read_list(reader, &pmd->canvas->surfaces);
LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) {
surface->canvas = pmd->canvas;
2022-09-29 16:43:09 -05:00
surface->data = nullptr;
BKE_ptcache_blend_read_data(reader, &(surface->ptcaches), &(surface->pointcache), 1);
BLO_read_data_address(reader, &surface->effector_weights);
2022-09-29 16:43:09 -05:00
if (surface->effector_weights == nullptr) {
surface->effector_weights = BKE_effector_add_weights(nullptr);
}
}
}
}
if (pmd->brush) {
BLO_read_data_address(reader, &pmd->brush);
pmd->brush->pmd = pmd;
BLO_read_data_address(reader, &pmd->brush->psys);
BLO_read_data_address(reader, &pmd->brush->paint_ramp);
BLO_read_data_address(reader, &pmd->brush->vel_ramp);
}
}
if ((mti != nullptr) && (mti->blend_read != nullptr)) {
mti->blend_read(reader, md);
}
}
}
Modifiers: measure execution time and provide Python access The goal is to give technical artists the ability to optimize modifier usage and/or geometry node groups for performance. In the long term, it would be useful if Blender could provide its own UI to display profiling information to users. However, right now, there are too many open design questions making it infeasible to tackle this in the short term. This commit uses a simpler approach: Instead of adding new ui for profiling data, it exposes the execution-time of modifiers in the Python API. This allows technical artists to access the information and to build their own UI to display the relevant information. In the long term this will hopefully also help us to integrate a native ui for this in Blender by observing how users use this information. Note: The execution time of a modifier highly depends on what other things the CPU is doing at the same time. For example, in many more complex files, many objects and therefore modifiers are evaluated at the same time by multiple threads which makes the measurement much less reliable. For best results, make sure that only one object is evaluated at a time (e.g. by changing it in isolation) and that no other process on the system keeps the CPU busy. As shown below, the execution time has to be accessed on the evaluated object, not the original object. ```lang=python import bpy depsgraph = bpy.context.view_layer.depsgraph ob = bpy.context.active_object ob_eval = ob.evaluated_get(depsgraph) modifier_eval = ob_eval.modifiers[0] print(modifier_eval.execution_time, "s") ``` Differential Revision: https://developer.blender.org/D17185
2023-02-06 15:39:59 +01:00
namespace blender::bke {
using Clock = std::chrono::high_resolution_clock;
static double get_current_time_in_seconds()
{
return std::chrono::duration<double, std::chrono::seconds::period>(
Clock::now().time_since_epoch())
.count();
}
ScopedModifierTimer::ScopedModifierTimer(ModifierData &md) : md_(md)
{
start_time_ = get_current_time_in_seconds();
}
ScopedModifierTimer::~ScopedModifierTimer()
{
const double end_time = get_current_time_in_seconds();
const double duration = end_time - start_time_;
md_.execution_time = duration;
}
} // namespace blender::bke