话题很旧,但是,因为这样可以帮助 处于同样情况下的其他人, 我认为我必须发布 这样做的方式。
使用 SphereMeshGenerator 的代码 XAML 代码 :
<Window x:Class="WpfSphereMeshGenerator.SphereMeshGeneratorMediaInto"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfSphereMeshGenerator"
Title="SphereMeshGeneratorMediaInto"
Height="300" Width="300"
Loaded="Window_Loaded">
<!-- OXYZ axis in WPF are in center of ViewPort3D-->
<Window.Resources>
<!--sphere diameter-->
<local:SphereMeshGenerator
x:Key="MySphereMeshGenerator"
Center="0 0 0"
Radius="100.0" />
</Window.Resources>
<Grid>
<Viewport3D>
<!--camera in center of ViewPort => 0,0,0-->
<Viewport3D.Camera>
<PerspectiveCamera
x:Name="Camera"
UpDirection="0,1,0"
LookDirection="-2,-2,-2"
Position="0,0,0"
FieldOfView="100" >
</PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight
Color="White">
</AmbientLight >
</ModelVisual3D.Content>
</ModelVisual3D>
<!--ModelVisualD by default in center of ViewPort-->
<ModelVisual3D
x:Name="ModelA">
<ModelVisual3D.Content>
<GeometryModel3D
Geometry="{Binding
Source={StaticResource
MySphereMeshGenerator},
Path=Geometry}">
<!--turn sphere-->
<GeometryModel3D.Transform>
<RotateTransform3D >
<RotateTransform3D.Rotation>
<AxisAngleRotation3D
x:Name="Rotate"
Axis="0,1,0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</GeometryModel3D.Transform>
<!--video put on BackMaterial-->
<!--inside face-->
<GeometryModel3D.BackMaterial>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<VisualBrush>
<VisualBrush.Visual>
<MediaElement>
<MediaElement.Triggers>
<EventTrigger RoutedEvent="MediaElement.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<MediaTimeline
x:Name="mediaTimeline"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</MediaElement.Triggers>
</MediaElement>
</VisualBrush.Visual>
</VisualBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.BackMaterial>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
<Window.Triggers>
<EventTrigger
RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Rotate"
Storyboard.TargetProperty="Angle"
From="0" To="360" Duration="0:0:10"
RepeatBehavior="Forever">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
向美宝基求救