<Window x:Class="_3D绘图_1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard x:Name="mySB">
<DoubleAnimation
Storyboard.TargetName="myAxiRot2"
Storyboard.TargetProperty="Angle"
From="0"
To="360"
RepeatBehavior="Forever"
AutoReverse="True"
Duration="0:0:5"
/>
<DoubleAnimation
Storyboard.TargetName="myAxiRot1"
Storyboard.TargetProperty="Angle"
From="0"
To="360"
RepeatBehavior="Forever"
AutoReverse="True"
Duration="0:0:5"
/>
<Point3DAnimation
Storyboard.TargetName="myCamera"
Storyboard.TargetProperty="Position"
From="0,0,-5"
To="0,0,-10"
AutoReverse="True"
RepeatBehavior="Forever"
Duration="0:0:2"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Viewport3D>
<!--定义照相机
Position: 照相机的位置
LookDirection: 通过照相机看模型的方向
UpDirection: 照相机的法向量
-->
<Viewport3D.Camera>
<PerspectiveCamera
x:Name="myCamera"
Position="0,0,-5"
LookDirection="0,0,5"
UpDirection="0,1,0"
/>
</Viewport3D.Camera>
<!--定义模型-->
<ModelVisual3D x:Name="myModelVisual3D">
<ModelVisual3D.Transform>
<Transform3DGroup>
<!--定义一个绕Y轴旋转的Transform-->
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D
x:Name="myAxiRot1"
Axis="0,1,0"
Angle="0"
/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<!--定义一个绕X轴旋转的Transform-->
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D
x:Name="myAxiRot2"
Axis="1,0,0"
Angle="0"
/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</ModelVisual3D.Transform>
<!--定义内容-->
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D Geometry="{StaticResource myTeaPot}">
<!--设置模型材质后模型才会显示出来-->
<GeometryModel3D.Material >
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<!--使用渐变色:从左上角到右下角打一束蓝色变到红色的光-->
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Blue" Offset="0"/>
<GradientStop Color="Red" Offset="2"/>
</LinearGradientBrush>
<!--<SolidColorBrush Color="Blue" Opacity="1.0"/>-->
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
<!--定义光源-->
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight
Color="Yellow"
Direction="0,0,1 "
/>
</ModelVisual3D.Content>
</ModelVisual3D>
</ModelVisual3D>
</Viewport3D>
</Grid>
</Window>
源码下载:点击打开链接