<UserControl x:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:tools="clr-namespace:_3DTools;assembly=3DTools"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Width="300" Height="300" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0">
<UserControl.Resources>
<VisualBrush x:Key="brush">
<VisualBrush.Visual>
<Border BorderBrush="Yellow" BorderThickness="2">
<Button Content="1fdsfsfs" Click="Button_Click"/>
</Border>
</VisualBrush.Visual>
</VisualBrush>
</UserControl.Resources>
<Grid>
<tools:TrackballDecorator>
<Viewport3D x:Name="viewPort3D">
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,-5" LookDirection="0,0,1" UpDirection="0,1,0" FieldOfView="80"/>
</Viewport3D.Camera>
<!--x-->
<tools:ScreenSpaceLines3D Points="-100,0,0 100,0,0" Thickness="1" Color="Red"></tools:ScreenSpaceLines3D>
<!--y-->
<tools:ScreenSpaceLines3D Points="0,-100,0 0,100,0" Thickness="1" Color="Blue"></tools:ScreenSpaceLines3D>
<!--z-->
<tools:ScreenSpaceLines3D Points="0,0,-100 0,0,100" Thickness="1" Color="Green"></tools:ScreenSpaceLines3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="0,0,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="0,0,1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Transform>
<Transform3DGroup>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D x:Name="axisUI" Axis="0,1,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</Viewport2DVisual3D.Transform>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,-1,0 -1,1,0 1,1,0 1,-1,0" TriangleIndices="0,1,2 2,3,0" TextureCoordinates="1,1 1,0 0,0 0,1"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Border BorderBrush="Yellow" BorderThickness="2">
<Button Content="1fdsfsfs" Click="Button_Click"/>
</Border>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Transform>
<Transform3DGroup>
<TranslateTransform3D OffsetX="3" OffsetY="0" OffsetZ="0"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</GeometryModel3D.Transform>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="-1,-1,0 -1,1,0 1,1,0 1,-1,0" TriangleIndices="0,1,2 2,3,0" TextureCoordinates=" 1,1 1,0 0,0 0,1 "/>
</GeometryModel3D.Geometry>
<GeometryModel3D.BackMaterial>
<DiffuseMaterial Brush="{StaticResource ResourceKey=brush}">
</DiffuseMaterial>
</GeometryModel3D.BackMaterial>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="3" OffsetY="0" OffsetZ="0"/>
</Transform3DGroup>
</Viewport2DVisual3D.Transform>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,-1,0 -1,1,0 1,1,0 1,-1,0" TriangleIndices="0,1,2 2,3,0" TextureCoordinates="1,1 1,0 0,0 0,1"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Border BorderBrush="Yellow" BorderThickness="2">
<Button Content="1fdsfsfs" Click="Button_Click"/>
</Border>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Transform>
<Transform3DGroup>
<TranslateTransform3D OffsetX="3" OffsetY="0" OffsetZ="0"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,1,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</GeometryModel3D.Transform>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="-1,-1,0 -1,1,0 1,1,0 1,-1,0" TriangleIndices="0,1,2 2,3,0" TextureCoordinates=" 1,1 1,0 0,0 0,1 "/>
</GeometryModel3D.Geometry>
<GeometryModel3D.BackMaterial>
<DiffuseMaterial Brush="{StaticResource ResourceKey=brush}">
</DiffuseMaterial>
</GeometryModel3D.BackMaterial>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</tools:TrackballDecorator>
</Grid>
</UserControl>
然后 同时修改两个模型的正反面 的Angle 可以看到效果
其实就是一个有偏移量,然后设置偏移量的属性要在Transform3DGroup的第一个,这样偏移过的就会围绕3D的中心来转,如果要原地转,那TranslateTransform3D 这个属性设置就放在 RotateTransform3D下面,依然会偏移,但不会按照3D的中心转,就原地转了
这里面有 Viewport2DVisual3D 和 ModelVisual3D各两个.ModelVisual3D是Viewport2DVisual3D 的背面