We had introduced a way to keep a few special models awalys on the top layer in 3D scene. The relative post: https://www.weiy.city/2020/03/make-model-always-on-top/. But it will fail to shift polygons, lines, and points sometimes, eg. when we are in the WebAssembly environment (wasm) for web page.
Let’s use an another method to get the same result.
Add a top renderer and move the target actors to the renderer, then set the same status for the new renderer’s active camera and keep it.
The following commit adds a renderer to make sure the actors in the renderer awalys on the top layer in the VTK 3D scene.

diff --git a/gMyTester.cpp b/gMyTester.cpp
index 71e8ac3..54f1df6 100644
--- a/gMyTester.cpp
+++ b/gMyTester.cpp
@@ -237,6 +237,7 @@ void CMyTester::Play()
 void CMyTester::StartLoop()
 {
     m_Renderer->GetActiveCamera()->ParallelProjectionOn();  // avoid z-buffer value issue. eg. rotated object will become very big.
+    m_OperatorRenderer->SetActiveCamera( m_Renderer->GetActiveCamera() );
     m_Renderer->GetRenderWindow()->GetInteractor()->Start();

@@ -250,6 +251,10 @@ void CMyTester::Test(std::string path)

     m_Renderer = vSP<vtkRenderer>::New();
+    m_Renderer->SetLayer( 0 );
+    m_OperatorRenderer = vSP<vtkRenderer>::New();
+    m_OperatorRenderer->SetLayer( 1 );
+    m_OperatorRenderer->SetInteractive( 0 );


@@ -259,7 +264,9 @@ void CMyTester::Test(std::string path)
 #endif

        m_RenderWindow->SetSize(1000, 600);
-    m_RenderWindow->AddRenderer(m_Renderer);
+    m_RenderWindow->SetNumberOfLayers(2);
+    m_RenderWindow->AddRenderer( m_Renderer );
+    m_RenderWindow->AddRenderer( m_OperatorRenderer );
     m_Renderer->SetRenderWindow(m_RenderWindow);

diff --git a/gMyTester.h b/gMyTester.h
index e9e7ef3..a293de5 100644
--- a/gMyTester.h
+++ b/gMyTester.h
@@ -13,7 +13,7 @@

 class CMyModel;
@@ -119,6 +119,7 @@ public:
        vSP<vtkRenderer> m_Renderer;
+       vSP<vtkRenderer> m_OperatorRenderer;

After that, we can add actors such as buttons in the m_OperatorRenderer to make sure the users’ operations successful.

Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

3D Model Editor
: add a web app 3D Model Editor, it's under development.

X
A prohibited operation
0
Would love your thoughts, please comment.x
()
x