This project is read-only.

Hi I'm trying to animate 3d objects with artifact - but I need a little help to get it right

Oct 31, 2013 at 2:57 PM
My camera looks like this in xaml
<h:HelixViewport3D.Camera>
                        <PerspectiveCamera x:Name="cam" LookDirection="-8.517 , 3.183 , -1.688" Position="8.562 , -3.541 , 0.815" UpDirection="0.05,0.0,1.0"></PerspectiveCamera></h:HelixViewport3D.Camera>
Here is my current working code this is what i would like "translated" to artifact tweens
 Vector3DAnimation tAnimation = new Vector3DAnimation(cam.LookDirection, new Vector3D(-newloc.X, newloc.Y, -newloc.Z), new Duration(TimeSpan.FromMilliseconds(animtime)));
            tAnimation.DecelerationRatio = deaccl; 
            cam.BeginAnimation(PerspectiveCamera.LookDirectionProperty, tAnimation);

            Point3DAnimation pAnimation = new Point3DAnimation(cam.Position, new Point3D(newloc.X, -newloc.Y, newloc.Z), new Duration(TimeSpan.FromMilliseconds(animtime)));
            pAnimation.DecelerationRatio = deaccl;
            cam.BeginAnimation(PerspectiveCamera.PositionProperty, pAnimation); 
and now we are add it .
I also have a
Viewport2DVisual3D TranslateTransform3D object
  <TranslateTransform3D x:Name="transf" 
                                      OffsetX="0"
                                      OffsetY="0" 
                                      OffsetZ="0" />
                </Transform3DGroup>
which I'm animating like this ( my question is can this be done In one go ? )
 tt = rot.Children[1] as TranslateTransform3D; ( rot being my transform group )
ArtefactAnimator.AddEase(tt, TranslateTransform3D.OffsetXProperty, pt.X, speed  , animEaseType, 0);
            ArtefactAnimator.AddEase(tt, TranslateTransform3D.OffsetYProperty, pt.Y, speed  , animEaseType, 0);
            ArtefactAnimator.AddEase(tt, TranslateTransform3D.OffsetZProperty, pt.Z, speed  , animEaseType, 0);
Oct 31, 2013 at 5:18 PM
Edited Nov 1, 2013 at 1:42 PM
If the question is "can you animate multiple properties on an object at the same time?" Then the answer is yes. Info: https://artefactanimator.codeplex.com/wikipage?title=easingmultiple

Here is how your code may look condensed:
ArtefactAnimator.AddEase(tt,
           new object[] { TranslateTransform3D.OffsetXProperty, TranslateTransform3D.OffsetYProperty, TranslateTransform3D.OffsetZProperty },
           new object[] { pt.X, pt.Y, pt.Z },
           speed, animEaseType, 0);
Does that help?
Jesse
Nov 2, 2013 at 2:58 PM
Thanks alot - yes that Was Half of The question , The other Was how to use artifact to animate lookposition and position of a 3D camera - dont know if i'm targeting it wrong or artifact is not able to animate vector3d/point3d - dont Think thats The case. Perhaps i just have The wrong addease setup ( please have a look below ).
?? Any ideas on that one
// Tried to animate the camera like this ( see the uncomitted ) But its not working for me.
//ArtefactAnimator.AddEase(cam.LookDirection, PerspectiveCamera.LookDirectionProperty, new Vector3D { X = 0, Y = 0, Z = -1.1000 }, .8, AnimationTransitions.ElasticEaseOut, 0).Complete += (eo, p) => UpdateShadow();
//ArtefactAnimator.AddEase(cam, PerspectiveCamera.LookDirectionProperty, new Vector3D(40, -40, -20), 1.8, AnimationTransitions.QuadEaseOut, 0);
I'm able to animate the camera with the Vector3DAnimation and Point3DAnimation ... see below - I don't why I can't animate the values with artifact.addease
            Point3D newloc = pos;
            Point3D oldloc = caminit;
            double deaccl = 0.3;
            int animtime = ms; //ms

            Vector3DAnimation tAnimation = new Vector3DAnimation(cam.LookDirection, new Vector3D(-oldloc.X + layer,  newloc.Y, -oldloc.Z), new Duration(TimeSpan.FromMilliseconds(animtime)));
            tAnimation.DecelerationRatio = deaccl; 
            cam.BeginAnimation(PerspectiveCamera.LookDirectionProperty, tAnimation);

            Point3DAnimation pAnimation = new Point3DAnimation(cam.Position, new Point3D(oldloc.X + layer , -newloc.Y, oldloc.Z), new Duration(TimeSpan.FromMilliseconds(animtime)));
            pAnimation.DecelerationRatio = deaccl;
            cam.BeginAnimation(PerspectiveCamera.PositionProperty, pAnimation); 
