Skip to main content

Function: createThreeWorldSensing()

function createThreeWorldSensing(renderer: XrRendererLike, options?: WorldSensingDirectorOptions & ThreeWorldSensingPortOptions): ThreeWorldSensingSetup;

Defined in: threejs-environment/src/index.ts:125

Wire a world-sensing director to a three.js renderer.

Separate from createThreeEnvironment on purpose: an app that only wants a sky pays for none of this, and the two directors share nothing but the vocabulary their reports are written in.

const { director: world } = createThreeWorldSensing(renderer, {
detection: { planes: true },
});
world.onChange(({ feature, added }) => {
if (feature === "planes") for (const id of added) console.log("new surface", id);
});
renderer.setAnimationLoop(() => {
world.update(clock.getDelta() * 1000); // this is where the frame is read
renderer.render(scene, camera);
});

The session still has to be asked for plane-detection, mesh-detection, anchors or hit-test when it is created - that is the platform layer's job, not this package's - and the reports say plainly when it was not.

Parameters

ParameterType
rendererXrRendererLike
optionsWorldSensingDirectorOptions & ThreeWorldSensingPortOptions

Returns

ThreeWorldSensingSetup