From affc947ce032f42155ff0b1fd189de0854e0b915 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Wed, 15 May 2019 09:06:49 -0700 Subject: [PATCH] gltf_baker: improve error reporting. --- libs/gltfio/src/AssetPipeline.cpp | 7 +++++++ libs/rays/src/PathTracer.cpp | 4 ++++ samples/gltf_baker.cpp | 26 +++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/libs/gltfio/src/AssetPipeline.cpp b/libs/gltfio/src/AssetPipeline.cpp index 0faf7612dd..458036bd83 100644 --- a/libs/gltfio/src/AssetPipeline.cpp +++ b/libs/gltfio/src/AssetPipeline.cpp @@ -1149,6 +1149,13 @@ const cgltf_data* Pipeline::parameterize(const cgltf_data* sourceAsset) { utils::slog.i << "Packing charts..." << utils::io::endl; xatlas::PackCharts(atlas); + if (atlas->atlasCount == 0) { + // When this occurs, try building in the debug configuration (xatlas has many asserts). + utils::slog.e << "Error: unable to generate atlas, mesh is not clean." << utils::io::endl; + xatlas::Destroy(atlas); + return nullptr; + } + utils::slog.i << "Produced " << atlas->atlasCount << " atlases, " << atlas->chartCount << " charts, " diff --git a/libs/rays/src/PathTracer.cpp b/libs/rays/src/PathTracer.cpp index 4be6b8b56c..5439757319 100644 --- a/libs/rays/src/PathTracer.cpp +++ b/libs/rays/src/PathTracer.cpp @@ -270,6 +270,10 @@ static void renderTileToGbuffer(EmbreeContext* context, PixelRectangle rect) { RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 0, position, 3); rtcInterpolate0(geo, rayhit.hit.primID, rayhit.hit.u, rayhit.hit.v, RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 1, normal, 3); + + // AO won't be computed until the second pass, but we show an instant preview of + // the chart shapes by setting a placeholder value in the AO map. + image.getPixelRef(col, row)[0] = 0.5f; } } } diff --git a/samples/gltf_baker.cpp b/samples/gltf_baker.cpp index 7ca65d0862..81a789f1c0 100644 --- a/samples/gltf_baker.cpp +++ b/samples/gltf_baker.cpp @@ -84,6 +84,7 @@ struct App { std::atomic requestOverlayUpdate; std::atomic requestStatePop; gltfio::AssetPipeline* pipeline; + std::string messageBoxText; }; struct OverlayVertex { @@ -333,19 +334,23 @@ static void prepAsset(App& app) { gltfio::AssetPipeline::AssetHandle asset = pipeline.load(app.filename); if (!asset) { std::cerr << "Unable to read " << app.filename << std::endl; - exit(1); + app.state = LOADED; + return; } asset = pipeline.flatten(asset); if (!asset) { std::cerr << "Unable to flatten " << app.filename << std::endl; - exit(1); + app.state = LOADED; + return; } asset = pipeline.parameterize(asset); if (!asset) { std::cerr << "Unable to parameterize " << app.filename << std::endl; - exit(1); + app.state = LOADED; + app.messageBoxText = "Unable to parameterize mesh, check terminal output for details."; + return; } const utils::Path folder = app.filename.getAbsolutePath().getParent(); @@ -537,6 +542,21 @@ int main(int argc, char** argv) { if (app.renderedImage) { ImGui::Checkbox("Show embree result", &app.showOverlay); } + + if (!app.messageBoxText.empty()) { + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {10, 10} ); + ImGui::OpenPopup("MessageBox"); + if (ImGui::BeginPopupModal("MessageBox", nullptr, + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar)) { + ImGui::TextUnformatted(app.messageBoxText.c_str()); + if (ImGui::Button("OK", ImVec2(120,0))) { + app.messageBoxText.clear(); + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + } }); // Leave FXAA enabled but we also enable MSAA for a nice result. The wireframe looks