Livelink React is a React library that sits on top of Livelink.js and provides core React components to easily build 3dverse applications.
To install the library, run:
npm install @3dverse/livelink-react
Here's a snippet for the simplest application:
import React from "react";
import { Livelink, Canvas, Viewport, CameraController, useCameraEntity } from "@3dverse/livelink-react";
function App() {
return (
<Livelink token="your-authentication-token" sceneId="your-scene-id">
<AppLayout />
</Livelink>
);
}
function AppLayout() {
const { cameraEntity } = useCameraEntity();
return (
<Canvas width="100vw" height="100vh">
<Viewport cameraEntity={cameraEntity} style={{ width: "100%", height: "100%" }}>
<CameraController />
</Viewport>
</Canvas>
);
}
Livelink React provides 3 contexts:
-
LivelinkContext
- Handles the connection to the Livelink server and gives access to the resulting session.
-
CanvasContext
- Creates an HTML
<canvas>
element and its underlyingRenderingSurface
and provides access to them.
- Creates an HTML
-
ViewportContext
- Creates a
Livelink.Viewport
and assign a<div>
element to it and attach the provided camera.
- Creates a
with their 3 respective components.
-
<Livelink>
- Instantiates a
LivelinkContext
- Instantiates a
<Canvas>
<Viewport>
It also provides a component
<CameraController>
and 2 hooks:
useEntity()
useCameraEntity()