Search code examples
matlabmatlab-figurepatchmatlab-guideperspective

Unexpected order of appearance / visual stacking of patches in Matlab


There seems to be a problem with my MATLAB GUIDE App concerning the rendering of 3D-Patches. I sadly could not reproduce the issue in another GUIDE instance or simply in a Matlab figure.

When a 3D-Patch is plotted that contains faces (which would obscure eachother from the given viewpoint). The gridlines of the axes are not visible through the faces, but the edges of the obscured face are seen through the other face. The image below displays my problem with two rectangles: The Edges of the second rectangle should not be visible through the first! I tried changing the FaceColor and all "Alpha"-Properties I could find, but nothing helped.

Example of the obscured face beeing seen through the other one

Edge Visibility Bug - You cannot see the gridlines behind the Objects, but every Edge is visible as if you could look inside it.

Edge Visibility Bug

Additionally, when multiple patches are plotted, the last defined patches are shown in front of the others, no matter what perspective is taken. The Image below displays that.

Visual Stacking Bug - The pillar on the left should normally be seen, because it is in front of the shelf.

Visual Stacking Bug

Normally, in a 3D-Situation if one Object is seen in front of the other, it is closer to the point of the viewer. Then, when you change the perspective on the objects by 180 degrees, the other should be in front, as it is closer now. This does not happen in my figure in the Matlab app.

Googling led me to believe, that the problem could have something to do with the renderer or be a problem of Hidden Surface Removal/Z-Buffer/....
I tried to switch the renderer to z-buffer, painters and back to opengl before executing the patch-commands, but if I am honest, I did not see any difference and do not know if I did it correctly.

Please help me fix this issue, I sadly cannot trace my code back to the moment it appeared first. Maybe its just some setting like the renderer? Or visual Stacking of Patches in a figure?


Solution

  • The Mathworks-Support-Team swiftly helped me on this issue:

    The behavior which you describe is expected if you have set the 'SortMethod' of your axes to 'childorder' instead of the default setting 'depth'. Please check what this property has been set to in your GUIDE GUI. See the following to learn more about that property:

    http://www.mathworks.com/help/releases/R2017b/matlab/ref/matlab.graphics.axis.axes-properties.html#property_d119e55686

    You may access the same page locally by typing the following at the MATLAB prompt:

    web([docroot, '/matlab/ref/matlab.graphics.axis.axes-properties.html#property_d119e55686'])

    I do not know how this property changed in my app, but I am grateful that it can be fixed easily by changing this property in GUIDE. Hope this here helps someone!