예제 #1
0
 void hVp3D_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
 {
     if (_enableHover)
     {
         var hits = hVp3D.FindHits(e.GetPosition(hVp3D));
         foreach (var hit in hits)
         {
             OnModelSelected(hit.ModelHit as MeshGeometryModel3D);
             break;
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Finds the hits for a given 2D viewport position.
 /// </summary>
 /// <param name="viewport">
 /// The viewport.
 /// </param>
 /// <param name="position">
 /// The position.
 /// </param>
 /// <returns>
 /// List of hits, sorted with the nearest hit first.
 /// </returns>
 public static IList <HitTestResult> FindHits(this Viewport3DX viewport, Point position)
 {
     return(viewport.FindHits(position.ToVector2()));
 }
예제 #3
0
        /// <summary>
        /// 連續點擊兩下產生出球
        /// </summary>
        public void OnMouseDoubleClickHandler(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //如果當前可點擊的狀態為否則直接return
            if (!MainViewModel.ProjData.CanSelectPoints)
            {
                return;
            }

            Viewport3DX viewport = sender as Viewport3DX;

            if (viewport == null)
            {
                return;
            }
            var point    = e.GetPosition(viewport);
            var hitTests = viewport.FindHits(point);

            //null或是點到的東西為少於零個
            if (hitTests == null || hitTests.Count <= 0)
            {
                return;
            }

            foreach (var hit in hitTests)
            {
                //有可能點到對稱面,不是BoneModel的話換下一個模型
                if (!(hit.ModelHit is BoneModel))
                {
                    continue;
                }

                BallModel ball = new BallModel
                {
                    BallName = "Ball",
                };

                //這邊很怪 拿不到該有的屬性資訊只有一些基底類別的資訊
                BoneModel model = hit.ModelHit as BoneModel;
                foreach (BoneModel modeltem in MainViewModel.ProjData.BoneCollection)
                {
                    //先找出當前點到的BoneModel是哪個,並將點擊的球的ModelType設定成跟該Model一樣
                    if (modeltem.Geometry.Positions.Count == model.Geometry.Positions.Count)
                    {
                        ball.ModelType = modeltem.ModelType;
                        Binding binding = new Binding("Transform");
                        binding.Source = modeltem;
                        binding.Mode   = BindingMode.OneWay;
                        BindingOperations.SetBinding(ball, HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, binding);
                    }
                }


                var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder();
                ball.BallCenter = new Vector3(Convert.ToSingle(hit.PointHit.X), Convert.ToSingle(hit.PointHit.Y), Convert.ToSingle(hit.PointHit.Z));
                ballContainer.AddSphere(ball.BallCenter, 1.5);
                ball.Geometry = ballContainer.ToMeshGeometry3D();
                ball.Material = PhongMaterials.White;

                MainViewModel.ProjData.BallCollection.Add(ball);

                break;
            }
        }