All files / src/components/VirtualWalkthrough xr-annotation-candidates.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                1x   6x       1x 10x           1x 10x  
import { Annotation as PcAnnotation } from 'playcanvas/scripts/esm/annotations.mjs';
 
import { AnnotationCandidate, AnnotationCandidateBuffer, HOTSPOT_HALF_EXTENT } from './xr-annotation-candidate-buffer';
 
export { HOTSPOT_HALF_EXTENT };
export type { AnnotationCandidate };
 
/** Multiplier on the hotspot's world radius to make controller targeting forgiving. */
export const HIT_RADIUS_PAD = 2.5;
 
const annotationScriptOf = (entity: any) => entity.script?.get(PcAnnotation.scriptName);
 
/** A buffer wired to the stock annotation script. Callers that collect every frame hold one of
 * these; its results are overwritten on the next collect, so one buffer cannot be shared. */
export const createAnnotationCandidateBuffer = (): AnnotationCandidateBuffer =>
  new AnnotationCandidateBuffer(annotationScriptOf);
 
/**
 * One-shot collection for callers that run on an input event rather than every frame, and so have no
 * reason to hold a buffer of their own.
 */
export const collectAnnotationHitCandidates = (app: any, radiusPad: number): AnnotationCandidate[] =>
  createAnnotationCandidateBuffer().collect(app, radiusPad);