Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
HTML
<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>
Posted
Updated 22-Oct-11 4:02am
v6

1 solution

Since the material of the Viewport2DVisual3D is the Visual that in it, you can put an UIElement as the Visual of the Viewport2DVisual3D and, animate the Opacity property of it.


For example, try the following Grid:


XML
<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>
 
Share this answer
 
Comments
hzawary 23-Oct-11 9:43am    
Thank you, I would just tried the "EasingDoubleKeyFrame" into the Storyboard by write code for this job!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900