Blender  V2.93
abc_subdiv_disabler.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 #include "abc_subdiv_disabler.h"
20 
21 #include <cstdio>
22 
23 #include "BLI_listbase.h"
24 
25 #include "DEG_depsgraph.h"
26 #include "DEG_depsgraph_query.h"
27 
28 #include "DNA_layer_types.h"
29 #include "DNA_mesh_types.h"
30 #include "DNA_modifier_types.h"
31 #include "DNA_object_types.h"
32 
33 #include "BKE_modifier.h"
34 
35 namespace blender::io::alembic {
36 
38 {
39 }
40 
42 {
43  for (ModifierData *modifier : disabled_modifiers_) {
44  modifier->mode &= ~eModifierMode_DisableTemporary;
45  }
46 }
47 
49 {
50  Scene *scene = DEG_get_input_scene(depsgraph_);
51  ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph_);
52 
53  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
54  Object *object = base->object;
55 
56  if (object->type != OB_MESH) {
57  continue;
58  }
59 
60  ModifierData *subdiv = get_subdiv_modifier(scene, object);
61  if (subdiv == nullptr) {
62  continue;
63  }
64 
65  /* This disables more modifiers than necessary, as it doesn't take restrictions like
66  * "export selected objects only" into account. However, with the subsurfs disabled,
67  * moving to a different frame is also going to be faster, so in the end this is probably
68  * a good thing to do. */
70  disabled_modifiers_.insert(subdiv);
72  }
73 }
74 
75 /* Check if the mesh is a subsurf, ignoring disabled modifiers and
76  * displace if it's after subsurf. */
78 {
79  ModifierData *md = static_cast<ModifierData *>(ob->modifiers.last);
80 
81  for (; md; md = md->prev) {
83  continue;
84  }
85 
86  if (md->type == eModifierType_Subsurf) {
87  SubsurfModifierData *smd = reinterpret_cast<SubsurfModifierData *>(md);
88 
89  if (smd->subdivType == ME_CC_SUBSURF) {
90  return md;
91  }
92  }
93 
94  /* mesh is not a subsurf. break */
96  return nullptr;
97  }
98  }
99 
100  return nullptr;
101 }
102 
103 } // namespace blender::io::alembic
bool BKE_modifier_is_enabled(const struct Scene *scene, struct ModifierData *md, int required_mode)
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
struct ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ ME_CC_SUBSURF
@ eModifierMode_Render
@ eModifierMode_DisableTemporary
@ eModifierType_ParticleSystem
@ eModifierType_Subsurf
@ eModifierType_Displace
Object is a sort of wrapper for general info.
@ OB_MESH
static ModifierData * get_subdiv_modifier(Scene *scene, Object *ob)
Scene scene
const Depsgraph * depsgraph
void * last
Definition: DNA_listBase.h:47
struct ModifierData * prev
ListBase modifiers
ListBase object_bases