如何将3d对象设为按钮? [英] How to make a 3d object as a button?

查看:69
本文介绍了如何将3d对象设为按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的任何人都知道如何将3d对象设为按钮?我从sketchup导入了3d对象,当我试图创建一个按钮时,viewport3d的子节点我没有看到事件列表。现在我很困惑,我怎么能做到这一点。有人请帮助我。如果它需要
代码教我如何用c#编码它。提前谢谢。

解决方案

将其粘贴到任何xaml视图中,您就拥有了包含3d内容的按钮。使用按钮事件。


 


  < Page.Resources>

  &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < MeshGeometry3D x:Key =" plane"法线="0,-1,0 0,-1,0 0,-1,0 0,-1,0"位置=" -0.5,0,0.5 0.5,0,-0.5 0.5,0,0.5 -0.5,0,-0.5" TextureCoordinates =" 0,1 1,0 1,1 0,0" TriangleIndices =" 0 1 2 1 0 3" />



     < Style TargetType =" {x:Type Button}">

      < Style.Resources>

        < Storyboard x:Key =" Spin">

          < DoubleAnimation

            Storyboard.TargetName = QUOT; CubeRotation"


            Storyboard.TargetProperty = QUOT;角"


           持续时间=" 0:0:5英寸从= QUOT; 0"为了= QUOT; 360" />
$
        < / Storyboard>

      < /Style.Resources>

      < Setter Property =" Template">

        < Setter.Value>

          < ControlTemplate>

            < ControlTemplate.Triggers>

              < Trigger Property =" Button.IsPressed"值=" true">

                < Trigger.EnterActions>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < BeginStoryboard故事板= QUOT; {StaticResource的自旋}" />

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP; < /Trigger.EnterActions>

              < / Trigger>&
            < /ControlTemplate.Triggers>

            < Viewport3D>

              < Viewport3D.Camera>&
                < PerspectiveCamera Position =" 4,4,4" LookDirection = QUOT; -1,-1,-1" />&
              < /Viewport3D.Camera>

              < Viewport3D.Children>&
                < ModelVisual3D>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < ModelVisual3D.Content>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; < DirectionalLight Direction =" -0.3,-0.4,-0.5" />                 < /ModelVisual3D.Content>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < / ModelVisual3D>&
                < ModelVisual3D X:名称= QUOT;立方">

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; < ModelVisual3D.Transform>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; < RotateTransform3D>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP; < RotateTransform3D.Rotation>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < AxisAngleRotation3D x:Name =" CubeRotation"轴= QUOT; 0,1,0"角= QUOT; 0" />

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; < /RotateTransform3D.Rotation>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; < / RotateTransform3D>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < /ModelVisual3D.Transform>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < ModelVisual3D.Content>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; < GeometryModel3D X:名称= QUOT; OB_Cube">

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < GeometryModel3D.Material>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < DiffuseMaterial>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < DiffuseMaterial.Brush>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < VisualBrush ViewportUnits =" Absolute" Transform =" 1,0,0,-1,0,1">

              ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < VisualBrush.Visual>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < Border Background =" {Binding Path = Background,RelativeSource ='{RelativeSource
TemplatedParent}'}">

       &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP; < Label Content =" {Binding Path = Content,RelativeSource ='{RelativeSource
TemplatedParent}'}" />

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;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SP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < MeshGeometry3D X:名称= QUOT; ME_Cube"

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;位置=" 1,1,-1 1,-1,-1 -1,-1,-1 -1,1,-1 1,1,1 -1,1,1 -1,-1,1 1,-1,1 1,1,-1 1,1,1 1,-1,1 1,-1,-1 1,-1,-1
1,-1,1 -1, -1,1 -1,-1,-1 -1,-1,-1 -1,-1,1 -1,1,1 -1,1,-1 1,1,1 1,1, - 1 -1,1,-1 -1,1,1"

               ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; TriangleIndices =" 0 1 2 0 2 3 4 5 6 4 6 7 8 9 10 8 10 11 12 13 14 12 14 15 16 17 18 16 18 19 20 21 22 20 22
23"
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; TextureCoordinates =" 0,1 0,0 1,0 1,1 1,1 -0,1 0,-0 1,0 1,1 -0,1 0,-0 1,0 1,0 1,1 -0,1 0,-0 -0,0 1,-0 1,1 0,1
1,-0 1,1 0,1 -0,0" />

                      < /GeometryModel3D.Geometry>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; < / GeometryModel3D>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < /ModelVisual3D.Content>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < / ModelVisual3D>

              < /Viewport3D.Children>

            < / Viewport3D>

          < / ControlTemplate>

        < /Setter.Value>

      < / Setter>

    < / Style>

  < /Page.Resources>

  <网格>

   < Button Width =" 100"高度= QUOT; 100" VerticalAlignment = QUOT;中心" X:名称= QUOT; zoomButton" >
