0

Animate color property of SphereVisual3D's material.brush

Anonymous 6 years ago 0
This discussion was imported from CodePlex

mfoste wrote at 2013-07-03 21:52:

Hello,

I'm trying to animate the Brush.ColorProperty of the DiffuseMaterial assigned to a SphereVisual3D object in code, but am not having any success. I'd appreciate any suggestions anyone can offer.

In the class constructor:
            targetModel = new SphereVisual3D();

            targetModel.Center = new Point3D(0,0,0);
            targetModel.Radius = 3;
            targetModel.Material = FindResource("TargetMaterial") as Material;
Later, as a response to a button press:
                ColorAnimation myColorAnimation = new ColorAnimation();
                myColorAnimation.To = Colors.Red;
                myColorAnimation.BeginTime = TimeSpan.FromSeconds(0);
                myColorAnimation.Duration = TimeSpan.FromSeconds(.5);
                myColorAnimation.FillBehavior = FillBehavior.HoldEnd;

                DiffuseMaterial material = targetModel.Model.Material as DiffuseMaterial;
                Storyboard.SetTarget(myColorAnimation, material.Brush);
                Storyboard.SetTargetProperty(myColorAnimation, new PropertyPath(SolidColorBrush.ColorProperty));

                Storyboard myStoryboard = new Storyboard();
                myStoryboard.Duration = TimeSpan.FromSeconds(3);
                myStoryboard.RepeatBehavior = RepeatBehavior.Forever;
                myStoryboard.Children.Add(myColorAnimation);
                myStoryboard.Begin();
BTW - I was able to successfully animate the SphereVisual3D's radius property, but I have not been successful at it's material brush color property.

mfoste wrote at 2013-07-03 22:21:

Forgot to mention... Great toolkit! Thanks for your hard work!