Skip to content

Commit

Permalink
[fix] cleanup rendering when open another scene.
Browse files Browse the repository at this point in the history
  • Loading branch information
legobadman committed Oct 30, 2023
1 parent d6a80ca commit f92c912
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ui/zenoedit/viewport/displaywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ void DisplayWidget::testCleanUp()
m_glView->testCleanUp();
}

void DisplayWidget::cleanUpScene()
{
if (m_glView)
{
m_glView->cleanUpScene();
}
else
{
m_optixView->cleanUpScene();
}
}

void DisplayWidget::init()
{
//m_camera->installEventFilter(this);
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/viewport/displaywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DisplayWidget : public QWidget
Zenovis* getZenoVis() const;
void runAndRecord(const VideoRecInfo& info);
void testCleanUp();
void cleanUpScene();
void beforeRun();
void afterRun();
void changeTransformOperation(const QString &node);
Expand Down
11 changes: 11 additions & 0 deletions ui/zenoedit/viewport/optixviewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ void OptixWorker::needUpdateCamera()
m_pTimer->start(m_sampleFeq);
}

void OptixWorker::onCleanUpScene()
{
m_zenoVis->cleanUpScene();
}


ZOptixViewport::ZOptixViewport(QWidget* parent)
: QWidget(parent)
Expand Down Expand Up @@ -392,6 +397,7 @@ ZOptixViewport::ZOptixViewport(QWidget* parent)
connect(this, &ZOptixViewport::sig_setSlidFeq, m_worker, &OptixWorker::onSetSlidFeq);
connect(this, &ZOptixViewport::sig_modifyLightData, m_worker, &OptixWorker::onModifyLightData);
connect(this, &ZOptixViewport::sig_updateCameraProp, m_worker, &OptixWorker::onUpdateCameraProp);
connect(this, &ZOptixViewport::sig_cleanUpScene, m_worker, &OptixWorker::onCleanUpScene);

setRenderSeparately(false, false);
m_thdOptix.start();
Expand Down Expand Up @@ -445,6 +451,11 @@ void ZOptixViewport::setSlidFeq(int feq)
emit sig_setSlidFeq(feq);
}

void ZOptixViewport::cleanUpScene()
{
emit sig_cleanUpScene();
}

void ZOptixViewport::modifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString name, UI_VECTYPE skipParam)
{
emit sig_modifyLightData(pos, scale, rotate, color, intensity, name, skipParam);
Expand Down
3 changes: 3 additions & 0 deletions ui/zenoedit/viewport/optixviewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public slots:
void onSetSlidFeq(int feq);
void onModifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString nodename, UI_VECTYPE skipParam);
void onUpdateCameraProp(float aperture, float disPlane, UI_VECTYPE skipParam = UI_VECTYPE());
void onCleanUpScene();

private:
Zenovis *m_zenoVis;
Expand Down Expand Up @@ -77,6 +78,7 @@ class ZOptixViewport : public QWidget
void killThread();
void setSlidFeq(int feq);
void modifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString name, UI_VECTYPE skipParam);
void cleanUpScene();

signals:
void cameraAboutToRefresh();
Expand All @@ -96,6 +98,7 @@ class ZOptixViewport : public QWidget
void sigscreenshoot(QString, QString, int, int);
void sig_modifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString name, UI_VECTYPE skipParam);
void sig_updateCameraProp(float aperture, float disPlane, UI_VECTYPE skipParam = UI_VECTYPE());
void sig_cleanUpScene();

public slots:
void onFrameRunFinished(int frame);
Expand Down
6 changes: 6 additions & 0 deletions ui/zenoedit/viewport/viewportwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ void ViewportWidget::changeTransformCoordSys() {
m_camera->changeTransformCoordSys();
}

void ViewportWidget::cleanUpScene() {
if (!m_zenovis)
return;
m_zenovis->cleanUpScene();
}

void ViewportWidget::updateCameraProp(float aperture, float disPlane) {
m_camera->setAperture(aperture);
m_camera->setDisPlane(disPlane);
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/viewport/viewportwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ViewportWidget : public QGLWidget
void changeTransformOperation(const QString& node);
void changeTransformOperation(int mode);
void changeTransformCoordSys();
void cleanUpScene();
void setNumSamples(int samples);
void setPickTarget(const std::string& prim_name);
void bindNodeToPicker(const QModelIndex& node, const QModelIndex& subgraph, const std::string& sock_name);
Expand Down
10 changes: 10 additions & 0 deletions ui/zenoedit/viewport/zenovis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ bool Zenovis::isLoopPlaying()
return m_loopPlaying;
}

void Zenovis::cleanUpScene()
{
if (!session)
return;

auto pScene = session->get_scene();
ZASSERT_EXIT(pScene);
pScene->cleanUpScene();
}

void Zenovis::startPlay(bool bPlaying)
{
m_playing = bPlaying;
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/viewport/zenovis.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public slots:
void updateCameraFront(QVector3D center, QVector3D front, QVector3D up);
void setLoopPlaying(bool enable);
bool isLoopPlaying();
void cleanUpScene();

//private:
void doFrameUpdate();
Expand Down
8 changes: 8 additions & 0 deletions ui/zenoedit/zenomainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,14 @@ bool ZenoMainWindow::openFile(QString filePath)
if (!pModel)
return false;

//cleanup
zeno::getSession().globalComm->clearFrameState();
auto views = viewports();
for (auto view : views)
{
view->cleanUpScene();
}

resetTimeline(pGraphs->timeInfo());
recordRecentFile(filePath);
initUserdata(pGraphs->userdataInfo());
Expand Down
1 change: 1 addition & 0 deletions zenovis/include/zenovis/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct Scene : zeno::disable_copy {

void draw();
bool loadFrameObjects(int frameid);
void cleanUpScene();
void switchRenderEngine(std::string const &name);
std::vector<char> record_frame_offline(int hdrSize = 1, int rgbComps = 3);
bool cameraFocusOnNode(std::string const &nodeid, zeno::vec3f &center, float &radius);
Expand Down
8 changes: 8 additions & 0 deletions zenovis/src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Scene::Scene()
switchRenderEngine("bate");
}

void Scene::cleanUpScene()
{
if (objectsMan)
objectsMan->clear_objects();
if (renderMan && renderMan->getEngine())
renderMan->getEngine()->update();
}

void Scene::switchRenderEngine(std::string const &name) {
renderMan->switchDefaultEngine(name);
}
Expand Down

0 comments on commit f92c912

Please sign in to comment.