void hv_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { HelixViewport3D hv = e.Source as HelixViewport3D; if (hv == null) { return; } Point3D p; Vector3D v; DependencyObject d; if (hv.FindNearest(e.GetPosition(hv), out p, out v, out d)) { ModelVisual3D mv3d = d as ModelVisual3D; ModelVisual3D parent = mv3d.GetValue(MyProperties.MyParentProperty) as ModelVisual3D; // object o = mv3d.GetValue(MyProperties.MyParentProperty); string mouseDownObjName = parent != null ? _dict[parent] : _dict[mv3d]; List <DataGridObject> objs = dg_Variables.ItemsSource as List <DataGridObject>; idxSelectedRow = objs.FindIndex(a => a.Name == mouseDownObjName); DataGridRow row = dg_Variables.ItemContainerGenerator.ContainerFromIndex(idxSelectedRow) as DataGridRow; row.Background = PropertyServer.SelectedRowBackground; Logger.Log(sender, "Row background color changed - selected"); } }
/// <summary> /// Generates the piece 3D visual according to the piece type. /// </summary> /// <param name="pieceType"></param> /// <returns></returns> private ModelVisual3D GeneratePieceVisual(Type pieceType) { string pieceName = pieceType.Name.Substring(5); string colorName = pieceType.Name.Substring(0, 5); // get the piece geometry MeshGeometry3D pieceGeometry = FindResource(pieceName + "Geometry") as MeshGeometry3D; // set the geometry and the material GeometryModel3D pieceModel = new GeometryModel3D(pieceGeometry, FindResource(colorName + "Material") as Material); // if the piece is black, rotate the model by 180 degrees if (colorName == "Black") { pieceModel.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180)); } ModelVisual3D pieceVisual = new ModelVisual3D(); pieceVisual.Content = pieceModel; pieceVisual.SetValue(name, pieceType.Name + random.Next(100000000, 1000000000).ToString(CultureInfo.InvariantCulture)); pieceVisual.Transform = new TranslateTransform3D(); // add it to the viewable group and register its tranform viewableGroup.Children.Add(pieceVisual); RegisterName(pieceVisual.GetValue(name).ToString() + "Transform", pieceVisual.Transform); return(pieceVisual); }
internal static CollisionMask _GetCollisionMask(ModelVisual3D visual) { if (visual == null) { throw new ArgumentNullException("visual"); } return((CollisionMask)visual.GetValue(World.CollisionMaskProperty)); }
/// <summary> /// Sets the fading animation for the captured piece. /// </summary> /// <param name="moveStoryboard"></param> /// <param name="move"></param> /// <param name="duration"></param> private void SetOpacityAnimation(Storyboard moveStoryboard, Move move, int duration) { // animate the captured piece opacity from the current value (1.0) to 0.0 // the animations and timelines will not be modified so they will be freezed // change the material to the animatable one ModelVisual3D capturedPieceVisual = visualPieces[move is EnPassantCaptureMove ? (move as EnPassantCaptureMove).Target : move.To]; (capturedPieceVisual.Content as GeometryModel3D).Material = FindResource("Animatable" + capturedPieceVisual.GetValue(name).ToString().Substring(0, 5) + "Material") as Material; // set the opacity animation DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.To = 0.0; opacityAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); opacityAnimation.BeginTime = TimeSpan.FromMilliseconds(Settings.Default.AnimationStartDelay); Storyboard.SetTargetName(opacityAnimation, "Animatable" + capturedPieceVisual.GetValue(name).ToString().Substring(0, 5) + "Brush"); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(Brush.OpacityProperty)); opacityAnimation.Freeze(); // add the animation to the move storyboard moveStoryboard.Children.Add(opacityAnimation); }
public static bool GetMaterialShared(ModelVisual3D visual) { return((bool)visual.GetValue(MaterialSharedProperty)); }
public static bool GetOpacityShared(ModelVisual3D visual) { return((bool)visual.GetValue(OpacitySharedProperty)); }