Blender V4.3
subdiv_disabler.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
5
6#include <cstdio>
7
8#include "BLI_listbase.h"
9
10#include "DEG_depsgraph.hh"
12
13#include "DNA_layer_types.h"
14#include "DNA_mesh_types.h"
15#include "DNA_modifier_types.h"
16#include "DNA_object_types.h"
17
18#include "BKE_layer.hh"
19#include "BKE_modifier.hh"
20
21namespace blender::io {
22
24 const Object *ob,
25 ModifierMode mode)
26{
27 /* Returns the last subdiv modifier associated with an object,
28 * if that modifier should be disabled.
29 * We do not disable the subdiv modifier if other modifiers are
30 * applied after it, with the sole exception of particle modifiers,
31 * which are allowed.
32 * Returns nullptr if there is not any subdiv modifier to disable.
33 */
34
35 ModifierData *md = static_cast<ModifierData *>(ob->modifiers.last);
36
37 for (; md; md = md->prev) {
38 /* Ignore disabled modifiers. */
39 if (!BKE_modifier_is_enabled(scene, md, mode)) {
40 continue;
41 }
42
43 if (md->type == eModifierType_Subsurf) {
44 SubsurfModifierData *smd = reinterpret_cast<SubsurfModifierData *>(md);
45
46 if (smd->subdivType == ME_CC_SUBSURF) {
47 /* This is a Catmull-Clark modifier. */
48 return md;
49 }
50
51 /* Not Catmull-Clark, so ignore it. */
52 return nullptr;
53 }
54
55 /* If any modifier other than a particle system exists after the
56 * subdiv modifier, then abort. */
58 return nullptr;
59 }
60 }
61
62 return nullptr;
63}
64
66
68{
69 /* Enable previously disabled modifiers. */
70 for (ModifierData *modifier : disabled_modifiers_) {
71 modifier->mode &= ~eModifierMode_DisableTemporary;
72 }
73
74 /* Update object to render with restored modifiers in the viewport. */
75 for (Object *object : modified_objects_) {
77 }
78}
79
81{
82 eEvaluationMode eval_mode = DEG_get_mode(depsgraph_);
83 const ModifierMode mode = eval_mode == DAG_EVAL_VIEWPORT ? eModifierMode_Realtime :
85
86 Scene *scene = DEG_get_input_scene(depsgraph_);
87 ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph_);
88
89 BKE_view_layer_synced_ensure(scene, view_layer);
91 Object *object = base->object;
92
93 if (object->type != OB_MESH) {
94 continue;
95 }
96
97 /* Check if a subdiv modifier exists, and should be disabled. */
98 ModifierData *mod = get_subdiv_modifier(scene, object, mode);
99 if (!mod) {
100 continue;
101 }
102
103 /* This might disable more modifiers than necessary, as it doesn't take restrictions like
104 * "export selected objects only" into account. However, with the subdivisions disabled,
105 * moving to a different frame is also going to be faster, so in the end this is probably
106 * a good thing to do. */
107 disable_modifier(mod);
108 modified_objects_.insert(object);
110 }
111}
112
113void SubdivModifierDisabler::disable_modifier(ModifierData *mod)
114{
116 disabled_modifiers_.insert(mod);
117}
118
119} // namespace blender::io
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
ListBase * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
#define LISTBASE_FOREACH(type, var, list)
void DEG_id_tag_update(ID *id, unsigned int flags)
eEvaluationMode
@ DAG_EVAL_VIEWPORT
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
Scene * DEG_get_input_scene(const Depsgraph *graph)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1041
@ ME_CC_SUBSURF
@ eModifierMode_Render
@ eModifierMode_DisableTemporary
@ eModifierMode_Realtime
@ eModifierType_ParticleSystem
@ eModifierType_Subsurf
Object is a sort of wrapper for general info.
@ OB_MESH
SubdivModifierDisabler(Depsgraph *depsgraph)
static ModifierData * get_subdiv_modifier(Scene *scene, const Object *ob, ModifierMode mode)
const Depsgraph * depsgraph
void * last
struct ModifierData * prev
ListBase modifiers
ccl_device_inline int mod(int x, int m)
Definition util/math.h:520