简体   繁体   English

3D 应用程序未渲染场景

[英]3D Application is not rendering the scene

I looked through the Microsoft page on 3D graphics and even tried to draw their example cone, but nothing's showing up on the screen.我浏览了有关 3D 图形的 Microsoft 页面,甚至尝试绘制他们的示例锥体,但屏幕上没有显示任何内容。 I've looked over the code several times but can't seem to find what's wrong...我已经多次查看代码,但似乎无法找到问题所在......

XAML code: XAML 代码:

<Window x:Class="WpfApp2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.Resources>
            <MeshGeometry3D x:Key="meshPyramid" Positions="0 75 0  -50 0 50  50 0 50  50 0 -50" TriangleIndices="0 1 2  0 2 3"></MeshGeometry3D>
            <MeshGeometry3D x:Key="desertFloor" Positions="-9999,0,-9999  9999,0,-9999  9999,0,9999  -9999,0,9999" TextureCoordinates="0,0  1,0  1,1  0,1" TriangleIndices="0 1 3  1 2 3"></MeshGeometry3D>
            <DiffuseMaterial x:Key="matFont" Brush="Black">
            </DiffuseMaterial>
            <DiffuseMaterial x:Key="backFont" Brush="Firebrick"></DiffuseMaterial>
            <DiffuseMaterial x:Key="texSand">
                <DiffuseMaterial.Brush>
                    <ImageBrush ImageSource="C:\Users\Julko\Documents\csharpprojects\wpf\3dProj\WpfApp2\WpfApp2\sand.jpg"></ImageBrush>
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
        </Grid.Resources>
        
        <Viewport3D Name ="viewPort" Width="640" Height="480">
            <Viewport3D.Camera>
                <PerspectiveCamera Position="57, 240, 41" LookDirection="-0.2, 0, -0.9" UpDirection="0, 1, 0" NearPlaneDistance="0.02" FarPlaneDistance="1000" FieldOfView="45">
                </PerspectiveCamera>
            </Viewport3D.Camera>
       
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <DirectionalLight Color="GreenYellow" Direction="1, -1, -1"/>
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D Positions="0.293893 -0.5 0.404509  0.475528 -0.5 0.154509  0 0.5 0  0.475528 -0.5 0.154509  0 0.5 0  0 0.5 0  0.475528 -0.5 0.154509  0.475528 -0.5 -0.154509  0 0.5 0  0.475528 -0.5 -0.154509  0 0.5 0  0 0.5 0  0.475528 -0.5 -0.154509  0.293893 -0.5 -0.404509  0 0.5 0  0.293893 -0.5 -0.404509  0 0.5 0  0 0.5 0  0.293893 -0.5 -0.404509  0 -0.5 -0.5  0 0.5 0  0 -0.5 -0.5  0 0.5 0  0 0.5 0  0 -0.5 -0.5  -0.293893 -0.5 -0.404509  0 0.5 0  -0.293893 -0.5 -0.404509  0 0.5 0  0 0.5 0  -0.293893 -0.5 -0.404509  -0.475528 -0.5 -0.154509  0 0.5 0  -0.475528 -0.5 -0.154509  0 0.5 0  0 0.5 0  -0.475528 -0.5 -0.154509  -0.475528 -0.5 0.154509  0 0.5 0  -0.475528 -0.5 0.154509  0 0.5 0  0 0.5 0  -0.475528 -0.5 0.154509  -0.293892 -0.5 0.404509  0 0.5 0  -0.293892 -0.5 0.404509  0 0.5 0  0 0.5 0  -0.293892 -0.5 0.404509  0 -0.5 0.5  0 0.5 0  0 -0.5 0.5  0 0.5 0  0 0.5 0  0 -0.5 0.5  0.293893 -0.5 0.404509  0 0.5 0  0.293893 -0.5 0.404509  0 0.5 0  0 0.5 0  " 
    Normals="0.7236065,0.4472139,0.5257313  0.2763934,0.4472138,0.8506507  0.5308242,0.4294462,0.7306172  0.2763934,0.4472138,0.8506507  0,0.4294458,0.9030925  0.5308242,0.4294462,0.7306172  0.2763934,0.4472138,0.8506507  -0.2763934,0.4472138,0.8506507  0,0.4294458,0.9030925  -0.2763934,0.4472138,0.8506507  -0.5308242,0.4294462,0.7306172  0,0.4294458,0.9030925  -0.2763934,0.4472138,0.8506507  -0.7236065,0.4472139,0.5257313  -0.5308242,0.4294462,0.7306172  -0.7236065,0.4472139,0.5257313  -0.858892,0.429446,0.279071  -0.5308242,0.4294462,0.7306172  -0.7236065,0.4472139,0.5257313  -0.8944269,0.4472139,0  -0.858892,0.429446,0.279071  -0.8944269,0.4472139,0  -0.858892,0.429446,-0.279071  -0.858892,0.429446,0.279071  -0.8944269,0.4472139,0  -0.7236065,0.4472139,-0.5257313  -0.858892,0.429446,-0.279071  -0.7236065,0.4472139,-0.5257313  -0.5308242,0.4294462,-0.7306172  -0.858892,0.429446,-0.279071  -0.7236065,0.4472139,-0.5257313  -0.2763934,0.4472138,-0.8506507  -0.5308242,0.4294462,-0.7306172  -0.2763934,0.4472138,-0.8506507  0,0.4294458,-0.9030925  -0.5308242,0.4294462,-0.7306172  -0.2763934,0.4472138,-0.8506507  0.2763934,0.4472138,-0.8506507  0,0.4294458,-0.9030925  0.2763934,0.4472138,-0.8506507  0.5308249,0.4294459,-0.7306169  0,0.4294458,-0.9030925  0.2763934,0.4472138,-0.8506507  0.7236068,0.4472141,-0.5257306  0.5308249,0.4294459,-0.7306169  0.7236068,0.4472141,-0.5257306  0.8588922,0.4294461,-0.27907  0.5308249,0.4294459,-0.7306169  0.7236068,0.4472141,-0.5257306  0.8944269,0.4472139,0  0.8588922,0.4294461,-0.27907  0.8944269,0.4472139,0  0.858892,0.429446,0.279071  0.8588922,0.4294461,-0.27907  0.8944269,0.4472139,0  0.7236065,0.4472139,0.5257313  0.858892,0.429446,0.279071  0.7236065,0.4472139,0.5257313  0.5308242,0.4294462,0.7306172  0.858892,0.429446,0.279071  "                   TriangleIndices="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 " />
                            </GeometryModel3D.Geometry></GeometryModel3D>
                        <GeometryModel3D Geometry='{StaticResource meshPyramid}' Material='{StaticResource matFont}' BackMaterial='{StaticResource backFont}'/>
                        <GeometryModel3D Geometry='{StaticResource desertFloor}' Material='{StaticResource texSand}'/>
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
            
        </Viewport3D>
    </Grid>
</Window>

The position of camera is wrong.相机位置不对。 Change it eg to the将其更改为例如

PerspectiveCamera Position="57, 41, 240"

and you will see pyramid.你会看到金字塔。 Just do play with Position , UpDirection , LookDirection .只需使用Position , UpDirection , LookDirection
Also do swap Material and BackMaterial by meshPyramid :也可以通过meshPyramid交换MaterialBackMaterial

<GeometryModel3D Geometry='{StaticResource meshPyramid}' Material='{StaticResource backFont}' BackMaterial='{StaticResource matFont}'/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM