我有以下 XAML:
<Viewport3D>
<Viewport3D.Camera>
<OrthographicCamera FarPlaneDistance="100" LookDirection="0, 0,-1" UpDirection="0,1,0" NearPlaneDistance="1" Position="0,0,5" Width="10" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="0,0,-1" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<LinearGradientBrush>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Blue" Offset="1" />
</LinearGradientBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="-1,-1,0 -1,1,0 1,1,0 1,-1,0" TriangleIndices="0,2,1 2,0,3" TextureCoordinates="0,0 .5,0, .5,.5 0,.5"/>
</GeometryModel3D.Geometry>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
我想要的是只使用一半的渐变(因为我的纹理坐标只能从 0 到 0.5)。不幸的是,无论使用的纹理坐标如何,LinearGradientBrush
都会拉伸以填充几何图形。
您可以使用ViewportUnits="Absolute"
使用TileBrush
派生的画笔来解决此问题,但我不知道如何LinearGradientBrush
修复它。有什么想法吗?
在全尺寸的RectangleGeometry
上使用LinearGradientBrush
,并在DrawingBrush
中使用它:
<DrawingBrush ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,1,1" />
</GeometryDrawing.Geometry>
<GeometryDrawing.Brush>
<LinearGradientBrush>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Green" Offset="0.5" />
<GradientStop Color="Blue" Offset="1" />
</LinearGradientBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
在LinearGradientBrush上设置MappingMode="Absolute"应该可以工作