Pgfplots 3D 补丁图:在补丁细化之前对面边框进行着色,而不会丢失深度缓冲区

Pgfplots 3D 补丁图:在补丁细化之前对面边框进行着色,而不会丢失深度缓冲区

我想我可能在这里有点夸大了 PGFPlots,但我想为面片图的面边框赋予纯色。但是,patch refines必须处于活动状态,否则颜色图采样不足;同时,我想为原始网格的面边框着色,而不是为细化网格着色。另外,我不想丢失深度缓冲区:我希望面“后面”的片段不可见。一张图片:

不同的渲染模式

(A) shader=faceted interppatch refines=3在精致的脸上产生那些不想要的线条

(二)禁用patch refines显示正确的面边框,但现在渐变仅在顶点处进行采样,并且我们失去了蓝色。

(C)使用两个不同的\addplot3命令(一个带有patch,一个带有mesh)也不起作用,该mesh命令不使用深度缓冲区,所以我看到隐藏的线。

(四)期望结果。对于这个,我使用了一个带有精炼的补丁,然后是另一个带有黑色刻面边框和白色刻面填充的补丁,然后我将两者混合在一起blend group=multiply。白色填充剪裁了刻面边框的隐藏部分(需要将其包裹在透明组中)。

这在显示器上运行良好,但不出所料,打印机(以及一些编辑器/查看器)并不喜欢它:结果是叠印,并且颜色非常暗,或者您可以看到面细分,或者您丢失了混合组并且面颜色为白色。

我该怎么做才能获得 (d),而不必使用 atransparency group和 a blend group(或使用更传统的 PDF 功能)?

我对 TeX 的了解不足以理解 PGFPlots 的内部原理。以下是上图的 MVE:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{filecontents}{model.dat}
  -1 -1 0
  1 -1 0
  0 0 0.3

  1 -1 0
  1 1 0
  0 0 0.3

  -1 -1 0
  -1 1 0
  0 0 0.3

  1 1 0
  -1 1 0
  0 0 0.3
\end{filecontents}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.18}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[colormap/cool, title={(a)}]
      % Gradient is fine, but facet boundary is ugly
      \addplot3 [patch, shader=faceted interp, faceted color=black, patch refines=3] file {model.dat};
    \end{axis}
  \end{tikzpicture}

  \begin{tikzpicture}
    \begin{axis}[colormap/cool, title={(b)}]
      % Facet boundary is correct, but gradient is subsampled
      \addplot3 [patch, shader=faceted interp, faceted color=black] file {model.dat};
    \end{axis}
  \end{tikzpicture}
  
  \begin{tikzpicture}
    \begin{axis}[colormap/cool, title={(c)}]
      % Depth is lost
      \addplot3 [patch, shader=interp, patch refines=3] file {model.dat};
      \addplot3 [patch, mesh, draw=black] file {model.dat};
    \end{axis}
  \end{tikzpicture}

  \begin{tikzpicture}
    \begin{axis}[colormap/cool, title={(d)}]
      % What I came up with does not print correctly. I want to blend multiply the two plots, forcing
      % the facet color to white so it does not mask the gradient underneath it
      \begin{scope}[blend group=multiply]
        % This one brings the color:
        \addplot3 [patch, shader=interp, patch refines=3] file {model.dat};
        % If I don't explicitly set the transparecy group, we can see through the model
        \begin{scope}[transparency group]
          % This one brings the border
          \addplot3 [patch, shader=faceted, faceted color=black, fill=white] file {model.dat};
        \end{scope}
      \end{scope}
    \end{axis}
  \end{tikzpicture}
\end{document}
 

答案1

你可以tikzfadingfrompicture像这样使用:

\begin{filecontents}{model.dat}
-1 -1 0
1 -1 0
0 0 0.3

1 -1 0
1 1 0
0 0 0.3

1 1 0
-1 1 0
0 0 0.3

-1 1 0
-1 -1 0
0 0 0.3
\end{filecontents}

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{patchplots}
\begin{tikzfadingfrompicture}[name=myfading]
\begin{axis}[axis lines=none]
\addplot3[patch, shader=faceted, faceted color=transparent!0, fill=transparent!100] file{model.dat};
\end{axis}
\path (0,0) circle[radius=10]; %encompassing circle for alignment
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colormap/cool]
\addplot3[patch, shader=interp, patch refines=3] file{model.dat};
\end{axis}
\fill[path fading=myfading, fit fading=false] (0,0) rectangle (7,5);
\end{tikzpicture}
\end{document}

带阴影侧面和线条的 3D 金字塔

相关内容