WPF convert 2d mouse click into 3d space

2019-02-15 19:44发布

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25).

When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)...

How can I achieve this?

Thanks! Mark

标签: wpf 3d
1条回答
我只想做你的唯一
2楼-- · 2019-02-15 20:34

Just use VisualTreeHelper.HitTest with the callback.

  • If you have a Viewport3D containing the model, you can just pass in a PointHitTestParameters containing the mouse location.

  • If you need to operate directly on a Visual3D, pass in a RayHitTestParameters computed from your camera parameters and the mouse location.

In either case your callback will be called with a RayTestHitResult, and if you hit a mesh it will be a RayMeshGeometry3DHitTestResult. This includes a Point3D property telling you the 3D point in space that was hit, and also the mesh and triangle that was hit.

See 3D Hit testing for more details.

查看更多
登录 后发表回答