Blender  V3.3
usd_writer_metaball.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 #include "usd_writer_metaball.h"
5 
6 #include <pxr/usd/usdGeom/mesh.h>
7 #include <pxr/usd/usdShade/material.h>
8 #include <pxr/usd/usdShade/materialBindingAPI.h>
9 
10 #include "BLI_assert.h"
11 
12 #include "BKE_displist.h"
13 #include "BKE_lib_id.h"
14 #include "BKE_mball.h"
15 #include "BKE_mesh.h"
16 #include "BKE_object.h"
17 
18 #include "DNA_mesh_types.h"
19 #include "DNA_meta_types.h"
20 
21 namespace blender::io::usd {
22 
24 {
25 }
26 
28 {
30  return is_basis_ball(scene, context->object) && USDGenericMeshWriter::is_supported(context);
31 }
32 
34 {
35  /* We assume that metaballs are always animated, as the current object may
36  * not be animated but another ball in the same group may be. */
37  return true;
38 }
39 
40 Mesh *USDMetaballWriter::get_export_mesh(Object *object_eval, bool &r_needsfree)
41 {
42  Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object_eval);
43  if (mesh_eval != nullptr) {
44  /* Mesh_eval only exists when generative modifiers are in use. */
45  r_needsfree = false;
46  return mesh_eval;
47  }
48  r_needsfree = true;
49  return BKE_mesh_new_from_object(usd_export_context_.depsgraph, object_eval, false, false);
50 }
51 
53 {
54  BKE_id_free(nullptr, mesh);
55 }
56 
57 bool USDMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const
58 {
59  Object *basis_ob = BKE_mball_basis_find(scene, ob);
60  return ob == basis_ob;
61 }
62 
63 } // 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)
Definition: mball.c:508
struct Mesh * BKE_mesh_new_from_object(struct Depsgraph *depsgraph, struct Object *object, bool preserve_all_data_layers, bool preserve_origindex)
General operations, lookup, etc. for blender objects.
struct Mesh * BKE_object_get_evaluated_mesh(const struct Object *object)
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