注釈
Go to the end をクリックすると完全なサンプルコードをダウンロードできます.
シェーディングのタイプ#
デフォルトのフラットシェーディングとスムーズシェーディングの比較.
from __future__ import annotations
import pyvista
from pyvista import examples
PyVistaでは,VTKのPhongシェーディングアルゴリズムを使用したフラットシェーディングとスムーズシェーディングの2種類のシェーディングがサポートされています.
これは,デフォルトのフラットシェーディングを使用したプロットです.
mesh = examples.load_nut()
mesh.plot()

次に,スムーズシェーディングを適用した同じ球を示します.
mesh.plot(smooth_shading=True)

スムーズシェーディングによって,シャープであるべきエッジが奇妙に見えることに注意してください.これは,これらの法線のポイントが,鋭い角度を持つ2つの面の間で平均化されるためです. これを避けるには split_sharp_edges
を有効にします.
注釈
オプションの feature_angle
キーワード引数で分割角度を構成することができます.
mesh.plot(smooth_shading=True, split_sharp_edges=True)

extract_feature_edges
を使って,分割されるエッジをプロットすることもできます.
# extract the feature edges exceeding 30 degrees
edges = mesh.extract_feature_edges(
boundary_edges=False,
non_manifold_edges=False,
feature_angle=30,
manifold_edges=False,
)
# plot both the edges and the smoothed mesh
pl = pyvista.Plotter()
pl.enable_anti_aliasing()
pl.add_mesh(mesh, smooth_shading=True, split_sharp_edges=True)
pl.add_mesh(edges, color='k', line_width=5)
pl.show()

キーワード引数の split_sharp_edges
は,物理ベースのレンダリングにも対応しています.
# plot both the edges and the smoothed mesh
pl = pyvista.Plotter()
pl.enable_anti_aliasing()
pl.add_mesh(mesh, color='w', split_sharp_edges=True, pbr=True, metallic=1.0, roughness=0.5)
pl.show()

Total running time of the script: (0 minutes 1.546 seconds)