Blender  V3.3
usd_writer_hair.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. All rights reserved. */
3 #include "usd_writer_hair.h"
5 
6 #include <pxr/usd/usdGeom/basisCurves.h>
7 #include <pxr/usd/usdGeom/tokens.h>
8 
9 #include "BKE_particle.h"
10 
11 #include "DNA_particle_types.h"
12 
13 namespace blender::io::usd {
14 
16 {
17 }
18 
20 {
21  ParticleSystem *psys = context.particle_system;
22  ParticleCacheKey **cache = psys->pathcache;
23  if (cache == nullptr) {
24  return;
25  }
26 
27  pxr::UsdTimeCode timecode = get_export_time_code();
28  pxr::UsdGeomBasisCurves curves = pxr::UsdGeomBasisCurves::Define(usd_export_context_.stage,
30 
31  /* TODO(Sybren): deal with (psys->part->flag & PART_HAIR_BSPLINE) */
32  curves.CreateBasisAttr(pxr::VtValue(pxr::UsdGeomTokens->bspline));
33  curves.CreateTypeAttr(pxr::VtValue(pxr::UsdGeomTokens->cubic));
34 
35  pxr::VtArray<pxr::GfVec3f> points;
36  pxr::VtIntArray curve_point_counts;
37  curve_point_counts.reserve(psys->totpart);
38 
39  ParticleCacheKey *strand;
40  for (int strand_index = 0; strand_index < psys->totpart; ++strand_index) {
41  strand = cache[strand_index];
42 
43  int point_count = strand->segments + 1;
44  curve_point_counts.push_back(point_count);
45 
46  for (int point_index = 0; point_index < point_count; ++point_index, ++strand) {
47  points.push_back(pxr::GfVec3f(strand->co));
48  }
49  }
50 
51  pxr::UsdAttribute attr_points = curves.CreatePointsAttr(pxr::VtValue(), true);
52  pxr::UsdAttribute attr_vertex_counts = curves.CreateCurveVertexCountsAttr(pxr::VtValue(), true);
53  if (!attr_points.HasValue()) {
54  attr_points.Set(points, pxr::UsdTimeCode::Default());
55  attr_vertex_counts.Set(curve_point_counts, pxr::UsdTimeCode::Default());
56  }
57  usd_value_writer_.SetAttribute(attr_points, pxr::VtValue(points), timecode);
58  usd_value_writer_.SetAttribute(attr_vertex_counts, pxr::VtValue(curve_point_counts), timecode);
59 
60  if (psys->totpart > 0) {
61  pxr::VtArray<pxr::GfVec3f> colors;
62  colors.push_back(pxr::GfVec3f(cache[0]->col));
63  curves.CreateDisplayColorAttr(pxr::VtValue(colors));
64  }
65 }
66 
68 {
69  return true;
70 }
71 
72 } // namespace blender::io::usd
#define UNUSED(x)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
pxr::UsdTimeCode get_export_time_code() const
pxr::UsdUtilsSparseValueWriter usd_value_writer_
const USDExporterContext usd_export_context_
virtual bool check_is_animated(const HierarchyContext &context) const override
virtual void do_write(HierarchyContext &context) override
USDHairWriter(const USDExporterContext &ctx)
uint col
struct ParticleCacheKey ** pathcache