Ray hits bounds but not the object

I have a model, that has weird behavior for selection. I am using the selection in following way:

Ray pickRay = view.DXScene.GetRayFromNearPlane((int)currentMousePosition.X, (int)currentMousePosition.Y);
SceneNode rootNode = view.DXScene.RootNode ?? view.DXScene.MasterDXScene.RootNode;
view.DXScene.GetAllHitObjects(pickRay, rootNode)
view.DXScene.GetHitSceneNodeBounds(pickRay, rootNode)

What is weird is, that the GethitSceneNodeBounds correctly returns the correct bounding box, however GetAllHitObjects does return an empty list. In the attached dump, it's SceneNode NurbsPath.003 and its child NurbsPath.003_ImportScaleFactorScaledMesh. The bounds returned belong to the child. Visually there doesn't seem to be anything wrong. The setup seems correct as well.

Best regards,
Janovsky Roman

Attached Files
.txt   DXEngineDump.txt (Size: 154.55 KB / Downloads: 0)
You should not pass the SceneNode to the GetAllHitObjects or GetHitSceneNodeBounds method if this SceneNode does not belong to the DXScene.

I have just added an additional check to the code that will throw an exception in this case and inform the user that this should not be done.

Also creating a ray from another DXScene will in most cases create invalid results (except when the camera and sizes are the same and the mouse position is relative to the DXScene).

So you should change your code into:
var dxScene = view.DXScene.RootNode != null ? view.DXScene : view.DXScene.MasterDXScene;
SceneNode rootNode = dxScene.RootNode;

Ray pickRay = dxScene.GetRayFromNearPlane((int)currentMousePosition.X, (int)currentMousePosition.Y);

dxScene.GetAllHitObjects(pickRay, rootNode)
dxScene.GetHitSceneNodeBounds(pickRay, rootNode)
Andrej Benedik
I've tested the code. It yields the same result because 

view.DXScene.RootNode ?? view.DXScene.MasterDXScene.RootNode


var dxScene = view.DXScene.RootNode != null ? view.DXScene : view.DXScene.MasterDXScene;
SceneNode rootNode = dxScene.RootNode;

are equivalent.

To provide more information, I use multiple scene views that share rendering steps. That results in only one scene (the master scene) having a root node which implies that the nodes are there only once. If I check the rootNode, the children are there (even those that I want to check). When I swap to single view (and only one scene) the result is the same. The object is not tested (or is rejected for some reason).

Just to be sure I've checked if the root node belongs to the scene and it does.
I've further investigated this. The vertices of the object are very small (it's bounding box sizes are 10mm x 1mm x 0.7mm). Could the issue be here?

If I consider common ray-triangle Moller-Trumbore intersection algorithm, it uses epsilon around 1e-7 to check for floating point errors and whether the ray is parallel with the triangle. Might this be the case? I've tried the methods directly in HitTester yet it yields the same results (bounding box is hit by the ray, the object is not).

Forum Jump:

Users browsing this thread:
1 Guest(s)