

    let meshId = 1;
    let allMeshes = new Map();
    // Iterate over the meshes array and compare to our internal state
    // This is the code that keeps track of the mesh state and adds them to the scene.
    function processMeshes(timestamp, frame) {
      const referenceSpace = renderer.xr.getReferenceSpace();

      if (frame.detectedMeshes) {
        allMeshes.forEach((meshContext, mesh) => {
          // if a previous mesh is no longer reported
          if (!frame.detectedMeshes.has(mesh)) {
   