-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneDelegate.cpp
139 lines (111 loc) · 4.27 KB
/
SceneDelegate.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
133
134
135
136
137
138
139
#include "SceneDelegate.h"
#include "pxr/imaging/hd/camera.h"
#include "pxr/imaging/hd/rprimCollection.h"
#include "pxr/imaging/cameraUtil/conformWindow.h"
#include "pxr/imaging/pxOsd/tokens.h"
#include "pxr/imaging/hdx/renderTask.h"
#include "pxr/base/gf/range3f.h"
#include "pxr/base/gf/frustum.h"
#include "pxr/base/vt/array.h"
#include <iostream>
SceneDelegate::SceneDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID)
: pxr::HdSceneDelegate(parentIndex, delegateID)
{
cameraPath = pxr::SdfPath("/camera");
GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->camera, this, cameraPath);
pxr::GfFrustum frustum;
frustum.SetPosition(pxr::GfVec3d(0, 0, 3));
SetCamera(frustum.ComputeViewMatrix(), frustum.ComputeProjectionMatrix());
GetRenderIndex().InsertRprim(pxr::HdPrimTypeTokens->mesh, this, pxr::SdfPath("/triangle") );
}
void
SceneDelegate::AddRenderTask(pxr::SdfPath const &id)
{
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, id);
_ValueCache &cache = _valueCacheMap[id];
cache[pxr::HdTokens->collection] = pxr::HdRprimCollection(pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull));
}
void
SceneDelegate::AddRenderSetupTask(pxr::SdfPath const &id)
{
GetRenderIndex().InsertTask<pxr::HdxRenderSetupTask>(this, id);
_ValueCache &cache = _valueCacheMap[id];
pxr::HdxRenderTaskParams params;
params.camera = cameraPath;
params.viewport = pxr::GfVec4f(0, 0, 512, 512);
cache[pxr::HdTokens->params] = pxr::VtValue(params);
}
void SceneDelegate::SetCamera(pxr::GfMatrix4d const &viewMatrix, pxr::GfMatrix4d const &projMatrix)
{
SetCamera(cameraPath, viewMatrix, projMatrix);
}
void SceneDelegate::SetCamera(pxr::SdfPath const &cameraId, pxr::GfMatrix4d const &viewMatrix, pxr::GfMatrix4d const &projMatrix)
{
_ValueCache &cache = _valueCacheMap[cameraId];
cache[pxr::HdCameraTokens->windowPolicy] = pxr::VtValue(pxr::CameraUtilFit);
cache[pxr::HdCameraTokens->worldToViewMatrix] = pxr::VtValue(viewMatrix);
cache[pxr::HdCameraTokens->projectionMatrix] = pxr::VtValue(projMatrix);
GetRenderIndex().GetChangeTracker().MarkSprimDirty(cameraId, pxr::HdCamera::AllDirty);
}
pxr::VtValue SceneDelegate::GetCameraParamValue(pxr::SdfPath const &cameraId, pxr::TfToken const ¶mName) {
return Get(cameraId, paramName);
}
pxr::VtValue SceneDelegate::Get(pxr::SdfPath const &id, const pxr::TfToken &key)
{
std::cout << "[" << id.GetString() <<"][" << key << "]" << std::endl;
_ValueCache *vcache = pxr::TfMapLookupPtr(_valueCacheMap, id);
pxr::VtValue ret;
if (vcache && pxr::TfMapLookup(*vcache, key, &ret)) {
return ret;
}
if (key == pxr::HdShaderTokens->fragmentShader)
{
return pxr::VtValue();
}
if (key == pxr::HdTokens->points)
{
pxr::VtVec3fArray points;
points.push_back(pxr::GfVec3f(0,0,0));
points.push_back(pxr::GfVec3f(1,0,0));
points.push_back(pxr::GfVec3f(0,1,0));
return pxr::VtValue(points);
}
return ret;
}
bool SceneDelegate::GetVisible(pxr::SdfPath const &id)
{
std::cout << "[" << id.GetString() <<"][Visible]" << std::endl;
return true;
}
pxr::GfRange3d SceneDelegate::GetExtent(pxr::SdfPath const &id)
{
std::cout << "[" << id.GetString() <<"][Extent]" << std::endl;
return pxr::GfRange3d(pxr::GfVec3d(-1,-1,-1), pxr::GfVec3d(1,1,1));
}
pxr::GfMatrix4d SceneDelegate::GetTransform(pxr::SdfPath const &id)
{
std::cout << "[" << id.GetString() <<"][Transform]" << std::endl;
return pxr::GfMatrix4d(1.0f);
}
pxr::HdMeshTopology SceneDelegate::GetMeshTopology(pxr::SdfPath const &id)
{
std::cout << "[" << id.GetString() <<"][Topology]" << std::endl;
pxr::VtArray<int> vertCountsPerFace;
pxr::VtArray<int> verts;
vertCountsPerFace.push_back(3);
verts.push_back(0);
verts.push_back(1);
verts.push_back(2);
pxr::HdMeshTopology triangleTopology(pxr::PxOsdOpenSubdivTokens->none, pxr::HdTokens->rightHanded, vertCountsPerFace, verts);
return triangleTopology;
}
pxr::HdPrimvarDescriptorVector SceneDelegate::GetPrimvarDescriptors(pxr::SdfPath const& id, pxr::HdInterpolation interpolation)
{
std::cout << "[" << id.GetString() <<"][GetPrimvarDescriptors]" << std::endl;
pxr::HdPrimvarDescriptorVector primvarDescriptors;
if (interpolation == pxr::HdInterpolation::HdInterpolationVertex)
{
primvarDescriptors.push_back(pxr::HdPrimvarDescriptor(pxr::HdTokens->points, interpolation));
}
return primvarDescriptors;
}