This is a comprehensive CloudXR.js React Three Fiber example application that demonstrates how to integrate CloudXR streaming with modern React development patterns. This example showcases the power of combining CloudXR.js with React Three Fiber, React Three XR, and React Three UIKit to create immersive XR experiences with rich 3D user interfaces.
NOTE: This example is not meant to be used for production.
This example showcases the integration of CloudXR.js with the React Three Fiber ecosystem, providing:
Navigate to the example folder
cd react
Install Dependencies
# For this early access release, please run the following to install SDK from the given tarball. This step will not be needed when SDK is publicly accessible.
npm install ../nvidia-cloudxr-6.0.0-beta.tgz
npm install
Build the Application
npm run build
Start Development Server
npm run dev-server
Open in Browser
http://localhost:8080 (or the port shown in terminal)Configure Connection
Adjust Settings (Optional)
Start Streaming
NOTE: In order to connect to an actual server and start streaming, you need:
- A CloudXR server running and accessible
- A WebXR-compatible device (VR/AR headset) or desktop browser (IWER loads automatically for emulation)
App.tsxMain React application component managing:
CloudXRComponent.tsxHandles the core CloudXR streaming functionality:
CloudXR2DUI.tsxManages the 2D HTML interface:
CloudXRUI.tsx (3D UI)Renders the in-VR user interface:
react/
├── src/
│ ├── App.tsx # Main React application
│ ├── CloudXRComponent.tsx # CloudXR streaming component
│ ├── CloudXR2DUI.tsx # 2D UI management class
│ ├── CloudXRUI.tsx # 3D VR UI component
│ ├── index.tsx # React app entry point
│ └── index.html # HTML template
├── public/
│ ├── play-circle.svg # Play button icon (Heroicons)
│ ├── stop-circle.svg # Stop button icon (Heroicons)
│ ├── arrow-uturn-left.svg # Reset button icon (Heroicons)
│ └── arrow-left-start-on-rectangle.svg # Disconnect button icon (Heroicons)
├── package.json # Dependencies and scripts
├── webpack.common.js # Webpack configuration
├── webpack.dev.js # Development webpack config
├── webpack.prod.js # Production webpack config
└── tsconfig.json # TypeScript configuration
The application uses React Three XR's store for XR session management:
const store = createXRStore({
foveation: 0,
emulate: { syntheticEnvironment: false },
});
React Three Fiber Canvas with WebXR integration:
<Canvas events={noEvents} gl={{ preserveDrawingBuffer: true }}>
<XR store={store}>
<CloudXRComponent config={config} />
<CloudXR3DUI onAction1={handleAction1} />
</XR>
</Canvas>
The CloudXR component uses useFrame for custom rendering:
useFrame((state, delta) => {
if (webXRManager.isPresenting && session) {
// CloudXR rendering logic
cxrSession.sendTrackingStateToServer(timestamp, xrFrame);
cxrSession.render(timestamp, xrFrame, layer);
}
}, -1000);
The 3D UI uses React Three UIKit for modern VR/AR interfaces:
3D UI elements are positioned in world space:
<group position={[1.8, -0.5, -1.3]} rotation={[0, -0.3, 0]}>
<Root pixelSize={0.001} width={1920} height={1440}>
{/* UI components */}
</Root>
</group>
This example uses WebGL state tracking to prevent rendering conflicts between React Three Fiber and CloudXR. Both libraries render to the same WebGL context, but CloudXR's rendering operations modify WebGL state (framebuffers, textures, buffers, VAOs, shaders, blend modes, etc.) which can interfere with React Three Fiber's expectations. The example wraps the WebGL context with bindGL() from @helpers/WebGLStateBinding, then uses CloudXR's onWebGLStateChangeBegin and onWebGLStateChangeEnd callbacks to automatically save and restore state around CloudXR's rendering. This ensures React Three Fiber always finds the WebGL context in the expected state after each CloudXR render operation.
See examples/helpers/WebGLStateBinding.ts, WebGLState.ts, and WebGLStateApply.ts for implementation details. Comprehensive tests are available in tests/unit/WebGLState.test.ts and tests/playwright/WebGLTests/src/WebGLStateBindingTests.ts.
See the LICENSE file for details.
Icons used in the immersive UI are from Heroicons by Tailwind Labs, licensed under the MIT License. See HEROICONS_LICENSE for details.
Experience one of the compatible OpenXR applications with CloudXR Runtime