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.

Hi, I am working with two actors in a 3D scene, where I need one actor (highlightActor) to always appear on top of another actor (currentActor), even when they are in close proximity or overlapping. Currently, I’m facing Z-fighting issues in certain views, where the two actors seem to compete for visibility, especially when viewed from different camera angles.


I have tried using the following approaches to resolve the issue:
mapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-1, -100);
mapper->SetResolveCoincidentTopologyToPolygonOffset();
While this works in some views, it doesn’t entirely solve the problem as the highlightActor sometimes still appears behind the other actor, depending on the camera angle.
Like this:
I try 2 renderer but I have same problem like topology.
What I actually want to do is to make sure that the two actors do not interfere with each other:
I would like to know if there is a more reliable method in VTK to ensure that one actor always renders on top of another, regardless of camera angle or geometry.
Thank you for your help!
I remember that if you set render or mapper correcly, the actor will always be on the above no matter what angle view.
Can you show me your complete code?