Blender  V2.93
usd_writer_abstract.h
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) 2019 Blender Foundation.
17  * All rights reserved.
18  */
19 #pragma once
20 
22 #include "usd_exporter_context.h"
23 
24 #include <pxr/usd/sdf/path.h>
25 #include <pxr/usd/usd/stage.h>
26 #include <pxr/usd/usdShade/material.h>
27 #include <pxr/usd/usdUtils/sparseValueWriter.h>
28 
29 #include <vector>
30 
31 #include "DEG_depsgraph_query.h"
32 
33 #include "DNA_material_types.h"
34 
35 struct Material;
36 
37 namespace blender::io::usd {
38 
41 
43  protected:
45  pxr::UsdUtilsSparseValueWriter usd_value_writer_;
46 
49 
50  public:
51  USDAbstractWriter(const USDExporterContext &usd_export_context);
52 
53  virtual void write(HierarchyContext &context) override;
54 
55  /* Returns true if the data to be written is actually supported. This would, for example, allow a
56  * hypothetical camera writer accept a perspective camera but reject an orthogonal one.
57  *
58  * Returning false from a transform writer will prevent the object and all its descendants from
59  * being exported. Returning false from a data writer (object data, hair, or particles) will
60  * only prevent that data from being written (and thus cause the object to be exported as an
61  * Empty). */
62  virtual bool is_supported(const HierarchyContext *context) const;
63 
64  const pxr::SdfPath &usd_path() const;
65 
66  protected:
67  virtual void do_write(HierarchyContext &context) = 0;
68  pxr::UsdTimeCode get_export_time_code() const;
69 
70  pxr::UsdShadeMaterial ensure_usd_material(Material *material);
71 
73  const pxr::UsdTimeCode timecode,
74  pxr::UsdGeomImageable &usd_geometry);
75 
76  /* Turn `prim` into an instance referencing `context.original_export_path`.
77  * Return true when the instancing was successful, false otherwise. */
78  virtual bool mark_as_instance(const HierarchyContext &context, const pxr::UsdPrim &prim);
79 };
80 
81 } // namespace blender::io::usd
virtual void do_write(HierarchyContext &context)=0
const pxr::SdfPath & usd_path() const
void write_visibility(const HierarchyContext &context, const pxr::UsdTimeCode timecode, pxr::UsdGeomImageable &usd_geometry)
pxr::UsdShadeMaterial ensure_usd_material(Material *material)
virtual bool mark_as_instance(const HierarchyContext &context, const pxr::UsdPrim &prim)
pxr::UsdTimeCode get_export_time_code() const
pxr::UsdUtilsSparseValueWriter usd_value_writer_
USDAbstractWriter(const USDExporterContext &usd_export_context)
virtual void write(HierarchyContext &context) override
virtual bool is_supported(const HierarchyContext *context) const
const USDExporterContext usd_export_context_
Material material
struct SELECTID_Context context
Definition: select_engine.c:47