为什么Tringle没有绘图 [英] Why Tringle is not drawing

查看:100
本文介绍了为什么Tringle没有绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我是WPF的新手
我正在尝试绘制三角形,但未渲染
我的代码出了什么问题?

Hi all
I am newbie with WPF
I am trying to draw triangle but it not rendering
what is going wrong with my code?

<Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="0,0,100" LookDirection="0,0,-100"

                         UpDirection="0,1,0" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup>
                    <DirectionalLight Color="White" Direction="-1,-1,-3" />
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="10,0,0 -10,0,0 0,10,0"/>
                        </GeometryModel3D.Geometry>                        
                        <GeometryModel3D.Material>
                            <DiffuseMaterial Brush="Red"/>
                        </GeometryModel3D.Material>
                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

推荐答案

问题是每个三角形都有正面和背面两个面,而WPF默认仅渲染正面(我不确定是否可以启用背面渲染,但我相信是这样.

应用右手规则来确定三角形的正面和背面(这意味着三角形的顶点声明确实的顺序很重要!).在您的情况下,三角形的背面朝向相机,因此无法渲染.

一种解决方法是在代码中切换顶点的顺序:
The problem is that every triangle has 2 sides, front and back, and WPF only renders the front side by default (I''m not sure if it''s possible to enable backface rendering, but I believe it is).

The right-hand rule is applied to determine the front and back side of the triangle (which means that the order in which the vertices of a triangle are declared does matter!). In your case the back face of the triangle is facing to the camera, so it does not get rendered.

One soluton is to switch the order of vertices in your code:
<MeshGeometry3D Positions="-10,0,0 10,0,0 0,10,0"/>



另一种方法是显式指定顶点的顺序:



The other way to do it is to specify the order of vertices explicitly:

<MeshGeometry3D Positions="10,0,0 -10,0,0 0,10,0" TriangleIndices="0 2 1"/>



就是这样...祝您的项目好运!



That''s it... Good luck with your project!


这篇关于为什么Tringle没有绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