The triangle SegmentIntersect code does the following:

It builds a bounding box arround your segment and tests this bounding box for potential triangle which intersects your segment. For every potential triangle is checks the intersection with 'Intersection.SegmentTriangleIntersection'.

In the code i found the following:

int numTriangles = GetTrianglesIntersectingtAABox(potentialTriangles, DetectFunctor.MaxLocalStackSCPI, ref segBox);

here is a typo! DetectFunctor.MaxLocalStackSCPI is 10 but it should be DetectFunctor.MaxLocalStackTris which is 2048. So we always just find 10 potential triangles and not all.

**So, to fix it, change in TriangleMesh.SegmentIntersect**

` ``int numTriangles = GetTrianglesIntersectingtAABox(potentialTriangles, DetectFunctor.MaxLocalStackSCPI, ref segBox);`

to

` ``int numTriangles = GetTrianglesIntersectingtAABox(potentialTriangles, DetectFunctor.MaxLocalStackTris, ref segBox);`

That is a very good idea. A good time to re-explore render targets too! Brilliant!

]]>(Woho, 500th post)

]]>Boxes still seem to be easily selectable. I'll keep at it.

]]>I'm going to try some sort of temporary bounding box collision, just have to figure out how to make an AABB on the fly.

]]>Vector3 farPoint = Engine.Graphics.GraphicsDevice.Viewport.Unproject(farSource, Engine.World.Camera.Projection, Engine.World.Camera.View, Matrix.Identity);

No matter what farSource is, the two test objects spawn in virtually the same place, so the direction resuly is probably quite inaccurate. Maybe I can temporarily move the nearclip plane to solve it.

]]>Is there anything specific to be aware of here? Did any of you have to do anything special to improve your ray picking for trianglemesh objects?

I bet it's time to spam you all with some code.

` ``if (Engine.Input.MouseHit(1)) { if (Engine.Tool == Engine.Tools.Select) { Vector3 ray = RayTo((int)Engine.Input.AbsMouseX, (int)Engine.Input.AbsMouseY); float frac; CollisionSkin skin; Vector3 pos, normal; SkinPredicate pred = new SkinPredicate(); Segment Segment = new Segment(Engine.World.Camera.Position, ray * 1000f); Engine.World.Simulation.PhysicsSystem.CollisionSystem.SegmentIntersect(out frac, out skin, out pos, out normal, Segment, pred); if (skin != null && (skin.Owner != null)) { // Found an object to select } } } --------------------------------- private Vector3 RayTo(int x, int y) { Vector3 nearSource = new Vector3(x, y, 0f); Vector3 farSource = new Vector3(x, y, 1f); Vector3 nearPoint = Engine.Graphics.GraphicsDevice.Viewport.Unproject(nearSource, Engine.World.Camera.Projection, Engine.World.Camera.View, Matrix.Identity); Vector3 farPoint = Engine.Graphics.GraphicsDevice.Viewport.Unproject(farSource, Engine.World.Camera.Projection, Engine.World.Camera.View, Matrix.Identity); Vector3 direction = farPoint - nearPoint; return direction; }`