$
          < Image Height =" 250"来源=" large.png" />

        < / Button>

  < /网格>


anyone here knows how to make a 3d object a button? i imported the 3d object from sketchup, when im trying to make a button the children of viewport3d i dont see the list of event. Now im confused on how can i make it. someone please help me. if it needs to code teach me how to code it using c#. thanks in advance.

解决方案

Paste this into any xaml view and you have the button with 3d content. Use the events of button.

 

  <Page.Resources>
          <MeshGeometry3D x:Key="plane" Normals="0,-1,0 0,-1,0 0,-1,0 0,-1,0" Positions="-0.5,0,0.5 0.5,0,-0.5 0.5,0,0.5 -0.5,0,-0.5" TextureCoordinates="0,1 1,0 1,1 0,0" TriangleIndices="0 1 2 1 0 3"/>

     <Style TargetType="{x:Type Button}">
      <Style.Resources>
        <Storyboard x:Key="Spin">
          <DoubleAnimation
            Storyboard.TargetName="CubeRotation"
            Storyboard.TargetProperty="Angle"
            Duration="0:0:5" From="0" To="360" />
        </Storyboard>
      </Style.Resources>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate>
            <ControlTemplate.Triggers>
              <Trigger Property="Button.IsPressed" Value="true">
                <Trigger.EnterActions>
                  <BeginStoryboard Storyboard="{StaticResource Spin}"/>
                </Trigger.EnterActions>
              </Trigger>
            </ControlTemplate.Triggers>
            <Viewport3D>
              <Viewport3D.Camera>
                <PerspectiveCamera Position="4,4,4" LookDirection="-1,-1,-1" />
              </Viewport3D.Camera>
              <Viewport3D.Children>
                <ModelVisual3D>
                  <ModelVisual3D.Content>
                    <DirectionalLight Direction="-0.3,-0.4,-0.5" />
                  </ModelVisual3D.Content>
                </ModelVisual3D>
                <ModelVisual3D x:Name="Cube">
                  <ModelVisual3D.Transform>
                    <RotateTransform3D>
                      <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D x:Name="CubeRotation" Axis="0,1,0" Angle="0" />
                      </RotateTransform3D.Rotation>
                    </RotateTransform3D>
                  </ModelVisual3D.Transform>
                  <ModelVisual3D.Content>
                    <GeometryModel3D x:Name="OB_Cube">
                      <GeometryModel3D.Material>
                        <DiffuseMaterial>
                          <DiffuseMaterial.Brush>
                            <VisualBrush ViewportUnits="Absolute" Transform="1,0,0,-1,0,1">
                              <VisualBrush.Visual>
                                <Border Background="{Binding Path=Background, RelativeSource='{RelativeSource TemplatedParent}'}">
                                  <Label Content="{Binding Path=Content, RelativeSource='{RelativeSource TemplatedParent}'}" />
                                </Border>
                              </VisualBrush.Visual>
                            </VisualBrush>
                          </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                      </GeometryModel3D.Material>
                      <GeometryModel3D.Geometry>
                        <MeshGeometry3D x:Name="ME_Cube"
                          Positions="1,1,-1 1,-1,-1 -1,-1,-1 -1,1,-1 1,1,1 -1,1,1 -1,-1,1 1,-1,1 1,1,-1 1,1,1 1,-1,1 1,-1,-1 1,-1,-1 1,-1,1 -1,-1,1 -1,-1,-1 -1,-1,-1 -1,-1,1 -1,1,1 -1,1,-1 1,1,1 1,1,-1 -1,1,-1 -1,1,1"
                          TriangleIndices="0 1 2 0 2 3 4 5 6 4 6 7 8 9 10 8 10 11 12 13 14 12 14 15 16 17 18 16 18 19 20 21 22 20 22 23"
                          TextureCoordinates="0,1 0,0 1,0 1,1 1,1 -0,1 0,-0 1,0 1,1 -0,1 0,-0 1,0 1,0 1,1 -0,1 0,-0 -0,0 1,-0 1,1 0,1 1,-0 1,1 0,1 -0,0"/>
                      </GeometryModel3D.Geometry>
                    </GeometryModel3D>
                  </ModelVisual3D.Content>
                </ModelVisual3D>
              </Viewport3D.Children>
            </Viewport3D>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Page.Resources>
  <Grid>
   <Button Width="100" Height="100" VerticalAlignment="Center" x:Name="zoomButton" >
          <Image Height="250" Source="large.png"/>
        </Button>
  </Grid>


这篇关于如何将3d对象设为按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