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; var OutlineShape: TShapeNode; OutlineCoords: TCoordinateNode; OutlineGeometry: TLineSetNode; rootNode: TX3DRootNode; rec: TVector3Rec; arrPoints: array of TVector3; arrIdx: array of Integer; idx, val, i: Integer; lprop: TLinePropertiesNode; begin OutlineShape := TShapeNode.Create(); OutlineCoords := TCoordinateNode.Create; SetLength(arrPoints, list.Count); idx := 0; for rec in list do begin arrPoints[idx] := Vector3(rec.x, rec.y, rec.z); Inc(idx); end; OutlineCoords.SetPoint(arrPoints); OutlineGeometry := TLineSetNode.CreateWithShape(OutlineShape); OutlineGeometry.Coord := OutlineCoords; OutlineGeometry.Solid := true; OutlineGeometry.Mode := lmStrip; OutlineGeometry.SetVertexCount([OutlineCoords.FdPoint.Count]); if appearance = nil then begin appearance := TAppearanceNode.Create('Appearance'); whiteEmissiveMaterial := TMaterialNode.Create('Material'); whiteEmissiveMaterial.EmissiveColor := WhiteRGB; appearance.Material := whiteEmissiveMaterial end; OutlineShape.Appearance := appearance; rootNode := TX3DRootNode.Create; rootNode.AddChildren(OutlineShape); Result := TCastleSceneCustom.Create(Application); Result.Appearance := appearance; Result.Spatial := [ssRendering]; Result.Load(rootNode, true); // Result.PreciseCollisions := true; end;
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.