本文介绍了如何为"ViewPort2DVisual3D"制作动画?和"ModelVisual3D"一起使用Expression Blend吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个窗口项目,并在"ViewPort3D"中使用.它包括使用"ViewPort2DVisual3D"对象和"ModelVisual3D"对象的UserControl.

但是我无法将"EpacingFunction"(在每个KeyFrame中)的不透明度"动画设置为"ViewPort2DVisual3D" +"ModelVisual3D".

换句话说,"ViewPort2DVisual3D"的关键帧中没有"EasingFunction",而"ModelVisual3D"具有它.

如何在Expression Blend中在每个KeyFrame上设置"EasingFunction"(例如反弹")效果并对其进行动画处理(ViewPort2DVisual3D和ModelVisual3D)?

请给我您的解决方案和想法.
提前谢谢.

HZ

我的xaml代码是:

Hi everybody

I have a window project and use within a "ViewPort3D". It is include a UserControl using "ViewPort2DVisual3D" object and a "ModelVisual3D" object.

But I can''t set animate "Opacity" with "EasingFunction" (in each KeyFrame) to "ViewPort2DVisual3D" + "ModelVisual3D".

In other words, "ViewPort2DVisual3D" not able to have "EasingFunction" in its KeyFrames, but "ModelVisual3D" have it.

How to set "EasingFunction" such as "bounces" effect on each KeyFrame and animate them (ViewPort2DVisual3D and ModelVisual3D) together in Expression Blend?

Please give me any your solution and ideas.
Thanks in advance.

HZ

My xaml Code is:

<window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp_HZ3D" mc:ignorable="d">
	x:Class="WpfApp_HZ3D.LightMonitorWindow"
	x:Name="Window"
	Title="LightMonitorWindow"
	removed="{x:Null}" AllowsTransparency="True" WindowStyle="None" SizeToContent="WidthAndHeight">
	<window.resources>
		<storyboard x:key="ParasiteStoryboard" repeatbehavior="Forever">
			<doubleanimationusingkeyframes storyboard.targetproperty="(GeometryModel3D.Material).(EmissiveMaterial.Brush).(Brush.Opacity)" storyboard.targetname="geometryModel3D">
				<easingdoublekeyframe keytime="0" value="1" />
				<easingdoublekeyframe keytime="0:0:0.774" value="0.85">
					<easingdoublekeyframe.easingfunction>
						<elasticease easingmode="EaseIn" oscillations="2" springiness="0" />
					</easingdoublekeyframe.easingfunction>
				</easingdoublekeyframe>
				<easingdoublekeyframe keytime="0:0:1.742" value="0.8">
					<easingdoublekeyframe.easingfunction>
						<elasticease easingmode="EaseOut" springiness="0" oscillations="2" />
					</easingdoublekeyframe.easingfunction>
				</easingdoublekeyframe>
				<easingdoublekeyframe keytime="0:0:3" value="1">
					<easingdoublekeyframe.easingfunction>
						<bounceease easingmode="EaseOut" bounces="2" bounciness="3" />
					</easingdoublekeyframe.easingfunction>
				</easingdoublekeyframe>
			</doubleanimationusingkeyframes>
		</storyboard>
	</window.resources>
	<window.triggers>
		<eventtrigger routedevent="FrameworkElement.Loaded">
			<beginstoryboard x:name="ParasiteStoryboard_BeginStoryboard" storyboard="{StaticResource ParasiteStoryboard}" />
		</eventtrigger>
	</window.triggers>

    <grid x:name="LayoutRoot">
        <viewport3d width="300" height="300" mouseleftbuttondown="Viewport3D_MouseLeftButtonDown">
            <viewport3d.camera>
                <perspectivecamera position="0,0.3,4" />
            </viewport3d.camera>
            <modelvisual3d x:name="Light">
                <modelvisual3d.content>
                    <ambientlight>
                        <ambientlight.transform>
                            <transform3dgroup>
                                <translatetransform3d offsetz="0" offsetx="0" offsety="0" />
                                <scaletransform3d scalez="1" scaley="1" scalex="1" />
                                <rotatetransform3d>
                                    <rotatetransform3d.rotation>
                                        <axisanglerotation3d axis="0,1,0" angle="0" />
                                    </rotatetransform3d.rotation>
                                </rotatetransform3d>
                                <translatetransform3d offsetz="0" offsetx="0" offsety="0" />
                                <translatetransform3d offsetz="3" offsety="-0.5" />
                            </transform3dgroup>
                        </ambientlight.transform>
                    </ambientlight>
                </modelvisual3d.content>
            </modelvisual3d>
            <modelvisual3d>
            	<modelvisual3d.content>
            		<geometrymodel3d x:name="geometryModel3D">
            			<geometrymodel3d.material>
            				<emissivematerial>
            					<emissivematerial.brush>
            						<ImageBrush ImageSource="projection.png"/>
            					</emissivematerial.brush>
            				</emissivematerial>
            			</geometrymodel3d.material>
            			<geometrymodel3d.transform>
            				<transform3dgroup>
            					<translatetransform3d offsetz="0" offsetx="0" offsety="0" />
            					<scaletransform3d scalez="1" scaley="1" scalex="1" />
            					<rotatetransform3d d:eulerangles="0,0,0">
            						<rotatetransform3d.rotation>
            							<axisanglerotation3d axis="0,1,0" angle="0" />
            						</rotatetransform3d.rotation>
            					</rotatetransform3d>
            					<translatetransform3d offsetz="0" offsetx="0" offsety="0" />
            					<translatetransform3d offsetz="0.001" offsety="0.1" />
            				</transform3dgroup>
            			</geometrymodel3d.transform>
            			<geometrymodel3d.geometry>
            				<meshgeometry3d texturecoordinates="0,0 0.5,1 1,0">
            					<meshgeometry3d.triangleindices>
            						<system:int32>0</system:int32>
            						<system:int32>1</system:int32>
            						<system:int32>2</system:int32>
            					</meshgeometry3d.triangleindices>
            					<meshgeometry3d.positions>
            						<point3d>-0.75,0,0</point3d>
            						<point3d>0,-0.3,0.05</point3d>
            						<point3d>0.75,0,0</point3d>
            					</meshgeometry3d.positions>
            				</meshgeometry3d>
            			</geometrymodel3d.geometry>
            		</geometrymodel3d>
            	</modelvisual3d.content>
            	<viewport2dvisual3d x:name="viewport2DVisual3D">
            		<viewport2dvisual3d.material>
            			<diffusematerial viewport2dvisual3d.isvisualhostmaterial="True" />
            		</viewport2dvisual3d.material>
            		<viewport2dvisual3d.geometry>
            			<meshgeometry3d>
            				Positions="-1,1.25,0 -1,0,0 1,0,0 1,1.25,0"
            				TriangleIndices="0 1 2 0 2 3" TextureCoordinates="0,0 0,1 1,1 1,0"/>
            		</meshgeometry3d></viewport2dvisual3d.geometry>
            		<local:lightingmonitorusercontrol />
            	</viewport2dvisual3d>
            </modelvisual3d>
        </viewport3d>
    </grid>
</window>

推荐答案

例如,尝试以下Grid:

<Grid Background="Blue">
    <Grid.Resources>
        <Storyboard x:Key="sb1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="grd1"

                                           Storyboard.TargetProperty="Opacity">
                <EasingDoubleKeyFrame Value="0"

                                      KeyTime="0:0:0.5">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <BounceEase />
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame Value="1"

                                      KeyTime="0:0:1">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <BounceEase />
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Viewport3D Margin="10">
        <Viewport3D.Camera>
            <PerspectiveCamera Position="0, 0, 4"/>
        </Viewport3D.Camera>
        <Viewport2DVisual3D>
            <Viewport2DVisual3D.Transform>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="40" Axis="0, 1, 0" />
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
            </Viewport2DVisual3D.Transform>
            <Viewport2DVisual3D.Geometry>
                <MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"

                        TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>
            </Viewport2DVisual3D.Geometry>
            <Viewport2DVisual3D.Material>
                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
            </Viewport2DVisual3D.Material>
            <Grid Name="grd1">
                <StackPanel Background="Green">
                    <Button Margin="5">Button 1</Button>
                    <Button>Button 2</Button>
                </StackPanel>
            </Grid>
        </Viewport2DVisual3D>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
    <Button Name="btnAnimate" Grid.Row="1" Content="Animate">
        <Button.Triggers>
            <EventTrigger RoutedEvent="ButtonBase.Click">
                <BeginStoryboard Storyboard="{StaticResource sb1}" />
            </EventTrigger>
        </Button.Triggers>
    </Button>
</Grid>


这篇关于如何为"ViewPort2DVisual3D"制作动画?和"ModelVisual3D"一起使用Expression Blend吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 02:07