[Tex/LaTex] How to draw this cube with holes

tikz-3dplot

I am trying to draw this cube

enter image description here

I tried

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
    \tdplotsetmaincoords{60}{120}
    \begin{tikzpicture}[tdplot_main_coords,declare function={a=3;
        }]
        \path 
        (a,-a,-a) coordinate (A)
        (a,a,-a) coordinate (B)
        (-a,a,-a) coordinate (C)
        (-a,-a,-a) coordinate (D)
        (a,-a,a) coordinate (E)
        (a,a,a) coordinate (F)
        (-a,a,a) coordinate (G)
        (-a,-a,a) coordinate (H)
        (0,0,0)  coordinate (O)
        ;
\draw (E) -- (A) -- (B) --(C) -- (G) -- (H) -- (E) (E) -- (F) -- (G) (B) -- (F);
%\path foreach \p/\g in {A/-90,B/90,C/0,D/0,E/0,F/0,G/0,H/0}{(\p)node{}+(\g:2.5mm) node{$\p$}}; 
\end{tikzpicture}
\end{document}  

And got

enter image description here

How can I get cube with holes?

Best Answer

With TikZ this is easy to draw using pics, styles and the 3d library:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d}

\tikzset
{%
  front face/.style={fill=gray!20,canvas is xy plane at z=1},
  up    face/.style={fill=gray!50,canvas is xz plane at y=1},
  east  face/.style={fill=gray!80,canvas is yz plane at x=1},
  pics/square/.style={
    code={\draw[fill=white,even odd rule] (0,0) rectangle (3,3) (1,1) rectangle (2,2);}},
}

\begin{document}
\begin{tikzpicture}
\foreach\i in {0,1} \foreach\s in {front face, up face, east face}
  \draw[\s] (\i,1-\i) rectangle ++(1,1);
\foreach\i in {1,2} \foreach\s in {front face, up face, east face}
  \draw[\s] (\i,3-\i) rectangle ++(1,1);
\pic[canvas is xy plane at z=3] {square};
\pic[canvas is xz plane at y=3] {square};
\pic[canvas is yz plane at x=3] {square};
\end{tikzpicture}
\end{document}

enter image description here

Update: An animated version. I shifted all the points and changed the perspective, but the rest is the same:

\documentclass     {beamer}
\usepackage        {tikz}
\usetikzlibrary    {3d,perspective}

% beamer configuration
\setbeamertemplate {navigation symbols}{}

\tikzset
{%
      up face/.style={fill=gray!30,canvas is xy plane at z=-0.5},
  pics/square/.style={code={\draw[fill=white,even odd rule] (-1.5,-1.5) rectangle (1.5,1.5)
                                                            (-0.5,-0.5) rectangle (0.5,0.5);}},
}

\begin{document}
\begin{frame}
\foreach\i in{1,...,18}
{
  \only<\i>
  {
    \begin{figure}\centering
    \begin{tikzpicture}[line cap=round,line join=round,isometric view,rotate around z=5*\i-45]
    \pgfmathsetmacro\lc{50+2*\i} % left  color proportion
    \pgfmathsetmacro\rc{86-2*\i} % right color proportion
    \tikzset
    {
      left  face/.style={fill=gray!\lc,canvas is xz plane at y=0.5},
      right face/.style={fill=gray!\rc,canvas is yz plane at x=0.5},
    }
    \useasboundingbox (0,0) circle (3cm);
    \draw[thick,red] (0,0,-4) -- (0,0,-1.5);
    \foreach\i in {0,1} 
    {  
      \draw[up    face] (0.5-\i,-0.5+\i) rectangle ++(1,1);
      \draw[left  face] (0.5-\i,-0.5-\i) rectangle ++(1,1);
      \draw[right face] (0.5-\i,-0.5-\i) rectangle ++(1,1);
    }
    \draw[thick,red] (0,0,-1.5) -- (0,0,-0.5);
    \foreach\i in {0,1} 
    {
      \draw[up    face] (-1.5+\i,-0.5-\i) rectangle ++(1,1);
      \draw[left  face] (-1.5+\i,-0.5+\i) rectangle ++(1,1);
      \draw[right face] (-1.5+\i,-0.5+\i) rectangle ++(1,1);
    }
    \draw[thick,red] (0,0,-0.5) -- (0,0,1.5);
    \pic[canvas is xy plane at z= 1.5] at (0,0) {square};
    \pic[canvas is xz plane at y=-1.5] at (0,0) {square};
    \pic[canvas is yz plane at x=-1.5] at (0,0) {square};
    \draw[thick,red] (0,0,1.5) -- (0,0,4);
    \end{tikzpicture}
    \end{figure}
  }
}
\end{frame}
\end{document}

enter image description here