Nov 7, 2013 at 5:04 PM
Edited Nov 7, 2013 at 5:20 PM
Bomanden,

?
how to use artifact to animate lookposition and position of a 3D camera - dont know if i'm targeting it wrong or artifact is not able to animate vector3d/point3d - dont Think thats The case.
?

Short Answer:

Artefact Animator has no idea what a Vector3D is nor does it know what a Point3D is - but that's great cause we can tell it what to do.

Long Answer:

The goal of Artefact Animator is to make it easy to animate Dependency Properties. To do this a lot of things get wrapped in helper functions internally but the plug-in architecture makes it easy to customize.

So lets see what needs to get animated here.

Offset X,Y,Z

rot.Children[1] as TranslateTransform3D to pt.x,pt.y,pt.z using  TranslateTransform3D.OffsetXProperty,  TranslateTransform3D.OffsetYProperty and  TranslateTransform3D.OffsetZProperty

LookDirection

cam.LookDirection to new Vector3D(-newloc.X, newloc.Y, -newloc.Z) using PerspectiveCamera.LookDirectionProperty

Position

cam.Position to new Point3D(newloc.X, -newloc.Y, newloc.Z) using PerspectiveCamera.PositionProperty
At the time of AA’s creation, double was included but not a lot of 3D properties because that was in flux and I didn't have much experience with it. Also, I never wanted to code AA to include all possibilities since nobody can predict the future. So we’ll need to make a custom getter/setter for Point3D & Vector3D. This example should cover the Point3D but it is NOT TESTED. I actually wrote this in Pages on the Mac just now so if you copy directly you will probably get errors - but this is the general gist of what should be covered.

For the currently supported types you can see the code:
https://artefactanimator.codeplex.com/SourceControl/latest#trunk/Artefact/Animation/AnimationTypes.cs

In our case we’ll need to make a custom getter/setter following the documentation at https://artefactanimator.codeplex.com/wikipage?title=gettersetter&referringTitle=Documentation but with slight modification because we are using the Dependency Property directly instead of creating a shortcut name.

Position Info

http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.projectioncamera.position(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.projectioncamera.positionproperty(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.point3d(v=vs.110).aspx

Easing Position / Vector3D

// Make sure to include the namespace

using Artefact.Animation;
// Create simple helper method to ease a Point3D (shortens code in getter/setter)

var myEaseValuePoint3D( Point3D startValue, Point3D endValue, double percent)
{
    return new Point3D( EaseHelper.EaseValue(startValue.X, endValue.X, percent),
                        EaseHelper.EaseValue(startValue.Y, endValue.Y, percent),
                        EaseHelper.EaseValue(startValue.Z, endValue.Z, percent));
}
// Create a getter/setter for the Dependency Property

var getterSetterPositionProperty = new GetterSetter {
       Getter = AnimationTypes.GetDependencyPropValue,
       Setter = (obj, data, percent)=> ((DependencyObject)obj).SetValue((DependencyProperty)data.Prop, myEaseValuePoint3D ((Point3D) data.ValueStart, (Point3D) data.ValueEnd, percent ))
};
// Then register with Artefact Animator to use these functions when it sees a PositionProperty object

AnimationTypes.RegisterDependencyPropertyForGetterSetter (PerspectiveCamera.PositionProperty, getterSetterPositionProperty);
// Now AA should know what to do

ArtefactAnimator.AddEase(cam,
           ProjectionCamera.PositionProperty,
           new Point3D(newloc.X, -newloc.Y, newloc.Z),
           speed, animEaseType, 0);
After the getter/setter is registered/initialized you can then run addEase. You should be able to adapt this same concept to the LookDirectionProperty.

Next Steps

If the above sample works and you successfully create another getter/setter for the LookDirection, then you can group them together with AA using;
ArtefactAnimator.AddEase(cam,
           new object[] { ProjectionCamera.PositionProperty, PerspectiveCamera.LookDirectionProperty },
           new object[] { new Point3D(newloc.X, -newloc.Y, newloc.Z), new Vector3D(-newloc.X, newloc.Y, -newloc.Z)},
           speed, animEaseType, 0);
Hope that helps,
Jesse

NOTE: This code isn’t tested and may contain errors.