private async void FigureRotation() { int?sideRotation = null; while (start_stop == 1) { NameScope scope = new NameScope(); FrameworkContentElement element = new FrameworkContentElement(); NameScope.SetNameScope(element, scope); //myView.Children.Add(model_visual); myView.ZoomExtents(); AxisAngleRotation3D rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0); RotateTransform3D myRotateTransform3D = new RotateTransform3D(rotation, new Point3D(0, 0, 0)); try { MyModel.Transform = myRotateTransform3D; } catch { } element.RegisterName("rotation", rotation); // Create two DoubleAnimations and set their properties. DoubleAnimation animation = new DoubleAnimation(); if (sideRotation == 0) { animation.From = SliderValueMin; animation.To = SliderValueMax; sideRotation = 1; } else { animation.From = SliderValueMax; animation.To = SliderValueMin; sideRotation = 0; } animation.Duration = TimeSpan.FromSeconds(2); Storyboard.SetTargetProperty(animation, new PropertyPath("Angle")); Storyboard.SetTargetName(animation, "rotation"); myStoryboard.Children.Add(animation); myStoryboard.Duration = TimeSpan.FromSeconds(2); // Make the Storyboard a resource. try { this.Resources.Add("unique_id1", myStoryboard); } catch { } myStoryboard.Begin(element, HandoffBehavior.Compose); await System.Threading.Tasks.Task.Delay(2000); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { LoadObj(); view1.ZoomExtents(); NameScope scope = new NameScope(); FrameworkContentElement element = new FrameworkContentElement(); NameScope.SetNameScope(element, scope); // Create a box that will be the target // of the animation. // Material material = HelixToolkit.Wpf.MaterialHelper.CreateMaterial(Colors.DarkBlue); // MeshBuilder meshBuilder = new MeshBuilder(); // meshBuilder.AddBox(new Point3D(0, 0, 0), 200, 200, 200); // GeometryModel3D modelFloor = new GeometryModel3D(meshBuilder.ToMesh(), material); // modelFloor.SetName("floor"); // MainModel3Dgroup.Children.Add(modelFloor); var lights = new DefaultLights(); view1.Children.Add(lights); ModelVisual3D model_visual = new ModelVisual3D(); model_visual.Content = modelFloor; view1.Children.Add(model_visual); view1.ZoomExtents(); AxisAngleRotation3D rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0); RotateTransform3D myRotateTransform3D = new RotateTransform3D(rotation, new Point3D(0, 0, 0)); modelFloor.Transform = myRotateTransform3D; element.RegisterName("rotation", rotation); // Create two DoubleAnimations and set their properties. DoubleAnimation animation = new DoubleAnimation(); animation.From = 0; animation.To = 200; animation.Duration = TimeSpan.FromSeconds(2); Storyboard.SetTargetProperty(animation, new PropertyPath("Angle")); Storyboard.SetTargetName(animation, "rotation"); myStoryboard.Children.Add(animation); myStoryboard.Duration = TimeSpan.FromSeconds(2); // Make the Storyboard a resource. this.Resources.Add("unique_id1", myStoryboard); myStoryboard.Begin(element, HandoffBehavior.Compose); }
private void SimpleBallAnimation() { Transform3DGroup myTransform3DGroup = new Transform3DGroup(); //rotation AxisAngleRotation3D axis = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0); RotateTransform3D rotate = new RotateTransform3D(axis); rotate.CenterX = -46; rotate.CenterY = 2; rotate.CenterZ = 46; myTransform3DGroup.Children.Add(rotate); SphereContainer.Transform = myTransform3DGroup; NameScope scope = new NameScope(); FrameworkContentElement element = new FrameworkContentElement(); NameScope.SetNameScope(element, scope); element.RegisterName("rotation", axis); DoubleAnimation animation = new DoubleAnimation { From = 0, To = -1548, Duration = TimeSpan.FromSeconds(4), AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; Storyboard myStoryboard = new Storyboard(); Storyboard.SetTargetProperty(animation, new PropertyPath("Angle")); Storyboard.SetTargetName(animation, "rotation"); myStoryboard.Children.Add(animation); myStoryboard.Duration = TimeSpan.FromSeconds(4); //translation TranslateTransform3D tran = new TranslateTransform3D(0, 0, 0); myTransform3DGroup.Children.Add(tran); SphereContainer.Transform = myTransform3DGroup; element.RegisterName("translation", tran); DoubleAnimation animation2 = new DoubleAnimation { From = 0, To = 54.036, Duration = TimeSpan.FromSeconds(4), AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; Storyboard.SetTargetProperty(animation2, new PropertyPath("OffsetX")); Storyboard.SetTargetName(animation2, "translation"); myStoryboard.Children.Add(animation2); myStoryboard.Duration = TimeSpan.FromSeconds(4); myStoryboard.RepeatBehavior = RepeatBehavior.Forever; myStoryboard.AutoReverse = true; this.Resources.Add("id1111", myStoryboard); myStoryboard.Begin(element, HandoffBehavior.Compose); }