HitTesting + Map clicked ModelVisual back to DB record

Nov 26, 2008 at 3:10 PM
Ok - let me see if I can explain this... I've got HitTesting setup according to the HitTesting sample code.  I've got some 500 objects (they are stars) on the scene being rendered. What I need to do is when the user clicks a star, I can determine which star was clicked. So here's what I'm up against so far:

1- When the camera is far away, far enough away that my star's sphere is but a simple dot (say 1x1 pixel in size), hitTesting won't work. In fact, hitTests don't work until the pixel size of the star's sphere is somewhere around 5x5. Is this just a downside/bug of the API or something I've done wrong?

2- When I do get a mesh, since I can't inherit from the ModelVisual3d class (it is sealed), I can't really store any additional information such as a starID (which comes from my database...) Does anyone have any ideas about how I can figure this out? I suppose I could look at the original point that was defined for the mesh, then look it up backwards... but that isn't very graceful and won't work for every scenario I'll have. Tips appreciated!


Nov 26, 2008 at 5:50 PM
1) I don't know - I'll have to look at the API.  I haven't looked into HitTesting as yet.

2) You probably want to store references to all your meshes at load time.  Get a ref to your Viewport3D, iterate through all Visual3D children, all of their Model3Ds, and all of their Geometry3Ds, storing refs in a Dictionary<(Mesh)Geometry3D, StarPointClass> of all the meshes you'd like to be able to associate to their points.  This assumes you're loading the meshes dynamically (i.e. via code not XAML).  Then just look up via the Dictionary from the mesh to the point when you get your hit test result.