Blender  V2.93
usd_writer_metaball.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 "usd_writer_metaball.h"
20 #include "usd_hierarchy_iterator.h"
21 
22 #include <pxr/usd/usdGeom/mesh.h>
23 #include <pxr/usd/usdShade/material.h>
24 #include <pxr/usd/usdShade/materialBindingAPI.h>
25 
26 #include "BLI_assert.h"
27 
28 #include "BKE_displist.h"
29 #include "BKE_lib_id.h"
30 #include "BKE_mball.h"
31 #include "BKE_mesh.h"
32 #include "BKE_object.h"
33 
34 #include "DNA_mesh_types.h"
35 #include "DNA_meta_types.h"
36 
37 namespace blender::io::usd {
38 
40 {
41 }
42 
44 {
46  return is_basis_ball(scene, context->object) && USDGenericMeshWriter::is_supported(context);
47 }
48 
50 {
51  /* We assume that metaballs are always animated, as the current object may
52  * not be animated but another ball in the same group may be. */
53  return true;
54 }
55 
56 Mesh *USDMetaballWriter::get_export_mesh(Object *object_eval, bool &r_needsfree)
57 {
58  Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object_eval);
59  if (mesh_eval != nullptr) {
60  /* Mesh_eval only exists when generative modifiers are in use. */
61  r_needsfree = false;
62  return mesh_eval;
63  }
64  r_needsfree = true;
65  return BKE_mesh_new_from_object(usd_export_context_.depsgraph, object_eval, false, false);
66 }
67 
69 {
70  BKE_id_free(nullptr, mesh);
71 }
72 
73 bool USDMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const
74 {
75  Object *basis_ob = BKE_mball_basis_find(scene, ob);
76  return ob == basis_ob;
77 }
78 
79 } // namespace blender::io::usd
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 USDExporterContext usd_export_context_
virtual bool is_supported(const HierarchyContext *context) const override
USDMetaballWriter(const USDExporterContext &ctx)
virtual bool check_is_animated(const HierarchyContext &context) const override
virtual Mesh * get_export_mesh(Object *object_eval, bool &r_needsfree) override
virtual bool is_supported(const HierarchyContext *context) const override
virtual void free_export_mesh(Mesh *mesh) override
Scene scene
struct SELECTID_Context context
Definition: select_engine.c:47