Here is a more user-friendly version.
```
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\makeatletter
\pgfkeys{/handlers/.add item/.code=\pgfkeys{\pgfkeyscurrentpath/.append={,#1}},
/handlers/.remove item/.code={%
\edef\pgfutil@tmpa{\pgfkeysvalueof{\pgfkeyscurrentpath}}%
\edef\pgfutil@tmpb{#1}%
\edef\pgfutil@tmpc{\noexpand\@removeelement{\pgfutil@tmpb}{\pgfutil@tmpa}{\noexpand\pgfutil@tmpa}}%
\pgfutil@tmpc
\pgfkeyssetvalue{\pgfkeyscurrentpath}{\pgfutil@tmpa}%
}}%
\tikzset{3d/draw behind/.code 2 args={% #1 object, #2 list of objects in front
%\typeout{Draw #1 behind #2.}
\tikzset{3d/current path=#1,
3d/draw clipped against/.list={#2},
3d/draw avoiding={#2}}
},3d/draw clipped against/.code={% #1=clip path
%\typeout{Clip \pgfkeysvalueof{/tikz/3d/current path} against #1.}
\begin{scope}
\clip[use named path/.expanded=#1];
\edef\temp{\pgfkeysvalueof{/tikz/3d/current path}}
\draw[3d/hidden,use named path=\pgfkeysvalueof{/tikz/3d/current path}];
\end{scope}},
3d/draw avoiding/.code={% #1=list of paths to be avoided
%\typeout{Draw \pgfkeysvalueof{/tikz/3d/current path} avoiding #1.}
\begin{scope}
\tikzset{protect/.list={#1}}
\draw[3d/visible,use named path/.expanded=\pgfkeysvalueof{/tikz/3d/current path}];
\end{scope}},3d/current path/.initial={},
3d/draw ordered objects/.code={%
\tikzset{3d/temporary list 1/.initial={#1},
3d/draw ordered object/.list={#1}}%
},3d/draw ordered object/.code={%
% test if remaining list has only one element
\edef\pgf@util@tempa{\noexpand\pgfutil@in@{,}{\pgfkeysvalueof{/tikz/3d/temporary list 1}}}%
\pgf@util@tempa
\tikzset{3d/temporary list 1/.remove item={#1}}
\ifpgfutil@in@%
\tikzset{3d/draw behind/.expanded={#1}{\pgfkeysvalueof{/tikz/3d/temporary list 1}}}
\else
\draw[3d/visible,use named path=#1];
\fi
}}
\makeatother
\tikzset{
protect/.code={
\clip[overlay,even odd clip,use named path=#1] [reset cm]
(-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt);
}}
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\foreach \Angle in {5,25,...,345} %{5,10,...,355} % {55} %
{\tdplotsetmaincoords{70}{\Angle}
\begin{tikzpicture}[scale=1,tdplot_main_coords,line join = round, line cap = round,
declare function={a=4;b=3;c=1;d=3;},
3d/hidden/.style={on layer=background,preaction={draw,white},draw,cheating dash,thin}]
\path[3d/screen coords,use as bounding box] (-8,-7) rectangle (8,7);
\path foreach \X [count=\Y] in {+,-}
{(a,b,\X c) coordinate (A\Y) (a,-b,\X c) coordinate (B\Y)
(-a,b,\X c) coordinate (A\Y') (-a,-b,\X c) coordinate (B\Y')
(0,b,\X c) coordinate (C\Y) (0,-b,\X c) coordinate (D\Y)
(0,-b,\X d) coordinate (E\Y) (0,b,\X d) coordinate (F\Y)
}
(0,0,0) coordinate (O);
\foreach \X in {1,2}
{\path[save named path=H\X] (A\X) -- (C\X) -- (D\X) -- (B\X) -- cycle;
\path[save named path=H\X'] (A\X') -- (C\X) -- (D\X) -- (B\X') -- cycle;
\path[save named path=F\X] (A\X) -- (B\X) -- (B\X') -- (A\X') -- cycle;
\path[save named path=V\X] (C\X) -- (D\X) -- (E\X) -- (F\X) -- cycle;}
\path[save named path=V3] (C1) -- (D1) -- (D2) -- (C2) -- cycle;
\path[save named path=V4] (E1) -- (F1) -- (F2) -- (E2) -- cycle;
\pgfmathsetmacro{\dAB}{TD("(1,0,0)")}
\pgfmathtruncatemacro{\itest}{(screendepth(\dAB)>0?1:0)}
\ifnum\itest=1
\edef\frontpoint{}
\edef\backpoint{'}
\else
\edef\frontpoint{'}
\edef\backpoint{}
\fi
\pgfmathsetmacro{\dZ}{TD("(0,0,1)")}
\pgfmathtruncatemacro{\itest}{(screendepth(\dZ)>0?1:0)}
\ifnum\itest=1
\edef\toppoint{1}
\edef\bottompoint{2}
\else
\edef\toppoint{2}
\edef\bottompoint{1}
\fi
\typeout{front point=\frontpoint, top point=\toppoint}
\tikzset{3d/draw ordered objects/.expanded={%
V\bottompoint,H\bottompoint\backpoint,H\bottompoint\frontpoint,%
V3,H\toppoint\backpoint,V\toppoint,H\toppoint\frontpoint}}
\end{tikzpicture}}
\end{document}
```