Reputation: 1637
What I want to do is to know if the user click the red button of my joystick. (for the purpose, I draw over the real joystick graphic to keep our drawing private)
This joystick is a XAML 3D.
The red button is a GeometryModel3D object, with the x:Name "Geo_Btn_CSS_TAKE". When I click on the joystick, I can do a HitTest, he gives me all the GeometryModel3D object but I can't access to the x:Name, so I cannot know witch one is the good one...
And this is how I do my HitTest:
private void OnTouchMouseDown(EventArgs e)
{
Viewport3D viewport3D = WtoHitTest((Grid)Parent, e) as Viewport3D; // My own HitTest works well, I get my viewport3D
Point mouseposition = WtoHelper.GetPositionFromEvent(e, viewport3D); // Get the point if it's a mouse event or touch event
Point3D testpoint3D = new Point3D(mouseposition.X, mouseposition.Y, 0);
Vector3D testdirection = new Vector3D(mouseposition.X, mouseposition.Y, 10);
PointHitTestParameters pointparams = new PointHitTestParameters(mouseposition);
RayHitTestParameters rayparams = new RayHitTestParameters(testpoint3D, testdirection);
VisualTreeHelper.HitTest(viewport3D, null, HTResult, pointparams);
}
public HitTestResultBehavior HTResult(System.Windows.Media.HitTestResult rawresult)
{
RayHitTestResult rayResult = rawresult as RayHitTestResult;
if (rayResult != null)
{
RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;
if (rayMeshResult != null)
{
GeometryModel3D hitgeo = rayMeshResult.ModelHit as GeometryModel3D;
**// HERE I NEED TO KNOW WHAT IS MY GEOMETRYMODEL3D'S X:NAME**
// ANY IDEA???
}
}
return HitTestResultBehavior.Continue;
}
What else I know:
The way I did it, I only need to know the x:name to complete my implementation... if someone have a tips or an other way to go, let me know.
Thank you
EDIT: this is the properties of my 3D object:
Upvotes: 0
Views: 2665
Reputation: 91
I know this is an old post, but it is high in the search rankings and I stumbled upon it because I am learning WPF 3D. A second way to solve the problem is to use the Helix Toolkit. They extend GeometryModel3D with the methods SetName() and GetName(). So you can call it something, and then when doing the ray test you can get the name:
RayMeshGeometry3DHitTestResult rayHit = hr as RayMeshGeometry3DHitTestResult; //hr is of type HitTestResult
MessageBox.Show("Model found: " + rayHit.ModelHit.GetName());
Of course this means adding Helix Toolkit into the mix, but so far it has been worth it in several ways.
Upvotes: 0