16#include <pxr/base/vt/array.h>
17#include <pxr/usd/usdGeom/points.h>
18#include <pxr/usd/usdGeom/primvarsAPI.h>
28 const PointCloud *points = id_cast<const PointCloud *>(context.object->data);
32 const pxr::UsdGeomPoints usd_points = pxr::UsdGeomPoints::Define(stage,
usd_path);
34 pxr::VtArray<pxr::GfVec3f> usd_positions;
35 usd_positions.assign(positions.
begin(), positions.
end());
37 pxr::UsdAttribute attr_positions = usd_points.CreatePointsAttr(pxr::VtValue(),
true);
38 if (!attr_positions.HasValue()) {
39 attr_positions.Set(usd_positions, pxr::UsdTimeCode::Default());
43 if (!radii.is_empty()) {
44 pxr::VtArray<float> usd_widths;
45 usd_widths.resize(radii.size());
46 for (
const int i : radii.index_range()) {
47 usd_widths[i] = radii[i] * 2.0f;
50 pxr::UsdAttribute attr_widths = usd_points.CreateWidthsAttr(pxr::VtValue(),
true);
51 if (!attr_widths.HasValue()) {
52 attr_widths.Set(usd_widths, pxr::UsdTimeCode::Default());
57 this->write_ids(points, usd_points, time);
58 this->write_velocities(points, usd_points, time);
59 this->write_custom_data(points, usd_points, time);
61 this->
author_extent(usd_points, points->bounds_min_max(), time);
67 switch (blender_domain) {
69 return pxr::UsdGeomTokens->varying;
77 const pxr::UsdGeomPoints &usd_points,
78 const pxr::UsdTimeCode time)
83 if (!pv_interp || !pv_type) {
86 "Attribute '%s' (Blender domain %d, type %d) cannot be converted to USD",
98 const pxr::TfToken pv_name(
100 const pxr::UsdGeomPrimvarsAPI pv_api = pxr::UsdGeomPrimvarsAPI(usd_points);
102 pxr::UsdGeomPrimvar pv_attr = pv_api.CreatePrimvar(pv_name, *pv_type, *pv_interp);
107void USDPointsWriter::write_custom_data(
const PointCloud *points,
108 const pxr::UsdGeomPoints &usd_points,
109 const pxr::UsdTimeCode time)
111 const bke::AttributeAccessor attributes = points->
attributes();
113 attributes.foreach_attribute([&](
const bke::AttributeIter &iter) {
116 ELEM(iter.name,
"position",
"radius",
"id",
"velocity"))
121 this->write_generic_data(iter, usd_points, time);
125void USDPointsWriter::write_ids(
const PointCloud *points,
126 const pxr::UsdGeomPoints &usd_points,
127 const pxr::UsdTimeCode time)
130 if (ids.is_empty()) {
134 pxr::VtInt64Array usd_ids(ids.begin(), ids.end());
135 pxr::UsdAttribute attr_ids = usd_points.CreateIdsAttr(pxr::VtValue(),
true);
139void USDPointsWriter::write_velocities(
const PointCloud *points,
140 const pxr::UsdGeomPoints &usd_points,
141 const pxr::UsdTimeCode time)
149 Span<pxr::GfVec3f>
data =
velocity.cast<pxr::GfVec3f>();
150 pxr::VtArray<pxr::GfVec3f> usd_velocities;
151 usd_velocities.assign(
data.begin(),
data.end());
153 pxr::UsdAttribute attr_vel = usd_points.CreateVelocitiesAttr(pxr::VtValue(),
true);
154 if (!attr_vel.HasValue()) {
155 attr_vel.Set(usd_velocities, pxr::UsdTimeCode::Default());
Object is a sort of wrapper for general info.
constexpr const T * end() const
constexpr const T * begin() const
constexpr const char * c_str() const
GAttributeReader get() const
constexpr bool is_empty() const
void author_extent(const pxr::UsdGeomBoundable &boundable, const pxr::UsdTimeCode time)
const pxr::SdfPath & usd_path() const
ReportList * reports() const
pxr::UsdTimeCode get_export_time_code() const
pxr::UsdUtilsSparseValueWriter usd_value_writer_
const USDExporterContext usd_export_context_
void do_write(HierarchyContext &context) override
bool attribute_name_is_anonymous(const StringRef name)
void copy_blender_attribute_to_primvar(const GVArray &attribute, const bke::AttrType data_type, const pxr::UsdTimeCode time, const pxr::UsdGeomPrimvar &primvar, pxr::UsdUtilsSparseValueWriter &value_writer)
std::optional< pxr::SdfValueTypeName > convert_blender_type_to_usd(const bke::AttrType blender_type, bool use_color3f_type)
static std::optional< pxr::TfToken > convert_blender_domain_to_usd(const bke::AttrDomain blender_domain, bool is_bezier)
void set_attribute(const pxr::UsdAttribute &attr, const USDT value, pxr::UsdTimeCode time, pxr::UsdUtilsSparseValueWriter &value_writer)
std::string make_safe_primvar_name(const StringRef name, bool allow_unicode)
constexpr StringRefNull velocity
BMesh const char void * data
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
VecBase< float, 3 > float3
const USDExportParams & export_params
const pxr::SdfPath usd_path
const pxr::UsdStageRefPtr stage