簡體   English   中英

Viewport3D內容大小

[英]Viewport3D content size

我有一個包含圖像的Viewport3D,這是我的代碼:

<Window>
    <Window.Resources>
    <MaterialGroup x:Key="mat1" >
            <DiffuseMaterial >
                <DiffuseMaterial.Brush >
                    <VisualBrush >
                        <VisualBrush.Visual >
                            <Grid Width="270" Height="638" Background="Red">
                                <Image Width="270" Height="638" Source="screenshot-1.Png"></Image>
                            </Grid>
                        </VisualBrush.Visual >
                    </VisualBrush >
                </DiffuseMaterial.Brush >
            </DiffuseMaterial >
        </MaterialGroup>
    </Window.Resources >
    <Grid>
        <Viewport3D x:Name="vp" UIElement.ClipToBounds ="False" Height="638" UIElement.IsHitTestVisible ="False" RenderOptions.EdgeMode ="Unspecified" >
            <Viewport3D.Camera >
                <PerspectiveCamera x:Name="camera" ProjectionCamera.Position="0,0,5" ProjectionCamera.LookDirection ="0,0,-1" PerspectiveCamera.FieldOfView ="28" />
            </Viewport3D.Camera>
            <Viewport3D.Children >
                <ModelVisual3D >
                    <ModelVisual3D.Content >
                        <SpotLight PointLightBase.Position="0,0,30" SpotLight.Direction ="0,0,-1" Light.Color ="white" />
                    </ModelVisual3D.Content>
                </ModelVisual3D>

                <ModelVisual3D >
                    <ModelVisual3D.Content >
                        <GeometryModel3D x:Name="gm3d" Material="{StaticResource mat1}" >
                            <GeometryModel3D.Geometry >
                                <MeshGeometry3D x:Name="plane3d" MeshGeometry3D.Normals ="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1" MeshGeometry3D.TextureCoordinates ="0,1 1,1 1,0 1,0 0,0 0,1" MeshGeometry3D.Positions ="-1,-1,1 1,-1,1 1,1,1 1,1,1 -1,1,1 -1,-1,1" />
                            </GeometryModel3D.Geometry>
                            <Model3D.Transform >
                                <RotateTransform3D >
                                    <RotateTransform3D.Rotation >
                                        <AxisAngleRotation3D AxisAngleRotation3D.Axis="0,1,0" AxisAngleRotation3D.Angle ="0" x:Name ="rAngle" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                            </Model3D.Transform>
                        </GeometryModel3D>
                    </ModelVisual3D.Content>
                </ModelVisual3D>
            </Viewport3D.Children>
        </Viewport3D>

        <Button Height="20" Width="30" VerticalAlignment="Top" HorizontalAlignment="Left" Click="Button_Click_2"></Button>
    </Grid>
</Window>

問題在於圖像大小應該是這樣的:

實際形象 但是在使用Viewport3D時看起來像這樣:

viewport3D圖片

請問有人可以幫助我嗎?

對此的簡單解釋是,您將矩形圖像放置在正方形面上。

更詳細的解釋是,您的MeshGeometry3D.TextureCoordinates定義了兩個覆蓋矩形圖像的三角形,並將它們擠壓到由MeshGeometry3D.Positions的值定義的正方形區域中。

現在,有許多解決方案取決於您要實現的目標。 讓我們從一個簡單的例子開始:

更改畫筆以具有正方形圖像。 因為默認情況下Image.StretchUniformImage.Stretch這將節省圖像的長寬比。 請注意,我還將背景更改為Transparent

    <MaterialGroup x:Key="mat1" >
        <DiffuseMaterial >
            <DiffuseMaterial.Brush >
                <VisualBrush >
                    <VisualBrush.Visual >
                        <Grid Width="800" Height="800" Background="Transparent">
                            <Image Source="screenshot-1.Png"></Image>
                        </Grid>
                    </VisualBrush.Visual >
                </VisualBrush >
            </DiffuseMaterial.Brush >
        </DiffuseMaterial >
    </MaterialGroup>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM