1

主要问题在于 LinearGradientBrush。它用纯红色填充三角形。怎么了?我已经尝试了几乎相同的二维形状代码。它工作得很好。

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="215" Width="336">
<Grid Height="146" Width="232">
    <Viewport3D Name="myViewPort" ClipToBounds="False">
        <Viewport3D.Camera>
            <PerspectiveCamera x:Name="myCamera"
                               Position="10,10,10" 
                               UpDirection="0,1,0" 
                               LookDirection="-10,-10,-10"
                               FieldOfView="10"/>

        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <GeometryModel3D>
                    <GeometryModel3D.Geometry>
                        <MeshGeometry3D Positions="-1,0,0 0,1,0 1,0,0" TriangleIndices="0,2,1" />
                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <GradientStop Color="Black" Offset="0"></GradientStop>
                                    <GradientStop Color="Red" Offset="0.6"></GradientStop>
                                </LinearGradientBrush>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.Material>
                </GeometryModel3D>

            </ModelVisual3D.Content>
        </ModelVisual3D>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight></AmbientLight>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

</Grid>

4

1 回答 1

3

您需要将 TextureCoordinates 添加到您的几何:

<GeometryModel3D.Geometry>
    <MeshGeometry3D 
        Positions="-1,0,0 0,1,0 1,0,0" 
        TextureCoordinates="0,0 1,0 1,1"
        TriangleIndices="0,2,1" 
    />
</GeometryModel3D.Geometry>

完成此操作后,材质将适当地映射到纹理坐标,您将看到黑色->红色渐变。现在,纹理坐标都默认为渐变的“红色”部分中的一个点。

于 2009-09-24T17:17:00.737 回答