gltf_viewer: add stats and view controls.

This commit is contained in:
Philip Rideout
2019-03-14 09:59:55 -07:00
parent 6b39569c14
commit df9791faaf
4 changed files with 50 additions and 12 deletions

View File

@@ -102,6 +102,11 @@ public:
*/
int getSidebarWidth() const { return mSidebarWidth; }
/**
* Allows clients to inject custom UI.
*/
void setUiCallback(std::function<void()> callback) { mCustomUI = callback; }
static constexpr int INITIAL_SIDEBAR_WIDTH = 350;
private:
@@ -116,6 +121,7 @@ private:
utils::NameComponentManager* mNames = nullptr;
Animator* mAnimator = nullptr;
filament::IndirectLight* mIndirectLight = nullptr;
std::function<void()> mCustomUI;
// Properties that can be changed from the UI.
int mCurrentAnimation = 1;
@@ -125,6 +131,9 @@ private:
bool mShowWireframe = false;
bool mEnableSunlight = true;
bool mEnableDithering = true;
bool mEnablePrepass = true;
bool mEnableFxaa = true;
bool mEnableMsaa = true;
int mSidebarWidth = INITIAL_SIDEBAR_WIDTH;
};
@@ -318,21 +327,35 @@ void SimpleViewer::updateUserInterface() {
ImGui::SetNextWindowSizeConstraints(ImVec2(20, height), ImVec2(width, height));
ImGui::Begin("Filament", nullptr, ImGuiWindowFlags_NoTitleBar);
if (mCustomUI) {
mCustomUI();
}
if (ImGui::CollapsingHeader("View")) {
ImGui::Checkbox("Dithering", &mEnableDithering);
auto mode = mEnableDithering ? View::Dithering::TEMPORAL : View::Dithering::NONE;
mView->setDithering(mode);
ImGui::Checkbox("Depth prepass", &mEnablePrepass);
ImGui::Checkbox("FXAA", &mEnableFxaa);
ImGui::Checkbox("MSAA 4x", &mEnableMsaa);
}
mView->setDepthPrepass(
mEnablePrepass ? View::DepthPrepass::ENABLED : View::DepthPrepass::DISABLED);
mView->setDithering(mEnableDithering ? View::Dithering::TEMPORAL : View::Dithering::NONE);
mView->setAntiAliasing(mEnableFxaa ? View::AntiAliasing::FXAA : View::AntiAliasing::NONE);
mView->setSampleCount(mEnableMsaa ? 4 : 1);
if (ImGui::CollapsingHeader("Light")) {
ImGui::SliderFloat("IBL intensity", &mIblIntensity, 0.0f, 100000.0f);
ImGui::SliderAngle("IBL rotation", &mIblRotation);
ImGui::Checkbox("Sunlight", &mEnableSunlight);
if (mEnableSunlight) {
mScene->addEntity(mSunlight);
} else {
mScene->remove(mSunlight);
}
}
if (mEnableSunlight) {
mScene->addEntity(mSunlight);
} else {
mScene->remove(mSunlight);
}
if (ImGui::CollapsingHeader("Model", ImGuiTreeNodeFlags_DefaultOpen)) {
if (mAnimator->getAnimationCount() > 0) {
intptr_t animationsNodeId = -1;
@@ -343,13 +366,15 @@ void SimpleViewer::updateUserInterface() {
}
}
ImGui::Checkbox("Wireframe", &mShowWireframe);
if (mShowWireframe) {
mScene->addEntity(mAsset->getWireframe());
} else {
mScene->remove(mAsset->getWireframe());
}
treeNode(mAsset->getRoot());
}
if (mShowWireframe) {
mScene->addEntity(mAsset->getWireframe());
} else {
mScene->remove(mAsset->getWireframe());
}
mSidebarWidth = ImGui::GetWindowWidth();
ImGui::End();

View File

@@ -365,6 +365,8 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback,
renderer->render(view->getView());
}
renderer->endFrame();
} else {
++mSkippedFrames;
}
if (postRender) {

View File

@@ -80,6 +80,8 @@ public:
void setSidebarWidth(int width) { mSidebarWidth = width; }
size_t getSkippedFrameCount() const { return mSkippedFrames; }
FilamentApp(const FilamentApp& rhs) = delete;
FilamentApp(FilamentApp&& rhs) = delete;
FilamentApp& operator=(const FilamentApp& rhs) = delete;
@@ -208,6 +210,7 @@ private:
AnimCallback mAnimation;
DropCallback mDropHandler;
int mSidebarWidth = 0;
size_t mSkippedFrames = 0;
};
#endif // TNT_FILAMENT_SAMPLE_FILAMENTAPP_H

View File

@@ -199,6 +199,14 @@ int main(int argc, char** argv) {
loadResources(filename);
app.viewer->setUiCallback([&app, scene] () {
if (ImGui::CollapsingHeader("Stats")) {
ImGui::Text("%zu entities in the asset", app.asset->getEntityCount());
ImGui::Text("%zu renderables (excluding UI)", scene->getRenderableCount());
ImGui::Text("%zu skipped frames", FilamentApp::get().getSkippedFrameCount());
}
});
// Leave FXAA enabled but we also enable MSAA for a nice result. The wireframe looks
// much better with MSAA enabled.
view->setSampleCount(4);