简体   繁体   中英

wpf 3d I can see the shpe when camera is front but when camera is back i cant

<Window x:Class="Wpf3DTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     Title="WPF 3D Test" Height="400" Width="400">
<Grid Background="Black"
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />

    </Grid.RowDefinitions>


    <Viewport3D x:Name="viewport" Grid.Row="1" >
        <Viewport3D.Camera>
            <PerspectiveCamera x:Name="camera" FarPlaneDistance="50" LookDirection="0,+10,0" 
                UpDirection="0,0,1" NearPlaneDistance="0" Position="0,-5,0"
                FieldOfView="50" />

        </Viewport3D.Camera>

        <ModelVisual3D x:Name="model">
            <ModelVisual3D.Content>
                <Model3DGroup x:Name="group" >
                    <AmbientLight Color="DarkGray" />


                    <DirectionalLight Color="White" Direction="0,7,0" />

                    <DirectionalLight Color="White" Direction="0,-7,0" />


                    <DirectionalLight Color="White" Direction="4,8,5" />
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>

                            <MeshGeometry3D Positions="-1,0,-1 -1,0,1 1,0,1 1,0,-1" TriangleIndices="0,1,2"/>
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>
                            <DiffuseMaterial Brush="Blue"/>
                        </GeometryModel3D.Material>
                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
</Grid>

hi this is my first question. ı hope to find. ı can see the shape when the camera is front. but when ı change camera to back ı cant.

ı think if it is cause of light. ı add 2 more diffrent place. but i cant

camera front

<PerspectiveCamera x:Name="camera" FarPlaneDistance="50" LookDirection="0,-10,0" 
                UpDirection="0,0,1" NearPlaneDistance="0" Position="0,5,0"
                FieldOfView="50" />

camera back

<PerspectiveCamera x:Name="camera" FarPlaneDistance="50" LookDirection="0,+10,0" 
                UpDirection="0,0,1" NearPlaneDistance="0" Position="0,-5,0"
                FieldOfView="50" />

both of camera is looking at shape thanks.

You are experiencing back-face culling .

Backface culling is an important part of how a 3D engine performs visibility checks. Its purpose is to detect polygons that are invisible in a particular scene – that is, polygons that face away from the viewer.

From Gamasutra

In most 3D systems, only the front face is visible. The front face is determined by the winding order or the points. In the case of the case the MeshGeometry3D , the winding order for the front face is counter clockwise. If you were to reverse the order of the points in the "TriangleIndices" property:

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

Then you should see the triangle only from the "back" camera and it would be invisible in the "front" camera.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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