7#include <pxr/imaging/hd/basisCurvesSchema.h>
8#include <pxr/imaging/hd/basisCurvesTopologySchema.h>
9#include <pxr/imaging/hd/materialBindingSchema.h>
10#include <pxr/imaging/hd/materialBindingsSchema.h>
11#include <pxr/imaging/hd/primvarSchema.h>
12#include <pxr/imaging/hd/primvarsSchema.h>
13#include <pxr/imaging/hd/retainedDataSource.h>
14#include <pxr/imaging/hd/tokens.h>
40static const pxr::TfToken
usd_st_token(
"st", pxr::TfToken::Immortal);
46 pxr::VtVec2fArray
uvs;
52 const Curves *curves_id = id_cast<const Curves *>(
object->data);
64 const float3 &p = positions[i];
65 r.
points[i] = pxr::GfVec3f(p.x, p.y, p.z);
71 for (
const int i :
curves.points_range()) {
72 r.
widths[i] = radii[i] * 2.0f;
75 const std::optional<Span<float2>> surface_uv_coords =
curves.surface_uv_coords();
76 if (surface_uv_coords) {
77 const int total =
curves.curves_num();
78 const int n = std::min<int>(surface_uv_coords->size(), total);
81 const float2 &uv = (*surface_uv_coords)[i];
82 r.
uvs[i] = pxr::GfVec2f(uv.x, uv.y);
85 r.
uvs[i] = pxr::GfVec2f(0.0f, 0.0f);
93 const pxr::SdfPath &material_path)
96 out.schema_token = pxr::HdBasisCurvesSchema::GetSchemaToken();
98 pxr::HdContainerDataSourceHandle topology =
99 pxr::HdBasisCurvesTopologySchema::Builder()
100 .SetCurveVertexCounts(
102 .SetBasis(pxr::HdRetainedTypedSampledDataSource<pxr::TfToken>::New(pxr::TfToken()))
103 .SetType(pxr::HdRetainedTypedSampledDataSource<pxr::TfToken>::New(pxr::HdTokens->linear))
105 pxr::HdRetainedTypedSampledDataSource<pxr::TfToken>::New(pxr::HdTokens->nonperiodic))
107 out.geometry = pxr::HdBasisCurvesSchema::Builder().SetTopology(topology).Build();
114 pxr::HdPrimvarsSchemaTokens->points,
115 pxr::HdPrimvarSchema::Builder()
117 pxr::HdRetainedTypedSampledDataSource<pxr::VtVec3fArray>::New(r.
points))
118 .SetInterpolation(pxr::HdPrimvarSchema::BuildInterpolationDataSource(
119 pxr::HdPrimvarSchemaTokens->vertex))
120 .SetRole(pxr::HdPrimvarSchema::BuildRoleDataSource(pxr::HdPrimvarSchemaTokens->point))
124 primvars.
add(pxr::HdPrimvarsSchemaTokens->widths,
125 pxr::HdPrimvarSchema::Builder()
127 pxr::HdRetainedTypedSampledDataSource<pxr::VtFloatArray>::New(r.
widths))
128 .SetInterpolation(pxr::HdPrimvarSchema::BuildInterpolationDataSource(
129 pxr::HdPrimvarSchemaTokens->vertex))
132 if (!r.
uvs.empty()) {
135 pxr::HdPrimvarSchema::Builder()
136 .SetPrimvarValue(pxr::HdRetainedTypedSampledDataSource<pxr::VtVec2fArray>::New(r.
uvs))
137 .SetInterpolation(pxr::HdPrimvarSchema::BuildInterpolationDataSource(
138 pxr::HdPrimvarSchemaTokens->uniform))
139 .SetRole(pxr::HdPrimvarSchema::BuildRoleDataSource(
140 pxr::HdPrimvarSchemaTokens->textureCoordinate))
143 out.primvars = pxr::HdPrimvarsSchema::BuildRetained(
146 if (!material_path.IsEmpty()) {
147 pxr::HdContainerDataSourceHandle binding =
148 pxr::HdMaterialBindingSchema::Builder()
149 .SetPath(pxr::HdRetainedTypedSampledDataSource<pxr::SdfPath>::New(material_path))
151 out.bindings = pxr::HdRetainedContainerDataSource::New(
152 pxr::HdMaterialBindingsSchemaTokens->allPurpose, binding);
166 object, std::clamp(slot, 1, mat_count)) :
169 return {entry ? entry->
path : pxr::SdfPath(), material};
186 for (
const Material *mat : cached->materials) {
204 pxr::HdPrimTypeTokens->basisCurves);
206 if (cached.
prims.is_empty()) {
211 emitted.
materials.append_non_duplicates(m);
217 ctx.
emit_object_prim(emitted, path, pxr::HdPrimTypeTokens->basisCurves, prim_ds);
223 pxr::HdPrimTypeTokens->basisCurves);
225 if (cached.
prims.is_empty()) {
230 const pxr::SdfPath proto_path = proto_root.AppendElementString(
"Curves");
234 ctx.
emit_prim(proto_path, pxr::HdPrimTypeTokens->basisCurves, prim_ds);
253 const bool has_particles = (psys->
particles !=
nullptr);
256 const bool emit_uvs = psmd && psmd->
mesh_final &&
258 const MFace *mfaces =
nullptr;
259 const MTFace *mtfaces =
nullptr;
261 mfaces =
static_cast<const MFace *
>(
263 mtfaces =
static_cast<const MTFace *
>(
272 for (
int pa_index = 0; pa_index < psys->
totpart; ++pa_index) {
274 const int point_count = strand->
segments + 1;
277 for (
int point_index = 0; point_index < point_count; ++point_index, ++strand) {
280 r.
points.push_back(pxr::GfVec3f(local_co));
281 const float x =
float(point_index) /
float(point_count - 1);
282 const float radius = std::pow(
x, std::pow(10.0f, -shape));
283 r.
widths.push_back(root + (tip - root) * radius);
294 float uv[2] = {0.0f, 0.0f};
298 r.
uvs.push_back(pxr::GfVec2f(uv[0], uv[1]));
325 const pxr::SdfPath path = ctx.
hair_prim_id(
object, &psys);
329 ctx.
emit_object_prim(emitted, path, pxr::HdPrimTypeTokens->basisCurves, prim_ds);
337 const pxr::HdContainerDataSourceHandle instanced_by_ds = ctx.
proto_instanced_by(source);
357 const pxr::SdfPath proto_path = proto_root.AppendElementString(ps_name);
360 gprim, pxr::GfMatrix4d(1.0),
true, instanced_by_ds);
362 ctx.
emit_prim(proto_path, pxr::HdPrimTypeTokens->basisCurves, prim_ds);
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for materials.
#define SNPRINTF(dst, format,...)
Object is a sort of wrapper for general info.
constexpr IndexRange()=default
constexpr int64_t size() const
constexpr IndexRange index_range() const
float3x3 scale(float3x3 mat, float2 scale)
void emit_hair_proto(PopulateContext &ctx, Object *source)
void emit_hair_for_object(PopulateContext &ctx, Object *object, EmittedObject &emitted)
static const EmittedGeometry & get_or_build_emitted_curves(PopulateContext &ctx, const BObjectInfo &info, const EmittedGeometryKey &key)
void emit_curves_proto(PopulateContext &ctx, const BObjectInfo &info)
static EmittedGeometryPrim build_curves_geometry(const CurvesBuilderResult &r, const pxr::SdfPath &material_path)
static CurvesMaterial resolve_curves_material(PopulateContext &ctx, Object *object, const int slot)
pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
static const pxr::TfToken usd_st_token("st", pxr::TfToken::Immortal)
pxr::HdContainerDataSourceHandle compose_gprim_data_source(const EmittedGeometryPrim &gprim, const pxr::GfMatrix4d &transform, const bool visible, const pxr::HdContainerDataSourceHandle &instanced_by_overlay)
static CurvesBuilderResult build_hair_data(Object *object, ParticleSystem *psys)
void emit_curves_object(PopulateContext &ctx, const BObjectInfo &info, EmittedObject &emitted)
static CurvesBuilderResult build_curves_data(const Object *object)
void resize_uninitialized(pxr::VtArray< T > &array, const int new_size)
void copy_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask, MutableSpan< int > sizes)
int BKE_object_material_count_eval(const Object *ob)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
struct ParticleSystemModifierData * psys_get_modifier(struct Object *ob, struct ParticleSystem *psys)
bool psys_in_edit_mode(struct Depsgraph *depsgraph, const struct ParticleSystem *psys)
VecBase< float, 2 > float2
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
ATTR_WARN_UNUSED_RESULT const size_t num
void psys_interpolate_uvs(const struct MTFace *tface, int quad, const float w[4], float r_uv[2])
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
Material * BKE_object_material_get_eval(Object *ob, short act)
VecBase< float, 3 > float3
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< struct ParticleSystem > particlesystem
eParticleShapeFlag shape_flag
struct ParticleCacheKey ** pathcache
bool is_real_object_data() const
pxr::VtIntArray curve_vertex_counts
const Material * material
Vector< EmittedGeometryPrim > prims
Vector< const Material * > materials
Vector< const Material * > materials
Vector< EmittedGeometryKey > geometry_keys
Vector< pxr::HdDataSourceBaseHandle > values
void add(const pxr::TfToken &name, const T &value)
Vector< pxr::TfToken > names
Map< const Object *, Vector< const ID * > > & instance_geometries_by_object
Set< EmittedGeometryKey > used_emitted_geometry
pxr::SdfPath object_prim_id(const Object *object) const
void emit_object_prim(EmittedObject &emitted, const pxr::SdfPath &path, const pxr::TfToken &type, const pxr::HdContainerDataSourceHandle &ds, const pxr::GfMatrix4d &geometry_xform=pxr::GfMatrix4d(1.0))
Set< const Object * > used_instance_sources
Vector< pxr::SdfPath > all_proto_paths
Vector< pxr::VtIntArray > per_proto_indices
const EmittedMaterial * get_or_create_material(const Material *material)
pxr::SdfPath instancer_proto_root(const Object *source) const
Map< EmittedGeometryKey, EmittedGeometry > & emitted_geometry
pxr::HdContainerDataSourceHandle proto_instanced_by(const Object *source) const
void emit_prim(const pxr::SdfPath &path, const pxr::TfToken &type, const pxr::HdContainerDataSourceHandle &ds)
pxr::SdfPath hair_prim_id(const Object *object, const ParticleSystem *psys) const
EmittedGeometryKey emitted_geometry_key(const BObjectInfo &info, const pxr::TfToken &type) const