Test release

test

by guillermo_matterport

HTML

<html>

  <head>
    <script src="https://static.matterport.com/showcase-sdk/2.0.1-0-g64e7e88/sdk.js"></script>
  </head>

  <body>
    <iframe
      id="showcase"
      title="test"
      width="800"
      height="600"
      frameBorder="0"
      allowFullScreen
      allow="xr-spatial-tracking"
      src="https://my.matterport.com/show?m=iL4RdJqi2yK&play=1">
    </iframe>
  </body>

</html>

JavaScript

var iframe = document.getElementById('showcase');
var jsFiddleKey = "08s53auxt9txz1w6hx2iww1qb";
var version = "3.9";


const main = async () => {
	const sdk = await window.MP_SDK.connect(iframe, jsFiddleKey, version);
  console.log('SDK Connected', sdk);
  
  await sdk.App.state.waitUntil((state) => state.phase === sdk.App.Phase.PLAYING);
  
  const sources = await Promise.all([
    sdk.Sensor.createSource(sdk.Sensor.SourceType.SPHERE, {
      origin: { x: 1, y: 2, z: 3 },
      radius: 20,
      userData: {
        id: 'my-sensor-1',
      },
    }),

    sdk.Sensor.createSource(sdk.Sensor.SourceType.SPHERE, {
      radius: 4,
      userData: {
        id: 'my-sensor-2',
      },
    }),
  ]);
  const sensor = await sdk.Sensor.createSensor(sdk.Sensor.SensorType.CAMERA);
  // show debug visuals
  sensor.showDebug(true);
  // add sources from calls to `Sensor.createSource()`
  sensor.addSource(...sources);
  // start listening for changes to the sensor's readings
  sensor.readings.subscribe({
    onAdded(source, reading) {
      console.log(source.userData.id, 'has a reading of ', reading);
    },
    onUpdated(source, reading) {
      console.log(source.userData.id, 'has an updated reading ', reading);
      if (reading.inRange) {
        console.log(source.userData.id, 'is currently in range');
        if (reading.inView) {
          console.log('... and currently visible on screen');
        }
      }
    }
  });
};

main();