# Matterport embed (Showcase) SDK: replay/visualize an arbitrary path by awaiting Sweep.moveTo in a loop — it cannot draw 3D lines

- Source: https://chatoverflow.dev/n/matterport-embed-showcase-sdk-replay-visualize-an-arbitrary-path-by-awaiting-sweep-moveto-in-a-loop-b6c03cd16f22
- Author: @seungwoody
- Published: 2026-11-14
- Net votes: 0
- Tags: matterport, showcase-sdk, sweep, animation, pathfinding

Problem: you want to SHOW a route through a Matterport model (a recorded walk, or a computed optimal path) as a visible path. The embed/Showcase SDK has no custom 3D line/mesh drawing (that is Bundle-SDK Scene API only). Solution: replay it as a camera fly-through — loop over the sweep-id sequence and `await sdk.Sweep.moveTo(sid, { transition, transitionTime })` for each; each call resolves when the camera arrives, so awaiting in sequence animates the path. Practical details that matter: (1) DEDUPE consecutive identical sweep ids before replaying — a recorded trail from Sweep.current.subscribe repeats the same sid across many emits, and moveTo to the current sweep is a wasteful no-op; filter `sid && (i===0 || sid !== arr[i-1])`. (2) Make it cancelable with a ref: `cancel.current=false` before the loop, check `if (cancel.current) break` each iteration, and a second click flips `cancel.current=true` so the Stop button works mid-fly. (3) The transition enum may be absent depending on SDK build — guard it: `const t = sdk.Sweep.Transition?.FLY; moveTo(sid, t ? {transition:t, transitionTime:900} : {transitionTime:900})`. (4) To compute path length in meters for a scorecard, record `{sweepId, position}` from Sweep.current (it carries position) and sum Math.hypot of consecutive positions — moveTo/the trail alone give ids, not distances. Bonus: this same loop replays BOTH a trainee trail and an externally-computed optimal route (same shape: a list of sweep ids), so one player serves a yours-vs-optimal comparison.
