Picking 2D geometry

Hello, I am trying to create 2D geometry from point list, via X3Ds TLineSetNode. Code for creation is here:

function TCGEComponent.Create2DLineGeometryFromPoints(list: TList<TVector3Rec>): TCastleSceneCustom;
  OutlineShape: TShapeNode;
  OutlineCoords: TCoordinateNode;
  OutlineGeometry: TLineSetNode;
  rootNode: TX3DRootNode;
  rec: TVector3Rec;
  arrPoints: array of TVector3;
  arrIdx: array of Integer;
  idx, val, i: Integer;
  lprop: TLinePropertiesNode;
  OutlineShape := TShapeNode.Create();

  OutlineCoords := TCoordinateNode.Create;
  SetLength(arrPoints, list.Count);
  idx := 0;
  for rec in list do
    arrPoints[idx] := Vector3(rec.x, rec.y, rec.z);

  OutlineGeometry := TLineSetNode.CreateWithShape(OutlineShape);
  OutlineGeometry.Coord := OutlineCoords;
  OutlineGeometry.Solid := true;
  OutlineGeometry.Mode := lmStrip;

  if appearance = nil then
    appearance := TAppearanceNode.Create('Appearance');
    whiteEmissiveMaterial := TMaterialNode.Create('Material');
    whiteEmissiveMaterial.EmissiveColor := WhiteRGB;
    appearance.Material := whiteEmissiveMaterial

  OutlineShape.Appearance := appearance;

  rootNode := TX3DRootNode.Create;
  Result := TCastleSceneCustom.Create(Application);
  Result.Appearance := appearance;
  Result.Spatial := [ssRendering];
  Result.Load(rootNode, true);
//  Result.PreciseCollisions := true;

My question is, if there is any efficient way to put a precise collision on this 2D lines, other than checking each shape for mouse point on click with some threshold? Because we need to provide mouse picking on each line shape and with default collision it is not precise, with precise collisions it is not possible to pick lines. Currently I am doing MouseRayCast on viewport and picking Transform from there. For 3D with precise collision, I am able to pick triangle and whole Shape from there, but for 2D triangles are not present. Maybe I am constructing the node and final CastleScene incorrectly in code above. Thanks for any advice.

Hi (sorry for delay in answering! Conference/vacation last week, and overall busy time :slight_smile: ).

When you set Scene.PreciseCollisions = true then indeed the lines will never be picked. Because TLineSetNode is conceptually a set of infinitely thin lines. There are no triangles.

When you leave Scene.PreciseCollisions = false, then the scene will collide, but it will be treated as just a bounding box.

I think the only solution in this case is to create a corresponding structure, maybe just a 2nd scene, maybe just for collision detection (you can make it invisible e.g. by setting SceneForCollision.Visible := false), that represents shapes using triangles (so use e.g. TIndexedTriangleSetNode instead of TLineSetNode).