2013-03-01 81 views

回答

0

您可以使用此代码里面UserControl

<Viewport3D x:Name="CubeLogo" 
      Height="400" Width="400" OpacityMask="#FF000000"> 
    <Viewport3D.Camera> 
     <PerspectiveCamera x:Name="Camara" 
          FarPlaneDistance="20" 
          NearPlaneDistance="1" 
          LookDirection="0,-0.65,-1" 
          UpDirection="0.220607433377356,0.678217480739237,-0.440841362480504" 
          Position="0,1.6,2.6" FieldOfView="40" /> 
    </Viewport3D.Camera> 

    <Viewport3D.Triggers> 
     <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
      <BeginStoryboard> 
       <Storyboard> 
        <DoubleAnimation From="0" To="360" Duration="0:0:6" 
          Storyboard.TargetName="LogoRotation3D" 
          Storyboard.TargetProperty="Angle" RepeatBehavior="Forever" x:Name="Animacion"/> 
       </Storyboard> 
      </BeginStoryboard> 
     </EventTrigger> 
    </Viewport3D.Triggers> 

    <ModelVisual3D> 
     <ModelVisual3D.Content> 
      <Model3DGroup> 
       <AmbientLight Color="White"/> 

       <GeometryModel3D ScrollViewer.IsDeferredScrollingEnabled="False"> 
        <GeometryModel3D.Geometry> 
           <MeshGeometry3D TriangleIndices="0,1,2 3,4,5 6,7,8 9,10,11 12,13,14 15,16,17 18,19,20 21,22,23 24,25,26 27,28,29 30,31,32 33,34,35 " 
             Normals="0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,-1,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0" 
             TextureCoordinates="1,1 1,0 0,0 0,0 0,1 1,1 0,1 1,1 1,0 1,0 0,0 0,1 0,1 1,1 1,0 1,0 0,0 0,1 1,1 1,0 0,0 0,0 0,1 1,1 1,0 0,0 0,1 0,1 1,1 1,0 0,0 0,1 1,1 1,1 1,0 0,0" 
             Positions="-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,-0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,-0.5,0.5 0.5,-0.5,0.5 -0.5,-0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,0.5 0.5,0.5,0.5 0.5,-0.5,0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,0.5 -0.5,0.5,0.5 0.5,0.5,0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 -0.5,-0.5,0.5 -0.5,0.5,0.5 -0.5,0.5,-0.5"/> 
        </GeometryModel3D.Geometry> 

        <GeometryModel3D.Transform> 
         <RotateTransform3D> 
          <RotateTransform3D.Rotation> 
           <AxisAngleRotation3D x:Name="LogoRotation3D" 
                Angle="35" 
                Axis="1 1 1"/> 
          </RotateTransform3D.Rotation> 
         </RotateTransform3D> 
        </GeometryModel3D.Transform> 

        <!-- Background color of the cube --> 
        <GeometryModel3D.BackMaterial> 
         <DiffuseMaterial Brush="WhiteSmoke"/> 
        </GeometryModel3D.BackMaterial> 

        <!-- Content of the cube --> 
        <GeometryModel3D.Material> 
         <DiffuseMaterial> 
          <DiffuseMaterial.Brush> 
           <VisualBrush> 
            <VisualBrush.Visual> 
             <Image x:Name="Logo" /> 
            </VisualBrush.Visual> 
           </VisualBrush> 
          </DiffuseMaterial.Brush> 
         </DiffuseMaterial> 
        </GeometryModel3D.Material> 
       </GeometryModel3D> 
      </Model3DGroup> 

     </ModelVisual3D.Content> 
    </ModelVisual3D> 

</Viewport3D> 

然后在另一个XAML这样称呼它:

xmlns:local="clr-namespace:RotatoryCube" 

<local:RotatoryCube x:Name="RotatoryCubeInterface"></local:RotatoryCube> 

Nothe,上面写着旋转会持续多久的DoubleAnimation,和角度为FromTo。请注意0​​表示哪个Axis要旋转哪个角度。

+0

非常感谢..... sonhja – user2090372 2013-03-01 09:20:43

+0

很高兴能帮到:) – Sonhja 2013-03-01 09:34:09

+0

@Sonhja ......一个问题.......为什么Geometry3D Triangle指数中的第二和第三个元素之间没有空间? .....同样适用于法线,纹理坐标和位置中的第二和第三个位置元素。它是否具有任何特殊重要性? – user2090372 2013-03-01 10:36:22