Blender V5.0
usd_writer_abstract.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
8
9#include <pxr/usd/sdf/path.h>
10#include <pxr/usd/usd/prim.h>
11#include <pxr/usd/usdGeom/boundable.h>
12#include <pxr/usd/usdShade/material.h>
13#include <pxr/usd/usdUtils/sparseValueWriter.h>
14
15#include "WM_types.hh"
16
17#include <string>
18
19struct ID;
20struct IDProperty;
21struct Material;
22struct ReportList;
23
24namespace blender {
25template<typename T> struct Bounds;
26}
27
28namespace blender::io::usd {
29
30using blender::io::AbstractHierarchyWriter;
31using blender::io::HierarchyContext;
32
34 protected:
36 pxr::UsdUtilsSparseValueWriter usd_value_writer_;
37
40
41 public:
42 USDAbstractWriter(const USDExporterContext &usd_export_context);
43
44 void write(HierarchyContext &context) override;
45
55 virtual bool is_supported(const HierarchyContext *context) const;
56
57 const pxr::SdfPath &usd_path() const;
58
61 {
62 return usd_export_context_.export_params.worker_status->reports;
63 }
64
65 protected:
66 virtual void do_write(HierarchyContext &context) = 0;
67 std::string get_export_file_path() const;
68 pxr::UsdTimeCode get_export_time_code() const;
69
70 /* Returns the parent path of exported materials. */
71 pxr::SdfPath get_material_library_path() const;
72 /* Returns the parent path of exported materials for instance prototypes. */
73 pxr::SdfPath get_proto_material_root_path(const HierarchyContext &context) const;
74 /* Ensure the USD material is created in the default material library folder. */
75 pxr::UsdShadeMaterial ensure_usd_material_created(const HierarchyContext &context,
76 Material *material) const;
77 /* Calls ensure_usd_material_created(). Additionally, if the context is an
78 * instancing prototype, creates a reference to the library material under the
79 * prototype root. */
80 pxr::UsdShadeMaterial ensure_usd_material(const HierarchyContext &context,
81 Material *material) const;
82
83 void write_id_properties(const pxr::UsdPrim &prim,
84 const ID &id,
85 pxr::UsdTimeCode = pxr::UsdTimeCode::Default()) const;
86 void write_user_properties(const pxr::UsdPrim &prim,
87 IDProperty *properties,
88 pxr::UsdTimeCode = pxr::UsdTimeCode::Default()) const;
89
90 void write_visibility(const HierarchyContext &context,
91 const pxr::UsdTimeCode time,
92 const pxr::UsdGeomImageable &usd_geometry);
93
100 virtual bool mark_as_instance(const HierarchyContext &context, const pxr::UsdPrim &prim);
101
118 void author_extent(const pxr::UsdGeomBoundable &boundable, const pxr::UsdTimeCode time);
119
123 void author_extent(const pxr::UsdGeomBoundable &boundable,
124 const std::optional<Bounds<float3>> &bounds,
125 const pxr::UsdTimeCode time);
126};
127
128} // namespace blender::io::usd
pxr::UsdShadeMaterial ensure_usd_material(const HierarchyContext &context, Material *material) const
virtual void do_write(HierarchyContext &context)=0
pxr::SdfPath get_proto_material_root_path(const HierarchyContext &context) const
void author_extent(const pxr::UsdGeomBoundable &boundable, const pxr::UsdTimeCode time)
const pxr::SdfPath & usd_path() const
void write_user_properties(const pxr::UsdPrim &prim, IDProperty *properties, pxr::UsdTimeCode=pxr::UsdTimeCode::Default()) const
pxr::UsdShadeMaterial ensure_usd_material_created(const HierarchyContext &context, Material *material) const
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)
void write_id_properties(const pxr::UsdPrim &prim, const ID &id, pxr::UsdTimeCode=pxr::UsdTimeCode::Default()) const
void write(HierarchyContext &context) override
void write_visibility(const HierarchyContext &context, const pxr::UsdTimeCode time, const pxr::UsdGeomImageable &usd_geometry)
virtual bool is_supported(const HierarchyContext *context) const
const USDExporterContext usd_export_context_
Definition DNA_ID.h:414