-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathpoints.cpp
108 lines (95 loc) · 3.12 KB
/
points.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "points.h"
#include <pxr/base/tf/diagnostic.h>
#include <pxr/base/tf/staticData.h>
#include <pxr/base/tf/token.h>
#include <pxr/base/vt/array.h>
#include <pxr/base/vt/types.h>
#include <pxr/base/vt/value.h>
#include <pxr/imaging/hd/changeTracker.h>
#include <pxr/imaging/hd/enums.h>
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hd/tokens.h>
#include <pxr/imaging/hd/types.h>
#include <algorithm>
#include <anari/anari_cpp.hpp>
#include <iterator>
// std
#include <string>
#include "anariTokens.h"
#include "geometry.h"
using namespace std::string_literals;
PXR_NAMESPACE_OPEN_SCOPE
// HdAnariPoints definitions
// ////////////////////////////////////////////////////
HdAnariPoints::HdAnariPoints(
anari::Device d, const SdfPath &id, const SdfPath &instancerId)
: HdAnariGeometry(d, HdAnariTokens->sphere, id, instancerId)
{}
HdDirtyBits HdAnariPoints::GetInitialDirtyBitsMask() const
{
auto mask = HdChangeTracker::Clean | HdChangeTracker::InitRepr
| HdChangeTracker::DirtyExtent | HdChangeTracker::DirtyPoints
| HdChangeTracker::DirtyPrimID | HdChangeTracker::DirtyPrimvar
| HdChangeTracker::DirtyRepr | HdChangeTracker::DirtyMaterialId
| HdChangeTracker::DirtyTransform | HdChangeTracker::DirtyVisibility
| HdChangeTracker::DirtyWidths | HdChangeTracker::DirtyInstancer;
return mask;
}
HdAnariMaterial::PrimvarBinding HdAnariPoints::UpdateGeometry(
HdSceneDelegate *sceneDelegate,
HdDirtyBits *dirtyBits,
const TfToken::Set &allPrimvars,
const VtValue &points)
{
// Sphere radii //
if (HdChangeTracker::IsDirty(HdChangeTracker::DirtyWidths)) {
if (const auto &widthsVt = sceneDelegate->Get(GetId(), HdTokens->widths);
widthsVt.IsHolding<VtFloatArray>()) {
const auto &widths = widthsVt.UncheckedGet<VtFloatArray>();
VtFloatArray radii;
radii.reserve(std::size(widths));
std::transform(std::cbegin(widths),
std::cend(widths),
std::back_inserter(radii),
[](auto v) { return v / 2.0f; });
_SetGeometryAttributeArray(
HdAnariTokens->radius, HdAnariTokens->vertexRadius, VtValue(radii));
} else {
_SetGeometryAttributeArray(
HdAnariTokens->radius, HdAnariTokens->vertexRadius, VtValue());
}
}
return {};
}
void HdAnariPoints::UpdatePrimvarSource(HdSceneDelegate *sceneDelegate,
HdInterpolation interpolation,
const TfToken &attributeName,
const VtValue &value)
{
switch (interpolation) {
case HdInterpolationConstant: {
_SetGeometryAttributeConstant(attributeName, value);
break;
}
case HdInterpolationUniform:
case HdInterpolationFaceVarying: {
break;
}
case HdInterpolationVarying:
case HdInterpolationVertex: {
auto bindingPoint = _GetVertexBindingPoint(attributeName);
if (bindingPoint.IsEmpty()) {
TF_CODING_ERROR("%s is not a valid vertex geometry attribute\n",
attributeName.GetText());
break;
}
_SetGeometryAttributeArray(attributeName, bindingPoint, value);
break;
}
default:
break;
}
}
PXR_NAMESPACE_CLOSE_SCOPE