@cds.id/splat-viewer
v3.11.0
Published
A Splat Viewer component for React
Readme
@cds.id/splat-viewer
A versatile Splat Viewer component available as both a Web Component and React component for displaying 3D Gaussian Splats with interactive controls.
About This Project
The Splat Viewer is a 3D visualization library that renders Gaussian Splat files (.splat) using the @mkkellogg/gaussian-splats-3d engine. It provides an interactive 3D viewer with camera controls, animation capabilities, and optimization features for web applications.
Key Features:
- 3D Gaussian Splat rendering
- Interactive camera controls with zoom and rotation
- Animation support with gradual scene reveal
- Intersection Observer for performance optimization
- Custom styling support
- Both Web Component and React component APIs
Installation
npm install @cds.id/splat-viewerWeb Component Usage
The Web Component provides a simple HTML tag interface for embedding Splat viewers in any web application.
Basic Usage
<!doctype html>
<html>
<head>
<script src="./dist/cds-splat.iife.js"></script>
</head>
<body>
<cds-splat src="https://example.com/model.splat" animate class="my-splat-viewer"> </cds-splat>
</body>
</html>Web Component Props
| Attribute | Type | Required | Default | Description |
| ----------- | ------- | -------- | --------- | ------------------------------------------------------------- |
| src | string | ✓ | - | URL path to the .splat file to be rendered |
| animate | boolean | - | false | Enable gradual scene reveal animation |
| thumbnail | string | - | undefined | Thumbnail image URL (currently supported but not implemented) |
| class | string | - | '' | CSS class name for custom styling |
Events
window.addEventListener('splat-ready', (event) => {
console.log('Splat viewer ready:', event.detail.viewerId);
});React Component Usage
The React component provides a more feature-rich interface with additional props for advanced customization.
Basic Usage
import React from 'react';
import SplatViewer from '@cds.id/splat-viewer';
function App() {
return (
<div style={{ width: '800px', height: '600px' }}>
<SplatViewer src="https://example.com/model.splat" isAnimate={true} />
</div>
);
}React Component Props
| Prop | Type | Required | Default | Description |
| ----------------------- | ------------------------ | -------- | ------------------ | --------------------------------------------------------- |
| src | string | ✓ | - | URL path to the .splat file to be rendered |
| isAnimate | boolean | - | false | Enable gradual scene reveal animation |
| thumbnail | string | - | undefined | Thumbnail image URL for loading state |
| className | string | - | '' | CSS class name for custom styling |
| position | [number, number, number] | - | [0, 2.5, 0] | 3D position offset for the splat model |
| scale | [number, number, number] | - | [1, 1, 1] | 3D scale factors for the splat model |
| initialCameraPosition | [number, number, number] | - | [-9.5, -3.3, -3.3] | Starting camera position in 3D space |
| useObserver | boolean | - | true | Enable Intersection Observer for performance optimization |
Advanced Example
import React from 'react';
import SplatViewer from '@cds.id/splat-viewer';
function AdvancedViewer() {
return (
<SplatViewer
src="https://example.com/model.splat"
isAnimate={true}
position={[0, 0, 0]}
scale={[2, 2, 2]}
initialCameraPosition={[-5, -2, -5]}
useObserver={false}
className="custom-splat-viewer"
/>
);
}Performance Considerations
- The
useObserverprop enables automatic loading only when the component is visible - Components automatically dispose of resources when unmounted
- Optimized for streaming with built-in compression and memory management
Container Sizing
The component will adapt to its container size. Always wrap it in a container with defined dimensions:
// React
<div style={{ width: '90vw', height: '400px' }}>
<SplatViewer src="path/to/splat.splat" />
</div>
<!-- Web Component -->
<div style="width: 90vw; height: 400px;">
<cds-splat src="path/to/splat.splat"></cds-splat>
</div>Development
- Clone the repository:
git clone https://github.com/cds-id/splat-viewer.git- Install dependencies:
npm install- Start development server:
npm run dev- Build for npm:
npm run build:libTesting Locally
Test the package locally before publishing:
# In the package directory
npm run build:lib
npm link
# In your test project
npm link @cds.id/splat-viewerScripts
npm run dev- Start development servernpm run build:lib- Build for npmnpm run clean- Clean build directorynpm run lint- Run ESLintnpm run format- Format code with Prettier
Dependencies
Core:
- React
- React DOM
- @mkkellogg/gaussian-splats-3d
Browser Support
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
Known Issues
- Type declarations might need manual refresh in some IDEs
- Web Component requires modern browser support
License
MIT License
Credits
Built with @mkkellogg/gaussian-splats-3d
