Dockable editor UI: timeline, pop-out viewport, render dialog #5

Merged
dev merged 3 commits from devin/1795874130-editor-ui into main 2026-11-28 09:11:12 -05:00
9 changed files with 698 additions and 91 deletions

No files matched your search

+4 -2
View File
@@ -44,8 +44,8 @@ endif()
# --- Dear ImGui ----------------------------------------------------------------
FetchContent_Declare(imgui
URL https://github.com/ocornut/imgui/archive/refs/tags/v1.91.5.tar.gz
URL_HASH SHA256=2aa2d169c569368439e5d5667e0796d09ca5cc6432965ce082e516937d7db254)
URL https://github.com/ocornut/imgui/archive/refs/tags/v1.91.5-docking.tar.gz
URL_HASH SHA256=f66c5d1b28fed044bd8dffa3882b4d1b29b2dbd1167fabe3d9d2219081e81cd8)
FetchContent_MakeAvailable(imgui)
add_library(imgui STATIC
@@ -105,6 +105,8 @@ add_executable(model_renderer
src/app/main.cpp
src/app/AppUi.cpp
src/app/FileBrowser.cpp
src/app/Timeline.cpp
src/app/Render.cpp
src/render/ModelNode.cpp
src/render/TextureLoader.cpp
src/render/Shaders.cpp
+20 -7
View File
@@ -107,14 +107,26 @@ Linux) so MMD bone and morph names display correctly.
## Using it
* **File > Open** picks a model; you can also pass the path on the command line.
The window is a dockable editor: **Scene** and **Bones** on the left, **Morphs** on the right,
the **Timeline** at the bottom and the 3D view in the middle. Drag a panel's tab to move, tab or
float it; the layout is saved to `~/.model_renderer_layout.ini` (**View > Reset panel layout**
restores the default).
* **File > Open** (or **Add media...** in the Timeline) picks a model, a dance `.vmd`, a camera
`.vmd` or a song (`.wav`/`.mp3`/`.flac`); camera files are detected automatically.
* **Bones**: select a bone, then use the rotation sliders / move fields. `*` marks posed bones.
Bones the motion drives can still be offset. Bones in an IK chain follow their IK bone while
**View > Solve IK** is on.
* **Morphs**: sliders grouped as Eye / Mouth / Eyebrow / Other, as in MMD.
* **Motion**: open a dance `.vmd`, a camera `.vmd` and a song with File > Open (camera files are
detected automatically); play/pause, rewind, loop and scrub the timeline. While the song plays
its clock drives the timeline, so motion stays in sync. Untick **Follow** to orbit freely.
Bones the motion drives can still be offset with the Bones panel. Bones in an IK chain (thighs,
knees) follow their IK bone while **View > Solve IK** is on.
* **Timeline**: transport (play/pause, step, jump, frame field, loop, volume), a ruler to scrub
and one row of keyframes per camera, song, bone and morph track. Click a bone row to select
that bone. Ctrl+wheel zooms, Shift+wheel or middle drag pans. While the song plays its clock
drives the timeline. Untick **Camera follow** to orbit freely.
* **Pop out** (top-left of the 3D view, or **View > Viewport in separate window**) moves the 3D
view into its own OS window, e.g. for a second monitor; close it or press **Dock viewport back**.
* **File > Render...** writes a PNG frame sequence at any resolution (presets up to 4K and
vertical), optionally with a transparent background. If `ffmpeg` is on the `PATH` it also
encodes `render.mp4` with the song.
* **View**: skeleton overlay, wireframe, culling, MMD toon vs Lambert shading, GPU vs CPU skinning,
UI scale (use 2 on Retina).
* Camera: left drag orbits, middle drag pans, right drag or wheel zooms, Space resets.
@@ -127,7 +139,8 @@ Command-line options (`--help`) allow scripted renders, e.g.
```
`--motion dance.vmd --camera camera.vmd --audio song.wav --play` plays a full MMD scene
(`--frame N` jumps to a frame);
(`--frame N` jumps to a frame, `--pop-out` opens the separate viewport window);
`--render DIR [--range A,B] [--render-size WxH]` renders PNG frames without opening the UI flow;
`tools/make_test_vmd.py --demo out.vmd` writes a short demo motion. `--skinning gpu|cpu` picks the skinning path; `--bench N` prints load, frame and deformation times.
## Tests
+144 -78
View File
@@ -4,7 +4,9 @@
#include "render/GpuCaps.h"
#include <imgui.h>
#include <imgui_internal.h>
#include <osg/NodeCallback>
#include <osgViewer/Renderer>
#include <algorithm>
#include <cctype>
@@ -59,6 +61,7 @@ App::App(osgViewer::Viewer& viewer, osg::Group* root, osgGA::TrackballManipulato
: viewer_(viewer), root_(root), manipulator_(manipulator) {
imgui_ = new ImGuiOsg([this]() { drawUi(); });
root_->addUpdateCallback(new TickCallback(this));
viewer_.getCamera()->setProjectionResizePolicy(osg::Camera::FIXED);
imgui_->attach(viewer_);
}
@@ -137,6 +140,7 @@ bool App::loadAudio(const std::string& path) {
}
audio_.setVolume(volume_);
audioName_ = path.substr(path.find_last_of("/\\") + 1);
audioPath_ = path;
setPlaying(false);
setMotionFrame(0.f);
return true;
@@ -188,25 +192,118 @@ void App::applyCamera() {
const osg::Matrixd toWorld = osg::Matrixd::rotate(osg::PI_2, osg::X_AXIS); // as ModelNode
manipulator_->setTransformation(osg::Vec3d(pose.eye) * toWorld, osg::Vec3d(pose.center) * toWorld,
osg::Vec3d(pose.up) * toWorld);
osg::Camera* camera = viewer_.getCamera();
double fovy, aspect, zNear, zFar;
if (!camera->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar)) return;
if (defaultFov_ <= 0.0) defaultFov_ = fovy;
camera->setProjectionMatrixAsPerspective(pose.fov, aspect, zNear, zFar);
fov_ = pose.fov;
}
void App::restoreCamera() {
if (defaultFov_ <= 0.0) return;
fov_ = 30.0;
}
// Pop-out: a slave camera with its own OS window that shares GL objects with the editor window.
// The editor window then draws only the UI.
void App::updatePopOut() {
osg::Camera* master = viewer_.getCamera();
if (popCamera_ && !(popCamera_->getGraphicsContext() && popCamera_->getGraphicsContext()->valid()))
wantPopOut_ = false; // the window was closed
if (wantPopOut_ && !popCamera_) {
osg::GraphicsContext* mainGc = master->getGraphicsContext();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
if (mainGc && mainGc->getTraits()) {
traits->hostName = mainGc->getTraits()->hostName;
traits->displayNum = mainGc->getTraits()->displayNum;
traits->screenNum = mainGc->getTraits()->screenNum;
}
traits->x = 140;
traits->y = 140;
traits->width = 1280;
traits->height = 720;
traits->windowName = "Model Renderer - Viewport";
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = mainGc;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc) {
loadError_ = "Could not open a separate viewport window.";
wantPopOut_ = false;
return;
}
gc->realize();
popCamera_ = new osg::Camera;
popCamera_->setGraphicsContext(gc.get());
popCamera_->setViewport(0, 0, traits->width, traits->height);
popCamera_->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
popCamera_->setProjectionResizePolicy(osg::Camera::FIXED);
popCamera_->setClearColor(master->getClearColor());
popCamera_->setClearMask(master->getClearMask());
// Slaves inherit the master's cull settings; the master's cull mask hides the scene.
popCamera_->setInheritanceMask(popCamera_->getInheritanceMask() & ~osg::CullSettings::CULL_MASK);
popCamera_->setDrawBuffer(GL_BACK);
popCamera_->setReadBuffer(GL_BACK);
viewer_.addSlave(popCamera_.get(), true);
if (!popCamera_->getRenderer()) popCamera_->setRenderer(new osgViewer::Renderer(popCamera_.get()));
master->setCullMask(0);
} else if (!wantPopOut_ && popCamera_) {
const unsigned index = viewer_.findSlaveIndexForCamera(popCamera_.get());
if (index < viewer_.getNumSlaves()) viewer_.removeSlave(index);
osg::ref_ptr<osg::GraphicsContext> gc = popCamera_->getGraphicsContext();
popCamera_->setGraphicsContext(nullptr);
if (gc && gc->valid()) gc->close();
popCamera_ = nullptr;
master->setCullMask(~0u);
}
if (!popCamera_) return;
const osg::GraphicsContext::Traits* traits = popCamera_->getGraphicsContext()->getTraits();
const int w = std::max(traits->width, 1), h = std::max(traits->height, 1);
popCamera_->setViewport(0, 0, w, h);
popCamera_->setProjectionMatrixAsPerspective(fov_, double(w) / h, 0.1, 1000.0);
popCamera_->setViewMatrix(manipulator_->getInverseMatrix());
}
void App::drawViewportOverlay() {
if (viewRect_.z() < 8.f) return;
ImGui::SetNextWindowPos(ImVec2(viewRect_.x() + 8.f, viewRect_.y() + 8.f));
ImGui::SetNextWindowBgAlpha(0.45f);
const ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove;
ImGui::Begin("##viewport-tools", nullptr, flags);
if (popCamera_) {
ImGui::TextUnformatted("The 3D view is in its own window.");
if (ImGui::Button("Dock viewport back")) setViewportPoppedOut(false);
} else {
if (ImGui::Button("Pop out")) setViewportPoppedOut(true);
ImGui::SameLine();
if (ImGui::Button("Frame model")) frameModel();
}
ImGui::End();
}
// The 3D view fills the window behind the panels; this squeezes the projection into the
// dockspace's free central area, so no extra render target is needed.
void App::updateProjection() {
osg::Camera* camera = viewer_.getCamera();
double fovy, aspect, zNear, zFar;
if (camera->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar))
camera->setProjectionMatrixAsPerspective(defaultFov_, aspect, zNear, zFar);
defaultFov_ = 0.0;
const osg::Viewport* vp = camera->getViewport();
if (!vp || vp->width() <= 0 || vp->height() <= 0) return;
const double W = vp->width(), H = vp->height();
double x = 0, y = 0, w = W, h = H;
if (imgui_->uiVisible() && viewRect_.z() > 8.f && viewRect_.w() > 8.f) {
x = viewRect_.x();
y = viewRect_.y();
w = viewRect_.z();
h = viewRect_.w();
}
const osg::Matrixd offset = osg::Matrixd::scale(w / W, h / H, 1.0) *
osg::Matrixd::translate((2.0 * x + w) / W - 1.0, 1.0 - (2.0 * y + h) / H, 0.0);
camera->setProjectionMatrix(osg::Matrixd::perspective(fov_, w / h, 0.1, 1000.0) * offset);
}
void App::tick(double time) {
const double dt = lastTick_ < 0.0 ? 0.0 : time - lastTick_;
lastTick_ = time;
updateRender();
updatePopOut();
updateProjection();
if (modelNode_) modelNode_->poser().setIkEnabled(ikEnabled_);
if (!player_ && !camera_ && !audio_.loaded()) return;
if (playing_) {
@@ -243,59 +340,6 @@ void App::openFile(const std::string& path) {
}
}
void App::drawMotionWindow() {
const ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y - 10.f), ImGuiCond_FirstUseEver,
ImVec2(0.5f, 1.f));
ImGui::SetNextWindowSize(ImVec2(520.f, 0.f), ImGuiCond_FirstUseEver);
ImGui::Begin("Motion");
if (!player_ && !camera_ && !audio_.loaded()) {
ImGui::TextDisabled("Open a motion .vmd, camera .vmd or song (.wav .mp3 .flac).");
if (ImGui::Button("Open...")) fileBrowser_.open();
} else {
const float last = timelineEnd();
if (player_) {
ImGui::Text("Motion: %s", motionName_.c_str());
ImGui::SameLine();
ImGui::TextDisabled("(bones %zu/%zu, morphs %zu/%zu matched)", player_->boundBones(),
player_->boneTrackCount(), player_->boundMorphs(), player_->morphTrackCount());
}
if (camera_) {
ImGui::Text("Camera: %s", cameraName_.c_str());
ImGui::SameLine();
if (ImGui::Checkbox("Follow##camera", &useMotionCamera_)) {
if (useMotionCamera_) applyCamera();
else restoreCamera();
}
}
if (audio_.loaded()) {
ImGui::Text("Audio: %s", audioName_.c_str());
ImGui::SameLine();
if (!audio_.hasDevice()) {
ImGui::TextDisabled("(no output device)");
} else {
ImGui::SetNextItemWidth(120.f);
if (ImGui::SliderFloat("Volume", &volume_, 0.f, 1.f, "%.2f")) audio_.setVolume(volume_);
}
}
if (ImGui::Button(playing_ ? "Pause" : "Play", ImVec2(60.f, 0.f))) setPlaying(!playing_);
ImGui::SameLine();
if (ImGui::Button("Rewind")) setMotionFrame(0.f);
ImGui::SameLine();
ImGui::Checkbox("Loop", &loopMotion_);
ImGui::SameLine();
if (ImGui::Button("Open...")) fileBrowser_.open();
ImGui::SameLine();
if (ImGui::Button("Unload")) unloadMotion();
ImGui::SameLine();
ImGui::Text("%.1f / %.1f s", motionFrame_ / kMotionFps, last / kMotionFps);
ImGui::SetNextItemWidth(-1.f);
float frame = motionFrame_;
if (ImGui::SliderFloat("##frame", &frame, 0.f, std::max(last, 1.f), "frame %.0f")) setMotionFrame(frame);
}
ImGui::End();
}
void App::setShowSkeleton(bool show) {
showSkeleton_ = show;
applyViewSettings();
@@ -316,6 +360,11 @@ void App::frameModel(float azimuthDeg, float elevationDeg) {
void App::drawUi() {
drawMenuBar();
const ImGuiID dockspace = ImGui::DockSpaceOverViewport(0, nullptr, ImGuiDockNodeFlags_PassthruCentralNode);
buildLayout(dockspace);
if (ImGuiDockNode* central = ImGui::DockBuilderGetCentralNode(dockspace))
viewRect_.set(central->Pos.x, central->Pos.y, central->Size.x, central->Size.y);
drawViewportOverlay();
if (!loadError_.empty()) {
ImGui::SetNextWindowPos(ImVec2(10, 40), ImGuiCond_Always);
ImGui::Begin("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse);
@@ -328,21 +377,43 @@ void App::drawUi() {
drawModelWindow();
drawBonesWindow();
drawMorphsWindow();
drawMotionWindow();
} else {
ImGui::SetNextWindowPos(ImVec2(10, 40), ImGuiCond_FirstUseEver);
ImGui::Begin("Welcome", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Open a .pmx, .pmd or .fbx model with File > Open.");
if (ImGui::Button("Open model...")) fileBrowser_.open();
ImGui::End();
for (const char* name : {"Scene", "Bones", "Morphs"}) {
ImGui::Begin(name);
ImGui::TextDisabled("No model loaded.");
if (name[0] == 'S' && ImGui::Button("Open model...")) fileBrowser_.open();
ImGui::End();
}
}
drawTimelineWindow();
drawRenderDialog();
if (showDemo_) ImGui::ShowDemoWindow(&showDemo_);
}
void App::buildLayout(unsigned dockspace) {
ImGuiDockNode* node = ImGui::DockBuilderGetNode(dockspace);
if (!resetLayout_ && node && node->IsSplitNode()) return; // restored from the saved layout
resetLayout_ = false;
ImGui::DockBuilderRemoveNode(dockspace);
ImGui::DockBuilderAddNode(dockspace, ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::DockBuilderSetNodeSize(dockspace, ImGui::GetMainViewport()->WorkSize);
ImGuiID center = dockspace;
const ImGuiID bottom = ImGui::DockBuilderSplitNode(center, ImGuiDir_Down, 0.30f, nullptr, &center);
ImGuiID left = ImGui::DockBuilderSplitNode(center, ImGuiDir_Left, 0.22f, nullptr, &center);
const ImGuiID right = ImGui::DockBuilderSplitNode(center, ImGuiDir_Right, 0.26f, nullptr, &center);
const ImGuiID leftBottom = ImGui::DockBuilderSplitNode(left, ImGuiDir_Down, 0.62f, nullptr, &left);
ImGui::DockBuilderDockWindow("Scene", left);
ImGui::DockBuilderDockWindow("Bones", leftBottom);
ImGui::DockBuilderDockWindow("Morphs", right);
ImGui::DockBuilderDockWindow("Timeline", bottom);
ImGui::DockBuilderFinish(dockspace);
}
void App::drawMenuBar() {
if (!ImGui::BeginMainMenuBar()) return;
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open model or motion...")) fileBrowser_.open();
if (ImGui::MenuItem("Render...", nullptr, false, modelNode_ != nullptr)) openRenderDialog();
if (ImGui::MenuItem("Quit")) viewer_.setDone(true);
ImGui::EndMenu();
}
@@ -367,6 +438,9 @@ void App::drawMenuBar() {
float scale = imgui_->uiScale();
if (ImGui::SliderFloat("UI scale", &scale, 0.75f, 2.5f, "%.2f")) imgui_->setUiScale(scale);
if (ImGui::MenuItem("Reset camera")) frameModel();
if (ImGui::MenuItem("Reset panel layout")) resetLayout_ = true;
if (ImGui::MenuItem("Viewport in separate window", nullptr, viewportPoppedOut()))
setViewportPoppedOut(!viewportPoppedOut());
ImGui::MenuItem("ImGui demo", nullptr, &showDemo_);
if (changed) applyViewSettings();
ImGui::EndMenu();
@@ -383,9 +457,7 @@ void App::drawMenuBar() {
void App::drawModelWindow() {
const Model& m = modelNode_->model();
ImGui::SetNextWindowPos(ImVec2(10, 35), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(300, 210), ImGuiCond_FirstUseEver);
ImGui::Begin("Model");
ImGui::Begin("Scene");
ImGui::TextWrapped("%s", m.name.c_str());
ImGui::TextDisabled("%s", m.format == SourceFormat::PMX ? "PMX" : m.format == SourceFormat::PMD ? "PMD" : "Assimp");
ImGui::Text("Vertices %zu Triangles %zu", m.vertices.size(), m.indices.size() / 3);
@@ -425,9 +497,6 @@ void App::drawBoneEditor() {
void App::drawBonesWindow() {
const Model& m = modelNode_->model();
const auto& poses = modelNode_->poser().bonePoses();
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowPos(ImVec2(10, 255), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(300, io.DisplaySize.y - 265), ImGuiCond_FirstUseEver);
ImGui::Begin("Bones");
drawBoneEditor();
ImGui::Separator();
@@ -460,9 +529,6 @@ void App::drawBonesWindow() {
void App::drawMorphsWindow() {
const Model& m = modelNode_->model();
auto& weights = modelNode_->poser().morphWeights();
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x - 330, 35), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(320, io.DisplaySize.y - 45), ImGuiCond_FirstUseEver);
ImGui::Begin("Morphs");
ImGui::SetNextItemWidth(-1);
ImGui::InputTextWithHint("##morphfilter", "Filter morphs", morphFilter_, sizeof(morphFilter_));
+39 -2
View File
@@ -1,4 +1,7 @@
#pragma once
#include <atomic>
#include <memory>
#include <osg/Image>
#include "app/FileBrowser.h"
#include "audio/AudioPlayer.h"
@@ -31,6 +34,10 @@ public:
void setPlaying(bool playing);
// Advances playback; called once per frame from the update traversal.
void tick(double time);
void setViewportPoppedOut(bool popped) { wantPopOut_ = popped; }
bool viewportPoppedOut() const { return popCamera_.valid(); }
// Batch render (command line): renders frames [start, end] into dir, then quits.
void renderToFolder(const std::string& dir, int start, int end, int width, int height);
ImGuiOsg* imgui() { return imgui_.get(); }
void drawUi();
@@ -42,7 +49,17 @@ private:
void drawBoneEditor();
void drawMorphsWindow();
void applyViewSettings();
void drawMotionWindow();
void drawTimelineWindow();
void drawTimelineTracks(float end);
void buildLayout(unsigned dockspace);
void updateProjection();
void updatePopOut();
void openRenderDialog();
void startRender();
void updateRender();
void finishRender(const std::string& status);
void drawRenderDialog();
void drawViewportOverlay();
void openFile(const std::string& path);
float timelineEnd() const;
void applyFrame();
@@ -74,7 +91,27 @@ private:
std::shared_ptr<Motion> camera_;
std::string cameraName_;
bool useMotionCamera_ = true;
double defaultFov_ = 0.0;
double fov_ = 30.0;
osg::Vec4f viewRect_; // 3D view area in UI pixels (x, y from top-left, w, h)
bool resetLayout_ = false;
bool wantPopOut_ = false;
bool showRenderDialog_ = false;
bool quitAfterRender_ = false;
std::string audioPath_;
struct RenderJob {
char dir[512] = {};
int width = 1920, height = 1080;
int start = 0, end = 0, current = 0, pending = -1;
bool transparent = false, mp4 = true, withAudio = true;
bool active = false, cancel = false;
std::string status;
osg::ref_ptr<osg::Camera> camera;
osg::ref_ptr<osg::Image> image;
std::shared_ptr<std::atomic<int>> encodeResult;
} render_;
osg::ref_ptr<osg::Camera> popCamera_; // renders the scene into the separate viewport window
float timelineZoom_ = 4.f; // pixels per frame
float timelineScroll_ = 0.f; // frame at the left edge
AudioPlayer audio_;
std::string audioName_;
float volume_ = 1.f;
+215
View File
@@ -0,0 +1,215 @@
#include "app/AppUi.h"
#include <imgui.h>
#include <osgDB/WriteFile>
#include <osgViewer/Renderer>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <thread>
namespace mr {
namespace {
bool ffmpegAvailable() {
static int found = -1;
if (found < 0) {
#ifdef _WIN32
found = std::system("ffmpeg -version > NUL 2>&1") == 0;
#else
found = std::system("ffmpeg -version > /dev/null 2>&1") == 0;
#endif
}
return found == 1;
}
std::string quotePath(const std::string& s) { return "\"" + s + "\""; }
} // namespace
void App::openRenderDialog() {
if (render_.dir[0] == '\0') {
std::error_code ec;
const std::string dir = (std::filesystem::current_path(ec) / "render").string();
std::snprintf(render_.dir, sizeof(render_.dir), "%s", dir.c_str());
}
render_.start = 0;
render_.end = static_cast<int>(timelineEnd());
showRenderDialog_ = true;
}
void App::renderToFolder(const std::string& dir, int start, int end, int width, int height) {
std::snprintf(render_.dir, sizeof(render_.dir), "%s", dir.c_str());
render_.start = start;
render_.end = end >= 0 ? end : static_cast<int>(timelineEnd());
render_.width = width;
render_.height = height;
quitAfterRender_ = true;
startRender();
if (!render_.active) {
std::fprintf(stderr, "%s\n", render_.status.c_str());
viewer_.setDone(true);
}
}
void App::startRender() {
std::error_code ec;
std::filesystem::create_directories(render_.dir, ec);
if (ec) {
render_.status = "Cannot create " + std::string(render_.dir) + ": " + ec.message();
return;
}
setPlaying(false);
render_.start = std::max(0, render_.start);
render_.end = std::max(render_.start, render_.end);
render_.current = render_.start;
render_.pending = -1;
render_.active = true;
render_.status.clear();
osg::Camera* master = viewer_.getCamera();
render_.image = new osg::Image;
render_.image->allocateImage(render_.width, render_.height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
osg::ref_ptr<osg::Camera> cam = new osg::Camera;
cam->setGraphicsContext(master->getGraphicsContext());
cam->setViewport(0, 0, render_.width, render_.height);
cam->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
cam->setRenderOrder(osg::Camera::PRE_RENDER);
cam->attach(osg::Camera::COLOR_BUFFER, render_.image.get(), 4, 0);
cam->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
cam->setInheritanceMask(cam->getInheritanceMask() & ~osg::CullSettings::CULL_MASK);
cam->setCullMask(~0u);
osg::Vec4 clear = master->getClearColor();
if (render_.transparent) clear.a() = 0.f;
cam->setClearColor(clear);
cam->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
viewer_.addSlave(cam.get(), true);
if (!cam->getRenderer()) cam->setRenderer(new osgViewer::Renderer(cam.get()));
render_.camera = cam;
}
void App::finishRender(const std::string& status) {
if (render_.camera) {
const unsigned index = viewer_.findSlaveIndexForCamera(render_.camera.get());
if (index < viewer_.getNumSlaves()) viewer_.removeSlave(index);
render_.camera = nullptr;
}
render_.image = nullptr;
render_.active = false;
render_.status = status;
if (quitAfterRender_) {
std::printf("%s\n", status.c_str());
render_.mp4 = false;
viewer_.setDone(true);
}
if (status.rfind("Done", 0) != 0 || !render_.mp4 || !ffmpegAvailable()) return;
const std::string dir = render_.dir;
std::string cmd = "ffmpeg -y -loglevel error -framerate 30 -i " +
quotePath((std::filesystem::path(dir) / "frame_%05d.png").string());
if (render_.withAudio && !audioPath_.empty()) {
char offset[32];
std::snprintf(offset, sizeof(offset), "%.3f", render_.start / 30.0);
cmd += " -ss " + std::string(offset) + " -i " + quotePath(audioPath_) + " -map 0:v -map 1:a -c:a aac -shortest";
}
cmd += " -c:v libx264 -pix_fmt yuv420p -crf 18 " + quotePath((std::filesystem::path(dir) / "render.mp4").string());
render_.status = "Encoding render.mp4 with ffmpeg...";
std::shared_ptr<std::atomic<int>> result = render_.encodeResult = std::make_shared<std::atomic<int>>(-1);
std::thread([cmd, result] { result->store(std::system(cmd.c_str()) == 0 ? 1 : 0); }).detach();
}
// Called every update: saves the frame drawn last time, then poses the next one.
void App::updateRender() {
if (render_.encodeResult && render_.encodeResult->load() >= 0) {
render_.status = render_.encodeResult->load() == 1 ? "Done: wrote render.mp4 and the PNG frames."
: "ffmpeg failed; the PNG frames are still there.";
render_.encodeResult.reset();
}
if (!render_.active) return;
if (render_.pending >= 0) {
char name[32];
std::snprintf(name, sizeof(name), "frame_%05d.png", render_.pending - render_.start);
const std::string file = (std::filesystem::path(render_.dir) / name).string();
if (!osgDB::writeImageFile(*render_.image, file)) {
finishRender("Could not write " + file);
return;
}
render_.pending = -1;
if (++render_.current > render_.end) {
finishRender("Done: wrote " + std::to_string(render_.end - render_.start + 1) + " frames to " + render_.dir);
return;
}
}
if (render_.cancel) {
render_.cancel = false;
finishRender("Cancelled.");
return;
}
setMotionFrame(static_cast<float>(render_.current));
render_.camera->setProjectionMatrixAsPerspective(fov_, double(render_.width) / render_.height, 0.1, 1000.0);
render_.camera->setViewMatrix(manipulator_->getInverseMatrix());
render_.pending = render_.current;
}
void App::drawRenderDialog() {
if (!showRenderDialog_) return;
ImGui::SetNextWindowSize(ImVec2(ImGui::GetFontSize() * 28.f, 0.f), ImGuiCond_Appearing);
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (!ImGui::Begin("Render", &showRenderDialog_, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse)) {
ImGui::End();
return;
}
ImGui::BeginDisabled(render_.active);
ImGui::InputText("Output folder", render_.dir, sizeof(render_.dir));
static const int presets[][2] = {{1280, 720}, {1920, 1080}, {2560, 1440}, {3840, 2160}, {1080, 1920}};
static const char* presetNames[] = {"720p", "1080p", "1440p", "4K", "Vertical 1080x1920"};
for (int i = 0; i < 5; ++i) {
if (i) ImGui::SameLine();
if (ImGui::SmallButton(presetNames[i])) {
render_.width = presets[i][0];
render_.height = presets[i][1];
}
}
int size[2] = {render_.width, render_.height};
if (ImGui::InputInt2("Resolution", size)) {
render_.width = std::clamp(size[0], 16, 8192);
render_.height = std::clamp(size[1], 16, 8192);
}
int range[2] = {render_.start, render_.end};
if (ImGui::InputInt2("Frames", range)) {
render_.start = std::max(0, range[0]);
render_.end = std::max(render_.start, range[1]);
}
ImGui::TextDisabled("%d frames, %.1f s at 30 fps", render_.end - render_.start + 1,
(render_.end - render_.start + 1) / 30.f);
ImGui::Checkbox("Transparent background", &render_.transparent);
const bool ffmpeg = ffmpegAvailable();
ImGui::BeginDisabled(!ffmpeg);
ImGui::Checkbox("Also encode render.mp4 (ffmpeg)", &render_.mp4);
if (render_.mp4 && !audioPath_.empty()) {
ImGui::SameLine();
ImGui::Checkbox("with song", &render_.withAudio);
}
ImGui::EndDisabled();
if (!ffmpeg) ImGui::TextDisabled("Install ffmpeg to get a video file; PNG frames always work.");
ImGui::EndDisabled();
ImGui::Separator();
if (render_.active) {
const float total = float(render_.end - render_.start + 1);
const float done = float(render_.current - render_.start);
char label[64];
std::snprintf(label, sizeof(label), "Frame %d of %d", render_.current - render_.start + 1, int(total));
ImGui::ProgressBar(done / total, ImVec2(-1.f, 0.f), label);
if (ImGui::Button("Cancel")) render_.cancel = true;
} else {
ImGui::BeginDisabled(!modelNode_ || render_.encodeResult != nullptr);
if (ImGui::Button("Render PNG frames", ImVec2(-1.f, 0.f))) startRender();
ImGui::EndDisabled();
ImGui::TextDisabled("Uses the motion camera when Camera follow is on, otherwise the current view.");
}
if (!render_.status.empty()) ImGui::TextWrapped("%s", render_.status.c_str());
ImGui::End();
}
} // namespace mr
+241
View File
@@ -0,0 +1,241 @@
#include "app/AppUi.h"
#include <imgui.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
namespace mr {
namespace {
const ImU32 kKeyColor = IM_COL32(255, 196, 92, 255);
const ImU32 kCameraKeyColor = IM_COL32(120, 200, 255, 255);
const ImU32 kMorphKeyColor = IM_COL32(220, 130, 255, 255);
const ImU32 kPlayheadColor = IM_COL32(255, 80, 90, 255);
void drawDiamond(ImDrawList* dl, float x, float y, float r, ImU32 color) {
dl->AddQuadFilled(ImVec2(x, y - r), ImVec2(x + r, y), ImVec2(x, y + r), ImVec2(x - r, y), color);
}
// Draws the keys of one track that fall inside [first, last] frames.
template <typename Key>
void drawKeys(ImDrawList* dl, const std::vector<Key>& keys, float first, float last, float x0, float zoom,
float y, float r, ImU32 color) {
auto it = std::lower_bound(keys.begin(), keys.end(), first,
[](const Key& k, float f) { return static_cast<float>(k.frame) < f; });
float lastX = -1e9f;
for (; it != keys.end() && static_cast<float>(it->frame) <= last; ++it) {
const float x = x0 + (static_cast<float>(it->frame) - first) * zoom;
if (x - lastX < 1.f) continue; // skip overdraw when zoomed far out
drawDiamond(dl, x, y, r, color);
lastX = x;
}
}
float niceStep(float zoom) {
static const float steps[] = {1, 2, 5, 10, 15, 30, 60, 150, 300, 600, 1800, 3600};
for (float s : steps)
if (s * zoom >= 56.f) return s;
return 7200.f;
}
} // namespace
void App::drawTimelineWindow() {
ImGui::Begin("Timeline");
const float end = std::max(timelineEnd(), 1.f);
const bool hasMedia = player_ || camera_ || audio_.loaded();
ImGui::BeginDisabled(!hasMedia);
if (ImGui::Button("|<")) setMotionFrame(0.f);
ImGui::SameLine();
if (ImGui::ArrowButton("##prev", ImGuiDir_Left)) setMotionFrame(std::max(0.f, std::ceil(motionFrame_) - 1.f));
ImGui::SameLine();
if (ImGui::Button(playing_ ? "Pause" : "Play", ImVec2(ImGui::GetFontSize() * 4.f, 0.f))) setPlaying(!playing_);
ImGui::SameLine();
if (ImGui::ArrowButton("##next", ImGuiDir_Right)) setMotionFrame(std::min(end, std::floor(motionFrame_) + 1.f));
ImGui::SameLine();
if (ImGui::Button(">|")) setMotionFrame(end);
ImGui::SameLine();
int frame = static_cast<int>(motionFrame_ + 0.5f);
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4.5f);
if (ImGui::InputInt("##frame", &frame, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue))
setMotionFrame(std::clamp(static_cast<float>(frame), 0.f, end));
ImGui::SameLine();
const float seconds = motionFrame_ / 30.f;
ImGui::Text("/ %.0f %d:%05.2f", end, static_cast<int>(seconds) / 60, std::fmod(seconds, 60.f));
ImGui::SameLine();
ImGui::Checkbox("Loop", &loopMotion_);
ImGui::EndDisabled();
if (camera_) {
ImGui::SameLine();
if (ImGui::Checkbox("Camera follow", &useMotionCamera_)) {
if (useMotionCamera_) applyCamera();
else restoreCamera();
}
}
if (audio_.loaded() && audio_.hasDevice()) {
ImGui::SameLine();
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 6.f);
if (ImGui::SliderFloat("Volume", &volume_, 0.f, 1.f, "%.2f")) audio_.setVolume(volume_);
}
ImGui::SameLine();
if (ImGui::Button("Add media...")) fileBrowser_.open();
ImGui::SameLine();
ImGui::BeginDisabled(!modelNode_);
if (ImGui::Button("Render...")) openRenderDialog();
ImGui::EndDisabled();
if (hasMedia) {
ImGui::SameLine();
if (ImGui::Button("Clear")) unloadMotion();
}
if (!hasMedia) {
ImGui::Spacing();
ImGui::TextDisabled("Open a dance .vmd, a camera .vmd or a song (.wav/.mp3/.flac) to fill the timeline.");
} else {
drawTimelineTracks(end);
}
ImGui::End();
}
void App::drawTimelineTracks(float end) {
ImGuiIO& io = ImGui::GetIO();
ImDrawList* dl = ImGui::GetWindowDrawList();
const float labelW = ImGui::GetFontSize() * 13.f;
const float rowH = ImGui::GetFrameHeight();
const float rulerH = ImGui::GetFontSize() * 1.4f;
const ImVec2 origin = ImGui::GetCursorScreenPos();
const float availW = ImGui::GetContentRegionAvail().x;
const float x0 = origin.x + labelW;
const float canvasW = std::max(availW - labelW, 10.f);
// Keep the playhead in view while playing.
const float visibleFrames = canvasW / timelineZoom_;
if (playing_ && (motionFrame_ < timelineScroll_ || motionFrame_ > timelineScroll_ + visibleFrames * 0.95f))
timelineScroll_ = motionFrame_ - visibleFrames * 0.05f;
timelineScroll_ = std::clamp(timelineScroll_, 0.f, std::max(0.f, end - visibleFrames * 0.5f));
const float first = timelineScroll_, last = timelineScroll_ + visibleFrames;
auto xToFrame = [&](float x) { return std::clamp(first + (x - x0) / timelineZoom_, 0.f, end); };
// Ruler: click or drag to scrub.
ImGui::SetCursorScreenPos(ImVec2(x0, origin.y));
ImGui::InvisibleButton("##ruler", ImVec2(canvasW, rulerH));
if (ImGui::IsItemActive()) setMotionFrame(xToFrame(io.MousePos.x));
const bool rulerHovered = ImGui::IsItemHovered();
dl->AddRectFilled(ImVec2(x0, origin.y), ImVec2(x0 + canvasW, origin.y + rulerH), IM_COL32(32, 34, 42, 255));
dl->PushClipRect(ImVec2(x0, origin.y), ImVec2(x0 + canvasW, origin.y + rulerH), true);
const float step = niceStep(timelineZoom_);
for (float f = std::floor(first / step) * step; f <= last; f += step) {
const float x = x0 + (f - first) * timelineZoom_;
dl->AddLine(ImVec2(x, origin.y + rulerH * 0.45f), ImVec2(x, origin.y + rulerH), IM_COL32(120, 125, 140, 255));
char label[32];
std::snprintf(label, sizeof(label), "%.0f", f);
dl->AddText(ImVec2(x + 3.f, origin.y), IM_COL32(170, 175, 190, 255), label);
}
dl->PopClipRect();
ImGui::SetCursorScreenPos(ImVec2(origin.x, origin.y));
ImGui::TextDisabled("frame");
// Rows.
struct Row {
std::string label;
int kind; // 0 camera, 1 audio, 2 bone, 3 morph
int index;
};
std::vector<Row> rows;
if (camera_) rows.push_back({"Camera " + cameraName_, 0, 0});
if (audio_.loaded()) rows.push_back({"Audio " + audioName_, 1, 0});
if (player_ && modelNode_) {
const Model& model = modelNode_->model();
const auto& bones = player_->boneBindings();
for (size_t i = 0; i < bones.size(); ++i) rows.push_back({model.bones[bones[i].first].name, 2, int(i)});
const auto& morphs = player_->morphBindings();
for (size_t i = 0; i < morphs.size(); ++i) rows.push_back({model.morphs[morphs[i].first].name, 3, int(i)});
}
ImGui::SetCursorScreenPos(ImVec2(origin.x, origin.y + rulerH + 2.f));
const ImGuiWindowFlags childFlags = (io.KeyCtrl || io.KeyShift) ? ImGuiWindowFlags_NoScrollWithMouse : 0;
ImGui::BeginChild("##tracks", ImVec2(availW, 0.f), ImGuiChildFlags_None, childFlags);
ImDrawList* cdl = ImGui::GetWindowDrawList();
const float tracksTop = ImGui::GetWindowPos().y;
const float tracksBottom = tracksTop + ImGui::GetWindowHeight();
bool canvasHovered = false;
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(rows.size()), rowH);
while (clipper.Step()) {
for (int r = clipper.DisplayStart; r < clipper.DisplayEnd; ++r) {
const Row& row = rows[r];
ImGui::PushID(r);
const ImVec2 p = ImGui::GetCursorScreenPos();
if (r % 2) cdl->AddRectFilled(p, ImVec2(p.x + availW, p.y + rowH), IM_COL32(255, 255, 255, 8));
bool selected = false;
int boneIndex = -1;
if (row.kind == 2) {
boneIndex = player_->boneBindings()[row.index].first;
selected = boneIndex == selectedBone_;
}
if (ImGui::Selectable(row.label.c_str(), selected, 0, ImVec2(labelW - 8.f, rowH)) && boneIndex >= 0) {
selectedBone_ = boneIndex;
modelNode_->setSelectedBone(selectedBone_);
}
if (ImGui::IsItemHovered() && ImGui::CalcTextSize(row.label.c_str()).x > labelW - 8.f)
ImGui::SetTooltip("%s", row.label.c_str());
ImGui::SameLine(labelW);
ImGui::InvisibleButton("##canvas", ImVec2(canvasW, rowH));
if (ImGui::IsItemActive()) setMotionFrame(xToFrame(io.MousePos.x));
canvasHovered |= ImGui::IsItemHovered();
const float cy = p.y + rowH * 0.5f, rad = rowH * 0.28f;
cdl->PushClipRect(ImVec2(x0, p.y), ImVec2(x0 + canvasW, p.y + rowH), true);
switch (row.kind) {
case 0: drawKeys(cdl, camera_->cameraKeys, first, last, x0, timelineZoom_, cy, rad, kCameraKeyColor); break;
case 1: {
const float len = static_cast<float>(audio_.length()) * 30.f;
cdl->AddRectFilled(ImVec2(x0 + (0.f - first) * timelineZoom_, p.y + 3.f),
ImVec2(x0 + (len - first) * timelineZoom_, p.y + rowH - 3.f),
IM_COL32(80, 170, 120, 150), 3.f);
break;
}
case 2:
drawKeys(cdl, *player_->boneBindings()[row.index].second, first, last, x0, timelineZoom_, cy, rad,
selected ? IM_COL32(255, 255, 255, 255) : kKeyColor);
break;
case 3:
drawKeys(cdl, *player_->morphBindings()[row.index].second, first, last, x0, timelineZoom_, cy, rad,
kMorphKeyColor);
break;
}
cdl->PopClipRect();
ImGui::PopID();
}
}
ImGui::EndChild();
// Zoom (Ctrl+wheel), pan (Shift+wheel or middle drag).
if (canvasHovered || rulerHovered) {
if (io.KeyCtrl && io.MouseWheel != 0.f) {
const float anchor = first + (io.MousePos.x - x0) / timelineZoom_;
timelineZoom_ = std::clamp(timelineZoom_ * std::pow(1.2f, io.MouseWheel), 0.05f, 40.f);
timelineScroll_ = anchor - (io.MousePos.x - x0) / timelineZoom_;
} else if (io.KeyShift && io.MouseWheel != 0.f) {
timelineScroll_ -= io.MouseWheel * 60.f / timelineZoom_;
}
if (io.MouseWheelH != 0.f) timelineScroll_ -= io.MouseWheelH * 60.f / timelineZoom_;
if (ImGui::IsMouseDragging(ImGuiMouseButton_Middle, 0.f)) timelineScroll_ -= io.MouseDelta.x / timelineZoom_;
}
// Playhead across ruler and tracks.
const float px = x0 + (motionFrame_ - first) * timelineZoom_;
if (px >= x0 && px <= x0 + canvasW) {
ImDrawList* fg = ImGui::GetWindowDrawList();
fg->PushClipRect(ImVec2(x0, origin.y), ImVec2(x0 + canvasW, tracksBottom), true);
fg->AddLine(ImVec2(px, origin.y), ImVec2(px, tracksBottom), kPlayheadColor, 2.f);
fg->AddTriangleFilled(ImVec2(px - 5.f, origin.y), ImVec2(px + 5.f, origin.y), ImVec2(px, origin.y + 7.f),
kPlayheadColor);
fg->PopClipRect();
}
}
} // namespace mr
+17
View File
@@ -45,6 +45,10 @@ void printUsage() {
" --camera FILE.vmd load an MMD camera motion\n"
" --audio FILE load a song (.wav .mp3 .flac)\n"
" --play start playback\n"
" --pop-out show the 3D view in its own window\n"
" --render DIR render PNG frames into DIR and exit\n"
" --range A,B frames to render (default: whole timeline)\n"
" --render-size WxH render resolution (default 1920x1080)\n"
" --bench N time N idle and N animated frames, then exit\n";
}
@@ -110,6 +114,9 @@ int main(int argc, char** argv) {
std::string modelPath, screenshot, motionPath, cameraPath, audioPath;
float motionFrame = 0.f;
bool play = false;
bool popOut = false;
std::string renderDir;
int renderStart = 0, renderEnd = -1, renderW = 1920, renderH = 1080;
std::vector<std::pair<std::string, std::string>> morphArgs, boneArgs;
int width = 1280, height = 800, frames = 5, benchFrames = 0;
float azimuth = 0.f, elevation = 0.f, uiScale = 1.f;
@@ -164,6 +171,14 @@ int main(int argc, char** argv) {
motionFrame = std::strtof(next().c_str(), nullptr);
} else if (a == "--play") {
play = true;
} else if (a == "--pop-out") {
popOut = true;
} else if (a == "--render") {
renderDir = next();
} else if (a == "--range") {
std::sscanf(next().c_str(), "%d,%d", &renderStart, &renderEnd);
} else if (a == "--render-size") {
std::sscanf(next().c_str(), "%dx%d", &renderW, &renderH);
} else if (a == "--bench") {
benchFrames = std::max(1, std::atoi(next().c_str()));
} else if (a == "--frames") {
@@ -229,6 +244,8 @@ int main(int argc, char** argv) {
if (!motionPath.empty() || !cameraPath.empty() || !audioPath.empty()) {
app.setMotionFrame(motionFrame);
app.setPlaying(play);
app.setViewportPoppedOut(popOut);
if (!renderDir.empty()) app.renderToFolder(renderDir, renderStart, renderEnd, renderW, renderH);
}
app.setShowSkeleton(skeleton);
app.frameModel(azimuth, elevation);
+3
View File
@@ -78,6 +78,9 @@ public:
void apply(float frame, Poser& poser) const;
const std::vector<std::pair<int, const std::vector<BoneKeyframe>*>>& boneBindings() const { return bones_; }
const std::vector<std::pair<int, const std::vector<MorphKeyframe>*>>& morphBindings() const { return morphs_; }
private:
std::shared_ptr<const Motion> motion_;
std::vector<std::pair<int, const std::vector<BoneKeyframe>*>> bones_;
+15 -2
View File
@@ -106,8 +106,15 @@ private:
};
class EventHandler : public osgGA::GUIEventHandler {
public:
explicit EventHandler(osg::Camera* camera) : camera_(camera) {}
osg::observer_ptr<osg::Camera> camera_;
public:
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&) override {
// Events from other windows (the popped-out viewport) belong to the 3D view only.
if (camera_.valid() && ea.getGraphicsContext() && ea.getGraphicsContext() != camera_->getGraphicsContext())
return false;
if (!ImGui::GetCurrentContext()) return false;
ImGuiIO& io = ImGui::GetIO();
using E = osgGA::GUIEventAdapter;
@@ -192,7 +199,13 @@ ImGuiOsg::ImGuiOsg(DrawFunction draw) : draw_(std::move(draw)) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
// Panel layout persists between runs.
static std::string iniPath;
const char* home = std::getenv("HOME");
if (!home) home = std::getenv("USERPROFILE");
iniPath = home ? std::string(home) + "/.model_renderer_layout.ini" : "model_renderer_layout.ini";
io.IniFilename = iniPath.c_str();
#if !defined(_WIN32) && !defined(__APPLE__)
ImGuiPlatformIO& platformIo = ImGui::GetPlatformIO();
platformIo.Platform_GetClipboardTextFn = getClipboardText;
@@ -256,7 +269,7 @@ void ImGuiOsg::setUiScale(float scale) {
void ImGuiOsg::attach(osgViewer::Viewer& viewer) {
camera_ = viewer.getCamera();
viewer.setRealizeOperation(new InitOperation(this));
viewer.addEventHandler(new EventHandler);
viewer.addEventHandler(new EventHandler(viewer.getCamera()));
viewer.getCamera()->setFinalDrawCallback(new DrawCallback(this));
}