Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
WPF で使える 3D プリミティブ(例えば球など)を持っていると、簡単な 3D シーンを作るとき使い回しができるので便利です。私は ResourceDictionary として MeshGeometry3D を定義したファイルを作って使っています。球と円錐と円柱と立方体のプリミティブ ファイルを公開しますので、ダウンロードしてお使いください。
使い方は、プロジェクトエクスプローラで[追加]→[既存の項目]で、プリミティブのxamlファイル(例えばsphere.xaml)を追加してから、Windows1.xaml などの Resource 中で次のように定義します。
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="sphere.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
そして、Viewport3D 内の ModelVisual3D で次のように使います。
<ModelVisual3D x:Name="myScene">
<ModelVisual3D.Content>
<GeometryModel3D Geometry="{StaticResource mySphere}" >
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Red" />
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>