-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelViewer.h
111 lines (97 loc) · 4.34 KB
/
ModelViewer.h
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
#pragma once
#include "Falcor.h"
#include "ModelResource.h"
#include "SceneRendererExtend.h"
#include "SceneExtend.h"
using namespace Falcor;
class ModelViewer
{
public:
using UniquePtr = std::unique_ptr<ModelViewer>;
ModelViewer();
~ModelViewer();
void onLoad(SampleCallbacks* pSample, RenderContext* pRenderContext);
void onFrameRender(SampleCallbacks* pSample, RenderContext* pRenderContext, const Fbo::SharedPtr& pTargetFbo);
void onResizeSwapChain(SampleCallbacks* pSample, uint32_t width, uint32_t height);
bool onKeyEvent(SampleCallbacks* pSample, const KeyboardEvent& keyEvent);
bool onMouseEvent(SampleCallbacks* pSample, const MouseEvent& mouseEvent);
void onGuiRender(SampleCallbacks* pSample, Gui* pGui);
bool hasModel() { return !mpScene->empty(); }
void loadModel(const std::string& Filename, ResourceFormat fboFormat, bool animation = false, bool useLinearFilter = true);
static ModelViewer* getCurrentViewer() { return mCurrentViewer; }
private:
void openDialogLoadModel(ResourceFormat fboFormat);
void deleteCulledMeshes(ModelResource& mesh);
void initDepthPass();
bool loadModelFromFile(ModelResource& r, const std::string& Filename, ResourceFormat fboFormat, bool animation = false, bool useLinearFilter = true);
void resetCamera(const Model::SharedPtr& model = nullptr, float distance = 5.0f);
void renderModelUI(Gui* pGui);
void loadSkyBox();
void loadShaderProgram();
void loadMaterialFunctions();
void loadModelResources();
SampleCallbacks* pSample;
static ModelViewer* mCurrentViewer;
std::shared_ptr<SceneExtend> mpScene;
SceneRendererExtend::SharedPtr pSceneRenderer;
ModelViewCameraController mModelViewCameraController;
FirstPersonCameraController mFirstPersonCameraController;
SixDoFCameraController m6DoFCameraController;
Sampler::SharedPtr mpPointSampler = nullptr;
Sampler::SharedPtr mpLinearSampler = nullptr;
enum
{
ModelViewCamera,
FirstPersonCamera,
SixDoFCamera
} mCameraType = ModelViewCamera;
enum HdrImage
{
EveningSun,
OvercastDay,
AtTheWindow,
DayTime,
Rathaus
};
static const Gui::DropdownList kSkyBoxDropDownList;
HdrImage mHdrImageIndex = HdrImage::EveningSun;
Texture::SharedPtr mHdrImage;
SkyBox::SharedPtr mpSkyBox;
Picking::UniquePtr mpScenePicker;
std::set<const Scene::ModelInstance*> mSelectedInstances;
CpuTimer mMouseHoldTimer;
Camera::SharedPtr mpCamera;
CameraController& getActiveCameraController();
float mNearZ;
float mFarZ;
bool mDrawWireframe = false;
uint32_t mActiveAnimationID = kBindPoseAnimationID;
static const uint32_t kBindPoseAnimationID = AnimationController::kBindPoseAnimationId;
RasterizerState::SharedPtr mpWireframeRS = nullptr;
RasterizerState::SharedPtr mpCullRastState[3]; // 0 = no culling, 1 = backface culling, 2 = frontface culling
uint32_t mCullMode = 1;
BlendState::SharedPtr mpBlendState[2];
uint32_t mBlendMode = 0;
DepthStencilState::SharedPtr mpNoDepthDS = nullptr;
DepthStencilState::SharedPtr mpDepthTestLessDS = nullptr;
DepthStencilState::SharedPtr mpDepthTestGreaterDS = nullptr;
DepthStencilState::SharedPtr mpDepthTestAlways = nullptr;
std::vector<DirectionalLight::SharedPtr> mpDirLight;
PointLight::SharedPtr mpPointLight;
GraphicsProgram::SharedPtr mpProgram = nullptr;
GraphicsVars::SharedPtr mpProgramVars = nullptr;
GraphicsState::SharedPtr mpGraphicsState = nullptr;
struct
{
GraphicsVars::SharedPtr pVars;
GraphicsProgram::SharedPtr pProgram;
} mDepthPass;
Fbo::SharedPtr mpDepthPassFbo;
static std::map<std::string, std::function<void(MaterialInstance::SharedPtr&)>>mMaterialFuncMap;
static std::map<std::string, GraphicsProgram::SharedPtr>mProgramMap;
public:
static std::function<void(MaterialInstance::SharedPtr&)>& getMaterialFunc(const std::string& name) { return mMaterialFuncMap[name]; };
static GraphicsProgram::SharedPtr& getProgram(const std::string& name) { return mProgramMap[name]; }
static const std::map<std::string, std::function<void(MaterialInstance::SharedPtr&)>>& getMaterialFuncMap() { return mMaterialFuncMap; };
static const std::map<std::string, GraphicsProgram::SharedPtr>& getProgramMap() { return mProgramMap; }
};