Blender  V2.93
abc_writer_mball.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 
21 #include "abc_writer_mball.h"
22 #include "abc_hierarchy_iterator.h"
23 
24 #include "BLI_assert.h"
25 
26 #include "BKE_displist.h"
27 #include "BKE_lib_id.h"
28 #include "BKE_mball.h"
29 #include "BKE_mesh.h"
30 #include "BKE_object.h"
31 
32 #include "DNA_mesh_types.h"
33 #include "DNA_meta_types.h"
34 
35 namespace blender::io::alembic {
36 
38  : ABCGenericMeshWriter(args)
39 {
40 }
41 
43 {
45  bool supported = is_basis_ball(scene, context->object) &&
47  return supported;
48 }
49 
51 {
52  /* We assume that metaballs are always animated, as the current object may
53  * not be animated but another ball in the same group may be. */
54  return true;
55 }
56 
58 {
59  /* Metaballs should be exported to subdivision surfaces, if the export options allow. */
60  return true;
61 }
62 
63 Mesh *ABCMetaballWriter::get_export_mesh(Object *object_eval, bool &r_needsfree)
64 {
65  Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object_eval);
66  if (mesh_eval != nullptr) {
67  /* Mesh_eval only exists when generative modifiers are in use. */
68  r_needsfree = false;
69  return mesh_eval;
70  }
71  r_needsfree = true;
72  return BKE_mesh_new_from_object(args_.depsgraph, object_eval, false, false);
73 }
74 
76 {
77  BKE_id_free(nullptr, mesh);
78 }
79 
80 bool ABCMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const
81 {
82  Object *basis_ob = BKE_mball_basis_find(scene, ob);
83  return ob == basis_ob;
84 }
85 
86 } // namespace blender::io::alembic
display list (or rather multi purpose list) stuff.
void BKE_id_free(struct Main *bmain, void *idv)
struct Object * BKE_mball_basis_find(struct Scene *scene, struct Object *ob)
This function finds the basis MetaBall.
Definition: mball.c:511
struct Mesh * BKE_mesh_new_from_object(struct Depsgraph *depsgraph, struct Object *object, const bool preserve_all_data_layers, const bool preserve_origindex)
General operations, lookup, etc. for blender objects.
struct Mesh * BKE_object_get_evaluated_mesh(struct Object *object)
Definition: object.c:4459
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
const ABCWriterConstructorArgs args_
virtual bool is_supported(const HierarchyContext *context) const override
virtual bool export_as_subdivision_surface(Object *ob_eval) const override
virtual Mesh * get_export_mesh(Object *object_eval, bool &r_needsfree) override
virtual void free_export_mesh(Mesh *mesh) override
ABCMetaballWriter(const ABCWriterConstructorArgs &args)
virtual bool is_supported(const HierarchyContext *context) const override
virtual bool check_is_animated(const HierarchyContext &context) const override
Scene scene
struct SELECTID_Context context
Definition: select_engine.c:47