-
Notifications
You must be signed in to change notification settings - Fork 17
/
triangleAdapter.cpp
132 lines (113 loc) · 4.09 KB
/
triangleAdapter.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// Copyright © 2024 Weta Digital Limited
//
// SPDX-License-Identifier: Apache-2.0
//
#include "triangleAdapter.h"
#include "debugCodes.h"
#include <usdpluginexamples/usdTri/triangle.h>
#include <pxr/imaging/hd/tokens.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usdImaging/usdImaging/indexProxy.h>
#include <pxr/usdImaging/usdImaging/tokens.h>
PXR_NAMESPACE_OPEN_SCOPE
TF_REGISTRY_FUNCTION(TfType)
{
typedef UsdTriImagingTriangleAdapter Adapter;
TfType adapterType =
TfType::Define<Adapter, TfType::Bases<Adapter::BaseAdapter>>();
adapterType.SetFactory<UsdImagingPrimAdapterFactory<Adapter>>();
}
bool
UsdTriImagingTriangleAdapter::IsSupported(
const UsdImagingIndexProxy* index) const
{
return index->IsRprimTypeSupported(HdPrimTypeTokens->mesh);
}
void
UsdTriImagingTriangleAdapter::TrackVariability(
const UsdPrim& usdPrim,
const SdfPath& cachePath,
HdDirtyBits* o_timeVaryingBits,
const UsdImagingInstancerContext* i_instancerContext) const
{
BaseAdapter::TrackVariability(
usdPrim, cachePath, o_timeVaryingBits, i_instancerContext);
// If sideLength varies over time then points need to be pulled on time
// change.
_IsVarying(usdPrim,
UsdTriTokens->sideLength,
HdChangeTracker::DirtyPoints,
UsdImagingTokens->usdVaryingPrimvar,
o_timeVaryingBits,
/*inherited*/ false);
TF_DEBUG(USDTRIIMAGING)
.Msg("[%s] <%s>, <%s>, dirtyBits: %s\n",
TF_FUNC_NAME().c_str(),
usdPrim.GetPath().GetText(),
cachePath.GetText(),
HdChangeTracker::StringifyDirtyBits(*o_timeVaryingBits).c_str());
}
SdfPath
UsdTriImagingTriangleAdapter::Populate(
const UsdPrim& usdPrim,
UsdImagingIndexProxy* index,
const UsdImagingInstancerContext* instancerContext)
{
TF_DEBUG(USDTRIIMAGING)
.Msg(
"[%s] <%s>\n", TF_FUNC_NAME().c_str(), usdPrim.GetPath().GetText());
return _AddRprim(HdPrimTypeTokens->mesh,
usdPrim,
index,
GetMaterialUsdPath(usdPrim),
instancerContext);
}
HdDirtyBits
UsdTriImagingTriangleAdapter::ProcessPropertyChange(const UsdPrim& usdPrim,
const SdfPath& cachePath,
const TfToken& propertyName)
{
TF_DEBUG(USDTRIIMAGING)
.Msg("[%s] <%s>, <%s>, propertyName: %s\n",
TF_FUNC_NAME().c_str(),
usdPrim.GetPath().GetText(),
cachePath.GetText(),
propertyName.GetText());
// If the sideLength attribute changes, then the points are dirty.
if (propertyName == UsdTriTokens->sideLength) {
return HdChangeTracker::DirtyPoints;
}
// Allow base class to handle change processing.
return BaseAdapter::ProcessPropertyChange(usdPrim, cachePath, propertyName);
}
VtValue
UsdTriImagingTriangleAdapter::GetPoints(const UsdPrim& usdPrim,
UsdTimeCode timeCode) const
{
UsdTriTriangle triangle(usdPrim);
TF_VERIFY(triangle);
double sideLength;
TF_VERIFY(triangle.GetSideLengthAttr().Get(&sideLength, timeCode));
VtVec3fArray points{
GfVec3f(0.0f, 0.57735027f * sideLength, 0.0f),
GfVec3f(-0.5f * sideLength, -0.28867513f * sideLength, 0.0f),
GfVec3f(0.5f * sideLength, -0.28867513f * sideLength, 0.0f)
};
return VtValue(points);
}
VtValue
UsdTriImagingTriangleAdapter::GetTopology(const UsdPrim& usdPrim,
const SdfPath& cachePath,
UsdTimeCode time) const
{
// A single triangle.
VtIntArray faceVertexCounts(1, 3);
VtIntArray faceVertexIndices{ 0, 1, 2 };
static HdMeshTopology planeTopology(UsdGeomTokens->catmullClark,
HdTokens->rightHanded,
faceVertexCounts,
faceVertexIndices);
return VtValue(planeTopology);
}
PXR_NAMESPACE_CLOSE_SCOPE