2

長方形の立方体のエッジまたは側面のみを描画して表示しようとしていますが、WPF を使用してもまだ成功しません。Windows フォーム (c#) アプリケーションで表示したいのは、ユーザー コントロール内です。私が見たように、WPFの3Dオブジェクトは三角形を使用して作成されているため、長方形の幅が小さい(立方体のエッジまたは側面として認識されるのに十分な)長方形を使用して線を描画しようとしましたが、表示されません正しく。私が使用しているコードは次のとおりです。

<UserControl x:Class="Spatial_and_Temporal_Research.BoundingBoxes"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" DataContext="{Binding}" Height="509" Width="739" FontFamily="Times New Roman">
        <Grid>

            <!-- Place a Label control at the top of the view. -->
            <Label 
                    HorizontalAlignment="Center" 
                    TextBlock.TextAlignment="Center" 
                    FontSize="20" 
                    Foreground="Red" 
                    Content="Model: Cone"/>

            <!-- Viewport3D is the rendering surface. -->
            <Viewport3D Name="myViewport" >

                <!-- Add a camera. -->
                <Viewport3D.Camera>
                    <PerspectiveCamera 
                            FarPlaneDistance="20" 
                            LookDirection="-6, -5, -4" 
                            UpDirection="0,1,0" 
                            NearPlaneDistance="1" 
                            Position="6 5 4"
                            FieldOfView="45" />

                </Viewport3D.Camera>

                <!-- Add models. -->
                <Viewport3D.Children>

                    <ModelVisual3D>
                        <ModelVisual3D.Content>

                            <Model3DGroup >
                                <Model3DGroup.Children>

                                    <!-- Lights, MeshGeometry3D and DiffuseMaterial objects are added to the ModelVisual3D. -->
                                    <AmbientLight Color="White" />

                                    <!-- Define a red cone. -->
                                    <GeometryModel3D>

                                        <GeometryModel3D.Geometry>
                                            <MeshGeometry3D 
        Positions="-0.55 -0.5 -0.5  -0.45 -0.5 -0.5  -0.55 -0.5 0.5  -0.45 -0.5 0.5  -0.55 0.5 -0.5  -0.45 0.5 -0.5  -0.55 0.5 0.5  -0.45 0.5 0.5  0.45 -0.5 -0.5  0.55 -0.5 -0.5  0.45 -0.5 0.5  0.55 -0.5 0.5  -0.5 -0.55 -0.5  -0.5 -0.45 -0.5  0.5 -0.55 -0.5  0.5 -0.45 -0.5  -0.5 -0.55 0.5  -0.5 -0.45 0.5  0.5 -0.55 0.5  0.5 -0.45 0.5  0.45 0.5 -0.5  0.55 0.5 -0.5  0.45 0.5 0.5  0.55 0.5 0.5  -0.5 0.45 -0.5  -0.5 0.55 -0.5  0.5 0.45 -0.5  0.5 0.55 -0.5  -0.5 0.45 0.5  -0.5 0.55 0.5  0.5 0.45 0.5  0.5 0.55 0.5"

         TriangleIndices="0 2 3  3 1 0  4 6 7  7 5 4  1 0 4  4 5 1  3 2 6  6 7 3  8 10 11  11 9 8  13 12 14  14 15 13  17 16 18  18 19 17  20 22 23  23 21 20  17 16 20  20 21 17  19 18 22  22 23 19  25 24 26  26 27 25  29 28 30  30 31 29"                                       
             >

                                            </MeshGeometry3D>
                                        </GeometryModel3D.Geometry>

                                        <GeometryModel3D.Material>
                                            <DiffuseMaterial>
                                                <DiffuseMaterial.Brush>
                                                    <SolidColorBrush 
                                Color="Red" 
                                Opacity="1.0"/>
                                                </DiffuseMaterial.Brush>
                                            </DiffuseMaterial>
                                        </GeometryModel3D.Material>                            

                                    </GeometryModel3D>

                                </Model3DGroup.Children>
                            </Model3DGroup>

                        </ModelVisual3D.Content>

                    </ModelVisual3D>

                </Viewport3D.Children>

            </Viewport3D>
        </Grid>

</UserControl>

opengl や gdi+ などの他のグラフィック ライブラリを試してみることを考えています。wpf で 3D 線を描画する方法を知っている場合は、例を示してください。

4

2 に答える 2

0

3D オブジェクトのメッシュをレンダリングする場合は、Helixtoolkit アドオンを推奨する人もいます。しかし、このアドオンに含まれる「linevisual3D」はかなり不自由です...

3D プリズム (SlimsGhost が言ったように) ではなく、2D 長方形として考え、バックマテリアル プロパティを使用して両方の方向から見えるようにすることをお勧めします。私はこれをコーディングしましたが、非常にうまく動作します (Helix Linevisual3D よりも優れています)。

PS: 本当に興味があれば、別の専用スレッドにメソッドを投稿できます。

于 2015-05-02T14:24:25.440 に答える